isundil 1 tahun lalu
induk
melakukan
aea5c9d48f
1 mengubah file dengan 27 tambahan dan 1 penghapusan
  1. 27 1
      static/public/js/uiFilter.js

+ 27 - 1
static/public/js/uiFilter.js

@@ -64,7 +64,8 @@ $(() => {
             let select = document.createElement('select');
             select.multiple = 'multiple';
             label.appendChild(select);
-            for (let i of [].concat(canBeEmpty ? [undefined] : [], possibleValues)) {
+            let allPossibleValues = [].concat(canBeEmpty ? [undefined] : [], possibleValues);
+            for (let i of allPossibleValues) {
                 let opt = document.createElement("option");
                 opt.textContent = i ? i : "(Empty)";
                 opt.value = i ?? "";
@@ -72,6 +73,31 @@ $(() => {
             }
             $(select).change(e => {
                 let val = Array.from(select.children).filter(i => i.selected).map(i => i.value === '' ? undefined : i.value);
+                Array.from(select.parentNode.querySelectorAll(".dropdown-menu li .form-check")).forEach((inputGroup, i) => {
+                    let input = inputGroup.querySelector("input");
+                    input.previousStatus = input.previousStatus || 0;
+                    if ((input.previousStatus == 0 && !input.checked && !input.indeterminate) ||
+                        (input.previousStatus == 1 && input.checked && !input.indeterminate) ||
+                        (input.previousStatus == 2 && input.checked && input.indeterminate))
+                        return;
+                    if (input.previousStatus == 0) {
+                        input.checked = true;
+                        input.indeterminate = false;
+                        input.previousStatus = 1;
+                    }
+                    else if (input.previousStatus == 1) {
+                        input.checked = true;
+                        input.indeterminate = true;
+                        input.previousStatus = 2;
+                    } else {
+                        input.checked = false;
+                        input.indeterminate = false;
+                        input.previousStatus = 0;
+                    }
+                    select.querySelectorAll("option")[i].selected = input.checked ? "selected" : "";
+                    console.log(select.querySelectorAll("option")[i]);
+                    $(select).bsMultiSelect("UpdateAppearance");
+                });
                 window.FilterManager.setFilterValue(labelText, val);
             });
             $(select).bsMultiSelect({cssPatch: {