Projekt

Obecné

Profil

Stáhnout (33 KB) Statistiky
| Větev: | Revize:
1 e278dcbf Ondřej Anděl
<script>
2 31a2bb94 Anděl Ondřej
    let pageIndex = 0;
3
    let itemPerPage = 50;
4
    let itemCount = 0;
5
    let pageCount = 0;
6
7
    //what to do when page renders
8 e278dcbf Ondřej Anděl
    window.onload = function() {
9 a908ef13 Anděl Ondřej
        let sourceSelect = new vanillaSelectBox("#source");
10 e278dcbf Ondřej Anděl
        filtersChange();
11 fb32f0e8 Anděl Ondřej
        fetchData(false);
12 31a2bb94 Anděl Ondřej
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 e278dcbf Ondřej Anděl
    };
20
</script>
21
22
<div class="search-filters container" onload="filtersChange()">
23 9a7b1f4c Ondřej Anděl
    <div class="row">
24 fb32f0e8 Anděl Ondřej
        <div class="mr-3">
25
            <label for="lemma" class="mr-2">Lemma</label>
26
            <input type="text" id="lemma">
27
        </div>
28 a5559649 Anděl Ondřej
        <div class="mr-3">
29
            <label for="wordshape" class="mr-2">Slovní tvar</label>
30
            <input type="text" id="wordshape">
31
        </div>
32 9a7b1f4c Ondřej Anděl
        <div class="mr-3">
33
            <label for="source" class="mr-2">Rukopisný pramen</label>
34 a908ef13 Anděl Ondřej
            <select id="source" multiple>
35 fb32f0e8 Anděl Ondřej
                <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 a908ef13 Anděl Ondřej
            </select>
52 9a7b1f4c Ondřej Anděl
        </div>
53
        <div class="mr-3">
54 a908ef13 Anděl Ondřej
            <label for="location" class="mr-2">Pozice</label>
55 9a7b1f4c Ondřej Anděl
            <input type="text" id="location">
56
        </div>
57 a5559649 Anděl Ondřej
        <div class="mr-3">
58
            <label for="description2" class="mr-2">Poznámka 2</label>
59
            <input type="text" id="description2" />
60
        </div>
61 e278dcbf Ondřej Anděl
62
        <div class="mr-3">
63
            <label for="wordclass" class="mr-2">Slovní druh</label>
64
            <select onchange="filtersChange()"  id="wordclass">
65 a5559649 Anděl Ondřej
                <option selected="selected" value = "">nevybráno</option>
66
                <option value = "N">substantivum</option>
67
                <option value = "A">adjektivum</option>
68
                <option value = "P">pronomen</option>
69
                <option value = "C">numeralie</option>
70
                <option value = "V">verbum</option>
71
                <option value = "D">adverbium</option>
72
                <option value = "R">prepozice</option>
73
                <option value = "J">konjunkce</option>
74
                <option value = "T">partikule</option>
75
                <option value = "I">interjekce</option>
76 e278dcbf Ondřej Anděl
            </select>
77
        </div>
78
79
        <script>
80
            function filtersChange() {
81
                const value = document.getElementById("wordclass").value;
82 388846c1 Anděl Ondřej
                let movedNode;
83
                let beforeNode;
84 e278dcbf Ondřej Anděl
                switch (value) {
85 fb32f0e8 Anděl Ondřej
                    case "N":
86 e278dcbf Ondřej Anděl
                        setFilerVisibility([
87
                            true,
88
                            true,
89
                            true,
90
                            false,
91
                            false,
92
                            false,
93
                            false,
94
                            false,
95
                            false,
96
                            false,
97
                            false,
98 0cfdee39 Anděl Ondřej
                            false,
99 e278dcbf Ondřej Anděl
                            false
100
                        ]);
101 388846c1 Anděl Ondřej
                        movedNode = document.getElementById("filter-case");
102
                        beforeNode = document.getElementById("filter-countability");
103
                        movedNode.parentNode.insertBefore(movedNode, beforeNode);
104 e278dcbf Ondřej Anděl
                        break;
105 fb32f0e8 Anděl Ondřej
                    case "A":
106 e278dcbf Ondřej Anděl
                        setFilerVisibility([
107
                            true,
108
                            true,
109
                            true,
110
                            true,
111
                            true,
112
                            false,
113
                            false,
114
                            false,
115
                            false,
116
                            false,
117
                            false,
118 0cfdee39 Anděl Ondřej
                            false,
119 e278dcbf Ondřej Anděl
                            false
120
                        ]);
121 388846c1 Anděl Ondřej
                        movedNode = document.getElementById("filter-case");
122
                        beforeNode = document.getElementById("filter-countability");
123
                        movedNode.parentNode.insertBefore(movedNode, beforeNode);
124 e278dcbf Ondřej Anděl
                        break;
125 fb32f0e8 Anděl Ondřej
                    case "P":
126 e278dcbf Ondřej Anděl
                        setFilerVisibility([
127
                            true,
128
                            true,
129
                            true,
130
                            false,
131
                            false,
132
                            true,
133
                            false,
134
                            false,
135
                            false,
136
                            false,
137
                            false,
138 0cfdee39 Anděl Ondřej
                            false,
139 e278dcbf Ondřej Anděl
                            false
140
                        ]);
141 388846c1 Anděl Ondřej
                        movedNode = document.getElementById("filter-case");
142
                        beforeNode = document.getElementById("filter-countability");
143
                        movedNode.parentNode.insertBefore(movedNode, beforeNode);
144 e278dcbf Ondřej Anděl
                        break;
145 fb32f0e8 Anděl Ondřej
                    case "C":
146 e278dcbf Ondřej Anděl
                        setFilerVisibility([
147
                            true,
148
                            true,
149
                            true,
150
                            false,
151
                            false,
152
                            false,
153
                            false,
154
                            false,
155
                            false,
156
                            false,
157
                            false,
158 0cfdee39 Anděl Ondřej
                            false,
159 e278dcbf Ondřej Anděl
                            false
160
                        ]);
161 388846c1 Anděl Ondřej
                        movedNode = document.getElementById("filter-case");
162
                        beforeNode = document.getElementById("filter-countability");
163
                        movedNode.parentNode.insertBefore(movedNode, beforeNode);
164 e278dcbf Ondřej Anděl
                        break;
165 fb32f0e8 Anděl Ondřej
                    case "V":
166 e278dcbf Ondřej Anděl
                        setFilerVisibility([
167
                            true,
168
                            true,
169
                            true,
170
                            false,
171
                            false,
172
                            false,
173
                            true,
174
                            true,
175
                            true,
176
                            true,
177
                            true,
178 0cfdee39 Anděl Ondřej
                            true,
179 e278dcbf Ondřej Anděl
                            false
180
                        ]);
181 388846c1 Anděl Ondřej
                        movedNode = document.getElementById("filter-case");
182 a5559649 Anděl Ondřej
                        beforeNode = document.getElementById("filter-control-div");
183 4779c9ce Anděl Ondřej
                        movedNode.parentNode.insertBefore(movedNode, beforeNode);
184 e278dcbf Ondřej Anděl
                        break;
185 fb32f0e8 Anděl Ondřej
                    case "D":
186 e278dcbf Ondřej Anděl
                        setFilerVisibility([
187
                            false,
188
                            false,
189
                            false,
190
                            false,
191
                            true,
192
                            false,
193
                            false,
194
                            false,
195
                            false,
196
                            false,
197
                            false,
198 0cfdee39 Anděl Ondřej
                            false,
199 e278dcbf Ondřej Anděl
                            false
200
                        ]);
201
                        break;
202 fb32f0e8 Anděl Ondřej
                    case "R":
203 e278dcbf Ondřej Anděl
                        setFilerVisibility([
204
                            true,
205
                            false,
206
                            false,
207
                            false,
208
                            false,
209
                            false,
210
                            false,
211
                            false,
212
                            false,
213
                            false,
214
                            false,
215 0cfdee39 Anděl Ondřej
                            false,
216 e278dcbf Ondřej Anděl
                            false
217
                        ]);
218
                        break;
219 fb32f0e8 Anděl Ondřej
                    case "J":
220 e278dcbf Ondřej Anděl
                        setFilerVisibility([
221
                            false,
222
                            false,
223
                            false,
224
                            false,
225
                            false,
226
                            false,
227
                            false,
228
                            false,
229
                            false,
230
                            false,
231
                            false,
232 0cfdee39 Anděl Ondřej
                            false,
233 e278dcbf Ondřej Anděl
                            true
234
                        ]);
235
                        break;
236 fb32f0e8 Anděl Ondřej
                    case "I":
237 e278dcbf Ondřej Anděl
                        setFilerVisibility([
238
                            false,
239
                            false,
240
                            false,
241
                            false,
242
                            false,
243
                            false,
244
                            false,
245
                            false,
246
                            false,
247
                            false,
248
                            false,
249 0cfdee39 Anděl Ondřej
                            false,
250 e278dcbf Ondřej Anděl
                            false
251
                        ]);
252
                        break;
253 fb32f0e8 Anděl Ondřej
                    case "T":
254 e278dcbf Ondřej Anděl
                        setFilerVisibility([
255
                            false,
256
                            false,
257
                            false,
258
                            false,
259
                            false,
260
                            false,
261
                            false,
262
                            false,
263
                            false,
264
                            false,
265
                            false,
266 0cfdee39 Anděl Ondřej
                            false,
267 e278dcbf Ondřej Anděl
                            false
268
                        ]);
269
                        break;
270
                    default:
271
                        setFilerVisibility([
272
                            false,
273
                            false,
274
                            false,
275
                            false,
276
                            false,
277
                            false,
278
                            false,
279
                            false,
280
                            false,
281
                            false,
282
                            false,
283 0cfdee39 Anděl Ondřej
                            false,
284 e278dcbf Ondřej Anděl
                            false
285
                        ]);
286
                        break;
287
                }
288
            }
289
290
            function setFilerVisibility(visibility) {
291
                const id = [
292
                    "filter-case",
293
                    "filter-countability",
294
                    "filter-gender",
295
                    "filter-shape",
296
                    "filter-grade",
297
                    "filter-type",
298
                    "filter-mood",
299 0cfdee39 Anděl Ondřej
                    "filter-irregular",
300 e278dcbf Ondřej Anděl
                    "filter-person",
301
                    "filter-time",
302
                    "filter-vid",
303
                    "filter-v-type",
304
                    "filter-k-type"
305
                ];
306
307
                for(let i = 0; i < id.length &&  i < visibility.length; i++){
308
                    document.getElementById(id[i]).style.display = visibility[i] === true ? "" : "none";
309
                    document.getElementById(id[i].replace("filter-", "")).value = "";
310
                }
311
            }
312
        </script>
313
314
        <!-- conditionaly rendered filters-->
315 388846c1 Anděl Ondřej
        <div class="mr-3" id="filter-person">
316
            <label for="person" class="mr-2">Osoba</label>
317
            <select id="person">
318 a5559649 Anděl Ondřej
                <option selected="selected" value = "">nevybráno</option>
319 388846c1 Anděl Ondřej
                <option value = "1">1.</option>
320
                <option value = "2">2.</option>
321
                <option value = "3">3.</option>
322
            </select>
323
        </div>
324 e278dcbf Ondřej Anděl
        <div class="mr-3" id="filter-case">
325
            <label for="case" class="mr-2">Pád</label>
326
            <select id="case">
327 a5559649 Anděl Ondřej
                <option selected="selected" value = "">nevybráno</option>
328
                <option value = "1">nominativ</option>
329
                <option value = "2">genitiv</option>
330
                <option value = "3">dativ</option>
331
                <option value = "4">akuzativ</option>
332
                <option value = "5">vokativ</option>
333
                <option value = "6">lokál</option>
334
                <option value = "7">instrumentál</option>
335 e278dcbf Ondřej Anděl
            </select>
336
        </div>
337
        <div class="mr-3" id="filter-countability">
338
            <label for="countability" class="mr-2">Číslo</label>
339
            <select id="countability">
340 a5559649 Anděl Ondřej
                <option selected="selected" value = "">nevybráno</option>
341
                <option value = "S">singulár</option>
342
                <option value = "P">plurál</option>
343
                <option value = "D">duál</option>
344
            </select>
345
        </div>
346
        <div class="mr-3" id="filter-mood">
347
            <label for="mood" class="mr-2">Způsob</label>
348
            <select id="mood" onchange="moodChange()">
349
                <option selected="selected" value = "">nevybráno</option>
350
                <option value = "d">indikativ</option>
351
                <option value = "i">imperativ</option>
352
                <option value = "c">kondicionál</option>
353
            </select>
354
        </div>
355
        <div class="mr-3" id="filter-time">
356
            <label for="time" class="mr-2">Čas</label>
357
            <select id="time">
358
                <option selected="selected" value = "">nevybráno</option>
359
                <option value = "P">prézens</option>
360
                <option value = "A">aorist</option>
361
                <option value = "R">préteritum</option>
362
                <option value = "I">imperfektum</option>
363
                <option value = "H">plusquamperfektum</option>
364
                <option value = "F">futurum</option>
365
            </select>
366
        </div>
367
        <div class="mr-3" id="filter-v-type">
368
            <label for="v-type" class="mr-2">Slovesný rod</label>
369
            <select id="v-type">
370
                <option selected="selected" value = "">nevybráno</option>
371
                <option value = "A">aktivum</option>
372
                <option value = "P">pasivum</option>
373
            </select>
374
        </div>
375
        <div class="mr-3" id="filter-vid">
376
            <label for="vid" class="mr-2">Vid</label>
377
            <select id="vid">
378
                <option selected="selected" value = "">nevybráno</option>
379
                <option value = "P">perfektivum</option>
380
                <option value = "I">imperfektivum </option>
381
            </select>
382
        </div>
383
        <div class="mr-3" id="filter-irregular">
384
            <label for="irregular" class="mr-2">Neurčitý slovesný tvar</label>
385
            <select id="irregular" onchange="irregularChange()">
386
                <option selected="selected" value = "">nevybráno</option>
387
                <option value = "f">infinitiv</option>
388
                <option value = "S">supinum</option>
389
                <option value = "e">přech. přítomný</option>
390
                <option value = "m">přech. minulý</option>
391
                <option value = "A">part. perf. akt.</option>
392
                <option value = "P">part. perf. pas.</option>
393 e278dcbf Ondřej Anděl
            </select>
394
        </div>
395
        <div class="mr-3" id="filter-gender">
396
            <label for="gender" class="mr-2">Rod</label>
397
            <select id="gender">
398 a5559649 Anděl Ondřej
                <option selected="selected" value = "">nevybráno</option>
399
                <option value = "M">maskulinum</option>
400
                <option value = "F">femininum</option>
401
                <option value = "N">neutrum</option>
402 e278dcbf Ondřej Anděl
            </select>
403
        </div>
404
        <div class="mr-3" id="filter-shape">
405
            <label for="shape" class="mr-2">Tvar</label>
406
            <select id="shape">
407 a5559649 Anděl Ondřej
                <option selected="selected" value = "">nevybráno</option>
408
                <option value = "C">složený</option>
409
                <option value = "N">jmenný</option>
410 e278dcbf Ondřej Anděl
            </select>
411
        </div>
412
        <div class="mr-3" id="filter-grade">
413
            <label for="grade" class="mr-2">Stupeň</label>
414
            <select id="grade">
415 a5559649 Anděl Ondřej
                <option selected="selected" value = "">nevybráno</option>
416
                <option value = "1">pozitiv</option>
417
                <option value = "2">komparativ</option>
418
                <option value = "3">superlativ</option>
419 e278dcbf Ondřej Anděl
            </select>
420
        </div>
421
        <div class="mr-3" id="filter-type">
422
            <label for="type" class="mr-2">Druh</label>
423
            <select id="type">
424 a5559649 Anděl Ondřej
                <option selected="selected" value = "">nevybráno</option>
425
                <option value = "P">personalia</option>
426
                <option value = "S">posesiva</option>
427
                <option value = "D">demonstrativa</option>
428
                <option value = "Q">interogativa</option>
429
                <option value = "J">relativa</option>
430
                <option value = "Z">indefinita</option>
431
                <option value = "L">limitativa</option>
432
                <option value = "W">negativa</option>
433 e278dcbf Ondřej Anděl
            </select>
434
        </div>
435
        <div class="mr-3" id="filter-k-type">
436
            <label for="k-type" class="mr-2">Typ</label>
437
            <select id="k-type">
438 a5559649 Anděl Ondřej
                <option selected="selected" value = "">nevybráno</option>
439
                <option value = "V">větná</option>
440
                <option value = "C">členská</option>
441
                <option value = "N">navazovací</option>
442
                <option value = "P">spojení s přechodníkem</option>
443 e278dcbf Ondřej Anděl
            </select>
444
        </div>
445 a908ef13 Anděl Ondřej
446
        <!-- send button-->
447 a5559649 Anděl Ondřej
        <div class="ml-auto" id="filter-control-div">
448
            <i class="mr-1 my-auto" id="hit-count">0 záznamů</i>
449
            <button class="btn" id="filter-but" onclick="callFilter()">
450
                Filtrovat
451
            </button>
452 176259e4 Anděl Ondřej
453 ddbf114a Ondrej Drtina
            <?php if(isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == true) {?>
454 176259e4 Anděl Ondřej
            <button class="btn" data-toggle="modal" data-target="#edit-modal" data-title="Nový záznam">
455
                <i class="fa fa-plus"></i>
456 ddbf114a Ondrej Drtina
            </button>
457
            <?php }?>
458 a5559649 Anděl Ondřej
        </div>
459 9a7b1f4c Ondřej Anděl
    </div>
460
</div>
461
462 6ddecabb Anděl Ondřej
<div class="search-results mt-4">
463 9a7b1f4c Ondřej Anděl
    <table class="table table-striped">
464
        <thead>
465
        <tr>
466 a9af2c07 Anděl Ondřej
            <?php if(isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == true) {?>
467
                <th scope="col">Vydáno</th>
468
            <?php }?>
469 9a7b1f4c Ondřej Anděl
            <th scope="col">Lemma</th>
470 a5559649 Anděl Ondřej
            <th scope="col">Slovní tvar</th>
471
            <th scope="col">Morfologie</th>
472 e278dcbf Ondřej Anděl
            <th scope="col">Rukopisy</th>
473
            <th scope="col">Pozice</th>
474 a5559649 Anděl Ondřej
            <th scope="col">Poznámka 2</th>
475 9a7b1f4c Ondřej Anděl
            <th scope="col"></th>
476
        </tr>
477
        </thead>
478
        <tbody id="search-table">
479
            <script>
480 86d083b4 Anděl Ondřej
                function moodChange() {
481
                    if(document.getElementById("mood").value !== ""){
482
                        document.getElementById("irregular").disabled = true;
483
                        document.getElementById("irregular").title = "Neurčitý slovesný tvar smí být nastaven pouze není-li nastaven způsob";
484
                    } else {
485
                        document.getElementById("irregular").disabled = false;
486
                        document.getElementById("irregular").title = "";
487
                    }
488
                }
489
490
                function irregularChange() {
491
                    if(document.getElementById("irregular").value !== ""){
492
                        document.getElementById("mood").disabled = true;
493
                        document.getElementById("mood").title = "Způsob smí být nastaven pouze není-li nastaven neurčitý slovesný tvar";
494
                    } else {
495
                        document.getElementById("mood").disabled = false;
496
                        document.getElementById("mood").title = "";
497
                    }
498
                }
499
500 a908ef13 Anděl Ondřej
                let data;
501 31a2bb94 Anděl Ondřej
                function callFilter() {
502
                    pageIndex = 0;
503
                    fetchData(true)
504
                }
505
506 fb32f0e8 Anděl Ondřej
                function filterData (formData) {
507
                    //regular
508
                    formData.append("lemma", document.getElementById("lemma").value);
509
                    formData.append("word", document.getElementById("wordshape").value);
510 a5559649 Anděl Ondřej
                    formData.append("description2", document.getElementById("description2").value);
511 fb32f0e8 Anděl Ondřej
512
                    //positions
513
                    const positionSplit = document.getElementById("location").value.split("/");
514
                    formData.append("position1", positionSplit[0] !== undefined ? positionSplit[0] : "");
515
                    formData.append("position2", positionSplit[1] !== undefined ? positionSplit[1] : "");
516
                    formData.append("positiondetail", positionSplit[2] !== undefined ? positionSplit[2] : "");
517 a908ef13 Anděl Ondřej
518 fb32f0e8 Anděl Ondřej
                    //multiselect
519
                    formData.append("manuscript", getValues("source"));
520
521
                    const pos = document.getElementById("wordclass").value;
522
                    formData.append("tag_pos", pos);
523
                    //those upcoming are dynamic based on the previous field
524
                    formData.append("tag_case", document.getElementById("case").value);
525
                    formData.append("tag_number", document.getElementById("countability").value);
526
                    formData.append("tag_gender", document.getElementById("gender").value);
527
                    formData.append("tag_degree", document.getElementById("grade").value);
528
                    formData.append("tag_shape", document.getElementById("shape").value);
529
                    formData.append("tag_num", "");//THIS ONE IS WORTHLESS
530
531
                    if(pos === "P"){
532
                        formData.append("tag_sentence", document.getElementById("type").value);
533
                    } else if(pos === "V"){
534 0cfdee39 Anděl Ondřej
                        const mood = document.getElementById("mood").value;
535
                        if(mood !== ""){
536
                            formData.append("tag_sentence", mood);
537
                        } else {
538
                            formData.append("tag_sentence", document.getElementById("irregular").value);
539
                        }
540 fb32f0e8 Anděl Ondřej
                    } else if(pos === "J"){
541
                        formData.append("tag_sentence", document.getElementById("k-type").value);
542
                    }
543
544
                    formData.append("tag_verb_person", document.getElementById("person").value);
545
                    formData.append("tag_verb_time", document.getElementById("time").value);
546
                    formData.append("tag_verb_degree", document.getElementById("vid").value);
547
                    formData.append("tag_verb_aspect", document.getElementById("v-type").value);
548
                }
549
550
                function fetchData (filter = true) {
551 a908ef13 Anděl Ondřej
                    // (A1) GET SEARCH TERM
552
                    const formData = new FormData();
553 31a2bb94 Anděl Ondřej
                    formData.append("page", ""+pageIndex);
554
                    formData.append("items_per_page", ""+itemPerPage);
555 a908ef13 Anděl Ondřej
                    formData.append("finished", "true");//TODO ADMIN
556 fb32f0e8 Anděl Ondřej
                    if(filter){
557
                        filterData(formData);
558
                    }
559
560 a5559649 Anděl Ondřej
                    // (A2) AJAX - USE HTTP:// NOT FILE:/
561 a908ef13 Anděl Ondřej
                    let xhr = new XMLHttpRequest();
562
                    xhr.open("POST", "./controller/TableController.php");
563
                    xhr.onload = function(){
564
                        let search = this.response;
565
                        let parsedJSON = JSON.parse(search);
566 fb32f0e8 Anděl Ondřej
                        if(parsedJSON.count === 0){
567
                            document.getElementById("no-data-label").style.display = "";
568 31a2bb94 Anděl Ondřej
                            document.getElementById("paging-control").style.display = "none";
569 fb32f0e8 Anděl Ondřej
                        } else {
570
                            document.getElementById("no-data-label").style.display = "none";
571 31a2bb94 Anděl Ondřej
                            document.getElementById("paging-control").style.display = "";
572 fb32f0e8 Anděl Ondřej
                        }
573 a5559649 Anděl Ondřej
574
                        if(parsedJSON.count === 1){
575
                            document.getElementById("hit-count").innerText = "1 záznamů";
576
                        } else if(parsedJSON.count < 5){
577
                            document.getElementById("hit-count").innerText = parsedJSON.count +" záznamů";
578
                        } else {
579
                            document.getElementById("hit-count").innerText = parsedJSON.count +" záznamů";
580
                        }
581
582 31a2bb94 Anděl Ondřej
                        itemCount = parsedJSON.count;
583
                        pageCount = Math.ceil(itemCount / itemPerPage);
584
                        document.getElementById("page-label").value = (pageIndex + 1) + " / " + pageCount;
585 a908ef13 Anděl Ondřej
                        data = parsedJSON.data;
586
                        renderData(parsedJSON.data);
587
                    };
588
                    xhr.send(formData);
589
                }
590
591
                function renderManuscript(manuscripts, shorten=true) {
592
                    let output = "";
593
                    for(let i = 0; i < manuscripts.length; i++){
594 56235f0a Anděl Ondřej
                        if(shorten)
595 a5559649 Anděl Ondřej
                            output += ("<span title=\""+ codeToManuscript[manuscripts[i]] +"\">" + codeToManuscriptShort[manuscripts[i]] + "</span>");
596 56235f0a Anděl Ondřej
                        else
597
                            output += codeToManuscript[manuscripts[i]];
598 a908ef13 Anděl Ondřej
599
                        if(i < manuscripts.length - 1){
600 56235f0a Anděl Ondřej
                            if(shorten)
601
                                output += ", ";
602
                            else
603
                                output += "; ";
604 a908ef13 Anděl Ondřej
                        }
605
                    }
606
                    return output;
607
                }
608
609 a9af2c07 Anděl Ondřej
                function publishItem(id){
610
                    let item = data[id];
611
                    const finishedChecked = document.getElementById("check-"+id).checked;
612
613
                    const formData = new FormData();
614
                    formData.append("finished", finishedChecked);
615
616
                    formData.append("id", item.id);
617
                    formData.append("ending", item.ending);
618
                    formData.append("prefix", item.prefix);
619
                    formData.append("suffix", item.suffix);
620
621
                    formData.append("namedentity", item.namedentity);
622
                    formData.append("position1", item.position1);
623
                    formData.append("position2", item.position2);
624
                    formData.append("positiondetail", item.positiondetail);
625
                    formData.append("word", item.word);
626
                    formData.append("lemma", item.lemma.lemma);
627
                    formData.append("manuscript", item.manuscript);
628
                    formData.append("context", item.context);
629
                    formData.append("description", item.description);
630
                    formData.append("description2", item.description2);
631
                    formData.append("description3", item.description3);
632
                    formData.append("tag", item.tag.tag);
633
                    formData.append("pos", item.lemma.pos);
634
                    formData.append("date", item.date);
635
636
                    var xhr = new XMLHttpRequest();
637
                    xhr.open("POST", "./controller/UpdateController.php");
638
                    xhr.send(formData);//TODO VACI CHECK?
639
                    setTimeout(function(){
640
                        location.reload();
641
                    }, 500);
642
                }
643
644 a908ef13 Anděl Ondřej
                function renderData(data) {
645
                    let result = "";
646
                    data.forEach((item,id) => {
647
                        result += "<tr>";
648 a9af2c07 Anděl Ondřej
                        <?php if(isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == true) {?>
649
                            result += "<td><input type='checkbox' id='check-"+item.id+"' onchange='publishItem("+item.id+")' "+ ((item.finished === true) ? 'checked' : '') +" /></td>";
650
                        <?php }?>
651 a908ef13 Anděl Ondřej
                        result += "<td>" + item.lemma.lemma + "</td>";
652 a5559649 Anděl Ondřej
                        result += "<td>" + item.word + "</td>";
653
                        result += "<td>" + item.tag.tag + "</td>";
654 a908ef13 Anděl Ondřej
                        result += "<td>" + renderManuscript(item.manuscript) + "</td>";
655
                        result += "<td>" + item.position1 + (item.position2 ? ("/" + item.position2 + (item.positiondetail ? "/"  + item.positiondetail :  "")) : "")  + "</td>";
656 a5559649 Anděl Ondřej
                        result += "<td>" + item.description2 + "</td>";
657 a908ef13 Anděl Ondřej
                        result += "<td class=\"action-td\">" +
658 a5559649 Anděl Ondřej
                            "<button class=\"btn mr-1\" title=\"Upravit\"  data-toggle=\"modal\" data-target=\"#edit-modal\" data-pseudo-id='" + id + "' data-title=\"Upravit záznam\"><i class=\"fa fa-pencil\"></i></button>" + //TODO ADMIN change , regular send report
659 424379e9 Ondrej Drtina
                            "<button class=\"btn\" title=\"Detail\"  data-toggle=\"modal\" data-target=\"#detail-modal\" data-pseudo-id='" + id + "'><i class=\"fa fa-search\"></i></button>";
660
                            <?php if(isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == true) { ?> //show remove only if logged in
661
                                result += "<button class=\"btn ml-1\" title=\"Odstranit\"  data-toggle=\"modal\" data-target=\"#remove-modal\" data-pseudo-id='" + id + "'><i class=\"fa fa-trash\"></i></button>";
662
                            <?php }?>
663
                        result += "</td>";    
664 a908ef13 Anděl Ondřej
                        result += "</tr>";
665
                    });
666
                    document.getElementById("search-table").innerHTML = result;
667
                }
668 9a7b1f4c Ondřej Anděl
            </script>
669
        </tbody>
670
    </table>
671 fb32f0e8 Anděl Ondřej
672
    <h3 id="no-data-label" class="mx-auto text-center font-italic">Žádná data nebyla nalezena</h3>
673 31a2bb94 Anděl Ondřej
674
    <script>
675 6c152ae0 Ondrej Drtina
        function removeSelectedItem(idToDelete){
676 6f8c9e05 Ondrej Drtina
            const data = new FormData(); //to pass ids, which we want to delete from DB
677 6c152ae0 Ondrej Drtina
            data.append("id", ""+idToDelete); //id to delete from table dd_wordform
678 6f8c9e05 Ondrej Drtina
            
679
            let xhr = new XMLHttpRequest();
680
            xhr.open("POST", "./controller/RemoveController.php");
681
            xhr.send(data);
682 6c152ae0 Ondrej Drtina
            fetchData(true); //reload data after item delete
683 6f8c9e05 Ondrej Drtina
        }
684
685 7a7b805f Ondrej Drtina
        function checkValidItemsPerPage(){
686 d845d95d Ondrej Drtina
            var visibleItemCount = document.getElementById("itemsPerPage");
687 7a7b805f Ondrej Drtina
            if(!isNaN(visibleItemCount.value) && visibleItemCount.value % 1 === 0 && parseInt(visibleItemCount.value) >= 1 && parseInt(visibleItemCount.value) <= 500){
688
                return true;
689
            }else{
690
                alert("Zadaný počet není validní, zkuste to znovu.\nPlatný rozsah: 1 - 500 položek na stránku.");
691
                visibleItemCount.value = itemPerPage;
692
                return false;
693
            }
694 d845d95d Ondrej Drtina
        }
695
696
        function changeItemsPerPage(){
697 7a7b805f Ondrej Drtina
            //if there is no valid input, return and dont save
698
            if(checkValidItemsPerPage() === false){
699
                return;
700
            }
701 d845d95d Ondrej Drtina
702 7a7b805f Ondrej Drtina
            pageIndex = 0;
703 d845d95d Ondrej Drtina
            var visibleItemCount = document.getElementById("itemsPerPage").value;
704
            itemPerPage = visibleItemCount;
705
            fetchData(true);
706
        }
707
708 31a2bb94 Anděl Ondřej
        function moveToFirst(){
709
            pageIndex = 0;
710
            fetchData(true);
711
        }
712
713
        function moveToPrevious(){
714
            pageIndex = (pageIndex - 1 > 0) ? (pageIndex - 1) : (0);
715
            fetchData(true);
716
        }
717
718
        function moveToNext(){
719
            pageIndex = (pageIndex + 1 < pageCount) ? (pageIndex + 1) : (pageCount - 1);
720
            fetchData(true);
721
        }
722
723
        function moveToLast(){
724
            pageIndex = pageCount - 1;
725
            fetchData(true);
726
        }
727
728
        function onManualPageStart(element){
729
            element.value = '';
730
        }
731
732
        function onManualPageEnd(element) {
733
            const value = Number(element.value) - 1;
734
            if(Number.isInteger(value) && value >= 0 && value < pageCount){
735
                pageIndex = value;
736
                fetchData(true);
737
            } else {
738
                element.value = (pageIndex + 1) + " / " + pageCount;
739
            }
740
741
        }
742
    </script>
743
    <div id="paging-control" class="mx-auto text-center" style="display: none">
744
        <button class="border-0 shadow-none bg-transparent" onclick="moveToFirst()"><b><<</b></button>
745
        <button class="border-0 shadow-none bg-transparent"  onclick="moveToPrevious()"><b><</b></button>
746
        <input class="border-0 shadow-none bg-transparent text-center font-weight-bold"
747
               id="page-label"
748
               onfocus="onManualPageStart(this)"
749
               onblur="onManualPageEnd(this)"
750
        />
751
        <button class="border-0 shadow-none bg-transparent"  onclick="moveToNext()"><b>></b></button>
752
        <button  class="border-0 shadow-none bg-transparent" onclick="moveToLast()"><b>>></b></button>
753
    </div>
754 9a7b1f4c Ondřej Anděl
</div>
755