Projekt

Obecné

Profil

Stáhnout (35.7 KB) Statistiky
| Větev: | Revize:
1
<div id="edit-modal" class="modal fade" role="dialog">
2
    <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
3
        <div class="modal-content">
4
            <div class="modal-header">
5
                <h4 class="modal-title"></h4>
6
                <button type="button" class="close" data-dismiss="modal">&times;</button>
7
            </div>
8
            <div class="modal-body">
9
                <div class="container">
10
                    <div class="row my-1">
11
                        <div class="col-xs-12 col-sm-4">
12
                            <label for="lemma_edit">Lemma: <b class="required">*</b></label>
13
                        </div>
14
                        <div class="col-xs-12 col-sm-8">
15
                            <input class="min-wdth" id="lemma_edit"/>
16
                        </div>
17
                    </div>
18
                    <div class="row my-1">
19
                        <div class="col-xs-12 col-sm-4">
20
                            <label for="word">Slovo: <b class="required">*</b></label>
21
                        </div>
22
                        <div class="col-xs-12 col-sm-8">
23
                            <input class="min-wdth" id="word"/>
24
                        </div>
25
                    </div>
26
                    <div class="row my-1">
27
                        <div class="col-xs-12 col-sm-4">
28
                            <label for="manuscript-m">Rukopisy: <b class="required">*</b></label>
29
                        </div>
30
                        <div class="col-xs-12 col-sm-8">
31
                            <select id="manuscript-m" multiple>
32
                                <option value = "0">rukopis Vídeňský</option>
33
                                <option value = "1">zlomky Hanušovy</option>
34
                                <option value = "2">zlomky Hradecké</option>
35
                                <option value = "3">rukopis Cambridžský</option>
36
                                <option value = "4">rukopis Františkánský</option>
37
                                <option value = "5">zlomek Olomoucký</option>
38
                                <option value = "6">fragment Strahovský</option>
39
                                <option value = "7">zlomky Klementinsko-Křižovnické</option>
40
                                <option value = "8">zlomky Mnichovské</option>
41
                                <option value = "9">rukopis Lobkovický</option>
42
                                <option value = "10">rukopis Pelclův</option>
43
                                <option value = "11">rukopis Cerronský</option>
44
                                <option value = "12">rukopis Fürstenberský</option>
45
                                <option value = "13">rukopis Zebererův</option>
46
                                <option value = "14">vydání Pavla Ješína z Bezdězi, Praha 1620</option>
47
                                <option value = "15">básně připsané při Pulkavově kronice v rukopisu Litoměřickém</option>
48
                            </select>
49
                        </div>
50
                    </div>
51
                    <div class="row my-1">
52
                        <div class="col-xs-12 col-sm-4">
53
                            <label for="position">Pozice: <b class="required">*</b></label>
54
                        </div>
55
                        <div class="col-xs-12 col-sm-8">
56
                            <input class="min-wdth" id="position" title="Jedotlivé oddíly zadávejte oddělené lomítkem (bez mezery)" />
57
                        </div>
58
                    </div>
59
                    <div class="row my-1">
60
                        <div class="col-xs-12 col-sm-4">
61
                            <label for="namedentity">Vlastní jméno:</label>
62
                        </div>
63
                        <div class="col-xs-12 col-sm-8">
64
                            <input type="checkbox" id="namedentity"/>
65
                        </div>
66
                    </div>
67
                    <div class="row my-1">
68
                        <div class="col-xs-12 col-sm-4">
69
                            <label for="context">Kontext:</label>
70
                        </div>
71
                        <div class="col-xs-12 col-sm-8">
72
                            <input class="min-wdth" id="context"/>
73
                        </div>
74
                    </div>
75
                    <div class="row my-1">
76
                        <div class="col-xs-12 col-sm-4">
77
                            <label for="description">Poznámka:</label>
78
                        </div>
79
                        <div class="col-xs-12 col-sm-8">
80
                            <input class="min-wdth" id="description"/>
81
                        </div>
82
                    </div>
83
                    <div class="row my-1">
84
                        <div class="col-xs-12 col-sm-4">
85
                            <label for="description2_edit">Doplňující údaj:</label>
86
                        </div>
87
                        <div class="col-xs-12 col-sm-8">
88
                            <input class="min-wdth" id="description2_edit"/>
89
                        </div>
90
                    </div>
91
                    <div class="row my-1">
92
                        <div class="col-xs-12 col-sm-4">
93
                            <label for="description3">Varia:</label>
94
                        </div>
95
                        <div class="col-xs-12 col-sm-8">
96
                            <input class="min-wdth" id="description3"/>
97
                        </div>
98
                    </div>
99
                    <div class="row my-1">
100
                        <div class="col-xs-12 col-sm-4">
101
                            <label for="wordclass">Slovní druh: <b class="required">*</b></label>
102
                        </div>
103
                        <div class="col-xs-12 col-sm-8">
104
                            <select class="min-wdth" onchange="changeWordType()"  id="wordclass">
105
                                <option selected="selected" value = "">nevybráno</option>
106
                                <option value = "N">substantivum</option>
107
                                <option value = "A">adjektivum</option>
108
                                <option value = "P">pronomen</option>
109
                                <option value = "C">numerále</option>
110
                                <option value = "V">verbum</option>
111
                                <option value = "D">adverbium</option>
112
                                <option value = "R">prepozice</option>
113
                                <option value = "J">konjunkce</option>
114
                                <option value = "T">partikule</option>
115
                                <option value = "I">interjekce</option>
116
                            </select>
117
                        </div>
118
                    </div>
119

    
120
                    <!-- conditional render -->
121
                    <div class="row my-1" id="person-wrapper">
122
                        <div class="col-xs-12 col-sm-4">
123
                            <label for="person">Osoba:</label>
124
                        </div>
125
                        <div class="col-xs-12 col-sm-8">
126
                            <select class="min-wdth" id="person">
127
                                <option selected="selected" value = "">nevybráno</option>
128
                                <option value = "1">1.</option>
129
                                <option value = "2">2.</option>
130
                                <option value = "3">3.</option>
131
                            </select>
132
                        </div>
133
                    </div>
134
                    <div class="row my-1" id="case-wrapper">
135
                        <div class="col-xs-12 col-sm-4">
136
                            <label for="case">Pád:</label>
137
                        </div>
138
                        <div class="col-xs-12 col-sm-8">
139
                            <select class="min-wdth" id="case">
140
                                <option selected="selected" value = "">nevybráno</option>
141
                                <option value = "1">nominativ</option>
142
                                <option value = "2">genitiv</option>
143
                                <option value = "3">dativ</option>
144
                                <option value = "4">akuzativ</option>
145
                                <option value = "5">vokativ</option>
146
                                <option value = "6">lokál</option>
147
                                <option value = "7">instrumentál</option>
148
                            </select>
149
                        </div>
150
                    </div>
151
                    <div class="row my-1" id="countability-wrapper">
152
                        <div class="col-xs-12 col-sm-4">
153
                            <label for="countability">Číslo:</label>
154
                        </div>
155
                        <div class="col-xs-12 col-sm-8">
156
                            <select class="min-wdth" id="countability">
157
                                <option selected="selected" value = "">nevybráno</option>
158
                                <option value = "S">singulár</option>
159
                                <option value = "P">plurál</option>
160
                                <option value = "D">duál</option>
161
                            </select>
162
                        </div>
163
                    </div>
164
                    <div class="row my-1" id="mood-wrapper">
165
                        <div class="col-xs-12 col-sm-4">
166
                            <label for="mood">Způsob:</label>
167
                        </div>
168
                        <div class="col-xs-12 col-sm-8">
169
                            <select class="min-wdth" id="mood">
170
                                <option selected="selected" value = "">nevybráno</option>
171
                                <option value = "d">indikativ</option>
172
                                <option value = "i">imperativ</option>
173
                                <option value = "c">kondicionál</option>
174
                            </select>
175
                        </div>
176
                    </div>
177
                    <div class="row my-1" id="time-wrapper">
178
                        <div class="col-xs-12 col-sm-4">
179
                            <label for="time">Čas:</label>
180
                        </div>
181
                        <div class="col-xs-12 col-sm-8">
182
                            <select class="min-wdth" id="time">
183
                                <option selected="selected" value = "">nevybráno</option>
184
                                <option value = "P">prézens</option>
185
                                <option value = "A">aorist</option>
186
                                <option value = "R">préteritum</option>
187
                                <option value = "I">imperfektum</option>
188
                                <option value = "H">plusquamperfektum</option>
189
                                <option value = "F">futurum</option>
190
                            </select>
191
                        </div>
192
                    </div>
193
                    <div class="row my-1" id="v-type-wrapper">
194
                        <div class="col-xs-12 col-sm-4">
195
                            <label for="v-type">Slovesný rod:</label>
196
                        </div>
197
                        <div class="col-xs-12 col-sm-8">
198
                            <select class="min-wdth" id="v-type">
199
                                <option selected="selected" value = "">nevybráno</option>
200
                                <option value = "A">aktivum</option>
201
                                <option value = "P">pasivum</option>
202
                            </select>
203
                        </div>
204
                    </div>
205
                    <div class="row my-1" id="vid-wrapper">
206
                        <div class="col-xs-12 col-sm-4">
207
                            <label for="vid">Slovesný vid:</label>
208
                        </div>
209
                        <div class="col-xs-12 col-sm-8">
210
                            <select class="min-wdth" id="vid">
211
                                <option selected="selected" value = "">nevybráno</option>
212
                                <option value = "P">perfektivum</option>
213
                                <option value = "I">imperfektivum </option>
214
                            </select>
215
                        </div>
216
                    </div>
217
                    <div class="row my-1" id="irregular-wrapper">
218
                        <div class="col-xs-12 col-sm-4">
219
                            <label for="irregular">Neurčitý slovesný tvar:</label>
220
                        </div>
221
                        <div class="col-xs-12 col-sm-8">
222
                            <select class="min-wdth" id="irregular">
223
                                <option selected="selected" value = "">nevybráno</option>
224
                                <option value = "f">infinitiv</option>
225
                                <option value = "S">supinum</option>
226
                                <option value = "e">přech. přítomný</option>
227
                                <option value = "m">přech. minulý</option>
228
                                <option value = "A">part. perf. akt.</option>
229
                                <option value = "P">part. perf. pas.</option>
230
                            </select>
231
                        </div>
232
                    </div>
233
                    <div class="row my-1" id="gender-wrapper">
234
                        <div class="col-xs-12 col-sm-4">
235
                            <label for="gender">Rod:</label>
236
                        </div>
237
                        <div class="col-xs-12 col-sm-8">
238
                            <select class="min-wdth" id="gender">
239
                                <option selected="selected" value = "">nevybráno</option>
240
                                <option value = "M">maskulinum</option>
241
                                <option value = "F">femininum</option>
242
                                <option value = "N">neutrum</option>
243
                            </select>
244
                        </div>
245
                    </div>
246
                    <div class="row my-1" id="shape-wrapper">
247
                        <div class="col-xs-12 col-sm-4">
248
                            <label for="shape">Tvar:</label>
249
                        </div>
250
                        <div class="col-xs-12 col-sm-8">
251
                            <select class="min-wdth" id="shape">
252
                                <option selected="selected" value = "">nevybráno</option>
253
                                <option value = "C">složený</option>
254
                                <option value = "N">jmenný</option>
255
                            </select>
256
                        </div>
257
                    </div>
258
                    <div class="row my-1" id="grade-wrapper">
259
                        <div class="col-xs-12 col-sm-4">
260
                            <label for="grade">Stupeň:</label>
261
                        </div>
262
                        <div class="col-xs-12 col-sm-8">
263
                            <select class="min-wdth" id="grade">
264
                                <option selected="selected" value = "">nevybráno</option>
265
                                <option value = "1">pozitiv</option>
266
                                <option value = "2">komparativ</option>
267
                                <option value = "3">superlativ</option>
268
                            </select>
269
                        </div>
270
                    </div>
271
                    <div class="row my-1" id="type-wrapper">
272
                        <div class="col-xs-12 col-sm-4">
273
                            <label for="type">Druh:</label>
274
                        </div>
275
                        <div class="col-xs-12 col-sm-8">
276
                            <select class="min-wdth" id="type">
277
                                <option selected="selected" value = "">nevybráno</option>
278
                                <option value = "P">personalia</option>
279
                                <option value = "S">posesiva</option>
280
                                <option value = "D">demonstrativa</option>
281
                                <option value = "Q">interogativa</option>
282
                                <option value = "J">relativa</option>
283
                                <option value = "Z">indefinita</option>
284
                                <option value = "L">limitativa</option>
285
                                <option value = "W">negativa</option>
286
                            </select>
287
                        </div>
288
                    </div>
289
                    <div class="row my-1" id="k-type-wrapper">
290
                        <div class="col-xs-12 col-sm-4">
291
                            <label for="k-type">Typ:</label>
292
                        </div>
293
                        <div class="col-xs-12 col-sm-8">
294
                            <select class="min-wdth" id="k-type">
295
                                <option selected="selected" value = "">nevybráno</option>
296
                                <option value = "V">větná</option>
297
                                <option value = "C">členská</option>
298
                                <option value = "N">navazovací</option>
299
                                <option value = "P">spojení s přechodníkem</option>
300
                            </select>
301
                        </div>
302
                    </div>
303
                </div>
304
            </div>
305
            <div class="modal-footer">
306
                <button type="button" id="submit-but" class="btn btn-default" data-dismiss="modal"></button>
307
                <button type="button" class="btn btn-default" data-dismiss="modal">Zavřít</button>
308
            </div>
309
        </div>
310
    </div>
311
</div>
312

    
313
<script>
314
    $('#edit-modal').on('show.bs.modal', function (event) {
315
        const button = $(event.relatedTarget);
316
        const pseudo_id = button.data('pseudo-id');// Extract info from data-* attributes
317
        const title = button.data('title');// Extract info from data-* attributes
318
        var $multis = $('#manuscript-m').multiSelect({
319
            'noneText': 'nevybráno',
320
        });
321

    
322
        let modal = $(this);
323
        modal.find('.modal-title').text(title);
324
        modal.find('#mood').change(() => moodMChange(modal));
325
        modal.find('#irregular').change(() => irregularMChange(modal));
326

    
327
        if(title === "Nový záznam"){
328
            prefill(modal);
329
            changeWordType();
330
            modal.find('#submit-but').text("Založit");
331
            modal.find('#submit-but').off().click(() => createData(modal));
332

    
333
            enableSubmit(modal);
334
            manuChange(modal);
335
            modal.find("#lemma_edit").change(() => enableSubmit(modal));
336
            modal.find("#word").change(() => enableSubmit(modal));
337
            modal.find("#position").change(() => enableSubmit(modal));
338
            modal.find("#wordclass").change(() => enableSubmit(modal));
339
            modal.find("#manuscript-m").change(() => manuChange(modal));
340
        } else {
341
            const data_obj = data[pseudo_id];
342
            modal.find('#submit-but').text("Upravit");
343
            modal.find('#submit-but').off().click(() => editData(data_obj, modal));
344
            prefill(modal, data_obj);
345
            changeWordType();
346
            prefill(modal, data_obj);
347
            moodMChange(modal);
348
            irregularMChange(modal);
349

    
350
            enableSubmit(modal);
351
            manuChange(modal);
352
            modal.find("#lemma_edit").change(() => enableSubmit(modal));
353
            modal.find("#word").change(() => enableSubmit(modal));
354
            modal.find("#position").change(() => enableSubmit(modal));
355
            modal.find("#wordclass").change(() => enableSubmit(modal));
356
            modal.find("#manuscript-m").change(() => manuChange(modal));
357
        }
358
    });
359

    
360
    function changeWordType() {
361
        let modal = $('#edit-modal');
362
        const value = modal.find("#wordclass")[0].value;
363
        let movedNode;
364
        let beforeNode;
365
        switch (value) {
366
            case "N":
367
                setElementVisibility([
368
                    true,
369
                    true,
370
                    true,
371
                    false,
372
                    false,
373
                    false,
374
                    false,
375
                    false,
376
                    false,
377
                    false,
378
                    false,
379
                    false,
380
                    false
381
                ], modal);
382
                movedNode = modal.find("#case-wrapper");
383
                beforeNode = modal.find("#countability-wrapper");
384
                beforeNode.before(movedNode);
385
                break;
386
            case "A":
387
                setElementVisibility([
388
                    true,
389
                    true,
390
                    true,
391
                    true,
392
                    true,
393
                    false,
394
                    false,
395
                    false,
396
                    false,
397
                    false,
398
                    false,
399
                    false,
400
                    false
401
                ], modal);
402
                movedNode = modal.find("#case-wrapper");
403
                beforeNode = modal.find("#countability-wrapper");
404
                beforeNode.before(movedNode);
405
                break;
406
            case "P":
407
                setElementVisibility([
408
                    true,
409
                    true,
410
                    true,
411
                    false,
412
                    false,
413
                    true,
414
                    false,
415
                    false,
416
                    false,
417
                    false,
418
                    false,
419
                    false,
420
                    false
421
                ], modal);
422
                movedNode = modal.find("#case-wrapper");
423
                beforeNode = modal.find("#countability-wrapper");
424
                beforeNode.before(movedNode);
425
                break;
426
            case "C":
427
                setElementVisibility([
428
                    true,
429
                    true,
430
                    true,
431
                    false,
432
                    false,
433
                    false,
434
                    false,
435
                    false,
436
                    false,
437
                    false,
438
                    false,
439
                    false,
440
                    false
441
                ], modal);
442
                movedNode = modal.find("#case-wrapper");
443
                beforeNode = modal.find("#countability-wrapper");
444
                beforeNode.before(movedNode);
445
                break;
446
            case "V":
447
                setElementVisibility([
448
                    true,
449
                    true,
450
                    true,
451
                    false,
452
                    false,
453
                    false,
454
                    true,
455
                    true,
456
                    true,
457
                    true,
458
                    true,
459
                    true,
460
                    false
461
                ], modal);
462
                movedNode = modal.find("#case-wrapper");
463
                beforeNode = modal.find("#vid-wrapper");
464
                beforeNode.after(movedNode);
465
                break;
466
            case "D":
467
                setElementVisibility([
468
                    false,
469
                    false,
470
                    false,
471
                    false,
472
                    true,
473
                    false,
474
                    false,
475
                    false,
476
                    false,
477
                    false,
478
                    false,
479
                    false,
480
                    false
481
                ], modal);
482
                break;
483
            case "R":
484
                setElementVisibility([
485
                    true,
486
                    false,
487
                    false,
488
                    false,
489
                    false,
490
                    false,
491
                    false,
492
                    false,
493
                    false,
494
                    false,
495
                    false,
496
                    false,
497
                    false
498
                ], modal);
499
                break;
500
            case "J":
501
                setElementVisibility([
502
                    false,
503
                    false,
504
                    false,
505
                    false,
506
                    false,
507
                    false,
508
                    false,
509
                    false,
510
                    false,
511
                    false,
512
                    false,
513
                    false,
514
                    true
515
                ], modal);
516
                break;
517
            case "I":
518
                setElementVisibility([
519
                    false,
520
                    false,
521
                    false,
522
                    false,
523
                    false,
524
                    false,
525
                    false,
526
                    false,
527
                    false,
528
                    false,
529
                    false,
530
                    false,
531
                    false
532
                ], modal);
533
                break;
534
            case "T":
535
                setElementVisibility([
536
                    false,
537
                    false,
538
                    false,
539
                    false,
540
                    false,
541
                    false,
542
                    false,
543
                    false,
544
                    false,
545
                    false,
546
                    false,
547
                    false,
548
                    false
549
                ], modal);
550
                break;
551
            default:
552
                setElementVisibility([
553
                    false,
554
                    false,
555
                    false,
556
                    false,
557
                    false,
558
                    false,
559
                    false,
560
                    false,
561
                    false,
562
                    false,
563
                    false,
564
                    false,
565
                    false
566
                ], modal);
567
                break;
568
        }
569
    }
570

    
571
    const dynamicFields = [
572
        "#case-wrapper",
573
        "#countability-wrapper",
574
        "#gender-wrapper",
575
        "#shape-wrapper",
576
        "#grade-wrapper",
577
        "#type-wrapper",
578
        "#mood-wrapper",
579
        "#irregular-wrapper",
580
        "#person-wrapper",
581
        "#time-wrapper",
582
        "#vid-wrapper",
583
        "#v-type-wrapper",
584
        "#k-type-wrapper"
585
    ];
586

    
587
    const staticFields = [
588
        "#word",
589
        "#lemma_edit",
590
        "#manuscript-m",
591
        "#position",
592
        "#namedentity",
593
        "#context",
594
        "#description",
595
        "#description2_edit",
596
        "#description3",
597
        "#wordclass"
598
    ];
599

    
600
    function setElementVisibility(visibility, modal) {
601
        for(let i = 0; i < dynamicFields.length &&  i < visibility.length; i++){
602
            if(visibility[i] === true){
603
                modal.find(dynamicFields[i]).show();
604
            } else {
605
                modal.find(dynamicFields[i]).hide();
606
            }
607
            modal.find(dynamicFields[i].replace("-wrapper", "")).val("");
608
        }
609
    }
610

    
611
    function prefill(modal, data = null){
612
        staticFields.forEach((item) => {
613
            modal.find(item).val("");
614
        });
615

    
616
        modal.find("#namedentity").prop('checked', false);
617

    
618
        dynamicFields.forEach((item) => {
619
            modal.find(item.replace("-wrapper", "")).val("");
620
        });
621

    
622
        if(data !== null){
623
            modal.find("#context").val(data.context);
624
            modal.find("#description").val(data.description);
625
            modal.find("#description2_edit").val(data.description2_edit);
626
            modal.find("#description3").val(data.description3);
627
            modal.find("#namedentity").prop('checked', data.namedentity === 1);
628

    
629
            let position = data.position1;
630
            position += ((data.position2 !== null && data.position2.length > 0) ? ("/" + data.position2) : "");
631
            position += ((data.positiondetail !== null && data.positiondetail.length > 0) ? ("/" + data.positiondetail) : "");
632
            modal.find("#position").val(position);
633

    
634
            modal.find("#word").val(data.word);
635
            modal.find("#lemma_edit").val(data.lemma.lemma);
636
            setManuscriptValue(modal, data.manuscript);
637

    
638
            //dynamic setting
639
            const morphem = data.tag.tag;
640
            const wordclass = morphem.charAt(0);
641
            modal.find("#wordclass").val(wordclass);
642
            modal.find("#case").val((morphem.charAt(1) !== '-') ? morphem.charAt(1) : "");
643
            modal.find("#countability").val((morphem.charAt(2) !== '-') ? morphem.charAt(2) : "");
644
            modal.find("#gender").val((morphem.charAt(3) !== '-') ? morphem.charAt(3) : "");
645
            modal.find("#grade").val((morphem.charAt(4) !== '-') ? morphem.charAt(4) : "");
646
            modal.find("#shape").val((morphem.charAt(5) !== '-') ? morphem.charAt(5) : "");
647

    
648
            if(morphem.charAt(7) !== '-'){
649
                if(wordclass === 'J'){
650
                    modal.find("#k-type").val(morphem.charAt(7));
651
                } else if(wordclass === 'P'){
652
                    modal.find("#type").val(morphem.charAt(7));
653
                } else if(wordclass === 'V'){
654
                    if(codeToMood[morphem.charAt(7)] !== undefined) {
655
                        modal.find("#mood").val(morphem.charAt(7));
656
                    } else {
657
                        modal.find("#irregular").val(morphem.charAt(7));
658
                    }
659
                }
660
            }
661

    
662
            modal.find("#person").val((morphem.charAt(8) !== '-') ? morphem.charAt(8) : "");
663
            modal.find("#time").val((morphem.charAt(9) !== '-') ? morphem.charAt(9) : "");
664
            modal.find("#v-type").val((morphem.charAt(10) !== '-') ? morphem.charAt(10) : "");
665
            modal.find("#vid").val((morphem.charAt(11) !== '-') ? morphem.charAt(11) : "");
666
        }
667
    }
668

    
669
    function enableSubmit(modal) {
670

    
671
        let ms_value = getManuscriptValue(modal);
672
        if (
673
            modal.find("#lemma_edit")[0].value === "" ||
674
            modal.find("#word")[0].value === "" ||
675
            modal.find("#position")[0].value === "" ||
676
            modal.find("#wordclass")[0].value === "" ||
677
            ms_value === undefined ||
678
            ms_value === null ||
679
            ms_value.length === 0
680
        ) {
681
            modal.find("#submit-but").prop("disabled", true);
682
        } else {
683
            modal.find("#submit-but").prop("disabled", false);
684
        }
685
    }
686

    
687
    function editData(data, modal){
688
        const formData = prepareFormData(modal);
689
        formData.append("id", data.id);
690

    
691
        formData.append("ending", data.ending);
692
        formData.append("finished", data.finished);
693
        formData.append("prefix", data.prefix);
694
        formData.append("suffix", data.suffix);
695

    
696
        var xhr = new XMLHttpRequest();
697
        xhr.open("POST", "./controller/UpdateController.php");
698
        xhr.send(formData);
699
        setTimeout(function(){
700
            location.reload();
701
        }, 500);
702
    }
703

    
704
    function prepareFormData(modal) {
705
        const formData = new FormData();
706

    
707
        formData.append("namedentity", (modal.find("#namedentity")[0].checked) ? "1" : "0");
708

    
709
        const position = modal.find("#position")[0].value.split("/");
710
        formData.append("position1", position[0]);
711
        formData.append("position2", (position[1] !== undefined) ? position[1] : "");
712
        formData.append("positiondetail", (position[2] !== undefined) ? position[2] : "");
713

    
714
        formData.append("word", modal.find("#word")[0].value);
715
        formData.append("lemma", modal.find("#lemma_edit")[0].value);
716

    
717
        //this is to get data from manuscript
718
        let ms_value = getManuscriptValue(modal);
719

    
720
        formData.append("manuscript", ms_value.join());
721
        formData.append("context", modal.find("#context")[0].value);
722
        formData.append("description", modal.find("#description")[0].value);
723
        formData.append("description2", modal.find("#description2_edit")[0].value);
724
        formData.append("description3", modal.find("#description3")[0].value);
725

    
726
        //morphem creation
727
        let morphem = "";
728
        const wordClass = modal.find("#wordclass")[0].value;
729
        morphem += ((wordClass.length > 0) ? wordClass : "-");
730
        morphem += ((modal.find("#case")[0].value.length > 0) ? modal.find("#case")[0].value : "-");
731
        morphem += ((modal.find("#countability")[0].value.length > 0) ? modal.find("#countability")[0].value : "-");
732
        morphem += ((modal.find("#gender")[0].value.length > 0) ? modal.find("#gender")[0].value : "-");
733
        morphem += ((modal.find("#grade")[0].value.length > 0) ? modal.find("#grade")[0].value : "-");
734
        morphem += ((modal.find("#shape")[0].value.length > 0) ? modal.find("#shape")[0].value : "-");
735
        morphem += "-";
736

    
737
        if(wordClass === "J"){
738
            morphem += ((modal.find("#k-type")[0].value.length > 0) ? modal.find("#k-type")[0].value : "-");
739
        } else if(wordClass === "P") {
740
            morphem += ((modal.find("#type")[0].value.length > 0) ? modal.find("#type")[0].value : "-");
741
        } else if(wordClass === "V"){
742
            const value1 = modal.find("#mood")[0].value;
743
            const value2 = modal.find("#irregular")[0].value;
744
            if(value1.length > 0){
745
                morphem += value1;
746
            } else if(value2.length > 0){
747
                morphem += value2;
748
            } else {
749
                morphem += "-";
750
            }
751
        } else {
752
            morphem += "-";
753
        }
754

    
755
        morphem += ((modal.find("#person")[0].value.length > 0) ? modal.find("#person")[0].value : "-");
756
        morphem += ((modal.find("#time")[0].value.length > 0) ? modal.find("#time")[0].value : "-");
757
        morphem += ((modal.find("#v-type")[0].value.length > 0) ? modal.find("#v-type")[0].value : "-");
758
        morphem += ((modal.find("#vid")[0].value.length > 0) ? modal.find("#vid")[0].value : "-");
759
        formData.append("tag", morphem);
760
        formData.append("pos", wordclassToNum[wordClass]);
761

    
762
        return formData;
763
    }
764

    
765
    function getManuscriptValue(modal){
766
        var elements = modal.find("#manuscript-m").data('multiSelectContainer').find('input:checked');
767
        let ms_value = [];
768
        Object.values(elements).forEach((item) => {
769
            if(item.value !== undefined){
770
                ms_value.push(""+item.value);
771
            }
772
        });
773
        return ms_value;
774
    }
775

    
776
    function setManuscriptValue(modal, value){
777
        var elements = modal.find("#manuscript-m").data('multiSelectContainer').find('input');
778
        Object.values(elements).forEach((item) => {
779
            if(value.includes(parseInt(item.value))){
780
                item.checked = true;
781
            } else {
782
                item.checked = false;
783
            }
784
        });
785
    }
786

    
787
    function manuChange(modal){
788
        var elements = modal.find("#manuscript-m").data('multiSelectContainer').find('input:checked');
789
        let docCount = 0;
790
        Object.values(elements).forEach((item) => {
791
            if(item.value !== undefined){
792
                docCount++;
793
            }
794
        });
795

    
796
        let extra = "";
797
        if(docCount === 1){
798
            extra += " rukopis";
799
        } else if(docCount < 5){
800
            extra += " rukopisy";
801
        } else {
802
            extra += " rukopisů";
803
        }
804
        modal.find(".multi-select-button")[0].innerText = docCount+extra;
805

    
806
        enableSubmit(modal);
807
    }
808

    
809
    function moodMChange(modal) {
810
        if(modal.find("#mood")[0].value !== ""){
811
            modal.find("#irregular").prop('disabled', true);
812
            modal.find("#irregular").prop('title', "Neurčitý slovesný tvar smí být nastaven pouze není-li nastaven způsob");
813
        } else {
814
            modal.find("#irregular").prop('disabled', false);
815
            modal.find("#irregular").prop('title', "");
816
        }
817
    }
818

    
819
    function irregularMChange(modal) {
820
        if(modal.find("#irregular")[0].value !== ""){
821
            modal.find("#mood").prop('disabled', true);
822
            modal.find("#mood").prop('title', "Způsob smí být nastaven pouze není-li nastaven neurčitý slovesný tvar");
823
        } else {
824
            modal.find("#mood").prop('disabled', false);
825
            modal.find("#mood").prop('title', "");
826
        }
827
    }
828

    
829
    function createData(modal){
830
        const formData = prepareFormData(modal);
831

    
832
        formData.append("finished", false);
833

    
834
        var xhr = new XMLHttpRequest();
835
        xhr.open("POST", "./controller/InsertController.php");
836
        xhr.send(formData);
837
        setTimeout(function(){
838
            location.reload();
839
        }, 500);
840
    }
841
</script>
(3-3/10)