commit 9359b9a15b5816f1a019f7dac11b79a5ebb566cf
Author: Anděl Ondřej <ondrej.andel@marbes.cz>
Date:   Thu Apr 29 19:27:32 2021 +0200

    Bug #8759: Opravit pole manuscriptu

diff --git a/application/view/modals/editModal.html b/application/view/modals/editModal.html
index c8e710d..e26de6f 100644
--- a/application/view/modals/editModal.html
+++ b/application/view/modals/editModal.html
@@ -25,7 +25,7 @@
                     </div>
                     <div class="row my-1">
                         <div class="col-xs-12 col-sm-4">
-                            <label for="manuscript-m">Rukopisy:</label>
+                            <label for="manuscript-m">Rukopisy: <b class="required">*</b></label>
                         </div>
                         <div class="col-xs-12 col-sm-8">
                             <select id="manuscript-m" multiple>
@@ -331,10 +331,12 @@
             modal.find('#submit-but').click(() => createData(modal));
 
             enableSubmit(modal);
+            manuChange(modal);
             modal.find("#lemma_edit").change(() => enableSubmit(modal));
             modal.find("#word").change(() => enableSubmit(modal));
             modal.find("#position").change(() => enableSubmit(modal));
             modal.find("#wordclass").change(() => enableSubmit(modal));
+            modal.find("#manuscript-m").change(() => manuChange(modal));
         } else {
             const data_obj = data[pseudo_id];
             modal.find('#submit-but').text("Upravit");
@@ -346,10 +348,12 @@
             irregularMChange(modal);
 
             enableSubmit(modal);
+            manuChange(modal);
             modal.find("#lemma_edit").change(() => enableSubmit(modal));
             modal.find("#word").change(() => enableSubmit(modal));
             modal.find("#position").change(() => enableSubmit(modal));
             modal.find("#wordclass").change(() => enableSubmit(modal));
+            modal.find("#manuscript-m").change(() => manuChange(modal));
         }
     });
 
@@ -629,7 +633,7 @@
 
             modal.find("#word").val(data.word);
             modal.find("#lemma_edit").val(data.lemma.lemma);
-            modal.find("#manuscript-m").val(data.manuscript);//TODO not sure if this one works... kinda does what it wants
+            setManuscriptValue(modal, data.manuscript);
 
             //dynamic setting
             const morphem = data.tag.tag;
@@ -663,11 +667,16 @@
     }
 
     function enableSubmit(modal) {
+
+        let ms_value = getManuscriptValue(modal);
         if (
             modal.find("#lemma_edit")[0].value === "" ||
             modal.find("#word")[0].value === "" ||
             modal.find("#position")[0].value === "" ||
-            modal.find("#wordclass")[0].value === ""
+            modal.find("#wordclass")[0].value === "" ||
+            ms_value === undefined ||
+            ms_value === null ||
+            ms_value.length === 0
         ) {
             modal.find("#submit-but").prop("disabled", true);
         } else {
@@ -705,14 +714,8 @@
         formData.append("word", modal.find("#word")[0].value);
         formData.append("lemma", modal.find("#lemma_edit")[0].value);
 
-        //this is to get data from manuscript --> possible better?
-        var elements = modal.find("#manuscript-m").data('multiSelectContainer').find('input:checked');
-        let ms_value = [];
-        Object.values(elements).forEach((item) => {
-            if(item.value !== undefined){
-                ms_value.push(""+item.value);
-            }
-        });
+        //this is to get data from manuscript
+        let ms_value = getManuscriptValue(modal);
 
         formData.append("manuscript", ms_value.join());
         formData.append("context", modal.find("#context")[0].value);
@@ -759,6 +762,50 @@
         return formData;
     }
 
+    function getManuscriptValue(modal){
+        var elements = modal.find("#manuscript-m").data('multiSelectContainer').find('input:checked');
+        let ms_value = [];
+        Object.values(elements).forEach((item) => {
+            if(item.value !== undefined){
+                ms_value.push(""+item.value);
+            }
+        });
+        return ms_value;
+    }
+
+    function setManuscriptValue(modal, value){
+        var elements = modal.find("#manuscript-m").data('multiSelectContainer').find('input');
+        Object.values(elements).forEach((item) => {
+            if(value.includes(parseInt(item.value))){
+                item.checked = true;
+            } else {
+                item.checked = false;
+            }
+        });
+    }
+
+    function manuChange(modal){
+        var elements = modal.find("#manuscript-m").data('multiSelectContainer').find('input:checked');
+        let docCount = 0;
+        Object.values(elements).forEach((item) => {
+            if(item.value !== undefined){
+                docCount++;
+            }
+        });
+
+        let extra = "";
+        if(docCount === 1){
+            extra += " rukopis";
+        } else if(docCount < 5){
+            extra += " rukopisy";
+        } else {
+            extra += " rukopisů";
+        }
+        modal.find(".multi-select-button")[0].innerText = docCount+extra;
+
+        enableSubmit(modal);
+    }
+
     function moodMChange(modal) {
         if(modal.find("#mood")[0].value !== ""){
             modal.find("#irregular").prop('disabled', true);
