Blame view

semantics/static/js/semantics_view.js 56.8 KB
Bartłomiej Nitoń authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var control = "meanings";
var op = "none";
var arg = "";
window.units_operations = [];
window.frames_operations = [];
var highlighted_id = "";
var highlighted_class = "";
var semantics_selected_id = "";

var relations_creating = ["hiponimia", "synonimia", "nie umiem umieścić"];

//////////////////////////// Control ////////////////////////////

function prepareControl() {  
    $(".semantics-control-tabs").tabs().bind('tabsselect', function(event, ui) {
        if(ui.panel.id == 'select_meanings') {
        	control="meanings";
        	frameClick("");
        	$('#assign_role').attr('disabled', "True");
        	$('#add_preference').attr('disabled', "True");
            $('#delete').attr('disabled', "True");
        } 
        else if(ui.panel.id == 'select_creating') {
        	control="connect";
            frameClick("");
            $('#assign_role').attr('disabled', "True");
            $('#add_preference').attr('disabled', "True");
            $('#delete').attr('disabled', "True");
        }
   });
}

function alertSemantics() {
    alert("Nie można modyfikować semantyki. Zapisz zmiany w składni.");
}

function alertOldSchemas() {
	alert('Działanie niemożliwe, wyświetlona wersja składni jest nieaktualna.');
}

/////////////////////////// Meanings ////////////////////////////
function hide() {
    $("#synset_input").css('visibility', 'hidden');
}

function reveal() {
    $("#synset_input").css('visibility', '');
}

function changeSynsetInput() {
    if (parseInt($("#synset_input_relation").val()) == 2) {
        hide();
    } else {
        reveal();
    }
}

function openMeaningsMenu() {
Tomasz Bartosiak authored
59
    if(window.lemma_id != getActualLemmaId(window.lemma_id)){
Bartłomiej Nitoń authored
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    	alertOldSchemas();
    }
    else {
    	displayMeanings();
    }
}

function displayMeanings() {

    var submitInitialState =
                function(e,v,m,f){ 
                    e.preventDefault();

                    if (v == 1) {
                        $.prompt.goToState('state1');
                    }
                    if (v == 2) {
                        if (f.meaning >= 0) {
                            if (isPlWNUnit(f.meaning)) {
                                $.prompt.goToState('state22');
                            } else {
                                $.prompt.goToState('state21');
                            }
                        } else {
                            if (f.meaning <= 0) {
                                $.prompt.goToState('state21');
                            } else {
Tomasz Bartosiak authored
87
88
                                // $.prompt.goToState('state20');
                                alert('Nie wybrano żadnego znaczenia!');
Bartłomiej Nitoń authored
89
90
91
92
                            }
                        }
                    }
                    if (v == 3) {
Tomasz Bartosiak authored
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
                        if ((typeof f.meaning) == 'undefined') {
                            alert('Nie wybrano żadnego znaczenia!');
                        } else {
			    $.prompt.removeState('state3');
			    $.prompt.addState('state3', 
					      {
						title: 'Modyfikuj glossę', 
						html: 'Jednostka leksykalna: ' + getLexicalUnit(f.meaning) + '<br />' + 
						      '<label>Glossa <input type="text" name="glossa" value="' + getGlossa(f.meaning) + '"></label><br />', 
						buttons: glossa_buttons, 
						focus: 1, 
						submit: submitGlossa
					      }, 
					      'state22');
			    $.prompt.goToState('state3');
			}
Bartłomiej Nitoń authored
109
110
                    }
                    if (v == 4) {
Tomasz Bartosiak authored
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
                        if ((typeof f.meaning) == 'undefined') {
                            alert('Nie wybrano żadnego znaczenia!');
                        } else {
			    var i = indexOfId(lexical_units, f.meaning);

			    $.prompt.removeState('state4');
			    $.prompt.addState('state4', 
					      {
						title: 'Podepnij przykłady do ' + getLexicalUnit(f.meaning), 
						html: getExamples(f.meaning), 
						buttons: examples_assignment_buttons, 
						focus:1, 
						submit: submitExamplesAssignment
					      }, 
					      'state22');
			    $.prompt.goToState('state4');
			}
Bartłomiej Nitoń authored
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
                    }
                    if (v == 5) {
                        saveMeanings();
                        displayFrames();
		                $.prompt.close();  
		            }

	            };
    var initial_state_buttons = { "Dodaj znaczenie": 1, "Usuń znaczenie": 2, "Modyfikuj glossę": 3, "Ustaw przykłady": 4, "Koniec": 5 };

    var submitGlossa = 
                function(e,v,m,f){ 
                    e.preventDefault();

                    if (v == -1) {
                        $.prompt.goToState('state0');
                    }
                    if (v == 1) {
                        setGlossa(f.meaning, f.glossa[1]); // TODO: WHY f.glossa[1]?
                        $.prompt.removeState('state0');
                        $.prompt.addState('state0', {title: 'Znaczenia', html: getMeanings(), buttons: initial_state_buttons, focus: 4, submit: submitInitialState}, 'state1')
                        $.prompt.goToState('state0');
                    }

	            };
    var glossa_buttons = { "Anuluj": -1, "Potwierdź": 1 };

    var submitExamplesAssignment = 
                function(e,v,m,f){ 
                    e.preventDefault();

                    var connect = normalizeFormData(f.connect);

                    if (v == -1) {
                        $.prompt.goToState('state0');
                    }
                    if (v == 1) {
                        setExamples(f.meaning, connect);
                        $.prompt.goToState('state0');
                    }

	            };
    var examples_assignment_buttons = { "Anuluj": -1, "Potwierdź": 1 };

    var addLexicalUnitLocation =
        function(e,v,m,f){
            // arg = "frame_26_comp_36_"

            if (v == -1) {
                e.preventDefault();
                $.prompt.goToState('state1');
            }        
            if (v == 0) {
                e.preventDefault();
                $.prompt.goToState('state0');
            }
            if (v == 1) {
                e.preventDefault();
                if (parseInt(f.relation) != 2) {
                    $.prompt.removeState('state12');
Tomasz Bartosiak authored
188
                    $.prompt.addState('state12', {title: 'Znaczenia', html: getFormContent(f) + getRelation(f) + "w stosunku do:<br />" + getSynsets(f.context, part_of_speech), buttons: {Wstecz: -1, Anuluj: 0, Zatwierdź: 1}, focus: 1, submit: submitSynsetSelection}, 'state11');
Bartłomiej Nitoń authored
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
                    $.prompt.goToState('state12');
                } else {
                    createLexicalUnit(f.refl, f.glossa, f.relation, -1);
                    $.prompt.removeState('state0');
                    $.prompt.addState('state0', 
                                      {
                                        title: 'Znaczenia', 
                                        html: getMeanings(), 
                                        buttons: initial_state_buttons, 
                                        focus: 4, 
                                        submit: submitInitialState
                                      }, 
                                      'state1');
                    $.prompt.goToState('state0');                
                }
            }
        };
    var add_lexical_unit_location_buttons = { Wstecz: -1, Anuluj: 0, Potwierdź: 1 };

    var getFormContent = 
        function(f) {
Tomasz Bartosiak authored
210
211
212
	    var result = '';
	    if (part_of_speech == 'czasownik') {
		result += '<label>Zwrotny <input type="checkbox" name="refl" value="true" disabled';
Bartłomiej Nitoń authored
213
214
	        if (f.refl == 'true') {
	            result += ' checked';
Tomasz Bartosiak authored
215
216
217
218
219
                }
	        result += '></label><br />';
	    }
            result += '<label>Glossa <input type="text" name="glossa" value="' + f.glossa + '" disabled></label><br />';
	    return result;
Bartłomiej Nitoń authored
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
        };

    var getRelation = 
        function(f) {
	        return '<label>Relacja <select name="relation" disabled><option value="' + f.relation + '">' + relations_creating[parseInt(f.relation)] + '</option></label></select><br />';
        };

    var getRelationsForm =
        function () {
            var result = '<label>Relacja ';
            result += '<select id="synset_input_relation" name="relation" onchange="changeSynsetInput()">';
            result += '<option value="0">' + relations_creating[0] + '</option>';
            result += '<option value="1">' + relations_creating[1] + '</option>';
            result += '<option value="2">' + relations_creating[2] + '</option>';
            result += '</select></label><br />';
            return result;
        };

    var submitSynsetSelection =
        function(e,v,m,f){
            if (v == -1) {
                e.preventDefault();
                $.prompt.goToState('state11');
            }
            if (v == 0) {
                e.preventDefault();
                $.prompt.goToState('state0');
            }
            if (v == 1) {
                e.preventDefault();
                if ((typeof f.synset) == 'undefined') {
                    alert('Nie wybrano żadnego synsetu!');
                } else {
                    createLexicalUnit(f.refl, f.glossa, f.relation, f.synset);
                    $.prompt.removeState('state0');
                    $.prompt.addState('state0', 
                                      {
                                        title: 'Znaczenia', 
                                        html: getMeanings(), 
                                        buttons: initial_state_buttons, 
                                        focus: 4, 
                                        submit: submitInitialState
                                      }, 
                                      'state1');
                    $.prompt.goToState('state0');
                }
            }
        };
Tomasz Bartosiak authored
269
270
271
272
273
274
275
276
277
278
    var addMeaningsHtml =
        function() {
	    var result = '';
	    if (part_of_speech == 'czasownik') {
		result += '<label>Zwrotny <input type="checkbox" name="refl" value="true"></label><br />';
	    }
            result += '<label>Glossa <input type="text" name="glossa" value=""></label><br />';
	    return result;
        };
Bartłomiej Nitoń authored
279
280
281
282
283
284
285
286
287
288
    var display_meanings = {
            state0: {
	            title: 'Znaczenia',
	            html: getMeanings(),
	            buttons: initial_state_buttons,
	            focus: 4,
	            submit: submitInitialState,
            },
            state1: {
	            title: 'Dodawanie znaczenia',
Tomasz Bartosiak authored
289
	            html: addMeaningsHtml(),
Bartłomiej Nitoń authored
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
	            buttons: { "Anuluj": -1, "Potwierdź": 1 },
	            focus: 1,
	            submit:function(e,v,m,f){ 
                    e.preventDefault();
                    if (v == -1) {
                        $.prompt.goToState('state0');
                    }
                    if (v == 1) {
                        $.prompt.removeState('state11');
                        $.prompt.addState('state11', 
                                          {
                                            title: 'Miejsce w Słowosieci', 
                                            html: getFormContent(f) + getRelationsForm() + "<label id=\"synset_input\">w stosunku do <input id=\"plWN_context_selection\" type=\"text\" name=\"context\"></label>",
                                            buttons: add_lexical_unit_location_buttons,
                                            focus: 1, 
                                            submit: addLexicalUnitLocation
                                          }, 
                                          'state1');
                        $.prompt.goToState('state11');
                        attachPlWNContextAutocomplete();
                    }
	            }
            },
            state21: {
	            title: 'Usuwanie znaczenia',
	            html: 'Czy chcesz usunąć znaczenie?',
	            buttons: { "Nie": -1, "Tak": 1 },
	            focus: 1,
	            submit:function(e,v,m,f){ 
                    e.preventDefault();
                    if (v == -1) {
                        $.prompt.goToState('state0');
                    }
                    if (v == 1) {
                        destroyLexicalUnit(f.meaning);
                        $.prompt.removeState('state0');
                        $.prompt.addState('state0', {title: 'Znaczenia', html: getMeanings(), buttons: initial_state_buttons, focus:4, submit: submitInitialState}, 'state1');
                        $.prompt.goToState('state0');
                    }
	            }
            },
            state22: {
	            title: 'Usuwanie znaczenia',
	            html: 'Nie można usunąć znaczenia ze Słowosieci',
	            buttons: { "Ok": 1 },
	            focus: 1,
	            submit:function(e,v,m,f){ 
                    e.preventDefault();
                    $.prompt.goToState('state0');
	            }
            },
            state20: {
Tomasz Bartosiak authored
342
	            // title: 'Usuwanie znaczenia',
Bartłomiej Nitoń authored
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
	            html: 'Nie wybrano żadnego znaczenia',
	            buttons: { "Ok": 1 },
	            focus: 1,
	            submit:function(e,v,m,f){ 
                    e.preventDefault();
                    $.prompt.goToState('state0');
	            }
            },
        };
    if (change == true) {
        alertSemantics();
    } else {
        $.prompt(display_meanings);
    }

}
/////////////////////// Creating (Frames) ///////////////////////
function createFrame() {

    var create_frame = {
            state0: {
	            title: 'Tworzenie ramy',
	            html: getMeaningsSelection(),
	            buttons: { "Anuluj": -1, "Potwierdź": 1 },
	            focus: 1,
	            submit:function(e,v,m,f){ 
                    e.preventDefault();
                    if (v == -1) {
                        $.prompt.close();
                    }
                    if (v == 1) {

                        var units;
                        if ((typeof f.meaning) == 'string') {
                            units = [f.meaning];
                        } else {
                            units = f.meaning;
                        }
Tomasz Bartosiak authored
381
382
383
			if ((typeof units) == 'undefined') {
			    units = [];
			}
Bartłomiej Nitoń authored
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

                        frameClick("");
                        newFrame(units);
                        displayFrames();

                        $.prompt.close();
                    }
	            }
            },
        };
    if (change == true) {
        alertSemantics();
    } else {
        $.prompt(create_frame);
    }

}

function changeLexicalUnits() {
Tomasz Bartosiak authored
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
    var getRelation = 
        function(f) {
	        return '<label>Relacja <select name="relation" disabled><option value="' + f.relation + '">' + relations_creating[parseInt(f.relation)] + '</option></label></select><br />';
        };

    var getRelationsForm =
        function () {
            var result = '<label>Relacja ';
            result += '<select id="synset_input_relation" name="relation" onchange="changeSynsetInput()">';
            result += '<option value="0">' + relations_creating[0] + '</option>';
            result += '<option value="1">' + relations_creating[1] + '</option>';
            result += '<option value="2">' + relations_creating[2] + '</option>';
            result += '</select></label><br />';
            return result;
        };

    var units = [];
    var mwes = [];
Tomasz Bartosiak authored
422
423
    var new_mwes = [];
    var old_mwes = [];
Tomasz Bartosiak authored
424
425
426
427
428
429
430
431
432
433
434
435
    var a = "";
    var gloss = "";

    var addPhraseology =
                function(e,v,m,f){
                    e.preventDefault();
                    if (v == -1)
                        $.prompt.goToState('state0');
                    if (v == 0) {
                        $.prompt.close();
                    }
                    if (v == 1) {
Tomasz Bartosiak authored
436
437
438
439
                        if ((typeof f.synset) == 'undefined') {
                            alert('Nie wybrano żadnego synsetu!');
                        } else {
			    changeUnits(highlighted_id, units);
Tomasz Bartosiak authored
440
Tomasz Bartosiak authored
441
			    addPhraseologicalUnits(highlighted_id, units, old_mwes, new_mwes, f.glossa, f.relation, f.synset);
Tomasz Bartosiak authored
442
Tomasz Bartosiak authored
443
444
445
446
447
			    frameClick("");
			    displayFrames();
			    frameClick(a);
			    $.prompt.close();
                        }
Tomasz Bartosiak authored
448
449
450
                    }
                };
Bartłomiej Nitoń authored
451
452
453
454
455
456
457
    var change_units = {
            state0: {
	            title: 'Zmiana jednostek leksykalnych',
	            html: getMeaningsSelectionForFrame(highlighted_id),
	            buttons: { "Anuluj": -1, "Potwierdź": 1 },
	            focus: 1,
	            submit:function(e,v,m,f){ 
Tomasz Bartosiak authored
458
459
460
461
462
463
			e.preventDefault();
			if (v == -1) {
			    $.prompt.close();
			}
			if (v == 1) {
Tomasz Bartosiak authored
464
465
                            new_mwes = [];
                            old_mwes = [];
Tomasz Bartosiak authored
466
467
468
469
470
471
472
473
474
475
476
477
			    units = normalizeFormData(f.meaning);
			    mwes = normalizeFormData(f.mwe);
			    a = semantics_selected_id;

                            if (mwes.length == 0) {
                                changeUnits(highlighted_id, units);

                                frameClick("");
                                displayFrames();
                                frameClick(a);
                                $.prompt.close();
                            } else {
Tomasz Bartosiak authored
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517

                                 var i;
                                 for (i = 0; i < mwes.length; i++) {
                                     var lu = mwes[i].split('_')[0];
                                     var id = mwes[i].split('_')[1];
                                     var luid = mwes[i].split('_')[2];
                                     var sid = mwes[i].split('_')[3];
                                     if (sid == '') {
                                         new_mwes.push(lu);
                                     } else {
                                         old_mwes.push({lu: lu, id: parseInt(id), luid: parseInt(luid), sid: parseInt(sid)});
                                     }
                                 }

                                 if (old_mwes.length > 0) {
                                     var sid = old_mwes[0].sid
                                     var ok = true;
                                     for (i = 0; i < old_mwes.length; i++) {
                                         if (old_mwes[i].sid != sid) {
                                             ok = false;
                                         }
                                     }
                                     if (ok) {
                                         changeUnits(highlighted_id, units);


                                         addPhraseologicalUnits(highlighted_id, units, old_mwes, new_mwes, old_mwes[0].lu, 1, sid);

                                         frameClick("");
                                         displayFrames();
                                         frameClick(a);
                                         $.prompt.close();
                                     } else {
                                         $.prompt.goToState('state1');
                                         attachPlWNContextAutocomplete();
                                     }
                                 } else {
                                     $.prompt.goToState('state1');
                                     attachPlWNContextAutocomplete();
                                 }
Tomasz Bartosiak authored
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
                            }

			}
	            }
            },
            state1: { /* nowa frazeologia */
	            title: 'Nowe jednostki frazeologiczne',
	            html: '<label>Glossa <input type="text" name="glossa" value=""></label><br />' + 
                          getRelationsForm() + "<label id=\"synset_input\">w stosunku do <input id=\"plWN_context_selection\" type=\"text\" name=\"context\"></label>",
	            buttons: { "Wstecz": -1, "Anuluj": 0, "Potwierdź": 1 },
	            focus: 1,
	            submit:function(e,v,m,f){ 
			e.preventDefault();
			if (v == -1) {
			    $.prompt.goToState('state0');
			}
                        if (v == 0) {
Bartłomiej Nitoń authored
535
536
                            $.prompt.close();
                        }
Tomasz Bartosiak authored
537
538
539
540
541
542
543
544
			if (v == 1) {
                            if (parseInt(f.relation) != 2) { 
                                /* podana lokalizacja w Słowosieci */
                                $.prompt.removeState('state2');
                                $.prompt.addState('state2',
                                                  {
                                                      title: 'Znaczenia',
                                                      html: '<label>Glossa <input type="text" name="glossa" value="' + gloss + '" disabled></label><br />' + 
Tomasz Bartosiak authored
545
                                                            getRelation(f) + "w stosunku do:<br />" + getSynsets(f.context, part_of_speech), 
Tomasz Bartosiak authored
546
547
548
549
550
551
552
                                                      buttons: {Wstecz: -1, Anuluj: 0, Zatwierdź: 1}, 
                                                      focus: 1, 
                                                      submit: addPhraseology
                                                  })
                                $.prompt.goToState('state2');
                            } else {
                                /* zignorowane umiejscowienie w Słowosieci */
Tomasz Bartosiak authored
553
                                addPhraseologicalUnits(highlighted_id, units, old_mwes, new_mwes, f.glossa, f.relation, -1);
Tomasz Bartosiak authored
554
555
556
557
558
559
560
			        frameClick("");
			        displayFrames();
			        frameClick(a)
                                $.prompt.close();
                            }
			}
	            }       
Bartłomiej Nitoń authored
561
562
563
564
565
566
567
568
569
570
            },
        };
    if (change == true) {
        alertSemantics();
    } else {
        $.prompt(change_units);
    }

}
Tomasz Bartosiak authored
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
function changeOpinion() {

    var change_opinion = {
            state0: {
	            title: 'Ustawianie statusu ramy',
	            html: getStatusesForFrame(highlighted_id),
	            buttons: { "Anuluj": -1, "Potwierdź": 1 },
	            focus: 1,
	            submit:function(e,v,m,f){ 
                    e.preventDefault();
                    if (v == -1) {
                        $.prompt.close();
                    }
                    if (v == 1) {

                        var opinion = normalizeFormData(f.opinion);
                        if (opinion.length > 0) {

                            var a = semantics_selected_id;
                            setOpinion(highlighted_id, opinion);
                            frameClick("");
                            displayFrames();
                            frameClick(a);

                            $.prompt.close();

                        } else {

                            alert("Nie wybrano żadnego statusu");

                        }
                    }
	            }
            },
        };
    if (change == true) {
        alertSemantics();
    } else {
        $.prompt(change_opinion);
    }

}
Bartłomiej Nitoń authored
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
// assign role to selected complement
function assignRole() {

    var result = false;

    var assign_role = {
            state0: {
                title: 'Wybierz rolę',
                html: roles_display_table,
                buttons: { Anuluj: -1, Zatwierdź: 1 },
                focus: 1,
                close: function(){return result;},
                submit: function(e,v,m,f){ 
                    // arg = "frame_26_comp_36_"

                    if (v == -1) {
                        e.preventDefault();
                        $.prompt.close();
                    }
                    if (v == 1) {
                        e.preventDefault();

                        var roles = normalizeFormData(f.roles);

                        var frame_id = parseInt(arg.split('_')[1]);
                        var complement_id = parseInt(arg.split('_')[3]);

                        if (setRole(frame_id, complement_id, roles)) {

                            var h = "frame_" + highlighted_id + "_";
                            var a = arg;

                            // re-draw and re-color frame
                            frameClick(h);
                            displayFrames();
                            frameClick(a);

                            result = true;
                            $.prompt.close();

                        } else {

                            alert("Wybrano niepoprawne role!");

                        }
                    }

                }
            },
        };
    if (change == true) {
        alertSemantics();
    } else {
        $.prompt(assign_role);
    }

}

function addSelectivePreference() {

    var submitSynsetSelection = function(e,v,m,f){ 
                    if (v == -1) {
                        e.preventDefault();
                        $.prompt.goToState('state2');                    
                    }
                    if (v == 1) {
                        e.preventDefault();
                        var frame_id = parseInt(arg.split('_')[1]);
                        var complement_id = parseInt(arg.split('_')[3]);
                        var synset = normalizeFormData(f.synset);

                        var i;
                        for (i = 0; i < synset.length; i++) {
                            addPreference(frame_id, complement_id, { type: 's', content: synset[i], text: synsets[indexOfId(synsets, synset[i])].content[0].base + "-" + synsets[indexOfId(synsets, synset[i])].content[0].sense });
                        }
                        $.prompt.goToState('state0');                       
                    }
                }

    var select_preference = {
            state0: {
                title: 'Typ preferencji selekcyjnej',
                html: 'Wybierz typ preferencji selekcyjnej',
                buttons: { Predefiniowana: 1, Słowosieć: 2, Relacja: 3, Koniec: -1 },
                focus: -1,
                submit: function(e,v,m,f){ 
                    if (v == -1) {
                        e.preventDefault();

                        var h = "frame_" + highlighted_id + "_";
                        var a = arg;

                        // re-draw and re-color frame
                        frameClick(h);
                        displayFrames();
                        frameClick(a);

                        $.prompt.close();
                    }
                    if (v == 1) {
                        e.preventDefault();
                        $.prompt.goToState('state1');

                    } 
                    if (v == 2) {
                        e.preventDefault();
                        $.prompt.goToState('state2');

                    } 
                    if (v == 3) {
                        e.preventDefault();
                        $.prompt.goToState('state3');

                    } 
                }
            },
            state1: {
                title: 'Wybierz preferencję selekcyjną',
                html: predefinedSelect(),
                buttons: { Anuluj: -1, Zatwierdź: 1 },
                focus: 1,
                submit: function(e,v,m,f){
                    // arg = "frame_26_comp_36_"

                    if (v == -1) {
                        e.preventDefault();
                        $.prompt.goToState('state0');
                    }
                    if (v == 1) {
                        e.preventDefault();
                        var frame_id = parseInt(arg.split('_')[1]);
                        var complement_id = parseInt(arg.split('_')[3]);
                        var predef = normalizeFormData(f.predef);

                        var i;
                        for (i = 0; i < predef.length; i++) {
                            addPreference(frame_id, complement_id, { type: 'g', content: predef[i], text: predefined[indexOfId(predefined, predef[i])].content });
                        }
                        $.prompt.goToState('state0');
                    }
                }
            },
            state2: {
                title: 'Wybierz preferencję selekcyjną',
                html: "<input id=\"plWN_context_selection\" type=\"text\" name=\"context\">",
                buttons: { Anuluj: -1, Wyszukaj: 1 },
                focus: 1,
                submit: function(e,v,m,f){
                    // arg = "frame_26_comp_36_"

                    if (v == -1) {
                        e.preventDefault();
                        $.prompt.goToState('state0');
                    }
                    if (v == 1) {
                        e.preventDefault();
                        $.prompt.removeState('state21');
                        $.prompt.addState('state21', {title: 'Znaczenia', html: getSynsets(f.context), buttons: {Anuluj: -1, Zatwierdź: 1}, focus: 1, submit: submitSynsetSelection}, 'state2');
                        $.prompt.goToState('state21');
                    }
                }
            },
            state3: {
                title: 'Wybierz relację i argument',
                html: relationArgument(arg),
                buttons: { Anuluj: -1, Zatwierdź: 1 },
                focus: 1,
                submit: function(e,v,m,f){
                    // arg = "frame_26_comp_36_"

                    if (v == -1) {
                        e.preventDefault();
                        $.prompt.goToState('state0');
                    }
                    if (v == 1) {
                        e.preventDefault();

                        var frame_id = parseInt(arg.split('_')[1]);
                        var complement_id = parseInt(arg.split('_')[3]);
                        var rel = normalizeFormData(f.rel);
                        var args = normalizeFormData(f.arg);

                        var i, j;
                        for (i = 0; i < rel.length; i++) {
                            var text = [];
                            for (j = 0; j < args.length; j++) {
                                var list = args[j].split(',');
                                var k;
                                for (k = 0; k < list.length; k++) {
                                    text.push(role_name[list[k]]);
                                }
                                addPreference(frame_id, complement_id, {type: 'r', content: { relation: rel[i], to: args[j] }, text: relations[indexOfId(relations, rel[i])].content + "<br>-> [" + text + "]" });
                            }
                        }

                        $.prompt.goToState('state0');
                    }
                }
            },
        };
    if (change == true) {
        alertSemantics();
    } else {
        $.prompt(select_preference);
        attachPlWNContextAutocomplete();
    }

}

function removeFromFrame() {
    if (change == true) {
        alertSemantics();
        return;
    }
    if (op == "none") {
    }
    if (op == "add_argument") {
        // highlighted_id = "26"

        removeFrame(highlighted_id);
Tomasz Bartosiak authored
834
Bartłomiej Nitoń authored
835
836
837
838
839
        frameClick("frame_" + highlighted_id + "_");
        displayFrames();

    }
    if (op == "add_realization") {
Tomasz Bartosiak authored
840
        // arg = "frame_26_comp_36_(lemma_)"
Bartłomiej Nitoń authored
841
842
843
844
845
846
847

        var frame_id = parseInt(arg.split('_')[1]);
        var complement_id = parseInt(arg.split('_')[3]);
        var pos = -1;
        var h = "frame_" + highlighted_id + "_";

        frameClick(h);
Tomasz Bartosiak authored
848
849

        removeArgument(frame_id, complement_id, arg);
Bartłomiej Nitoń authored
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879

        op = "add_argument";
        arg = "";

        displayFrames();
        frameClick(h);

    }
    if (op == "remove_preference") {
        // arg = "frame_26_comp_36_pref_s1_"

        var frame_id = parseInt(arg.split('_')[1]);
        var complement_id = parseInt(arg.split('_')[3]);
        var preference_id = arg.split('_')[5];
        var pos = -1;
        var h = "frame_" + highlighted_id + "_";

        frameClick(h);

        removePreference(frame_id, complement_id, preference_id);

        op = "add_argument";
        arg = "";

        displayFrames();
        frameClick(h);

    }
}
Tomasz Bartosiak authored
880
881
882
///////////////////////// Frame Sharing /////////////////////////

function sharableFrames() {
Tomasz Bartosiak authored
883
    return getDisplay(false, true);
Tomasz Bartosiak authored
884
885
886
887
888
889
890
891
892
893
894
895
896
}

function shareFrame() {

    var share_frame = {
	state0: {
	    title: 'Współdzielona rama',
	    html: sharableFrames(),
	    buttons: { Anuluj: -1, Zatwierdź: 1 },
	    focus: 1,
	    submit: function(e,v,m,f) {
		if (v == -1) {
		    e.preventDefault();
Tomasz Bartosiak authored
897
		    $.prompt.close();
Tomasz Bartosiak authored
898
899
		}
		if (v == 1) {
Tomasz Bartosiak authored
900
901
902
903
904
905
		    var frames = normalizeFormData(f.frames);
		    var i;
		    for (i = 0; i < frames.length; i++) {
			frame_content[frames[i]].visible = true;
		    }
		    displayFrames();
Tomasz Bartosiak authored
906
		    e.preventDefault();
Tomasz Bartosiak authored
907
		    $.prompt.close();
Tomasz Bartosiak authored
908
909
910
911
912
913
914
915
916
		}
	    }
	},
    };

    $.prompt(share_frame);

}
Bartłomiej Nitoń authored
917
918
919
//////////////////////////// Display ////////////////////////////

function frameClick(clicked_id) {
Tomasz Bartosiak authored
920
Bartłomiej Nitoń authored
921
    if (clicked_id == "") {
Bartłomiej Nitoń authored
922
        deselect();
Bartłomiej Nitoń authored
923
924
        highlighted_id = "";
        semantics_selected_id = "";
Tomasz Bartosiak authored
925
926
927
928
929
930
	$('#assign_role').attr('disabled', "True");
	$('#add_preference').attr('disabled', "True");
	$('#delete').attr('disabled', "True");
	$('#multi_lus').attr('disabled', "True");
	$('#change_lus').attr('disabled', "True");
	$('#change_opinion').attr('disabled', "True");
Bartłomiej Nitoń authored
931
932
933
934
935
936
937
        return;
    }

    if (control != "connect") {
        var frame_id = clicked_id.split('_')[1]

        if (highlighted_id != "") {
Bartłomiej Nitoń authored
938
            deselect();
Bartłomiej Nitoń authored
939
940
941
942
943
944
945
946
947
948
949
950
951
        }

        if (semantics_selected_id == frame_id) {
            highlighted_id = "";
            semantics_selected_id = ""
        } else {
            select(frame_id, clicked_id.split('comp')[0]);
            highlighted_id = frame_id;
            semantics_selected_id = frame_id;
        }
    } else {
        if (clicked_id.split('_').length == 3) {    // frame click
            var frame_id = clicked_id.split('_')[1];
Tomasz Bartosiak authored
952
953
954
955
	    var local = true;
	    if (frame_content[frame_id] != null){
		local = frame_content[frame_id].local;
	    }
Bartłomiej Nitoń authored
956
957

            if (highlighted_id != "") {
Bartłomiej Nitoń authored
958
                deselect();
Bartłomiej Nitoń authored
959
960
961
962
963
964
965
966
967
            }
            if (semantics_selected_id == clicked_id) {
                highlighted_id = "";
                semantics_selected_id = "";
                op = "none";

                $('#assign_role').attr('disabled', "True");
                $('#add_preference').attr('disabled', "True");
                $('#delete').attr('disabled', "True");
Tomasz Bartosiak authored
968
		$('#multi_lus').attr('disabled', "True");
Bartłomiej Nitoń authored
969
                $('#change_lus').attr('disabled', "True");
Tomasz Bartosiak authored
970
		$('#change_opinion').attr('disabled', "True");
Bartłomiej Nitoń authored
971
972
973
974
975
976
977
978
            } else {
                select(frame_id, clicked_id);
                highlighted_id = frame_id;
                semantics_selected_id = clicked_id;
                op = "add_argument";

                $('#assign_role').attr('disabled', "True");
                $('#add_preference').attr('disabled', "True");
Tomasz Bartosiak authored
979
		$('#multi_lus').removeAttr('disabled');
Bartłomiej Nitoń authored
980
                $('#change_lus').removeAttr('disabled');
Tomasz Bartosiak authored
981
982
983
984
985
986
987
		if (!local) {
                    $('#delete').attr('disabled', "True");
		    $('#change_opinion').attr('disabled', "True");
		} else {
                    $('#delete').removeAttr('disabled');
		    $('#change_opinion').removeAttr('disabled');
		}
Bartłomiej Nitoń authored
988
            }
Tomasz Bartosiak authored
989
990
        } else if (clicked_id.split('_')[4] == 'lemma') { // part of lemma click
            frame_id = clicked_id.split('_')[1]
Tomasz Bartosiak authored
991
992
993
994
	    var local = true;
	    if (frame_content[frame_id] != null){
		local = frame_content[frame_id].local;
	    }
Tomasz Bartosiak authored
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021

            if (highlighted_id != "") {
                deselect();
            }
            if (semantics_selected_id == clicked_id) {
                highlighted_id = "";
                semantics_selected_id = "";
                op = "none";

                $('#assign_role').attr('disabled', "True");
                $('#add_preference').attr('disabled', "True");
                $('#delete').attr('disabled', "True");
		$('#multi_lus').attr('disabled', "True");
                $('#change_lus').attr('disabled', "True");
		$('#change_opinion').attr('disabled', "True");
            } else {
                select(frame_id, clicked_id);

                highlighted_id = frame_id;
                semantics_selected_id = clicked_id;
                op = "add_realization";
                arg = clicked_id //.split('pref')[0]

                $('#assign_role').attr('disabled', "True");
                $('#add_preference').attr('disabled', "True");
		$('#multi_lus').removeAttr('disabled');
                $('#change_lus').removeAttr('disabled');
Tomasz Bartosiak authored
1022
1023
1024
1025
1026
1027
1028
		if (!local) {
                    $('#delete').attr('disabled', "True");
		    $('#change_opinion').attr('disabled', "True");
		} else {
                    $('#delete').removeAttr('disabled');
		    $('#change_opinion').removeAttr('disabled');
		}
Tomasz Bartosiak authored
1029
            }
Bartłomiej Nitoń authored
1030
1031
        } else { // argument click
            frame_id = clicked_id.split('_')[1]
Tomasz Bartosiak authored
1032
1033
1034
1035
	    var local = true;
	    if (frame_content[frame_id] != null){
		local = frame_content[frame_id].local;
	    }
Bartłomiej Nitoń authored
1036
1037

            if (highlighted_id != "") {
Bartłomiej Nitoń authored
1038
                deselect();
Bartłomiej Nitoń authored
1039
1040
1041
1042
1043
1044
1045
1046
1047
            }
            if (semantics_selected_id == clicked_id) {
                highlighted_id = "";
                semantics_selected_id = "";
                op = "none";

                $('#assign_role').attr('disabled', "True");
                $('#add_preference').attr('disabled', "True");
                $('#delete').attr('disabled', "True");
Tomasz Bartosiak authored
1048
		$('#multi_lus').attr('disabled', "True");
Bartłomiej Nitoń authored
1049
                $('#change_lus').attr('disabled', "True");
Tomasz Bartosiak authored
1050
		$('#change_opinion').attr('disabled', "True");
Bartłomiej Nitoń authored
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
            } else {
                select(frame_id, clicked_id);

                highlighted_id = frame_id;
                semantics_selected_id = clicked_id;
                if(clicked_id.split('_').length == 5) {        
                    op = "add_realization";
                } else {
                    op = "remove_preference";
                }
                arg = clicked_id //.split('pref')[0]
Tomasz Bartosiak authored
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073

		if (!local) {
                    $('#assign_role').attr('disabled', "True");
                    $('#add_preference').attr('disabled', "True");
                    $('#delete').attr('disabled', "True");
		    $('#change_opinion').attr('disabled', "True");
		} else {
                    $('#assign_role').removeAttr('disabled');
                    $('#add_preference').removeAttr('disabled');
                    $('#delete').removeAttr('disabled');
		    $('#change_opinion').removeAttr('disabled');
		}
Tomasz Bartosiak authored
1074
		$('#multi_lus').removeAttr('disabled');
Bartłomiej Nitoń authored
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
                $('#change_lus').removeAttr('disabled');
            }
        }
    }
}

function select(frame_id, clicked_id) { 

    redrawSchemas(frame_id);
    getDisplayedExamples(frame_id);
    displayExamples();
    fadeSchemas();
    highlighted_id = frame_id;
    brightenSchemasForDisplayedExamples();
    selectFrame(frame_id, clicked_id);

}   
Bartłomiej Nitoń authored
1093
function deselect() {
Bartłomiej Nitoń authored
1094
1095
1096
1097
1098
1099

    redrawSchemas();
    displayed_examples = [];
    clearExampleArgumentsSelection();
    displayExamples();
    deselectFrame();
Bartłomiej Nitoń authored
1100
    deselectSchema();
Bartłomiej Nitoń authored
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
    brightenSchemas();

} 

function selectFrame(frame_id, clicked_id) {

    $("#frame_" + frame_id + "_").css('background-color', 'LightSteelBlue');

    var i;
    var roles = frame_content[frame_id].display.roles;
    for (i = 0; i < roles.length; i++) {
        var style = getStyle(frame_id, i)
        $('#' + roles[i].csv_id).css(style.type, style.value);
        var j;
        for (j = 0; j < connected[roles[i].csv_class].length; j++) {
            $('#' + connected[roles[i].csv_class][j]).css(style.type, style.value);
            $('#' + connected[roles[i].csv_class][j]).css('color', '');
            $('#' + functionCsvId(connected[roles[i].csv_class][j])).css(style.type, style.value);
            $('#' + functionCsvId(connected[roles[i].csv_class][j])).css('color', '');
        }
    }
Tomasz Bartosiak authored
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134

    var lemma = frame_content[frame_id].lemma;
    if (lemma.include) {
        var style = {type: 'background-color', value: 'white'};
        $('#' + lemma.csv_id).css(style.type, style.value);
        var j;
        for (j = 0; j < connected[lemma.csv_class].length; j++) {
            $('#' + connected[lemma.csv_class][j]).css(style.type, style.value);
            $('#' + connected[lemma.csv_class][j]).css('color', '');
            $('#' + functionCsvId(connected[lemma.csv_class][j])).css(style.type, style.value);
            $('#' + functionCsvId(connected[lemma.csv_class][j])).css('color', '');
        }
    }
Bartłomiej Nitoń authored
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288

    $("#" + clicked_id).css('border-width', '5px');

}

function deselectFrame() {

	$('[class^=frame_]').each(function(){
		$(this).css('background-color', "");
		$(this).css('background', "");
		$(this).css('border-width', '');
	});
}

function fadeSchemas() {

	$('[class^=schema_]').each(function(){
		$(this).css('color', "#aaaaaa");
		$(this).css('background-color', "#e8e8e8");
	});

}


function brightenSchemas() {

	$('[class^=schema_]').each(function(){
		$(this).css('color', "");
		$(this).css('background-color', "");
		$(this).css('background', "");
	});

}

function brightenSchemasForDisplayedExamples() {

    var i;
    for (i = 0; i < displayed_examples.length; i++){
        brightenSchemaArguments(displayed_examples[i].arguments);
    }

}

function brightenSchemaArguments(arguments_list) {

    if (arguments_list.length > 0) {
        brightenSchemaHeader(schemaId(arguments_list[0].id))

        var alts = alternations(selectedFrameId(), schemaId(arguments_list[0].id));
        var i, j;   
        for (i = 0; i < arguments_list.length; i++) {
            for (j = 0; j < alts; j++) {
                $('#schema_' + arguments_list[i].id.split('_')[1] + '_pos_' + arguments_list[i].id.split('_')[3] + '_alt_' + (j + 1) + '_').css('color', "");
                $('#schema_' + arguments_list[i].id.split('_')[1] + '_pos_' + arguments_list[i].id.split('_')[3] + '_alt_' + (j + 1) + '_').css('background-color', "");
                $('#' + arguments_list[i].id + 'alt_' + (j + 1) + '_').css('color', "");
		        $('#' + arguments_list[i].id + 'alt_' + (j + 1) + '_').css('background-color', "");
            }
        }
    }

}

function brightenSchemaHeader(schema_id) {

    $("#schema_" + schema_id + '_').css('color', "");
    $("#schema_" + schema_id + '_').css('background-color', "");   

}

function getDisplayedExamples(frame_id) {

    var lexical_units = getFrameLexicalUnits(frame_id);

    displayed_examples = [];

    var i;
    var to_display = false;
    for (i = 0; i < examples.length; i++) {
        to_display = false;
        var j;
        for (j = 0; j < lexical_units.length; j++) {
            if(examples[i].meanings.indexOf(parseInt(lexical_units[j].id)) != -1) {
                to_display = true;
            }
        }
        if (to_display) {
            displayed_examples.push(examples[i]);
        }
    }

}

function displayExamples() {

    $("#semantics-examples").html(getDisplayedExamplesTable());

}

function getFrameLexicalUnits(frame_id) {

    var selected_lexical_units = [];

    var i;
    for (i = 0; i < lexical_units_frames.length; i++) {
        if (lexical_units_frames[i].indexOf(frame_id) != -1) {
            selected_lexical_units = selected_lexical_units.concat(lexical_units_num[i]);
        }
    }

    return selected_lexical_units;

}

function getDisplayedExamplesTable() {
    var table = '<table id="examples_table" class="ChangeControlTable">';

    table += '<tr>';
    table += '<td class="ColumnHeader">Identyfikator:</td>';
    table += '<td class="ColumnHeader">Przykład:</td>';
    table += '<td class="ColumnHeader">Źródło:</td>';
    table += '<td class="ColumnHeader">Ocena:</td>';
    table += '</tr>';

    var i;
    for (i = 0; i < displayed_examples.length; i++){
    	var exampleDomId = 'example_' + displayed_examples[i].id;
        table += '<tr id="' + exampleDomId + '" class="ExampleRow">';
        table += '<td ' + 'onclick=showExampleArguments("' + exampleDomId + '")' + '>' + displayed_examples[i].id + '</td>';
        table += '<td ' + 'onclick=showExampleArguments("' + exampleDomId + '")' + '>' + displayed_examples[i].sentence + '</td>';
        table += '<td ' + 'onclick=showExampleArguments("' + exampleDomId + '")' + '>' + displayed_examples[i].source + '</td>';
        table += '<td ' + 'onclick=showExampleArguments("' + exampleDomId + '")' + '>' + displayed_examples[i].opinion + '</td>';
        table += '</tr>';
    }

    table += '</table>';

    return table;
}

function color(what, how, disconnected_background, disconnected_text) {

    for (i = 0; i < connected[what].length; i++) {
        $('.' + connected[what][i]).css('background-color', how);
        $('.' + what).css('background-color', how);
    }

    capo = frame_id(what)
    for (i = 0; i < disconnected[capo].length; i++) {
        $('.' + disconnected[capo][i]).css('background-color', disconnected_background);
        $('.' + disconnected[capo][i]).css('color', disconnected_text);
    }

}
Tomasz Bartosiak authored
1289
function schemaClick(class_id, lex) {
Bartłomiej Nitoń authored
1290
Tomasz Bartosiak authored
1291
1292
1293
1294
1295
    var table = roles_display_table;
    if (lex.length != 0){
	table = roles_display_table_full;
    }
Bartłomiej Nitoń authored
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
    var field_ids;
    if (class_id.split('arg').length == 1) {
        field_ids = position_arguments[class_id].slice();
    } else {
        if (class_id.split('_').length > 7) {
            if (parseInt(class_id.split('_')[5]) < 0) {
                return;
            }
        }
        field_ids = [class_id];
    }
Tomasz Bartosiak authored
1307
Bartłomiej Nitoń authored
1308
1309
1310
1311
1312
1313
    if (control == "connect") {
        if (op == "none") {
            return;
        }
        if (op == "add_argument") {
            // highlighted_id = "26"
Tomasz Bartosiak authored
1314
1315
1316
1317
	    var local = frame_content[highlighted_id].local;
	    if (!local) {
		return;
	    }
Bartłomiej Nitoń authored
1318
1319
            var frame_id = parseInt(highlighted_id);
Tomasz Bartosiak authored
1320
1321
1322
1323
1324
            if (roleFree(frame_id, field_ids)) {

                var choose_role = {
                        state0: {
                            title: 'Wybierz rolę',
Tomasz Bartosiak authored
1325
                            html: table,
Tomasz Bartosiak authored
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
                            buttons: { Anuluj: -1, Zatwierdź: 1 },
                            focus: 1,
                            close: function(){return result;},
                            submit: function(e,v,m,f){ 

                                if (v == -1) {
                                    e.preventDefault();
                                    $.prompt.close();
                                }
                                if (v == 1) {
                                    e.preventDefault();
Bartłomiej Nitoń authored
1337
Tomasz Bartosiak authored
1338
1339
1340
1341
                                    var roles = normalizeFormData(f.roles);

                                    // var frame_id = parseInt(highlighted_id);
                                    var complement_id = addArgument(frame_id, field_ids, roles);
Bartłomiej Nitoń authored
1342
Tomasz Bartosiak authored
1343
1344
                                    if (complement_id) {
                                        var h = "frame_" + highlighted_id + "_";
Tomasz Bartosiak authored
1345
                                        var a = complement_id;  //"frame_" + highlighted_id + "_comp_" + complement_id + "_";
Tomasz Bartosiak authored
1346
1347
1348
1349
1350
1351
1352
1353

                                        // re-draw and re-color frame
                                        frameClick(h);
                                        displayFrames();
                                        frameClick(a);

                                        result = true;
                                        $.prompt.close();
Tomasz Bartosiak authored
1354
                                    } /*else {
Tomasz Bartosiak authored
1355
                                        alert("Wybrano niepoprawne role!");
Tomasz Bartosiak authored
1356
                                    } */ 
Bartłomiej Nitoń authored
1357
                                }
Tomasz Bartosiak authored
1358
Bartłomiej Nitoń authored
1359
                            }
Tomasz Bartosiak authored
1360
1361
1362
1363
1364
1365
1366
                        },
                    };
                if (change == true) {
                    alertSemantics();
                } else {
                    $.prompt(choose_role);
                }
Bartłomiej Nitoń authored
1367
            } else {
Tomasz Bartosiak authored
1368
                alert("Nie można ponownie podłączyć tej samej pozycji składniowej");
Bartłomiej Nitoń authored
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
            }

        }
        if (op == "add_realization") {
            if (change == true) {
                alertSemantics();
                return;
            }
            if (arg == "") {
                return;
            } else {
Tomasz Bartosiak authored
1380
1381
1382
1383
1384
                // arg = "frame_26_comp_36_(lemma_)"
                if (arg.split('_')[4] == 'lemma' && lex.length == 0) {
                    alert("Nie można podłączyć do lematu!");
                    return;
                }
Tomasz Bartosiak authored
1385
                var frame_id = parseInt(parseInt(arg.split('_')[1]));
Bartłomiej Nitoń authored
1386
                var i, j;
Tomasz Bartosiak authored
1387
                var can_connect = false;
Tomasz Bartosiak authored
1388
                if (roleFree(frame_id, field_ids)) {
Tomasz Bartosiak authored
1389
                    can_connect = true;
Tomasz Bartosiak authored
1390
1391
                }
                var connect = true;
Bartłomiej Nitoń authored
1392
                for (i = 0; i < field_ids.length; i++) {
Tomasz Bartosiak authored
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
                    if (connected[arg].indexOf(field_ids[i]) != -1) {
                    connect = false;
                    break;
                    }
                }
                if (connect && !can_connect) {
                    alert("Nie można ponownie podłączyć tej samej pozycji składniowej");
                } else {
                    for (i = 0; i < field_ids.length; i++) {
                        if (!connect) {
                            // disconnect
                            j = connected[arg].indexOf(field_ids[i])
                            if (j != -1) {
                                connected[arg].splice(j, 1);
Tomasz Bartosiak authored
1407
1408
                                j = connected_reverse[field_ids[i]].indexOf('frame_' + frame_id + '_')
                                connected_reverse[field_ids[i]].splice(j, 1);
Tomasz Bartosiak authored
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
                                frames_operations.push({operation: 'disconnect', arg: arg, connect: field_ids[i]});
                                var a = arg;
                                frameClick("");
                                frameClick(a);
                            }
                        } else {
                            //connect
                            j = connected[arg].indexOf(field_ids[i])
                            if (j == -1) { // redundant
                                connected[arg].push(field_ids[i]);
Tomasz Bartosiak authored
1419
1420
1421
1422
                                if (typeof(connected_reverse[field_ids[i]]) == 'undefined') {
                                    connected_reverse[field_ids[i]] = []
                                }
                                connected_reverse[field_ids[i]].push('frame_' + frame_id + '_');
Tomasz Bartosiak authored
1423
1424
1425
1426
1427
1428
                                frames_operations.push({operation: 'connect', arg: arg, connect: field_ids[i]});
                                var a = arg;
                                frameClick("");
                                frameClick(a);
                            }
                        }
Bartłomiej Nitoń authored
1429
1430
1431
1432
1433
1434
1435
1436
1437
                    }
                } 
            } 
        }
    } else {
        return;
    }
}
Bartłomiej Nitoń authored
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
function selectSchema(schema_id) {
	deselect();
    $("#schema_" + schema_id + "_").css('background-color', 'LightSteelBlue');
    $("#schema_" + schema_id + "_").css('border-width', '5px');
    getSchemaExamples(schema_id);
    displayExamples();
}

function deselectSchema() {
	$('[class^=schema_]').each(function(){
		$(this).css('background-color', "");
		$(this).css('background', "");
		$(this).css('border-width', '');
	});
}

function getSchemaExamples(schema_id) {

    displayed_examples = [];
    for(var i=0; i<window.examples.length; i++) {
      var exampleSchemaId = schemaId(window.examples[i].arguments[0].id);
      if(exampleSchemaId == schema_id) {
    	  displayed_examples.push(window.examples[i]);
      }
    }

}
Bartłomiej Nitoń authored
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
var exampleSelectionColor = "rgb(176,196,222)";

function showExampleArguments(id) {
	clearExamplesSelection();
	selectExample(id);
	selectExampleArguments(id);
}

function clearExamplesSelection() {
	$('[id^=example_][selected=selected]').children().css('background-color', "");
	$('[id^=example_][selected=selected]').removeAttr('selected');
}

function selectExample(example_dom_id)
{  	 
	$('#' + example_dom_id).attr('selected', "selected");
	$('#' + example_dom_id).children().css('background-color', exampleSelectionColor);
}

function selectExampleArguments(example_dom_id) {
	var selected_example = null;
	var selected_example_id = example_dom_id.replace('example_', '');
	clearExampleArgumentsSelection();

	for(i = 0; i < window.nkjp_examples.length; i++) {
		if(window.nkjp_examples[i].example_id == selected_example_id) {
			selected_example = window.nkjp_examples[i];
			break;
		}
	}

	if(selected_example) {
		var selected_schema_id = parseId(selected_example.arguments_ids[0])['frame_id'];
		goToFrame('schema_'+selected_schema_id+'_', document.getElementById('schemas'));
		for(i = 0; i < selected_example.arguments_ids.length; i++) {
			var arg_dom_id = selected_example.arguments_ids[i].replace('frame', 'schema');
			$('[id^=' + arg_dom_id + ']').each(function(){
				$(this).attr('selected', "selected");
			});
		}
	}
}

function clearExampleArgumentsSelection() {
	$('[id^=schema_][id*=_arg_][selected=selected]').each(function() {
		$(this).removeAttr('selected');
	});
}

function frame_id(class_id) {
    parts = class_id.split('_');
    if (parts.length < 3) {
        console.log("Błąd wywołania");
        return "";
    }
    var result = "";
    for (i = 0; i < 2; i++) {
        result += parts[i] + '_';
    }
    return result;
}

function value_compare(a, b) {
    return b.value - a.value;
}

/////////////////////////// Splitters ///////////////////////////

var hSplitterId = 'semantics-hsplit';
var topSplitId = 'semantics-hsplit-top';
var bottomSplitId = 'semantics-hsplit-bottom';
var topVSplitterId = 'semantics-vsplit-top';
var bottomVSplitterId = 'semantics-vsplit-bottom';
var topLeftSplitId = 'frames';
var topRightSplitId = 'schemas';
var bottomLeftSplitId = 'control';
var bottomRightSplitId = 'semantics-examples';

function createHSplitter() {
  $('#'+hSplitterId).height($('#right').height() - 70);

  if ($.fn.splitter) {

	$(window).resize(function() {
		$('#'+hSplitterId).height($('#right').height() - 70);
	});

    $('#'+hSplitterId).bind('resize', function(e) {
		  var resizeEvt;
	      clearTimeout(resizeEvt);
	      resizeEvt = setTimeout(function() {
	        	$('#'+topVSplitterId).trigger('resize', $('#'+topLeftSplitId).width());
	            $('#'+bottomVSplitterId).trigger('resize', $('#'+bottomLeftSplitId).width()+7);
	        }, 50);
		  e.stopPropagation();
	});

    $('#'+topSplitId).bind('resize', function(e) {
    	$('#'+topVSplitterId).height($('#'+topSplitId).height());
    	$('#'+topVSplitterId).children().each(function () {
    		$(this).height($('#'+topSplitId).height() - 7);
    	});

    	$('#'+bottomVSplitterId).height($('#'+bottomSplitId).height());
    	$('#'+bottomVSplitterId).children().each(function () {
    		$(this).height($('#'+bottomSplitId).height() - 7);
    	});
        e.stopPropagation();
    });
    $('#'+bottomSplitId).bind('resize', function(e) {
      e.stopPropagation();
    });
    $('#'+hSplitterId).splitter({
      type: "h",
      minTop: 200,
      minBottom: 100,
      sizeBottom: 170,
      resizeToWidth: true,
      outline: true
    });
  }
}

function createVTopSplitter() {
  var w=$('#'+topVSplitterId).width();

  $('#'+topVSplitterId).height(2*$('#right').height()/3);

  if ($.fn.splitter) {
    $('#'+topLeftSplitId).bind('resize', function(e) {
    	$('#'+topVSplitterId).height($('#'+topSplitId).height());
    	$('#'+topVSplitterId).children().each(function () {
    		$(this).height($('#'+topSplitId).height() - 7);
    	});
    	$('#'+topRightSplitId).width($('#'+topRightSplitId).width() - 20);
        e.stopPropagation();
    });
    $('#'+topRightSplitId).bind('resize', function(e) {
      e.stopPropagation();
    });
    $('#'+topVSplitterId).splitter({
      type: "v",
      minLeft: 50,
      sizeLeft: w/2,
      resizeToWidth: true,
      outline: true
    });
  }
}

function createVBottomSplitter() {
  var w=$('#'+bottomVSplitterId).width();
  $('#'+bottomVSplitterId).height($('#right').height()/3);
  if ($.fn.splitter) {
    $('#'+bottomLeftSplitId).bind('resize', function(e) {
    	$('#'+bottomVSplitterId).height($('#'+bottomSplitId).height());
    	$('#'+bottomVSplitterId).children().each(function () {
    		$(this).height($('#'+bottomSplitId).height()-7);
    	});

    	$('#'+bottomLeftSplitId).width($('#'+bottomLeftSplitId).width() - 7);
    	$('#'+bottomRightSplitId).width($('#'+bottomRightSplitId).width() - 20);
        e.stopPropagation();
    });
    $('#'+bottomRightSplitId).bind('resize', function(e) {
      e.stopPropagation();
    });
    $('#'+bottomVSplitterId).splitter({
      type: "v",
      sizeLeft: w/3,
      minLeft: 200,
      resizeToWidth: true,
      outline: true
    });
  }
}