Projekt

Obecné

Profil

Stáhnout (26.1 KB) Statistiky
| Větev: | Revize:
1
<script>
2
    let pageIndex = 0;
3
    let itemPerPage = 50;
4
    let itemCount = 0;
5
    let pageCount = 0;
6

    
7
    //what to do when page renders
8
    window.onload = function() {
9
        let sourceSelect = new vanillaSelectBox("#source");
10
        filtersChange();
11
        fetchData(false);
12

    
13
        //page-label listener
14
        document.getElementById('page-label').addEventListener('keyup',function(e){
15
            if (e.key === 'Enter' || e.keyCode === 13) {
16
                this.blur();
17
            }
18
        });
19
    };
20
</script>
21

    
22
<div class="search-filters container" onload="filtersChange()">
23
    <div class="row">
24
        <div class="mr-3">
25
            <label for="wordshape" class="mr-2">Slovo</label>
26
            <input type="text" id="wordshape">
27
        </div>
28
        <div class="mr-3">
29
            <label for="lemma" class="mr-2">Lemma</label>
30
            <input type="text" id="lemma">
31
        </div>
32
        <div class="mr-3">
33
            <label for="source" class="mr-2">Rukopisný pramen</label>
34
            <select id="source" multiple>
35
                <option value = "0">rukopis Vídeňský</option>
36
                <option value = "1">zlomky Hanušovy</option>
37
                <option value = "2">zlomky Hradecké</option>
38
                <option value = "3">rukopis Cambridžský</option>
39
                <option value = "4">rukopis Františkánský</option>
40
                <option value = "5">zlomek Olomoucký</option>
41
                <option value = "6">fragment Strahovský</option>
42
                <option value = "7">zlomky Klementinsko-Křižovnické</option>
43
                <option value = "8">zlomky Mnichovské</option>
44
                <option value = "9">rukopis Lobkovický</option>
45
                <option value = "10">rukopis Pelclův</option>
46
                <option value = "11">rukopis Cerronský</option>
47
                <option value = "12">rukopis Fürstenberský</option>
48
                <option value = "13">rukopis Zebererův</option>
49
                <option value = "14">vydání Pavla Ješína z Bezdězi, Praha 1620</option>
50
                <option value = "15">básně připsané při Pulkavově kronice v rukopisu Litoměřickém</option>
51
            </select>
52
        </div>
53
        <div class="mr-3">
54
            <label for="location" class="mr-2">Pozice</label>
55
            <input type="text" id="location">
56
        </div>
57

    
58

    
59
        <div class="mr-3">
60
            <label for="wordclass" class="mr-2">Slovní druh</label>
61
            <select onchange="filtersChange()"  id="wordclass">
62
                <option selected="selected" value = "">Nevybráno</option>
63
                <option value = "N">Substantiva</option>
64
                <option value = "A">Adjektiva</option>
65
                <option value = "P">Pronomina</option>
66
                <option value = "C">Numeralia</option>
67
                <option value = "V">Verba</option>
68
                <option value = "D">Adverbia</option>
69
                <option value = "R">Prepozice</option>
70
                <option value = "J">Konjunkce</option>
71
                <option value = "I">Interjekce</option>
72
                <option value = "T">Partikule</option>
73
            </select>
74
        </div>
75

    
76
        <script>
77
            function filtersChange() {
78
                const value = document.getElementById("wordclass").value;
79
                switch (value) {
80
                    case "N":
81
                        setFilerVisibility([
82
                            true,
83
                            true,
84
                            true,
85
                            false,
86
                            false,
87
                            false,
88
                            false,
89
                            false,
90
                            false,
91
                            false,
92
                            false,
93
                            false,
94
                            false
95
                        ]);
96
                        break;
97
                    case "A":
98
                        setFilerVisibility([
99
                            true,
100
                            true,
101
                            true,
102
                            true,
103
                            true,
104
                            false,
105
                            false,
106
                            false,
107
                            false,
108
                            false,
109
                            false,
110
                            false,
111
                            false
112
                        ]);
113
                        break;
114
                    case "P":
115
                        setFilerVisibility([
116
                            true,
117
                            true,
118
                            true,
119
                            false,
120
                            false,
121
                            true,
122
                            false,
123
                            false,
124
                            false,
125
                            false,
126
                            false,
127
                            false,
128
                            false
129
                        ]);
130
                        break;
131
                    case "C":
132
                        setFilerVisibility([
133
                            true,
134
                            true,
135
                            true,
136
                            false,
137
                            false,
138
                            false,
139
                            false,
140
                            false,
141
                            false,
142
                            false,
143
                            false,
144
                            false,
145
                            false
146
                        ]);
147
                        break;
148
                    case "V":
149
                        setFilerVisibility([
150
                            true,
151
                            true,
152
                            true,
153
                            false,
154
                            false,
155
                            false,
156
                            true,
157
                            true,
158
                            true,
159
                            true,
160
                            true,
161
                            true,
162
                            false
163
                        ]);
164
                        break;
165
                    case "D":
166
                        setFilerVisibility([
167
                            false,
168
                            false,
169
                            false,
170
                            false,
171
                            true,
172
                            false,
173
                            false,
174
                            false,
175
                            false,
176
                            false,
177
                            false,
178
                            false,
179
                            false
180
                        ]);
181
                        break;
182
                    case "R":
183
                        setFilerVisibility([
184
                            true,
185
                            false,
186
                            false,
187
                            false,
188
                            false,
189
                            false,
190
                            false,
191
                            false,
192
                            false,
193
                            false,
194
                            false,
195
                            false,
196
                            false
197
                        ]);
198
                        break;
199
                    case "J":
200
                        setFilerVisibility([
201
                            false,
202
                            false,
203
                            false,
204
                            false,
205
                            false,
206
                            false,
207
                            false,
208
                            false,
209
                            false,
210
                            false,
211
                            false,
212
                            false,
213
                            true
214
                        ]);
215
                        break;
216
                    case "I":
217
                        setFilerVisibility([
218
                            false,
219
                            false,
220
                            false,
221
                            false,
222
                            false,
223
                            false,
224
                            false,
225
                            false,
226
                            false,
227
                            false,
228
                            false,
229
                            false,
230
                            false
231
                        ]);
232
                        break;
233
                    case "T":
234
                        setFilerVisibility([
235
                            false,
236
                            false,
237
                            false,
238
                            false,
239
                            false,
240
                            false,
241
                            false,
242
                            false,
243
                            false,
244
                            false,
245
                            false,
246
                            false,
247
                            false
248
                        ]);
249
                        break;
250
                    default:
251
                        setFilerVisibility([
252
                            false,
253
                            false,
254
                            false,
255
                            false,
256
                            false,
257
                            false,
258
                            false,
259
                            false,
260
                            false,
261
                            false,
262
                            false,
263
                            false,
264
                            false
265
                        ]);
266
                        break;
267
                }
268
            }
269

    
270
            function setFilerVisibility(visibility) {
271
                const id = [
272
                    "filter-case",
273
                    "filter-countability",
274
                    "filter-gender",
275
                    "filter-shape",
276
                    "filter-grade",
277
                    "filter-type",
278
                    "filter-mood",
279
                    "filter-irregular",
280
                    "filter-person",
281
                    "filter-time",
282
                    "filter-vid",
283
                    "filter-v-type",
284
                    "filter-k-type"
285
                ];
286

    
287
                for(let i = 0; i < id.length &&  i < visibility.length; i++){
288
                    document.getElementById(id[i]).style.display = visibility[i] === true ? "" : "none";
289
                    document.getElementById(id[i].replace("filter-", "")).value = "";
290
                }
291
            }
292
        </script>
293

    
294
        <!-- conditionaly rendered filters-->
295
        <div class="mr-3" id="filter-case">
296
            <label for="case" class="mr-2">Pád</label>
297
            <select id="case">
298
                <option selected="selected" value = "">Nevybráno</option>
299
                <option value = "1">Nominativ</option>
300
                <option value = "2">Genitiv</option>
301
                <option value = "3">Dativ</option>
302
                <option value = "4">Akuzativ</option>
303
                <option value = "5">Vokativ</option>
304
                <option value = "6">Lokál</option>
305
                <option value = "7">Instrumentál</option>
306
            </select>
307
        </div>
308
        <div class="mr-3" id="filter-countability">
309
            <label for="countability" class="mr-2">Číslo</label>
310
            <select id="countability">
311
                <option selected="selected" value = "">Nevybráno</option>
312
                <option value = "S">Singulár</option>
313
                <option value = "P">Plurál</option>
314
                <option value = "D">Duál</option>
315
            </select>
316
        </div>
317
        <div class="mr-3" id="filter-gender">
318
            <label for="gender" class="mr-2">Rod</label>
319
            <select id="gender">
320
                <option selected="selected" value = "">Nevybráno</option>
321
                <option value = "M">Maskulinum</option>
322
                <option value = "F">Femininum</option>
323
                <option value = "N">Neutrum</option>
324
            </select>
325
        </div>
326
        <div class="mr-3" id="filter-shape">
327
            <label for="shape" class="mr-2">Tvar</label>
328
            <select id="shape">
329
                <option selected="selected" value = "">Nevybráno</option>
330
                <option value = "C">Složený</option>
331
                <option value = "N">Jmenný</option>
332
            </select>
333
        </div>
334
        <div class="mr-3" id="filter-grade">
335
            <label for="grade" class="mr-2">Stupeň</label>
336
            <select id="grade">
337
                <option selected="selected" value = "">Nevybráno</option>
338
                <option value = "1">Pozitiv</option>
339
                <option value = "2">Komparativ</option>
340
                <option value = "3">Superlativ</option>
341
            </select>
342
        </div>
343
        <div class="mr-3" id="filter-type">
344
            <label for="type" class="mr-2">Druh</label>
345
            <select id="type">
346
                <option selected="selected" value = "">Nevybráno</option>
347
                <option value = "P">Personalia</option>
348
                <option value = "S">Posesiva</option>
349
                <option value = "D">Demonstrativa</option>
350
                <option value = "Q">Interogativa</option>
351
                <option value = "J">Relativa</option>
352
                <option value = "Z">Indefinita</option>
353
                <option value = "L">Limitativa</option>
354
                <option value = "W">Negativa</option>
355
            </select>
356
        </div>
357
        <div class="mr-3" id="filter-mood">
358
            <label for="mood" class="mr-2">Způsob</label>
359
            <select id="mood" onchange="moodChange()">
360
                <option selected="selected" value = "">Nevybráno</option>
361
                <option value = "d">Indikativ</option>
362
                <option value = "i">Imperativ</option>
363
                <option value = "c">Kondicionál</option>
364
            </select>
365
        </div>
366
        <div class="mr-3" id="filter-irregular">
367
            <label for="irregular" class="mr-2">Neurčitý slovesný tvar</label>
368
            <select id="irregular" onchange="irregularChange()">
369
                <option selected="selected" value = "">Nevybráno</option>
370
                <option value = "f">Infinitiv</option>
371
                <option value = "S">Supinum</option>
372
                <option value = "e">Přech. přítomný</option>
373
                <option value = "m">Přech. minulý</option>
374
                <option value = "A">Part. perf. akt.</option>
375
                <option value = "P">Part. perf. pas.</option>
376
            </select>
377
        </div>
378
        <div class="mr-3" id="filter-person">
379
            <label for="person" class="mr-2">Osoba</label>
380
            <select id="person">
381
                <option selected="selected" value = "">Nevybráno</option>
382
                <option value = "1">1.</option>
383
                <option value = "2">2.</option>
384
                <option value = "3">3.</option>
385
            </select>
386
        </div>
387
        <div class="mr-3" id="filter-time">
388
            <label for="time" class="mr-2">Čas</label>
389
            <select id="time">
390
                <option selected="selected" value = "">Nevybráno</option>
391
                <option value = "P">Prézens</option>
392
                <option value = "A">Aorist</option>
393
                <option value = "R">Préteritum</option>
394
                <option value = "I">Imperfektum</option>
395
                <option value = "H">Plusquamperfektum</option>
396
                <option value = "F">Futurum</option>
397
            </select>
398
        </div>
399
        <div class="mr-3" id="filter-vid">
400
            <label for="vid" class="mr-2">Vid</label>
401
            <select id="vid">
402
                <option selected="selected" value = "">Nevybráno</option>
403
                <option value = "P">Perfektivum</option>
404
                <option value = "I">Imperfektivum </option>
405
            </select>
406
        </div>
407
        <div class="mr-3" id="filter-v-type">
408
            <label for="v-type" class="mr-2">Slovesný rod</label>
409
            <select id="v-type">
410
                <option selected="selected" value = "">Nevybráno</option>
411
                <option value = "A">Aktivum</option>
412
                <option value = "P">Pasivum</option>
413
            </select>
414
        </div>
415
        <div class="mr-3" id="filter-k-type">
416
            <label for="k-type" class="mr-2">Typ</label>
417
            <select id="k-type">
418
                <option selected="selected" value = "">Nevybráno</option>
419
                <option value = "V">Větná</option>
420
                <option value = "C">Členská</option>
421
                <option value = "N">Navazovací</option>
422
                <option value = "P">Spojení s přechodníkem</option>
423
            </select>
424
        </div>
425

    
426
        <!-- send button-->
427
        <button class="ml-auto btn" onclick="callFilter()">
428
            Filtrovat
429
        </button>
430
    </div>
431
</div>
432

    
433
<div class="search-results my-4">
434
    <table class="table table-striped">
435
        <thead>
436
        <tr>
437
            <th scope="col">Slovo</th>
438
            <th scope="col">Lemma</th>
439
            <th scope="col">Rukopisy</th>
440
            <th scope="col">Pozice</th>
441
            <th scope="col"></th>
442
        </tr>
443
        </thead>
444
        <tbody id="search-table">
445
            <script>
446
                function moodChange() {
447
                    if(document.getElementById("mood").value !== ""){
448
                        document.getElementById("irregular").disabled = true;
449
                        document.getElementById("irregular").title = "Neurčitý slovesný tvar smí být nastaven pouze není-li nastaven způsob";
450
                    } else {
451
                        document.getElementById("irregular").disabled = false;
452
                        document.getElementById("irregular").title = "";
453
                    }
454
                }
455

    
456
                function irregularChange() {
457
                    if(document.getElementById("irregular").value !== ""){
458
                        document.getElementById("mood").disabled = true;
459
                        document.getElementById("mood").title = "Způsob smí být nastaven pouze není-li nastaven neurčitý slovesný tvar";
460
                    } else {
461
                        document.getElementById("mood").disabled = false;
462
                        document.getElementById("mood").title = "";
463
                    }
464
                }
465

    
466
                let data;
467
                function callFilter() {
468
                    pageIndex = 0;
469
                    fetchData(true)
470
                }
471

    
472
                function filterData (formData) {
473
                    //regular
474
                    formData.append("lemma", document.getElementById("lemma").value);
475
                    formData.append("word", document.getElementById("wordshape").value);
476

    
477
                    //positions
478
                    const positionSplit = document.getElementById("location").value.split("/");
479
                    formData.append("position1", positionSplit[0] !== undefined ? positionSplit[0] : "");
480
                    formData.append("position2", positionSplit[1] !== undefined ? positionSplit[1] : "");
481
                    formData.append("positiondetail", positionSplit[2] !== undefined ? positionSplit[2] : "");
482

    
483
                    //multiselect
484
                    formData.append("manuscript", getValues("source"));
485

    
486
                    const pos = document.getElementById("wordclass").value;
487
                    formData.append("tag_pos", pos);
488
                    //those upcoming are dynamic based on the previous field
489
                    formData.append("tag_case", document.getElementById("case").value);
490
                    formData.append("tag_number", document.getElementById("countability").value);
491
                    formData.append("tag_gender", document.getElementById("gender").value);
492
                    formData.append("tag_degree", document.getElementById("grade").value);
493
                    formData.append("tag_shape", document.getElementById("shape").value);
494
                    formData.append("tag_num", "");//THIS ONE IS WORTHLESS
495

    
496
                    if(pos === "P"){
497
                        formData.append("tag_sentence", document.getElementById("type").value);
498
                    } else if(pos === "V"){
499
                        const mood = document.getElementById("mood").value;
500
                        if(mood !== ""){
501
                            formData.append("tag_sentence", mood);
502
                        } else {
503
                            formData.append("tag_sentence", document.getElementById("irregular").value);
504
                        }
505
                    } else if(pos === "J"){
506
                        formData.append("tag_sentence", document.getElementById("k-type").value);
507
                    }
508

    
509
                    formData.append("tag_verb_person", document.getElementById("person").value);
510
                    formData.append("tag_verb_time", document.getElementById("time").value);
511
                    formData.append("tag_verb_degree", document.getElementById("vid").value);
512
                    formData.append("tag_verb_aspect", document.getElementById("v-type").value);
513
                }
514

    
515
                function fetchData (filter = true) {
516
                    // (A1) GET SEARCH TERM
517
                    const formData = new FormData();
518
                    formData.append("page", ""+pageIndex);
519
                    formData.append("items_per_page", ""+itemPerPage);
520
                    formData.append("finished", "true");//TODO ADMIN
521

    
522
                    if(filter){
523
                        filterData(formData);
524
                    }
525

    
526
                    // (A2) AJAX - USE HTTP:// NOT FILE://
527
                    let xhr = new XMLHttpRequest();
528
                    xhr.open("POST", "./controller/TableController.php");
529
                    xhr.onload = function(){
530
                        let search = this.response;
531
                        let parsedJSON = JSON.parse(search);
532
                        if(parsedJSON.count === 0){
533
                            document.getElementById("no-data-label").style.display = "";
534
                            document.getElementById("paging-control").style.display = "none";
535
                        } else {
536
                            document.getElementById("no-data-label").style.display = "none";
537
                            document.getElementById("paging-control").style.display = "";
538
                        }
539
                        itemCount = parsedJSON.count;
540
                        pageCount = Math.ceil(itemCount / itemPerPage);
541
                        document.getElementById("page-label").value = (pageIndex + 1) + " / " + pageCount;
542
                        data = parsedJSON.data;
543
                        renderData(parsedJSON.data);
544
                    };
545
                    xhr.send(formData);
546
                }
547

    
548
                function renderManuscript(manuscripts, shorten=true) {
549
                    let output = "";
550
                    for(let i = 0; i < manuscripts.length; i++){
551
                        if(shorten)
552
                            output += codeToManuscriptShort[manuscripts[i]];
553
                        else
554
                            output += codeToManuscript[manuscripts[i]];
555

    
556
                        if(i < manuscripts.length - 1){
557
                            if(shorten)
558
                                output += ", ";
559
                            else
560
                                output += "; ";
561
                        }
562
                    }
563
                    return output;
564
                }
565

    
566
                function renderData(data) {
567
                    let result = "";
568
                    data.forEach((item,id) => {
569
                        result += "<tr>";
570
                        result += "<td>" + item.word + "</td>";
571
                        result += "<td>" + item.lemma.lemma + "</td>";
572
                        result += "<td>" + renderManuscript(item.manuscript) + "</td>";
573
                        result += "<td>" + item.position1 + (item.position2 ? ("/" + item.position2 + (item.positiondetail ? "/"  + item.positiondetail :  "")) : "")  + "</td>";
574
                        result += "<td class=\"action-td\">" +
575
                            "<button class=\"btn\" title=\"Detail\"  data-toggle=\"modal\" data-target=\"#detail-modal\" data-pseudo-id='" + id + "'><i class=\"fa fa-search\"></i></button>" +
576
                            "</td>";
577
                        result += "</tr>";
578
                    });
579
                    document.getElementById("search-table").innerHTML = result;
580
                }
581
            </script>
582
        </tbody>
583
    </table>
584

    
585
    <h3 id="no-data-label" class="mx-auto text-center font-italic">Žádná data nebyla nalezena</h3>
586

    
587
    <script>
588
        function moveToFirst(){
589
            pageIndex = 0;
590
            fetchData(true);
591
        }
592

    
593
        function moveToPrevious(){
594
            pageIndex = (pageIndex - 1 > 0) ? (pageIndex - 1) : (0);
595
            fetchData(true);
596
        }
597

    
598
        function moveToNext(){
599
            pageIndex = (pageIndex + 1 < pageCount) ? (pageIndex + 1) : (pageCount - 1);
600
            fetchData(true);
601
        }
602

    
603
        function moveToLast(){
604
            pageIndex = pageCount - 1;
605
            fetchData(true);
606
        }
607

    
608
        function onManualPageStart(element){
609
            element.value = '';
610
        }
611

    
612
        function onManualPageEnd(element) {
613
            const value = Number(element.value) - 1;
614
            if(Number.isInteger(value) && value >= 0 && value < pageCount){
615
                pageIndex = value;
616
                fetchData(true);
617
            } else {
618
                element.value = (pageIndex + 1) + " / " + pageCount;
619
            }
620

    
621
        }
622
    </script>
623
    <div id="paging-control" class="mx-auto text-center" style="display: none">
624
        <button class="border-0 shadow-none bg-transparent" onclick="moveToFirst()"><b><<</b></button>
625
        <button class="border-0 shadow-none bg-transparent"  onclick="moveToPrevious()"><b><</b></button>
626
        <input class="border-0 shadow-none bg-transparent text-center font-weight-bold"
627
               id="page-label"
628
               onfocus="onManualPageStart(this)"
629
               onblur="onManualPageEnd(this)"
630
        />
631
        <button class="border-0 shadow-none bg-transparent"  onclick="moveToNext()"><b>></b></button>
632
        <button  class="border-0 shadow-none bg-transparent" onclick="moveToLast()"><b>>></b></button>
633
    </div>
634
</div>
635

    
636

    
(6-6/7)