1
async function choiceOneUUID(element, method) {
2
var display_title = element.getAttribute('display-title')
3
var filter = element.getAttribute('filter')
4
var is_filter = element.getAttribute('is-filter')
5
var model_name = element.getAttribute('model-name')
8
searchPlaceholderValue: 'Start typing to search',
9
placeholderValue: "Enter " + display_title
11
if (method === 'get' || element.getAttribute('readonly')) {
12
attrs.removeItemButton = false
14
attrs.removeItemButton = true
16
let choices = new Choices(element, attrs);
17
if (method === 'get' || element.getAttribute('readonly')) {
19
} else if (method === 'update' && element.getAttribute('readonly')) {
20
choices.containerInner.element.classList.add('disabled');
24
function check_valid(event) {
25
if (method === 'get' || element.getAttribute('readonly')) {
29
if (element.required) {
31
if (event.type === 'choice') {
32
if (event.detail.choice.value) {
33
choices.containerInner.element.classList.remove('is-invalid');
34
choices.containerInner.element.classList.add('is-valid');
36
} else if (event.type === 'removeItem') {
37
if (event.detail.value) {
38
if (!choices.containerInner.element.innerText) {
39
choices.containerInner.element.classList.add('is-invalid');
40
choices.containerInner.element.classList.remove('is-valid');
42
choices.containerInner.element.classList.add('is-valid');
43
choices.containerInner.element.classList.remove('is-invalid');
50
if (!choices.containerInner.element.innerText) {
51
choices.containerInner.element.classList.add('is-invalid');
52
choices.containerInner.element.classList.remove('is-valid');
54
choices.containerInner.element.classList.add('is-valid');
55
choices.containerInner.element.classList.remove('is-invalid');
58
} else if (element.id.includes('__in')) {
59
choices.containerInner.element.classList.remove('is-invalid');
60
choices.containerInner.element.classList.remove('is-invalid');
63
choices.containerInner.element.classList.remove('is-invalid');
67
choices.containerInner.element.classList.add('is-valid');
71
choices.containerInner.element.classList.add('form-control');
73
async function searchChoices(value) {
75
const items = await fetch('/base/search?model=' + model_name + '&filter=' + filter + '&search=' + encodeURIComponent(value));
76
const results = await items.json();
77
if (0 === results.length) {
86
async function getValues() {
89
let value = await choices.getValue();
91
value.label = 'Loading....'
95
choices.setValue([value])
102
var maybe_cache = Singleton.results[id__in]
104
return [{value: id__in, label: maybe_cache}]
106
Singleton.pushUUID(model_name, id__in)
108
if (Singleton.results[id__in]) {
109
return [{value: id__in, label: Singleton.results[id__in]}]
111
await new Promise(r => setTimeout(r, 50));
119
let init_values = await getValues()
120
choices.removeActiveItems()
121
choices.clearChoices()
122
choices.setValue(init_values)
123
element.addEventListener('search', async e => {
125
let value = e.detail.value;
126
choices.clearChoices()
128
await searchChoices(value)
133
element.addEventListener('choice', function (event) {
136
element.addEventListener('showDropdown', async e => {
137
choices.clearChoices()
139
await searchChoices('')
142
element.addEventListener('removeItem', function (event) {
148
async function choiceMultiUUID(element, method) {
149
var display_title = element.getAttribute('display-title')
150
var filter = element.getAttribute('filter')
151
var is_filter = element.getAttribute('is-filter')
152
var model_name = element.getAttribute('model-name')
154
placeholderValue: "Enter " + display_title
156
if (method === 'get' || element.getAttribute('readonly')) {
157
attrs.removeItemButton = false
158
attrs.placeholderValue = ''
160
attrs.removeItemButton = true
162
let choices = new Choices(element, attrs);
163
if (method === 'get' || element.getAttribute('readonly')) {
165
} else if (method === 'update' && element.getAttribute('readonly')) {
166
choices.containerInner.element.classList.add('disabled');
170
function check_valid(event) {
171
if (method === 'get' || element.getAttribute('readonly')) {
175
if (element.required) {
177
if (event.type === 'choice') {
178
if (event.detail.choice.value) {
179
choices.containerInner.element.classList.remove('is-invalid');
180
choices.containerInner.element.classList.add('is-valid');
182
} else if (event.type === 'removeItem') {
183
if (event.detail.value) {
184
if (!choices.containerInner.element.innerText) {
185
choices.containerInner.element.classList.add('is-invalid');
186
choices.containerInner.element.classList.remove('is-valid');
188
choices.containerInner.element.classList.add('is-valid');
189
choices.containerInner.element.classList.remove('is-invalid');
196
if (!choices.containerInner.element.innerText) {
197
choices.containerInner.element.classList.add('is-invalid');
198
choices.containerInner.element.classList.remove('is-valid');
200
choices.containerInner.element.classList.add('is-valid');
201
choices.containerInner.element.classList.remove('is-invalid');
204
} else if (element.id.includes('__in')) {
205
choices.containerInner.element.classList.remove('is-invalid');
206
choices.containerInner.element.classList.remove('is-invalid');
209
choices.containerInner.element.classList.remove('is-invalid');
213
choices.containerInner.element.classList.add('is-valid');
217
choices.containerInner.element.classList.add('form-control');
219
async function getValues() {
221
let values = await choices.getValue();
224
for (let v in values) {
225
var maybe_cache = Singleton.results[v]
227
Singleton.pushUUID(model_name, values[v].value)
232
for (let v in values) {
233
id__in = values[v].value
234
if (Singleton.results[id__in]) {
236
value: values[v].label,
237
label: Singleton.results[id__in]
242
if (values.length === 0) {
245
await new Promise(r => setTimeout(r, 50));
249
let init_values = await getValues()
250
choices.removeActiveItems()
251
choices.clearChoices()
252
choices.setValue(init_values)
253
element.addEventListener('search', async e => {
255
let value = e.detail.value;
256
choices.clearChoices()
257
choices.setChoices(async () => {
259
const items = await fetch('/base/search?model=' + model_name + '&filter=' + filter + '&search=' + encodeURIComponent(value));
260
const results = await items.json();
261
if (0 === results.length) {
267
choices.input.element.style = ""
270
e.target.parentNode.querySelector('input').focus();
272
choices.input.element.style = ""
277
async function choicesMultiBadges(element, method) {
278
var model_name = element.getAttribute('model-name')
280
async function getValues() {
282
var str = element.innerText.replace(/[\s\n\t]+/g, ' ').trim()
283
let values = str ? str.split(',') : [];
285
for (let v in values) {
286
var maybe_cache = Singleton.results[values[v]]
288
Singleton.pushUUID(model_name, values[v])
293
for (let v in values) {
294
if (Singleton.results[values[v]]) {
297
label: Singleton.results[values[v]]
302
if (values.length === 0) {
305
await new Promise(r => setTimeout(r, 50));
309
let res = await getValues()
310
element.innerText = ''
311
res.forEach(function (line) {
313
element.insertAdjacentHTML('beforeend', '<span class="badge bg-secondary">' + line.label + '</span>');
317
async function choiceMultiBabel() {
318
var display_title = element.getAttribute('display-title')
319
var filter = element.getAttribute('filter')
320
var is_filter = element.getAttribute('is-filter')
321
var model_name = element.getAttribute('model-name')
323
placeholderValue: "Enter " + display_title
325
if (method === 'get' || element.getAttribute('readonly')) {
326
attrs.removeItemButton = false
328
attrs.removeItemButton = true
330
let choices = new Choices(element, attrs);
331
if (method === 'get' || element.getAttribute('readonly')) {
332
choices.containerInner.element.classList.add('disabled');
335
choices.containerInner.element.classList.add('form-control');
337
function check_valid() {
338
if (element.required) {
339
choices.containerInner.element.classList.add('is-invalid');
340
choices.containerInner.element.classList.remove('is-valid');
342
choices.containerInner.element.classList.remove('is-invalid');
343
choices.containerInner.element.classList.add('is-valid');
351
choices.setChoices(async () => {
353
const items = await fetch('/base/search?model=' + model_name + '&search=');
354
const results = await items.json();
355
if (0 === results.length) {
363
choices.input.element.focus()
371
async function choiceOneBabel() {
372
var display_title = element.getAttribute('display-title')
373
var filter = element.getAttribute('filter')
374
var is_filter = element.getAttribute('is-filter')
375
var model_name = element.getAttribute('model-name')
377
placeholderValue: "Enter " + display_title
379
if (method === 'get' || element.getAttribute('readonly')) {
380
attrs.removeItemButton = false
382
attrs.removeItemButton = true
384
let choices = new Choices(element, attrs);
385
if (method === 'get' || element.getAttribute('readonly')) {
386
choices.containerInner.element.classList.add('disabled');
389
choices.containerInner.element.classList.add('form-control');
392
function check_valid() {
393
if (element.required) {
394
choices.containerInner.element.classList.add('is-invalid');
395
choices.containerInner.element.classList.remove('is-valid');
397
choices.containerInner.element.classList.remove('is-invalid');
398
choices.containerInner.element.classList.add('is-valid');
406
choices.setChoices(async () => {
408
const items = await fetch('/base/search?model=' + model_name + '&search=');
409
const results = await items.json();
410
if (0 === results.length) {
418
choices.input.element.focus()
425
async function choiceMultiEnum(element, method) {
426
var display_title = element.getAttribute('display-title')
427
var filter = element.getAttribute('filter')
428
var is_filter = element.getAttribute('is-filter')
429
var model_name = element.getAttribute('model-name')
431
placeholderValue: "Enter " + display_title
433
if (method === 'get' || element.getAttribute('readonly')) {
434
attrs.removeItemButton = false
436
attrs.removeItemButton = true
438
let choices = new Choices(element, attrs);
439
if (method === 'get' || element.getAttribute('readonly')) {
440
choices.containerInner.element.classList.add('disabled');
443
choices.containerInner.element.classList.add('form-control');
445
function check_valid(event) {
446
if (method === 'get' || element.getAttribute('readonly')) {
450
if (element.required) {
452
if (event.type === 'choice') {
453
if (event.detail.choice.value) {
454
choices.containerInner.element.classList.remove('is-invalid');
455
choices.containerInner.element.classList.add('is-valid');
457
} else if (event.type === 'removeItem') {
458
if (event.detail.value) {
459
if (!choices.containerInner.element.innerText) {
460
choices.containerInner.element.classList.add('is-invalid');
461
choices.containerInner.element.classList.remove('is-valid');
463
choices.containerInner.element.classList.add('is-valid');
464
choices.containerInner.element.classList.remove('is-invalid');
471
if (!choices.containerInner.element.innerText) {
472
choices.containerInner.element.classList.add('is-invalid');
473
choices.containerInner.element.classList.remove('is-valid');
475
choices.containerInner.element.classList.add('is-valid');
476
choices.containerInner.element.classList.remove('is-invalid');
479
} else if (element.id.includes('__in')) {
480
choices.containerInner.element.classList.remove('is-invalid');
481
choices.containerInner.element.classList.remove('is-invalid');
484
choices.containerInner.element.classList.remove('is-invalid');
488
choices.containerInner.element.classList.add('is-valid');
492
choices.containerInner.element.classList.add('form-control');
498
async function createModal(modal_id) {
499
var modal = new bootstrap.Modal(modal_id)
500
function createDragModal(modal) {
501
var header = modal.querySelector('.modal-header');
503
header.onmousedown = function (e) {
504
var offsetX = e.clientX - modal.getBoundingClientRect().left;
505
var offsetY = e.clientY - modal.getBoundingClientRect().top;
507
function mouseMoveHandler(e) {
508
modal.style.position = 'absolute';
509
modal.style.left = (e.clientX - offsetX) + 'px';
510
modal.style.top = (e.clientY - offsetY) + 'px';
513
function mouseUpHandler() {
514
document.removeEventListener('mousemove', mouseMoveHandler);
515
document.removeEventListener('mouseup', mouseUpHandler);
518
document.addEventListener('mousemove', mouseMoveHandler);
519
document.addEventListener('mouseup', mouseUpHandler);
523
document.addEventListener('hidden.bs.modal', function (event) {
525
event.target.remove()