commit fb32f0e8ea00e9b59acd115931a64e6dc2cc839f
Author: Anděl Ondřej <ondrej.andel@marbes.cz>
Date:   Mon Mar 29 17:34:56 2021 +0200

    Feature #8349: Napojení metod serveru

diff --git a/application/view/library/vanillaSelectBox/vanillaSelectBox.js b/application/view/library/vanillaSelectBox/vanillaSelectBox.js
index 2917735..0e3ba6c 100644
--- a/application/view/library/vanillaSelectBox/vanillaSelectBox.js
+++ b/application/view/library/vanillaSelectBox/vanillaSelectBox.js
@@ -22,6 +22,18 @@ previous version : v0.24 : corrected bug affecting options with more than one cl
 https://github.com/PhilippeMarcMeyer/vanillaSelectBox
 */
 
+
+function getValues(id) {
+    let result = [];
+    let collection = document.querySelectorAll("#" + id + " option");
+    collection.forEach(function (x) {
+        if (x.selected) {
+            result.push(x.value);
+        }
+    });
+    return result;
+}
+
 let VSBoxCounter = function () {
     let count = 0;
     let instances = [];
@@ -529,7 +541,19 @@ function vanillaSelectBox(domSelector, options) {
                         selectedTexts = nrActives + " " + wordForItems;
                     }
                 }
-                self.title.textContent = selectedTexts;
+                //self.title.textContent = selectedTexts;
+                let result = nrActives;
+                if(nrActives < 1){
+                    result = "Nevybráno";
+                } else if(nrActives === 1){
+                    result += " rukopis";
+                } else if(nrActives < 5){
+                    result += " rukopisy";
+                } else {
+                    result += " rukopisů";
+                }
+
+                self.title.textContent = result;
 
                 self.checkUncheckAll();
                 self.privateSendChange();
@@ -716,7 +740,19 @@ vanillaSelectBox.prototype.setValue = function (values) {
                         selectedTexts = nrActives + " " + wordForItems;
                     }
                 }
-                self.title.textContent = selectedTexts;
+                //self.title.textContent = selectedTexts;
+                let result = nrActives;
+                if(nrActives < 1){
+                    result = "Nevybráno";
+                } else if(nrActives === 1){
+                    result += " rukopis";
+                } else if(nrActives < 5){
+                    result += " rukopisy";
+                } else {
+                    result += " rukopisů";
+                }
+
+                self.title.textContent = result;
                 self.privateSendChange();
             }
             self.checkUncheckAll();
diff --git a/application/view/searchContent.php b/application/view/searchContent.php
index f2ef111..d9d5c05 100644
--- a/application/view/searchContent.php
+++ b/application/view/searchContent.php
@@ -2,38 +2,39 @@
     window.onload = function() {
         let sourceSelect = new vanillaSelectBox("#source");
         filtersChange();
-        fetchData();
+        fetchData(false);
     };
 </script>
 
 <div class="search-filters container" onload="filtersChange()">
     <div class="row">
-        <div class="mr-3">
-            <label for="lemma" class="mr-2">Lemma</label>
-            <input type="text" id="lemma">
-        </div>
         <div class="mr-3">
             <label for="wordshape" class="mr-2">Slovo</label>
             <input type="text" id="wordshape">
         </div>
+        <div class="mr-3">
+            <label for="lemma" class="mr-2">Lemma</label>
+            <input type="text" id="lemma">
+        </div>
         <div class="mr-3">
             <label for="source" class="mr-2">Rukopisný pramen</label>
             <select id="source" multiple>
-                <option value = "1">C</option>
-                <option value = "2">Cr</option>
-                <option value = "3">F</option>
-                <option value = "4">Fs</option>
-                <option value = "5">H</option>
-                <option value = "6">Hr</option>
-                <option value = "7">Jš</option>
-                <option value = "8">K</option>
-                <option value = "9">L</option>
-                <option value = "10">M</option>
-                <option value = "11">O</option>
-                <option value = "12">P</option>
-                <option value = "13">S</option>
-                <option value = "14">V</option>
-                <option value = "15">Z</option>
+                <option value = "0">rukopis Vídeňský</option>
+                <option value = "1">zlomky Hanušovy</option>
+                <option value = "2">zlomky Hradecké</option>
+                <option value = "3">rukopis Cambridžský</option>
+                <option value = "4">rukopis Františkánský</option>
+                <option value = "5">zlomek Olomoucký</option>
+                <option value = "6">fragment Strahovský</option>
+                <option value = "7">zlomky Klementinsko-Křižovnické</option>
+                <option value = "8">zlomky Mnichovské</option>
+                <option value = "9">rukopis Lobkovický</option>
+                <option value = "10">rukopis Pelclův</option>
+                <option value = "11">rukopis Cerronský</option>
+                <option value = "12">rukopis Fürstenberský</option>
+                <option value = "13">rukopis Zebererův</option>
+                <option value = "14">vydání Pavla Ješína z Bezdězi, Praha 1620</option>
+                <option value = "15">básně připsané při Pulkavově kronice v rukopisu Litoměřickém</option>
             </select>
         </div>
         <div class="mr-3">
@@ -46,16 +47,16 @@
             <label for="wordclass" class="mr-2">Slovní druh</label>
             <select onchange="filtersChange()"  id="wordclass">
                 <option selected="selected" value = "">Nevybráno</option>
-                <option value = "1">Substantiva</option>
-                <option value = "2">Adjektiva</option>
-                <option value = "3">Pronomina</option>
-                <option value = "4">Numeralia</option>
-                <option value = "5">Verba</option>
-                <option value = "6">Adverbia</option>
-                <option value = "7">Prepozice</option>
-                <option value = "8">Konjunkce</option>
-                <option value = "9">Interjekce</option>
-                <option value = "10">Partikule</option>
+                <option value = "N">Substantiva</option>
+                <option value = "A">Adjektiva</option>
+                <option value = "P">Pronomina</option>
+                <option value = "C">Numeralia</option>
+                <option value = "V">Verba</option>
+                <option value = "D">Adverbia</option>
+                <option value = "R">Prepozice</option>
+                <option value = "J">Konjunkce</option>
+                <option value = "I">Interjekce</option>
+                <option value = "T">Partikule</option>
             </select>
         </div>
 
@@ -63,7 +64,7 @@
             function filtersChange() {
                 const value = document.getElementById("wordclass").value;
                 switch (value) {
-                    case "1":
+                    case "N":
                         setFilerVisibility([
                             true,
                             true,
@@ -79,7 +80,7 @@
                             false
                         ]);
                         break;
-                    case "2":
+                    case "A":
                         setFilerVisibility([
                             true,
                             true,
@@ -95,7 +96,7 @@
                             false
                         ]);
                         break;
-                    case "3":
+                    case "P":
                         setFilerVisibility([
                             true,
                             true,
@@ -111,7 +112,7 @@
                             false
                         ]);
                         break;
-                    case "4":
+                    case "C":
                         setFilerVisibility([
                             true,
                             true,
@@ -127,7 +128,7 @@
                             false
                         ]);
                         break;
-                    case "5":
+                    case "V":
                         setFilerVisibility([
                             true,
                             true,
@@ -143,7 +144,7 @@
                             false
                         ]);
                         break;
-                    case "6":
+                    case "D":
                         setFilerVisibility([
                             false,
                             false,
@@ -159,7 +160,7 @@
                             false
                         ]);
                         break;
-                    case "7":
+                    case "R":
                         setFilerVisibility([
                             true,
                             false,
@@ -175,7 +176,7 @@
                             false
                         ]);
                         break;
-                    case "8":
+                    case "J":
                         setFilerVisibility([
                             false,
                             false,
@@ -191,7 +192,7 @@
                             true
                         ]);
                         break;
-                    case "9":
+                    case "I":
                         setFilerVisibility([
                             false,
                             false,
@@ -207,7 +208,7 @@
                             false
                         ]);
                         break;
-                    case "10":
+                    case "T":
                         setFilerVisibility([
                             false,
                             false,
@@ -392,7 +393,7 @@
         </div>
 
         <!-- send button-->
-        <button class="ml-auto btn" onclick="filterData()">
+        <button class="ml-auto btn" onclick="fetchData(true)">
             Filtrovat
         </button>
     </div>
@@ -411,25 +412,67 @@
         </thead>
         <tbody id="search-table">
             <script>
-                function filterData () {
-                    //TODO
-                }
-
                 let data;
+                function filterData (formData) {
+                    //regular
+                    formData.append("lemma", document.getElementById("lemma").value);
+                    formData.append("word", document.getElementById("wordshape").value);
+
+                    //positions
+                    const positionSplit = document.getElementById("location").value.split("/");
+                    formData.append("position1", positionSplit[0] !== undefined ? positionSplit[0] : "");
+                    formData.append("position2", positionSplit[1] !== undefined ? positionSplit[1] : "");
+                    formData.append("positiondetail", positionSplit[2] !== undefined ? positionSplit[2] : "");
 
-                function fetchData () {
+                    //multiselect
+                    formData.append("manuscript", getValues("source"));
+
+                    const pos = document.getElementById("wordclass").value;
+                    formData.append("tag_pos", pos);
+                    //those upcoming are dynamic based on the previous field
+                    formData.append("tag_case", document.getElementById("case").value);
+                    formData.append("tag_number", document.getElementById("countability").value);
+                    formData.append("tag_gender", document.getElementById("gender").value);
+                    formData.append("tag_degree", document.getElementById("grade").value);
+                    formData.append("tag_shape", document.getElementById("shape").value);
+                    formData.append("tag_num", "");//THIS ONE IS WORTHLESS
+
+                    if(pos === "P"){
+                        formData.append("tag_sentence", document.getElementById("type").value);
+                    } else if(pos === "V"){
+                        formData.append("tag_sentence", document.getElementById("mood").value);
+                    } else if(pos === "J"){
+                        formData.append("tag_sentence", document.getElementById("k-type").value);
+                    }
+
+                    formData.append("tag_verb_person", document.getElementById("person").value);
+                    formData.append("tag_verb_time", document.getElementById("time").value);
+                    formData.append("tag_verb_degree", document.getElementById("vid").value);
+                    formData.append("tag_verb_aspect", document.getElementById("v-type").value);
+                }
+
+                function fetchData (filter = true) {
                     // (A1) GET SEARCH TERM
                     const formData = new FormData();
                     formData.append("page", "0");//TODO PAGING
                     formData.append("items_per_page", "50");//TODO PAGING
                     formData.append("finished", "true");//TODO ADMIN
 
+                    if(filter){
+                        filterData(formData);
+                    }
+
                     // (A2) AJAX - USE HTTP:// NOT FILE://
                     let xhr = new XMLHttpRequest();
                     xhr.open("POST", "./controller/TableController.php");
                     xhr.onload = function(){
                         let search = this.response;
                         let parsedJSON = JSON.parse(search);
+                        if(parsedJSON.count === 0){
+                            document.getElementById("no-data-label").style.display = "";
+                        } else {
+                            document.getElementById("no-data-label").style.display = "none";
+                        }
                         data = parsedJSON.data;
                         renderData(parsedJSON.data);
                     };
@@ -489,6 +532,8 @@
             </script>
         </tbody>
     </table>
+
+    <h3 id="no-data-label" class="mx-auto text-center font-italic">Žádná data nebyla nalezena</h3>
 </div>
 
 
