@windwalker-io/unicorn-next 0.1.18 → 0.1.21
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.
- package/dist/chunks/_arrayPush.js +325 -108
- package/dist/chunks/_arrayPush.js.map +1 -1
- package/dist/chunks/_baseRest.js +155 -60
- package/dist/chunks/_baseRest.js.map +1 -1
- package/dist/chunks/_baseUnary.js +463 -0
- package/dist/chunks/_baseUnary.js.map +1 -0
- package/dist/chunks/_getPrototype.js +292 -100
- package/dist/chunks/_getPrototype.js.map +1 -1
- package/dist/chunks/alert-adapter.js +29 -0
- package/dist/chunks/alert-adapter.js.map +1 -0
- package/dist/chunks/alert.js +21 -0
- package/dist/chunks/alert.js.map +1 -0
- package/dist/chunks/arr.js +24 -0
- package/dist/chunks/arr.js.map +1 -0
- package/dist/chunks/button-radio.js +127 -145
- package/dist/chunks/button-radio.js.map +1 -1
- package/dist/chunks/checkboxes-multi-select.js +44 -43
- package/dist/chunks/checkboxes-multi-select.js.map +1 -1
- package/dist/chunks/chunk.js +24 -0
- package/dist/chunks/cloneDeep.js +679 -212
- package/dist/chunks/cloneDeep.js.map +1 -1
- package/dist/chunks/cropper.min.js +6 -5
- package/dist/chunks/cropper.min.js.map +1 -1
- package/dist/chunks/crypto.js +26 -0
- package/dist/chunks/crypto.js.map +1 -0
- package/dist/chunks/data.js +49 -0
- package/dist/chunks/data.js.map +1 -0
- package/dist/chunks/dom.js +128 -0
- package/dist/chunks/dom.js.map +1 -0
- package/dist/chunks/events.js +270 -0
- package/dist/chunks/events.js.map +1 -0
- package/dist/chunks/field-cascade-select.js +207 -250
- package/dist/chunks/field-cascade-select.js.map +1 -1
- package/dist/chunks/field-file-drag.js +175 -209
- package/dist/chunks/field-file-drag.js.map +1 -1
- package/dist/chunks/field-flatpickr.js +94 -898
- package/dist/chunks/field-flatpickr.js.map +1 -1
- package/dist/chunks/field-modal-select.js +728 -467
- package/dist/chunks/field-modal-select.js.map +1 -1
- package/dist/chunks/field-modal-tree.js +771 -766
- package/dist/chunks/field-modal-tree.js.map +1 -1
- package/dist/chunks/field-multi-uploader.js +249 -256
- package/dist/chunks/field-multi-uploader.js.map +1 -1
- package/dist/chunks/field-repeatable.js +111 -127
- package/dist/chunks/field-repeatable.js.map +1 -1
- package/dist/chunks/field-single-image-drag.js +286 -338
- package/dist/chunks/field-single-image-drag.js.map +1 -1
- package/dist/chunks/form.js +146 -159
- package/dist/chunks/form.js.map +1 -1
- package/dist/chunks/grid.js +349 -418
- package/dist/chunks/grid.js.map +1 -1
- package/dist/chunks/helper.js +39 -0
- package/dist/chunks/helper.js.map +1 -0
- package/dist/chunks/http-client.js +221 -211
- package/dist/chunks/http-client.js.map +1 -1
- package/dist/chunks/iframe-modal.js +95 -115
- package/dist/chunks/iframe-modal.js.map +1 -1
- package/dist/chunks/keep-tab.js +92 -101
- package/dist/chunks/keep-tab.js.map +1 -1
- package/dist/chunks/lang.js +250 -0
- package/dist/chunks/lang.js.map +1 -0
- package/dist/chunks/legacy.js +197 -201
- package/dist/chunks/legacy.js.map +1 -1
- package/dist/chunks/list-dependent.js +195 -228
- package/dist/chunks/list-dependent.js.map +1 -1
- package/dist/chunks/loader.js +106 -0
- package/dist/chunks/loader.js.map +1 -0
- package/dist/chunks/monthSelect.js +251 -0
- package/dist/chunks/monthSelect.js.map +1 -0
- package/dist/chunks/router.js +111 -0
- package/dist/chunks/router.js.map +1 -0
- package/dist/chunks/s3-multipart-uploader.js +183 -210
- package/dist/chunks/s3-multipart-uploader.js.map +1 -1
- package/dist/chunks/s3-uploader.js +106 -128
- package/dist/chunks/s3-uploader.js.map +1 -1
- package/dist/chunks/show-on.js +358 -205
- package/dist/chunks/show-on.js.map +1 -1
- package/dist/chunks/timing.js +10 -0
- package/dist/chunks/timing.js.map +1 -0
- package/dist/chunks/tinymce.js +153 -203
- package/dist/chunks/tinymce.js.map +1 -1
- package/dist/chunks/ui-bootstrap5.js +58 -72
- package/dist/chunks/ui-bootstrap5.js.map +1 -1
- package/dist/chunks/ui.js +320 -0
- package/dist/chunks/ui.js.map +1 -0
- package/dist/chunks/unicorn.js.map +1 -1
- package/dist/chunks/useQueue.js +111 -0
- package/dist/chunks/useQueue.js.map +1 -0
- package/dist/chunks/useStack.js +76 -0
- package/dist/chunks/useStack.js.map +1 -0
- package/dist/chunks/validation.js +761 -853
- package/dist/chunks/validation.js.map +1 -1
- package/dist/editor.css +1 -1
- package/dist/index.d.ts +27 -15
- package/dist/multi-level-menu.css +1 -1
- package/dist/switcher.css +1 -1
- package/dist/unicorn.js +805 -130
- package/dist/unicorn.js.map +1 -1
- package/package.json +3 -3
- package/src/composable/useBsModalAlert.ts +92 -12
- package/src/composable/useHttp.ts +13 -1
- package/src/module/s3-uploader.ts +1 -1
- package/src/service/ui.ts +31 -15
- package/vite.config.ts +5 -1
- package/dist/chunks/_commonjsHelpers.js +0 -7
- package/dist/chunks/index.js +0 -314
- package/dist/chunks/isArguments.js +0 -146
- package/dist/chunks/unicorn.js +0 -2580
package/dist/chunks/grid.js
CHANGED
|
@@ -1,419 +1,350 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
getCheckedValues() {
|
|
348
|
-
return this.getChecked().map((input) => input.value);
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Validate there has one or more checked boxes.
|
|
352
|
-
*/
|
|
353
|
-
validateChecked(event, callback, errorMsg = true) {
|
|
354
|
-
if (!this.hasChecked()) {
|
|
355
|
-
if (errorMsg === true) {
|
|
356
|
-
errorMsg = this.getMustCheckedMessage();
|
|
357
|
-
}
|
|
358
|
-
if (typeof errorMsg === "string" && errorMsg !== "") {
|
|
359
|
-
simpleAlert(errorMsg);
|
|
360
|
-
} else if (typeof errorMsg === "function") {
|
|
361
|
-
errorMsg(this);
|
|
362
|
-
}
|
|
363
|
-
if (event) {
|
|
364
|
-
event.stopPropagation();
|
|
365
|
-
event.preventDefault();
|
|
366
|
-
const target = event.currentTarget;
|
|
367
|
-
if (target.dataset.bsToggle === "modal") {
|
|
368
|
-
if (target.dataset.bsTarget) {
|
|
369
|
-
this.preventBSModal(target.dataset.bsTarget);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
return this;
|
|
374
|
-
}
|
|
375
|
-
if (callback) {
|
|
376
|
-
callback(this);
|
|
377
|
-
}
|
|
378
|
-
return this;
|
|
379
|
-
}
|
|
380
|
-
async validateCheckedPromise() {
|
|
381
|
-
if (!this.hasChecked()) {
|
|
382
|
-
throw new Error("No items checked.");
|
|
383
|
-
}
|
|
384
|
-
return this;
|
|
385
|
-
}
|
|
386
|
-
getMustCheckedMessage() {
|
|
387
|
-
return __("unicorn.message.grid.checked");
|
|
388
|
-
}
|
|
389
|
-
hasChecked() {
|
|
390
|
-
return this.countChecked() > 0;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Reorder all.
|
|
394
|
-
*/
|
|
395
|
-
reorderAll(url, data) {
|
|
396
|
-
return this.updateListByTask("reorder", url, data);
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Reorder items.
|
|
400
|
-
*/
|
|
401
|
-
moveItem(id, delta, url, data) {
|
|
402
|
-
data = data || {};
|
|
403
|
-
data.delta = delta;
|
|
404
|
-
return this.updateItemByTask("move", id, url, data);
|
|
405
|
-
}
|
|
406
|
-
moveUp(id, url, data) {
|
|
407
|
-
return this.moveItem(id, -1, url, data);
|
|
408
|
-
}
|
|
409
|
-
moveDown(id, url, data) {
|
|
410
|
-
return this.moveItem(id, 1, url, data);
|
|
411
|
-
}
|
|
412
|
-
getId(suffix = "") {
|
|
413
|
-
return this.form.element?.id + suffix;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
export {
|
|
417
|
-
UnicornGridElement
|
|
1
|
+
import { a as h, t as delegate } from "./dom.js";
|
|
2
|
+
import { f as slideDown, m as slideUp, s as loadAlpine } from "./ui.js";
|
|
3
|
+
import { i as simpleConfirm, n as deleteConfirm, r as simpleAlert } from "./alert.js";
|
|
4
|
+
import { t as __ } from "./lang.js";
|
|
5
|
+
//#region src/module/grid.ts
|
|
6
|
+
var UnicornGridElement = class {
|
|
7
|
+
options;
|
|
8
|
+
ordering = "";
|
|
9
|
+
state = {};
|
|
10
|
+
constructor(selector, element, form, options = {}) {
|
|
11
|
+
this.element = element;
|
|
12
|
+
this.form = form;
|
|
13
|
+
this.options = { ...options };
|
|
14
|
+
this.bindEvents();
|
|
15
|
+
}
|
|
16
|
+
bindEvents() {
|
|
17
|
+
const inputs = this.element.querySelectorAll("input[data-role=grid-checkbox]");
|
|
18
|
+
for (const ch of inputs) ch.addEventListener("change", () => {
|
|
19
|
+
const event = new CustomEvent("unicorn:checked", { detail: { grid: this } });
|
|
20
|
+
this.form.element?.dispatchEvent(event);
|
|
21
|
+
});
|
|
22
|
+
if (this.form.element) this.bindMustCheckedEvent(this.form.element);
|
|
23
|
+
}
|
|
24
|
+
bindMustCheckedEvent(form) {
|
|
25
|
+
delegate(document, "[data-must-checked]", "mousedown", (e) => {
|
|
26
|
+
const target = e.currentTarget;
|
|
27
|
+
const selector = target.dataset.mustChecked;
|
|
28
|
+
if (!selector || !form.matches(selector)) return;
|
|
29
|
+
if (target.dataset.bsToggle === "modal") {
|
|
30
|
+
const modalTarget = target.dataset.bsTarget;
|
|
31
|
+
if (modalTarget) this.preventBSModal(modalTarget, this.getMustCheckedMessage());
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
preventBSModal(selector, msg) {
|
|
36
|
+
let modalElement = null;
|
|
37
|
+
if (typeof selector === "string") modalElement = document.querySelector(selector);
|
|
38
|
+
else if (selector instanceof HTMLElement) {
|
|
39
|
+
const modalTarget = selector.dataset.bsTarget;
|
|
40
|
+
if (modalTarget) modalElement = document.querySelector(modalTarget);
|
|
41
|
+
else modalElement = selector;
|
|
42
|
+
}
|
|
43
|
+
if (modalElement) modalElement?.addEventListener("show.bs.modal", (e) => {
|
|
44
|
+
if (!this.hasChecked()) {
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
e.stopPropagation();
|
|
47
|
+
if (msg) {
|
|
48
|
+
if (msg === true) msg = this.getMustCheckedMessage();
|
|
49
|
+
simpleAlert(msg);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}, { once: true });
|
|
53
|
+
}
|
|
54
|
+
initComponent(store = "grid", custom = {}) {
|
|
55
|
+
this.ordering = this.element?.dataset?.ordering || "";
|
|
56
|
+
if (this.ordering) {
|
|
57
|
+
if (!this.ordering.toLowerCase().endsWith(" asc") && !this.ordering.toLowerCase().endsWith(" desc")) this.ordering += " ASC";
|
|
58
|
+
}
|
|
59
|
+
return loadAlpine((Alpine) => {
|
|
60
|
+
Alpine.store(store, this.useState(custom));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
useState(custom = {}) {
|
|
64
|
+
const state = { form: this.form.useState(custom) };
|
|
65
|
+
Object.getOwnPropertyNames(Object.getPrototypeOf(this)).map((item) => {
|
|
66
|
+
if (typeof this[item] === "function") return state[item] = this[item].bind(this);
|
|
67
|
+
return item;
|
|
68
|
+
});
|
|
69
|
+
return Object.assign(state, custom);
|
|
70
|
+
}
|
|
71
|
+
getElement() {
|
|
72
|
+
return this.element;
|
|
73
|
+
}
|
|
74
|
+
sendFilter($event, method) {
|
|
75
|
+
if ($event) $event.preventDefault();
|
|
76
|
+
this.form.submit(null, null, method);
|
|
77
|
+
}
|
|
78
|
+
clearFilters(element, method) {
|
|
79
|
+
element.querySelectorAll("input, textarea, select").forEach((ele) => {
|
|
80
|
+
ele.value = "";
|
|
81
|
+
});
|
|
82
|
+
this.form.submit(null, null, method);
|
|
83
|
+
}
|
|
84
|
+
async toggleFilters(open, filterForm) {
|
|
85
|
+
if (open) await slideDown(filterForm);
|
|
86
|
+
else await slideUp(filterForm);
|
|
87
|
+
}
|
|
88
|
+
sort($el) {
|
|
89
|
+
const dir = this.getDirection($el);
|
|
90
|
+
const field = $el.dataset.field;
|
|
91
|
+
let asc = $el.dataset.asc;
|
|
92
|
+
let desc = $el.dataset.desc;
|
|
93
|
+
if (field) {
|
|
94
|
+
asc = field + " ASC";
|
|
95
|
+
desc = field + " DESC";
|
|
96
|
+
}
|
|
97
|
+
if (dir === "ASC") return this.sortBy(desc);
|
|
98
|
+
return this.sortBy(asc);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Sort two items.
|
|
102
|
+
*/
|
|
103
|
+
sortBy(ordering) {
|
|
104
|
+
if (!ordering) return false;
|
|
105
|
+
let orderingInput = this.element.querySelector("input[name=list_ordering]");
|
|
106
|
+
if (!orderingInput) {
|
|
107
|
+
orderingInput = h("input", {
|
|
108
|
+
name: "list_ordering",
|
|
109
|
+
type: "hidden",
|
|
110
|
+
value: ""
|
|
111
|
+
});
|
|
112
|
+
this.element.appendChild(orderingInput);
|
|
113
|
+
}
|
|
114
|
+
orderingInput.value = ordering;
|
|
115
|
+
return this.form.put();
|
|
116
|
+
}
|
|
117
|
+
isSortActive($el) {
|
|
118
|
+
return this.getDirection($el) != null;
|
|
119
|
+
}
|
|
120
|
+
getDirection($el) {
|
|
121
|
+
const field = $el.dataset.field;
|
|
122
|
+
let asc = $el.dataset.asc;
|
|
123
|
+
let desc = $el.dataset.desc;
|
|
124
|
+
if (field) {
|
|
125
|
+
asc = field + " ASC";
|
|
126
|
+
desc = field + " DESC";
|
|
127
|
+
}
|
|
128
|
+
if (this.orderingEquals(asc, this.ordering)) return "ASC";
|
|
129
|
+
else if (this.orderingEquals(desc, this.ordering)) return "DESC";
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
orderingEquals(a, b) {
|
|
133
|
+
a = a || "";
|
|
134
|
+
b = b || "";
|
|
135
|
+
a = a.replace(/\s+/g, " ").trim().toLowerCase();
|
|
136
|
+
b = b.replace(/\s+/g, " ").trim().toLowerCase();
|
|
137
|
+
return a === b;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Check a row's checkbox.
|
|
141
|
+
*/
|
|
142
|
+
checkRow(row, value = true) {
|
|
143
|
+
const ch = this.getCheckboxByRow(row);
|
|
144
|
+
if (!ch) throw new Error("Checkbox of row: " + row + " not found.");
|
|
145
|
+
ch.checked = value;
|
|
146
|
+
ch.dispatchEvent(new Event("input"));
|
|
147
|
+
ch.dispatchEvent(new Event("change"));
|
|
148
|
+
}
|
|
149
|
+
getCheckboxByRow(row) {
|
|
150
|
+
return this.form.element?.querySelector(`input[data-role=grid-checkbox][data-row-number="${row}"]`);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Update a row.
|
|
154
|
+
*/
|
|
155
|
+
updateRow(row, url, data) {
|
|
156
|
+
const ch = this.getCheckboxByRow(row);
|
|
157
|
+
if (!ch) return false;
|
|
158
|
+
return this.updateItem(ch.value, url, data);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Update an item by id.
|
|
162
|
+
*/
|
|
163
|
+
updateItem(id, url, data) {
|
|
164
|
+
this.toggleAll(false);
|
|
165
|
+
this.disableAllCheckboxes();
|
|
166
|
+
this.form.injectInput("id[]", id);
|
|
167
|
+
return this.form.patch(url, data);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Update a item with batch task.
|
|
171
|
+
*/
|
|
172
|
+
updateItemByTask(task, id, url, data) {
|
|
173
|
+
data = data || {};
|
|
174
|
+
data.task = task;
|
|
175
|
+
return this.updateItem(id, url, data);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* @deprecated Use updateItemByTask() instead.
|
|
179
|
+
*/
|
|
180
|
+
doTask(task, id, url, data) {
|
|
181
|
+
return this.updateItemByTask(task, id, url, data);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Update a row with batch task.
|
|
185
|
+
*/
|
|
186
|
+
updateRowByTask(task, row, url, data) {
|
|
187
|
+
const ch = this.getCheckboxByRow(row);
|
|
188
|
+
if (!ch) return false;
|
|
189
|
+
return this.updateItemByTask(task, ch.value, url, data);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Batch update items.
|
|
193
|
+
*/
|
|
194
|
+
updateListByTask(task, url, data) {
|
|
195
|
+
data = data || {};
|
|
196
|
+
data.task = task;
|
|
197
|
+
return this.form.patch(url, data);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* @deprecated Use updateListByTask() instead.
|
|
201
|
+
*/
|
|
202
|
+
batch(task, url, data) {
|
|
203
|
+
return this.updateListByTask(task, url, data);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* @deprecated Use updateListByTask() instead.
|
|
207
|
+
*/
|
|
208
|
+
updateByTask(task, url, data) {
|
|
209
|
+
return this.updateListByTask(task, url, data);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Copy a row.
|
|
213
|
+
*/
|
|
214
|
+
copyItem(id, url, data) {
|
|
215
|
+
this.toggleAll(false);
|
|
216
|
+
this.disableAllCheckboxes();
|
|
217
|
+
this.form.injectInput("id[]", id);
|
|
218
|
+
return this.form.post(url, data);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Copy a row.
|
|
222
|
+
*/
|
|
223
|
+
copyRow(row, url, data) {
|
|
224
|
+
const ch = this.getCheckboxByRow(row);
|
|
225
|
+
if (!ch) return false;
|
|
226
|
+
return this.copyItem(ch.value, url, data);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Delete checked items.
|
|
230
|
+
*/
|
|
231
|
+
deleteList(message, url, data) {
|
|
232
|
+
if (!this.validateChecked()) return false;
|
|
233
|
+
message = message == null ? __("unicorn.message.delete.confirm") : message;
|
|
234
|
+
if (message !== false) simpleConfirm(message).then((isConfirm) => {
|
|
235
|
+
if (isConfirm) this.form.delete(url, data);
|
|
236
|
+
});
|
|
237
|
+
else this.form.delete(url, data);
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Delete an item by row.
|
|
242
|
+
*/
|
|
243
|
+
async deleteRow(row, msg, url, data) {
|
|
244
|
+
const ch = this.getCheckboxByRow(row);
|
|
245
|
+
if (!ch) return false;
|
|
246
|
+
return this.deleteItem(ch.value, msg, url, data);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Delete an item.
|
|
250
|
+
*/
|
|
251
|
+
async deleteItem(id, msg, url, data) {
|
|
252
|
+
msg = msg || __("unicorn.message.delete.confirm");
|
|
253
|
+
const isConfirm = await deleteConfirm(msg);
|
|
254
|
+
if (isConfirm) {
|
|
255
|
+
data = data || {};
|
|
256
|
+
data.id = id;
|
|
257
|
+
this.form.delete(url, data);
|
|
258
|
+
}
|
|
259
|
+
return isConfirm;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Toggle all checkboxes.
|
|
263
|
+
*/
|
|
264
|
+
toggleAll(value) {
|
|
265
|
+
Array.from(this.element.querySelectorAll("input[data-role=grid-checkbox][type=checkbox]")).forEach((input) => {
|
|
266
|
+
input.checked = value;
|
|
267
|
+
input.dispatchEvent(new CustomEvent("input"));
|
|
268
|
+
input.dispatchEvent(new CustomEvent("change"));
|
|
269
|
+
});
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
disableAllCheckboxes() {
|
|
273
|
+
Array.from(this.element.querySelectorAll("input[data-role=grid-checkbox][type=checkbox]")).forEach((input) => {
|
|
274
|
+
input.disabled = true;
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Count checked checkboxes.
|
|
279
|
+
*/
|
|
280
|
+
countChecked() {
|
|
281
|
+
return this.getChecked().length;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Get Checked boxes.
|
|
285
|
+
*/
|
|
286
|
+
getChecked() {
|
|
287
|
+
return Array.from(this.element.querySelectorAll("input[data-role=grid-checkbox][type=checkbox]:checked"));
|
|
288
|
+
}
|
|
289
|
+
getCheckedValues() {
|
|
290
|
+
return this.getChecked().map((input) => input.value);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Validate there has one or more checked boxes.
|
|
294
|
+
*/
|
|
295
|
+
validateChecked(event, callback, errorMsg = true) {
|
|
296
|
+
if (!this.hasChecked()) {
|
|
297
|
+
if (errorMsg === true) errorMsg = this.getMustCheckedMessage();
|
|
298
|
+
if (typeof errorMsg === "string" && errorMsg !== "") simpleAlert(errorMsg);
|
|
299
|
+
else if (typeof errorMsg === "function") errorMsg(this);
|
|
300
|
+
if (event) {
|
|
301
|
+
event.stopPropagation();
|
|
302
|
+
event.preventDefault();
|
|
303
|
+
const target = event.currentTarget;
|
|
304
|
+
if (target.dataset.bsToggle === "modal") {
|
|
305
|
+
if (target.dataset.bsTarget) this.preventBSModal(target.dataset.bsTarget);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return this;
|
|
309
|
+
}
|
|
310
|
+
if (callback) callback(this);
|
|
311
|
+
return this;
|
|
312
|
+
}
|
|
313
|
+
async validateCheckedPromise() {
|
|
314
|
+
if (!this.hasChecked()) throw new Error("No items checked.");
|
|
315
|
+
return this;
|
|
316
|
+
}
|
|
317
|
+
getMustCheckedMessage() {
|
|
318
|
+
return __("unicorn.message.grid.checked");
|
|
319
|
+
}
|
|
320
|
+
hasChecked() {
|
|
321
|
+
return this.countChecked() > 0;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Reorder all.
|
|
325
|
+
*/
|
|
326
|
+
reorderAll(url, data) {
|
|
327
|
+
return this.updateListByTask("reorder", url, data);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Reorder items.
|
|
331
|
+
*/
|
|
332
|
+
moveItem(id, delta, url, data) {
|
|
333
|
+
data = data || {};
|
|
334
|
+
data.delta = delta;
|
|
335
|
+
return this.updateItemByTask("move", id, url, data);
|
|
336
|
+
}
|
|
337
|
+
moveUp(id, url, data) {
|
|
338
|
+
return this.moveItem(id, -1, url, data);
|
|
339
|
+
}
|
|
340
|
+
moveDown(id, url, data) {
|
|
341
|
+
return this.moveItem(id, 1, url, data);
|
|
342
|
+
}
|
|
343
|
+
getId(suffix = "") {
|
|
344
|
+
return this.form.element?.id + suffix;
|
|
345
|
+
}
|
|
418
346
|
};
|
|
419
|
-
//#
|
|
347
|
+
//#endregion
|
|
348
|
+
export { UnicornGridElement };
|
|
349
|
+
|
|
350
|
+
//# sourceMappingURL=grid.js.map
|