swop 0.1.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +47 -9
- data/app/assets/images/swop/favicon.ico +0 -0
- data/app/assets/stylesheets/rails_admin/application.scss.erb +11 -20
- data/app/assets/stylesheets/{rails_admin/themes/base/base.scss → swop/swop-base/swop-base.scss} +1 -5
- data/app/assets/stylesheets/swop/swop-base/swop-typography.scss +11 -0
- data/app/assets/stylesheets/swop/swop-colors/swop-colors.scss +2 -0
- data/app/assets/stylesheets/swop/swop-core/swop-bootstrap-variables.scss +172 -0
- data/app/assets/stylesheets/swop/swop-core/swop-variables.scss +34 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-base/swop-base.scss +3 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-base/swop-main.scss +25 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-base/swop-typography.scss +4 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-colors/swop-amethyst.scss +29 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-colors/swop-dark.scss +29 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-colors/swop-forest.scss +29 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-colors/swop-light.scss +29 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-colors/swop-royal.scss +29 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-alerts.scss +12 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-badges.scss +31 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-buttons.scss +133 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-dropdowns.scss +26 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-filters.scss +57 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-forms.scss +158 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-images.scss +31 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-input-groups.scss +18 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-loading.scss +14 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-navbar.scss +15 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-navs.scss +77 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-offcanvas.scss +64 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-pagination.scss +21 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-progress.scss +3 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-sidebars.scss +49 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-tables.scss +82 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-components/swop-tiles.scss +20 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-core/swop-bootstrap-variables.scss +149 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-core/swop-variables.scss +41 -0
- data/app/assets/stylesheets/{rails_admin/themes/simple/components/containers.scss → swop/swop-themes/swop-simple/swop-layouts/swop-containers.scss} +9 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-layouts/swop-header.scss +15 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-simple-amethyst.scss +35 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-simple-base.scss +3 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-simple-components.scss +17 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-simple-dark.scss +35 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-simple-forest.scss +35 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-simple-layouts.scss +2 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-simple-light.scss +35 -0
- data/app/assets/stylesheets/swop/swop-themes/swop-simple/swop-simple-royal.scss +35 -0
- data/app/assets/stylesheets/swop/swop.scss +8 -0
- data/app/views/kaminari/ra-twitter-bootstrap/_next_page.html.erb +7 -0
- data/app/views/kaminari/ra-twitter-bootstrap/_prev_page.html.erb +5 -0
- data/app/views/kaminari/ra-twitter-bootstrap/default/_next_page.html.erb +9 -0
- data/app/views/kaminari/ra-twitter-bootstrap/default/_prev_page.html.erb +9 -0
- data/app/views/kaminari/ra-twitter-bootstrap/swop-simple/_next_page.html.erb +9 -0
- data/app/views/kaminari/ra-twitter-bootstrap/swop-simple/_prev_page.html.erb +9 -0
- data/app/views/layouts/rails_admin/_head.html.erb +5 -32
- data/app/views/layouts/rails_admin/_sidebar_navigation.html.erb +5 -3
- data/app/views/layouts/rails_admin/application.html.erb +5 -27
- data/app/views/layouts/rails_admin/content.html.erb +4 -11
- data/app/views/layouts/rails_admin/default/_application.html.erb +27 -0
- data/app/views/layouts/rails_admin/default/_content.html.erb +22 -0
- data/app/views/layouts/rails_admin/default/_head.html.erb +32 -0
- data/app/views/layouts/rails_admin/default/_sidebar_navigation.html.erb +5 -0
- data/app/views/layouts/rails_admin/swop-simple/_application.html.erb +17 -0
- data/app/views/layouts/rails_admin/swop-simple/_content.html.erb +41 -0
- data/app/views/layouts/rails_admin/swop-simple/_head.html.erb +42 -0
- data/app/views/layouts/rails_admin/swop-simple/_sidebar_navigation.html.erb +12 -0
- data/app/views/rails_admin/main/_delete_notice.html.erb +7 -0
- data/app/views/rails_admin/main/default/_delete.html.erb +21 -0
- data/app/views/rails_admin/main/default/_delete_notice.html.erb +34 -0
- data/app/views/rails_admin/main/default/_edit.html.erb +3 -0
- data/app/views/rails_admin/main/default/_export.html.erb +149 -0
- data/app/views/rails_admin/main/default/_history.html.erb +80 -0
- data/app/views/rails_admin/main/default/_index.html.erb +184 -0
- data/app/views/rails_admin/main/default/_new.html.erb +3 -0
- data/app/views/rails_admin/main/default/_show.html.erb +30 -0
- data/app/views/rails_admin/main/delete.html.erb +5 -0
- data/app/views/rails_admin/main/edit.html.erb +5 -0
- data/app/views/rails_admin/main/export.html.erb +5 -128
- data/app/views/rails_admin/main/history.html.erb +4 -86
- data/app/views/rails_admin/main/index.html.erb +4 -173
- data/app/views/rails_admin/main/new.html.erb +5 -0
- data/app/views/rails_admin/main/show.html.erb +5 -20
- data/app/views/rails_admin/main/swop-simple/_delete.html.erb +11 -0
- data/app/views/rails_admin/main/swop-simple/_delete_notice.html.erb +23 -0
- data/app/views/rails_admin/main/swop-simple/_edit.html.erb +3 -0
- data/app/views/rails_admin/main/swop-simple/_export.html.erb +90 -0
- data/app/views/rails_admin/main/swop-simple/_history.html.erb +80 -0
- data/app/views/rails_admin/main/swop-simple/_index.html.erb +169 -0
- data/app/views/rails_admin/main/swop-simple/_new.html.erb +3 -0
- data/app/views/rails_admin/main/swop-simple/_show.html.erb +18 -0
- data/lib/swop/engine.rb +8 -3
- data/lib/swop/railtie.rb +7 -0
- data/lib/swop/version.rb +1 -1
- data/lib/swop.rb +20 -2
- metadata +102 -98
- data/CHANGELOG.md +0 -5
- data/CODE_OF_CONDUCT.md +0 -132
- data/LICENSE +0 -201
- data/Rakefile +0 -4
- data/app/assets/javascripts/rails_admin/application.js.erb +0 -33
- data/app/assets/javascripts/rails_admin/custom/abstract-select.js +0 -30
- data/app/assets/javascripts/rails_admin/custom/filter-box.js +0 -363
- data/app/assets/javascripts/rails_admin/custom/filtering-multiselect.js +0 -387
- data/app/assets/javascripts/rails_admin/custom/filtering-select.js +0 -304
- data/app/assets/stylesheets/rails_admin/themes/base/bootstrap-variables.scss +0 -252
- data/app/assets/stylesheets/rails_admin/themes/base/theming.scss +0 -22
- data/app/assets/stylesheets/rails_admin/themes/base/variables.scss +0 -71
- data/app/assets/stylesheets/rails_admin/themes/simple/base/typography.scss +0 -22
- data/app/assets/stylesheets/rails_admin/themes/simple/base/variables-dark.scss +0 -74
- data/app/assets/stylesheets/rails_admin/themes/simple/base/variables-light.scss +0 -77
- data/app/assets/stylesheets/rails_admin/themes/simple/base/variables-navy.scss +0 -74
- data/app/assets/stylesheets/rails_admin/themes/simple/base/variables.scss +0 -129
- data/app/assets/stylesheets/rails_admin/themes/simple/components/alerts.scss +0 -88
- data/app/assets/stylesheets/rails_admin/themes/simple/components/breadcrumbs.scss +0 -44
- data/app/assets/stylesheets/rails_admin/themes/simple/components/buttons.scss +0 -138
- data/app/assets/stylesheets/rails_admin/themes/simple/components/dropdowns.scss +0 -12
- data/app/assets/stylesheets/rails_admin/themes/simple/components/filter-box.scss +0 -8
- data/app/assets/stylesheets/rails_admin/themes/simple/components/filtering-multiselect.scss +0 -40
- data/app/assets/stylesheets/rails_admin/themes/simple/components/filtering-select.scss +0 -42
- data/app/assets/stylesheets/rails_admin/themes/simple/components/forms.scss +0 -27
- data/app/assets/stylesheets/rails_admin/themes/simple/components/images.scss +0 -19
- data/app/assets/stylesheets/rails_admin/themes/simple/components/links.scss +0 -25
- data/app/assets/stylesheets/rails_admin/themes/simple/components/navs.scss +0 -73
- data/app/assets/stylesheets/rails_admin/themes/simple/components/progress.scss +0 -4
- data/app/assets/stylesheets/rails_admin/themes/simple/components/sidebar.scss +0 -84
- data/app/assets/stylesheets/rails_admin/themes/simple/components/tables.scss +0 -84
- data/app/assets/stylesheets/rails_admin/themes/simple/layouts/rows.scss +0 -34
- data/app/assets/stylesheets/rails_admin/themes/simple/light/components/links.scss +0 -15
- data/app/assets/stylesheets/rails_admin/themes/simple/light/components/sidebar.scss +0 -25
- data/app/assets/stylesheets/rails_admin/themes/simple.scss.erb +0 -37
- data/app/helpers/rails_admin/application_helper.rb +0 -258
- data/app/helpers/rails_admin/form_builder.rb +0 -166
- data/app/views/layouts/rails_admin/_custom_navigation.html.erb +0 -10
- data/app/views/layouts/rails_admin/_header.html.erb +0 -43
- data/app/views/rails_admin/main/_form_polymorphic_association.html.erb +0 -15
- data/app/views/rails_admin/main/_submit_buttons.html.erb +0 -29
- data/app/views/rails_admin/main/dashboard.html.erb +0 -64
- data/config/locales/rails_admin.en.yml +0 -158
- data/sig/swop.rbs +0 -4
- /data/app/assets/stylesheets/{rails_admin/themes/base/mixins.scss → swop/swop-core/swop-mixins.scss} +0 -0
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
import jQuery from "jquery";
|
|
2
|
-
import "jquery-ui/ui/widget.js";
|
|
3
|
-
import I18n from "./i18n";
|
|
4
|
-
|
|
5
|
-
(function ($) {
|
|
6
|
-
$.widget("ra.filteringMultiselect", $.ra.abstractSelect, {
|
|
7
|
-
_cache: {},
|
|
8
|
-
options: {
|
|
9
|
-
sortable: false,
|
|
10
|
-
removable: true,
|
|
11
|
-
regional: {
|
|
12
|
-
add: "Add",
|
|
13
|
-
chooseAll: "Choose all",
|
|
14
|
-
clearAll: "Clear all",
|
|
15
|
-
down: "Down",
|
|
16
|
-
remove: "Remove",
|
|
17
|
-
search: "Search",
|
|
18
|
-
up: "Up",
|
|
19
|
-
},
|
|
20
|
-
searchDelay: 400,
|
|
21
|
-
remote_source: null,
|
|
22
|
-
xhr: false,
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
wrapper: null,
|
|
26
|
-
filter: null,
|
|
27
|
-
collection: null,
|
|
28
|
-
addAll: null,
|
|
29
|
-
add: null,
|
|
30
|
-
remove: null,
|
|
31
|
-
up: null,
|
|
32
|
-
down: null,
|
|
33
|
-
selection: null,
|
|
34
|
-
removeAll: null,
|
|
35
|
-
|
|
36
|
-
_create: function () {
|
|
37
|
-
this._cache = {};
|
|
38
|
-
this._build();
|
|
39
|
-
this._buildCache();
|
|
40
|
-
this._bindEvents();
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
_build: function () {
|
|
44
|
-
var i;
|
|
45
|
-
|
|
46
|
-
this.wrapper = this.element.siblings(
|
|
47
|
-
'.ra-multiselect[data-input-for="' + this.element.attr("id") + '"]'
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
// Prevent duplication on browser back
|
|
51
|
-
if (this.wrapper.length > 0) {
|
|
52
|
-
this.filter = this.wrapper.find("input.ra-multiselect-search");
|
|
53
|
-
this.collection = this.wrapper.find("select.ra-multiselect-collection");
|
|
54
|
-
this.addAll = this.wrapper.find("a.ra-multiselect-item-add-all");
|
|
55
|
-
this.add = this.wrapper.find("a.ra-multiselect-item-add");
|
|
56
|
-
this.remove = this.wrapper.find("a.ra-multiselect-item-remove");
|
|
57
|
-
this.up = this.wrapper.find("a.ra-multiselect-item-up");
|
|
58
|
-
this.down = this.wrapper.find("a.ra-multiselect-item-down");
|
|
59
|
-
this.selection = this.wrapper.find("select.ra-multiselect-selection");
|
|
60
|
-
this.removeAll = this.wrapper.find("a.ra-multiselect-item-remove-all");
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
this.wrapper = $('<div class="ra-multiselect row gy-3">').attr(
|
|
65
|
-
"data-input-for",
|
|
66
|
-
this.element.attr("id")
|
|
67
|
-
);
|
|
68
|
-
this.wrapper.insertAfter(this.element);
|
|
69
|
-
var header = $('<div class="ra-multiselect-header col-24 col-md-16 col-xl-15">');
|
|
70
|
-
this.filter = $(
|
|
71
|
-
'<input type="search" placeholder="' +
|
|
72
|
-
this.options.regional.search +
|
|
73
|
-
'" class="form-control ra-multiselect-search"/>'
|
|
74
|
-
);
|
|
75
|
-
header.append(this.filter);
|
|
76
|
-
this.wrapper.append(header);
|
|
77
|
-
|
|
78
|
-
var columns = {
|
|
79
|
-
left: $('<div class="ra-multiselect-column ra-multiselect-left col col-md-11">'),
|
|
80
|
-
center: $('<div class="ra-multiselect-column ra-multiselect-center col-auto gx-0">'),
|
|
81
|
-
right: $('<div class="ra-multiselect-column ra-multiselect-right col col-md-11">'),
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
for (i in columns) {
|
|
85
|
-
if (columns.hasOwnProperty(i)) {
|
|
86
|
-
this.wrapper.append(columns[i]);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
this.collection = $('<select multiple="multiple"></select>');
|
|
91
|
-
this.collection.addClass("form-control ra-multiselect-collection");
|
|
92
|
-
this.addAll = $(
|
|
93
|
-
'<a href="#" class="ra-multiselect-item-add-all"><span class="fas fa-chevron-circle-right"></span>' +
|
|
94
|
-
this.options.regional.chooseAll +
|
|
95
|
-
"</a>"
|
|
96
|
-
);
|
|
97
|
-
columns.left.html(this.collection).append(this.addAll);
|
|
98
|
-
this.collection.wrap('<div class="wrapper"/>');
|
|
99
|
-
|
|
100
|
-
this.add = $(
|
|
101
|
-
'<a href="#" class="fas fa-chevron-circle-right ra-multiselect-item-add d-block mb-3 mb-md-4"></a>'
|
|
102
|
-
).attr("title", this.options.regional.add);
|
|
103
|
-
columns.center.append(this.add);
|
|
104
|
-
if (this.options.removable) {
|
|
105
|
-
this.remove = $(
|
|
106
|
-
'<a href="#" class="fas fa-chevron-circle-left ra-multiselect-item-remove d-block"></a>'
|
|
107
|
-
).attr("title", this.options.regional.remove);
|
|
108
|
-
columns.center.append(this.remove);
|
|
109
|
-
}
|
|
110
|
-
if (this.options.sortable) {
|
|
111
|
-
this.up = $(
|
|
112
|
-
'<a href="#" class="fas fa-chevron-circle-up ra-multiselect-item-up"></a>'
|
|
113
|
-
).attr("title", this.options.regional.up);
|
|
114
|
-
this.down = $(
|
|
115
|
-
'<a href="#" class="fas fa-chevron-circle-down ra-multiselect-item-down"></a>'
|
|
116
|
-
).attr("title", this.options.regional.down);
|
|
117
|
-
columns.center.append(this.up).append(this.down);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this.selection = $(
|
|
121
|
-
'<select class="form-control ra-multiselect-selection" multiple="multiple"></select>'
|
|
122
|
-
);
|
|
123
|
-
columns.right.append(this.selection);
|
|
124
|
-
if (this.options.removable) {
|
|
125
|
-
this.removeAll = $(
|
|
126
|
-
'<a href="#" class="ra-multiselect-item-remove-all"><span class="fas fa-chevron-circle-left"></span>' +
|
|
127
|
-
this.options.regional.clearAll +
|
|
128
|
-
"</a>"
|
|
129
|
-
);
|
|
130
|
-
columns.right.append(this.removeAll);
|
|
131
|
-
}
|
|
132
|
-
this.selection.wrap('<div class="wrapper"/>');
|
|
133
|
-
|
|
134
|
-
this.element.css({ display: "none" });
|
|
135
|
-
|
|
136
|
-
this.tooManyObjectsPlaceholder = $('<option disabled="disabled" />').text(
|
|
137
|
-
I18n.t("too_many_objects")
|
|
138
|
-
);
|
|
139
|
-
this.noObjectsPlaceholder = $('<option disabled="disabled" />').text(
|
|
140
|
-
I18n.t("no_objects")
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
if (this.options.xhr) {
|
|
144
|
-
this.collection.append(this.tooManyObjectsPlaceholder);
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
_bindEvents: function () {
|
|
149
|
-
var widget = this;
|
|
150
|
-
|
|
151
|
-
/* Add all to selection */
|
|
152
|
-
this.addAll.click(function (e) {
|
|
153
|
-
widget._select($("option:not(:disabled)", widget.collection));
|
|
154
|
-
e.preventDefault();
|
|
155
|
-
widget.selection.trigger("change");
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
/* Add to selection */
|
|
159
|
-
this.add.click(function (e) {
|
|
160
|
-
widget._select($(":selected", widget.collection));
|
|
161
|
-
|
|
162
|
-
e.preventDefault();
|
|
163
|
-
widget.selection.trigger("change");
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
if (this.options.removable) {
|
|
167
|
-
/* Remove all from selection */
|
|
168
|
-
this.removeAll.click(function (e) {
|
|
169
|
-
widget._deSelect($("option", widget.selection));
|
|
170
|
-
e.preventDefault();
|
|
171
|
-
widget.selection.trigger("change");
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
/* Remove from selection */
|
|
175
|
-
this.remove.click(function (e) {
|
|
176
|
-
widget._deSelect($(":selected", widget.selection));
|
|
177
|
-
e.preventDefault();
|
|
178
|
-
widget.selection.trigger("change");
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
var timeout = null;
|
|
183
|
-
if (this.options.sortable) {
|
|
184
|
-
/* Move selection up */
|
|
185
|
-
this.up.click(function (e) {
|
|
186
|
-
widget._move("up", $(":selected", widget.selection));
|
|
187
|
-
e.preventDefault();
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
/* Move selection down */
|
|
191
|
-
this.down.click(function (e) {
|
|
192
|
-
widget._move("down", $(":selected", widget.selection));
|
|
193
|
-
e.preventDefault();
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/* Typing to the filter */
|
|
198
|
-
this.filter.bind("keyup click", function (e) {
|
|
199
|
-
if (timeout) {
|
|
200
|
-
clearTimeout(timeout);
|
|
201
|
-
}
|
|
202
|
-
timeout = setTimeout(function () {
|
|
203
|
-
widget._queryFilter(widget.filter.val());
|
|
204
|
-
}, widget.options.searchDelay);
|
|
205
|
-
});
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
_queryFilter: function (val) {
|
|
209
|
-
var widget = this;
|
|
210
|
-
widget._query(val, function (matches) {
|
|
211
|
-
var filtered = [];
|
|
212
|
-
var i;
|
|
213
|
-
|
|
214
|
-
for (i = 0; i < matches.length; i++) {
|
|
215
|
-
if (!widget.selected(matches[i].id)) {
|
|
216
|
-
filtered.push(i);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
if (filtered.length > 0) {
|
|
220
|
-
widget.collection.html("");
|
|
221
|
-
for (i = 0; i < filtered.length; i++) {
|
|
222
|
-
var newOptions = $("<option></option>")
|
|
223
|
-
.prop("value", matches[filtered[i]].id)
|
|
224
|
-
.prop("title", matches[filtered[i]].label)
|
|
225
|
-
.text(matches[filtered[i]].label);
|
|
226
|
-
widget.collection.append(newOptions);
|
|
227
|
-
}
|
|
228
|
-
} else {
|
|
229
|
-
widget.collection.html(widget.noObjectsPlaceholder);
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
},
|
|
233
|
-
|
|
234
|
-
/*
|
|
235
|
-
* Cache key is stored in the format `o_<option value>` to avoid JS
|
|
236
|
-
* engine coercing string keys to int keys, and thereby preserving
|
|
237
|
-
* the insertion order. The value for each key is in turn an object
|
|
238
|
-
* that stores the option tag's HTML text and the value. Example:
|
|
239
|
-
* cache = {
|
|
240
|
-
* 'o_271': { id: 271, value: 'CartItem #271'},
|
|
241
|
-
* 'o_270': { id: 270, value: 'CartItem #270'}
|
|
242
|
-
* }
|
|
243
|
-
*/
|
|
244
|
-
_buildCache: function (options) {
|
|
245
|
-
var widget = this;
|
|
246
|
-
|
|
247
|
-
this.element.find("option").each(function (i, option) {
|
|
248
|
-
widget._cache["o_" + option.value] = {
|
|
249
|
-
id: option.value,
|
|
250
|
-
value: $(option).text(),
|
|
251
|
-
};
|
|
252
|
-
if (option.selected) {
|
|
253
|
-
$(option)
|
|
254
|
-
.clone()
|
|
255
|
-
.appendTo(widget.selection)
|
|
256
|
-
.prop("selected", false)
|
|
257
|
-
.prop("title", $(option).text());
|
|
258
|
-
} else {
|
|
259
|
-
$(option)
|
|
260
|
-
.clone()
|
|
261
|
-
.appendTo(widget.collection)
|
|
262
|
-
.prop("selected", false)
|
|
263
|
-
.prop("title", $(option).text());
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
},
|
|
267
|
-
|
|
268
|
-
_deSelect: function (options) {
|
|
269
|
-
var widget = this;
|
|
270
|
-
options.each(function (i, option) {
|
|
271
|
-
widget.element
|
|
272
|
-
.find('option[value="' + option.value + '"]')
|
|
273
|
-
.prop("selected", false);
|
|
274
|
-
});
|
|
275
|
-
$(options).appendTo(this.collection).prop("selected", false);
|
|
276
|
-
},
|
|
277
|
-
|
|
278
|
-
_query: function (query, success) {
|
|
279
|
-
var i,
|
|
280
|
-
matches = [];
|
|
281
|
-
|
|
282
|
-
if (query === "") {
|
|
283
|
-
if (!this.options.xhr) {
|
|
284
|
-
for (i in this._cache) {
|
|
285
|
-
if (this._cache.hasOwnProperty(i)) {
|
|
286
|
-
var option = this._cache[i];
|
|
287
|
-
matches.push({ id: option.id, label: option.value });
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
success.apply(this, [matches]);
|
|
291
|
-
} else {
|
|
292
|
-
this.collection.html(this.tooManyObjectsPlaceholder);
|
|
293
|
-
}
|
|
294
|
-
} else {
|
|
295
|
-
if (this.options.xhr) {
|
|
296
|
-
$.ajax({
|
|
297
|
-
beforeSend: function (xhr) {
|
|
298
|
-
xhr.setRequestHeader("Accept", "application/json");
|
|
299
|
-
},
|
|
300
|
-
url: this.options.remote_source,
|
|
301
|
-
data: this.options.createQuery(query),
|
|
302
|
-
success: success,
|
|
303
|
-
});
|
|
304
|
-
} else {
|
|
305
|
-
query = new RegExp(query + ".*", "i");
|
|
306
|
-
|
|
307
|
-
for (i in this._cache) {
|
|
308
|
-
if (
|
|
309
|
-
this._cache.hasOwnProperty(i) &&
|
|
310
|
-
query.test(this._cache[i]["value"])
|
|
311
|
-
) {
|
|
312
|
-
var option = this._cache[i];
|
|
313
|
-
matches.push({ id: option.id, label: option.value });
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
success.apply(this, [matches]);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
|
|
322
|
-
_select: function (options) {
|
|
323
|
-
var widget = this;
|
|
324
|
-
options.each(function (i, option) {
|
|
325
|
-
var el = widget.element.find('option[value="' + option.value + '"]');
|
|
326
|
-
if (el.length) {
|
|
327
|
-
el.prop("selected", true);
|
|
328
|
-
} else {
|
|
329
|
-
widget.element.append(
|
|
330
|
-
$("<option></option>")
|
|
331
|
-
.prop("value", option.value)
|
|
332
|
-
.prop("selected", true)
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
$(options).appendTo(this.selection).prop("selected", false);
|
|
337
|
-
},
|
|
338
|
-
|
|
339
|
-
_move: function (direction, options) {
|
|
340
|
-
var widget = this;
|
|
341
|
-
if (direction == "up") {
|
|
342
|
-
options.each(function (i, option) {
|
|
343
|
-
var prev = $(option).prev();
|
|
344
|
-
if (prev.length > 0) {
|
|
345
|
-
var el = widget.element.find(
|
|
346
|
-
'option[value="' + option.value + '"]'
|
|
347
|
-
);
|
|
348
|
-
var el_prev = widget.element.find(
|
|
349
|
-
'option[value="' + prev[0].value + '"]'
|
|
350
|
-
);
|
|
351
|
-
el_prev.before(el);
|
|
352
|
-
prev.before($(option));
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
} else {
|
|
356
|
-
$.fn.reverse = [].reverse; // needed to lower last items first
|
|
357
|
-
options.reverse().each(function (i, option) {
|
|
358
|
-
var next = $(option).next();
|
|
359
|
-
if (next.length > 0) {
|
|
360
|
-
var el = widget.element.find(
|
|
361
|
-
'option[value="' + option.value + '"]'
|
|
362
|
-
);
|
|
363
|
-
var el_next = widget.element.find(
|
|
364
|
-
'option[value="' + next[0].value + '"]'
|
|
365
|
-
);
|
|
366
|
-
el_next.after(el);
|
|
367
|
-
next.after($(option));
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
},
|
|
372
|
-
|
|
373
|
-
selected: function (value) {
|
|
374
|
-
if (
|
|
375
|
-
this.selection[0].querySelectorAll('option[value="' + value + '"]')[0]
|
|
376
|
-
) {
|
|
377
|
-
return true;
|
|
378
|
-
}
|
|
379
|
-
},
|
|
380
|
-
|
|
381
|
-
destroy: function () {
|
|
382
|
-
this.wrapper.remove();
|
|
383
|
-
this.element.css({ display: "inline" });
|
|
384
|
-
$.Widget.prototype.destroy.apply(this, arguments);
|
|
385
|
-
},
|
|
386
|
-
});
|
|
387
|
-
})(jQuery);
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import jQuery from "jquery";
|
|
2
|
-
import "jquery-ui/ui/widget.js";
|
|
3
|
-
import "jquery-ui/ui/widgets/autocomplete.js";
|
|
4
|
-
import I18n from "./i18n";
|
|
5
|
-
|
|
6
|
-
(function ($) {
|
|
7
|
-
"use strict";
|
|
8
|
-
|
|
9
|
-
$.widget("ra.filteringSelect", $.ra.abstractSelect, {
|
|
10
|
-
options: {
|
|
11
|
-
minLength: 0,
|
|
12
|
-
searchDelay: 200,
|
|
13
|
-
remote_source: null,
|
|
14
|
-
source: null,
|
|
15
|
-
xhr: false,
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
button: null,
|
|
19
|
-
input: null,
|
|
20
|
-
select: null,
|
|
21
|
-
filtering_select: null,
|
|
22
|
-
|
|
23
|
-
_create: function () {
|
|
24
|
-
this.filtering_select = this.element.siblings(
|
|
25
|
-
'[data-input-for="' + this.element.attr("id") + '"]'
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
// When using the browser back and forward buttons, it is possible that
|
|
29
|
-
// the autocomplete field will be cached which causes duplicate fields
|
|
30
|
-
// to be generated.
|
|
31
|
-
if (this.filtering_select.length > 0) {
|
|
32
|
-
this.input = this.filtering_select.children("input");
|
|
33
|
-
this.button = this.filtering_select.children(".input-group-btn");
|
|
34
|
-
} else {
|
|
35
|
-
this.element.hide();
|
|
36
|
-
this.filtering_select = this._inputGroup(this.element.attr("id"));
|
|
37
|
-
this.input = this._inputField();
|
|
38
|
-
this.button = this._buttonField();
|
|
39
|
-
}
|
|
40
|
-
this.clearOption = $('<span></span>').append(
|
|
41
|
-
'<i class="fas fa-times me-2"></i> ' +
|
|
42
|
-
$('<span></span>').text(I18n.t("clear")).html()
|
|
43
|
-
);
|
|
44
|
-
this.noObjectsPlaceholder = $('<option disabled="disabled" />').text(
|
|
45
|
-
I18n.t("no_objects")
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
this._setOptionsSource();
|
|
49
|
-
this._initAutocomplete();
|
|
50
|
-
this._initKeyEvent();
|
|
51
|
-
this._overloadRenderItem();
|
|
52
|
-
this._autocompleteDropdownEvent(this.button);
|
|
53
|
-
|
|
54
|
-
return this.filtering_select
|
|
55
|
-
.append(this.input)
|
|
56
|
-
.append(this.button)
|
|
57
|
-
.insertAfter(this.element);
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
_getResultSet: function (request, data, xhr) {
|
|
61
|
-
var matcher = new RegExp(
|
|
62
|
-
$.ui.autocomplete.escapeRegex(request.term),
|
|
63
|
-
"i"
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
var spannedContent = function (content) {
|
|
67
|
-
return $("<span>").text(content).html();
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
var highlighter = function (label, word) {
|
|
71
|
-
if (word.length) {
|
|
72
|
-
return $.map(label.split(word), function (el) {
|
|
73
|
-
return spannedContent(el);
|
|
74
|
-
}).join($("<strong>").text(word)[0].outerHTML);
|
|
75
|
-
} else {
|
|
76
|
-
return spannedContent(label);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
var matches = $.map(data, function (el) {
|
|
81
|
-
var id = el.id || el.value;
|
|
82
|
-
var value = el.label || el.id;
|
|
83
|
-
// match regexp only for local requests, remote ones are already
|
|
84
|
-
// filtered, and label may not contain filtered term.
|
|
85
|
-
if (id && (xhr || matcher.test(el.label))) {
|
|
86
|
-
return {
|
|
87
|
-
html: highlighter(value, request.term),
|
|
88
|
-
value: value,
|
|
89
|
-
id: id,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
if (request.term.length === 0 && !this.input.attr("required")) {
|
|
95
|
-
return [{ html: this.clearOption, value: null, id: null }].concat(
|
|
96
|
-
matches
|
|
97
|
-
);
|
|
98
|
-
} else if (matches.length === 0) {
|
|
99
|
-
return [{ html: this.noObjectsPlaceholder, value: null, id: null }];
|
|
100
|
-
} else {
|
|
101
|
-
return matches;
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
_getSourceFunction: function (source) {
|
|
106
|
-
var self = this;
|
|
107
|
-
var requestIndex = 0;
|
|
108
|
-
|
|
109
|
-
if ($.isArray(source)) {
|
|
110
|
-
return function (request, response) {
|
|
111
|
-
response(self._getResultSet(request, source, false));
|
|
112
|
-
};
|
|
113
|
-
} else if (typeof source === "string") {
|
|
114
|
-
return function (request, response) {
|
|
115
|
-
if (this.xhr) {
|
|
116
|
-
this.xhr.abort();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
this.xhr = $.ajax({
|
|
120
|
-
url: source,
|
|
121
|
-
data: self.options.createQuery(request.term),
|
|
122
|
-
dataType: "json",
|
|
123
|
-
autocompleteRequest: ++requestIndex,
|
|
124
|
-
success: function (data, status) {
|
|
125
|
-
if (this.autocompleteRequest === requestIndex) {
|
|
126
|
-
response(self._getResultSet(request, data, true));
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
error: function () {
|
|
130
|
-
if (this.autocompleteRequest === requestIndex) {
|
|
131
|
-
response([]);
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
} else {
|
|
137
|
-
return source;
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
|
|
141
|
-
_setOptionsSource: function () {
|
|
142
|
-
if (this.options.xhr) {
|
|
143
|
-
this.options.source = this.options.remote_source;
|
|
144
|
-
} else {
|
|
145
|
-
this.options.source = this.element
|
|
146
|
-
.children("option")
|
|
147
|
-
.map(function () {
|
|
148
|
-
return { label: $(this).text(), value: this.value };
|
|
149
|
-
})
|
|
150
|
-
.toArray();
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
|
|
154
|
-
_buttonField: function () {
|
|
155
|
-
return $(
|
|
156
|
-
'<div class="input-group-btn btn btn-white dropdown-toggle" title="Show All Items" role="button">' +
|
|
157
|
-
"</div>"
|
|
158
|
-
);
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
_autocompleteDropdownEvent: function (element) {
|
|
162
|
-
var self = this;
|
|
163
|
-
|
|
164
|
-
return element.click(function () {
|
|
165
|
-
// close if already visible
|
|
166
|
-
if (self.input.autocomplete("widget").is(":visible")) {
|
|
167
|
-
self.input.autocomplete("close");
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// pass empty string as value to search for, displaying all results
|
|
172
|
-
self.input.autocomplete("search", "");
|
|
173
|
-
self.input.focus();
|
|
174
|
-
});
|
|
175
|
-
},
|
|
176
|
-
|
|
177
|
-
_inputField: function () {
|
|
178
|
-
var input;
|
|
179
|
-
var selected = this.element.children(":selected");
|
|
180
|
-
var value = selected.val() ? selected.text() : "";
|
|
181
|
-
|
|
182
|
-
input = $('<input type="text">')
|
|
183
|
-
.val(value)
|
|
184
|
-
.addClass("form-control ra-filtering-select-input")
|
|
185
|
-
.attr("style", this.element.attr("style"))
|
|
186
|
-
.show();
|
|
187
|
-
|
|
188
|
-
if (this.element.attr("placeholder")) {
|
|
189
|
-
input.attr("placeholder", this.element.attr("placeholder"));
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (this.element.attr("required")) {
|
|
193
|
-
input.attr("required", this.element.attr("required"));
|
|
194
|
-
this.element.attr("required", false);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return input;
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
_inputGroup: function (inputFor) {
|
|
201
|
-
return $("<div>")
|
|
202
|
-
.addClass("input-group filtering-select")
|
|
203
|
-
.attr("data-input-for", inputFor);
|
|
204
|
-
},
|
|
205
|
-
|
|
206
|
-
_initAutocomplete: function () {
|
|
207
|
-
var self = this;
|
|
208
|
-
|
|
209
|
-
return this.input.autocomplete({
|
|
210
|
-
delay: this.options.searchDelay,
|
|
211
|
-
minLength: this.options.minLength,
|
|
212
|
-
source: this._getSourceFunction(this.options.source),
|
|
213
|
-
select: function (event, ui) {
|
|
214
|
-
var option = self.element.find(
|
|
215
|
-
`option[value="${CSS.escape(ui.item.id)}"]`
|
|
216
|
-
);
|
|
217
|
-
self.element.find("option[selected]").attr("selected", false);
|
|
218
|
-
if (option.length > 0) {
|
|
219
|
-
option.attr("selected", "selected");
|
|
220
|
-
} else {
|
|
221
|
-
option = $("<option>")
|
|
222
|
-
.attr("value", ui.item.id)
|
|
223
|
-
.attr("selected", true)
|
|
224
|
-
.text(ui.item.value);
|
|
225
|
-
self.element.append(option);
|
|
226
|
-
}
|
|
227
|
-
self.element.trigger("change", ui.item.id);
|
|
228
|
-
self._trigger("selected", event, {
|
|
229
|
-
item: option,
|
|
230
|
-
});
|
|
231
|
-
$(self.element.parents(".controls")[0])
|
|
232
|
-
.find(".update")
|
|
233
|
-
.removeClass("disabled");
|
|
234
|
-
},
|
|
235
|
-
change: function (event, ui) {
|
|
236
|
-
if (ui.item) {
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
var matcher = new RegExp(
|
|
241
|
-
"^" + $.ui.autocomplete.escapeRegex($(this).val()) + "$",
|
|
242
|
-
"i"
|
|
243
|
-
);
|
|
244
|
-
var valid = false;
|
|
245
|
-
|
|
246
|
-
self.element.children("option").each(function () {
|
|
247
|
-
if ($(this).text().match(matcher)) {
|
|
248
|
-
valid = true;
|
|
249
|
-
return false;
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
if (valid || $(this).val() !== "") {
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// remove invalid value, as it didn't match anything
|
|
258
|
-
$(this).val(null);
|
|
259
|
-
self.element.html(
|
|
260
|
-
$('<option value="" selected="selected"></option>')
|
|
261
|
-
);
|
|
262
|
-
self.input.data("ui-autocomplete").term = "";
|
|
263
|
-
$(self.element.parents(".controls")[0])
|
|
264
|
-
.find(".update")
|
|
265
|
-
.addClass("disabled");
|
|
266
|
-
return false;
|
|
267
|
-
},
|
|
268
|
-
});
|
|
269
|
-
},
|
|
270
|
-
|
|
271
|
-
_initKeyEvent: function () {
|
|
272
|
-
var self = this;
|
|
273
|
-
|
|
274
|
-
return this.input.keyup(function () {
|
|
275
|
-
if ($(this).val().length) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/* Clear select options and trigger change if selected item is deleted */
|
|
280
|
-
return self.element
|
|
281
|
-
.html($('<option value="" selected="selected"></option>'))
|
|
282
|
-
.trigger("change");
|
|
283
|
-
});
|
|
284
|
-
},
|
|
285
|
-
|
|
286
|
-
_overloadRenderItem: function () {
|
|
287
|
-
this.input.data("ui-autocomplete")._renderItem = function (ul, item) {
|
|
288
|
-
return $("<li></li>")
|
|
289
|
-
.data("ui-autocomplete-item", item)
|
|
290
|
-
.append($("<a></a>").html(item.html || item.id))
|
|
291
|
-
.appendTo(ul);
|
|
292
|
-
};
|
|
293
|
-
},
|
|
294
|
-
|
|
295
|
-
destroy: function () {
|
|
296
|
-
this.input.remove();
|
|
297
|
-
this.button.remove();
|
|
298
|
-
this.element.html($('<option value="" selected="selected"></option>'));
|
|
299
|
-
this.element.show();
|
|
300
|
-
this.filtering_select.remove();
|
|
301
|
-
$.Widget.prototype.destroy.call(this);
|
|
302
|
-
},
|
|
303
|
-
});
|
|
304
|
-
})(jQuery);
|