From 0db52f288346f19d4ad052e34af16927aba9bc0a Mon Sep 17 00:00:00 2001
From: Tomasz Bartosiak <tomasz.bartosiak@gmail.com>
Date: Wed, 26 Jul 2017 15:25:39 +0200
Subject: [PATCH] Nieczasownikowe jednostki leksykalne

---
 semantics/static/js/semantics_lexical_units.js |  9 ++++++---
 semantics/static/js/semantics_view.js          | 31 ++++++++++++++++++++++---------
 semantics/views.py                             | 13 ++++++++++++-
 3 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/semantics/static/js/semantics_lexical_units.js b/semantics/static/js/semantics_lexical_units.js
index ea4e33e..60a41e2 100644
--- a/semantics/static/js/semantics_lexical_units.js
+++ b/semantics/static/js/semantics_lexical_units.js
@@ -4,6 +4,7 @@ var free_luid = -1;             // these ids will be temporarely given to new le
 var free_sense;                 // what sense should be given to new lexical unit
 var lexical_units_frames = [];
 var lexical_units_num = [];
+var part_of_speech;
 
 // store lexical units from database
 function memorizeLexicalUnits(input_lexical_units) {
@@ -18,8 +19,10 @@ function memorizeLexicalUnits(input_lexical_units) {
 function basicLexicalUnitsData(info){
     base = info.base;
     free_sense = info.sense;
+    part_of_speech = info.pos;
 }
 
+
 // create new lexical_unit
 function createLexicalUnit(refl, glossa, relation, to) {
 
@@ -34,7 +37,7 @@ function createLexicalUnit(refl, glossa, relation, to) {
         refl_text = "";
     }
 
-    var lu = {base: base + refl_text, glossa: "" + glossa, definition: "", id: free_luid, luid: -1, refl: refl, glossa: glossa, pos: "czasownik", sense: free_sense, relation: relation, to: to, location: ""};
+    var lu = {base: base + refl_text, glossa: "" + glossa, definition: "", id: free_luid, luid: -1, refl: refl, glossa: glossa, pos: part_of_speech, sense: free_sense, relation: relation, to: to, location: ""};
     var operation = {operation: 'add_unit', unit:lu};
     lexical_units.push(lu);
     lexical_unit_examples[free_luid] = []
@@ -441,7 +444,7 @@ function getLexicalUnit(luid) {
 
 
 function addPhraseologicalUnit(mwe, glossa, relation, to) {
-    var lu = {base: mwe, glossa: "" + glossa, definition: "", id: free_luid, luid: -1, refl: "false", glossa: glossa, pos: "czasownik", sense: "A", relation: relation, to: to, location: ""};
+    var lu = {base: mwe, glossa: "" + glossa, definition: "", id: free_luid, luid: -1, refl: "false", glossa: glossa, pos: part_of_speech, sense: "A", relation: relation, to: to, location: ""};
     var operation = {operation: 'add_unit', unit:lu};
     lexical_units.push(lu);
     lexical_unit_examples[free_luid] = [];
@@ -451,7 +454,7 @@ function addPhraseologicalUnit(mwe, glossa, relation, to) {
 }
 
 function unlockPhraseologicalUnit(mwe) {
-    var lu = {base: mwe.lu.split('-')[0], glossa: "", definition: "", id: mwe.id, luid: mwe.luid, refl: false, glossa: "", pos: "czasownik", sense: mwe.lu.split('-')[1], relation: 2, to: -1, location: ""};
+    var lu = {base: mwe.lu.split('-')[0], glossa: "", definition: "", id: mwe.id, luid: mwe.luid, refl: false, glossa: "", pos: part_of_speech, sense: mwe.lu.split('-')[1], relation: 2, to: -1, location: ""};
     lexical_units.push(lu);
     return mwe.id;
 }
diff --git a/semantics/static/js/semantics_view.js b/semantics/static/js/semantics_view.js
index 36c6676..7eb9166 100644
--- a/semantics/static/js/semantics_view.js
+++ b/semantics/static/js/semantics_view.js
@@ -56,7 +56,7 @@ function changeSynsetInput() {
 }
 
 function openMeaningsMenu() {
-	if(window.lemma_id != getActualLemmaId(window.lemma_id)){
+    if(window.lemma_id != getActualLemmaId(window.lemma_id)){
     	alertOldSchemas();
     }
     else {
@@ -185,7 +185,7 @@ function displayMeanings() {
                 e.preventDefault();
                 if (parseInt(f.relation) != 2) {
                     $.prompt.removeState('state12');
-                    $.prompt.addState('state12', {title: 'Znaczenia', html: getFormContent(f) + getRelation(f) + "w stosunku do:<br />" + getSynsets(f.context, "czasownik"), buttons: {Wstecz: -1, Anuluj: 0, Zatwierdź: 1}, focus: 1, submit: submitSynsetSelection}, 'state11');
+                    $.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');
                     $.prompt.goToState('state12');
                 } else {
                     createLexicalUnit(f.refl, f.glossa, f.relation, -1);
@@ -207,12 +207,16 @@ function displayMeanings() {
 
     var getFormContent = 
         function(f) {
-	        var result = '<label>Zwrotny <input type="checkbox" name="refl" value="true" disabled';
+	    var result = '';
+	    if (part_of_speech == 'czasownik') {
+		result += '<label>Zwrotny <input type="checkbox" name="refl" value="true" disabled';
 	        if (f.refl == 'true') {
 	            result += ' checked';
-            }
-	        result += '></label><br /><label>Glossa <input type="text" name="glossa" value="' + f.glossa + '" disabled></label><br />';
-	        return result;
+                }
+	        result += '></label><br />';
+	    }
+            result += '<label>Glossa <input type="text" name="glossa" value="' + f.glossa + '" disabled></label><br />';
+	    return result;
         };
 
     var getRelation = 
@@ -262,6 +266,16 @@ function displayMeanings() {
             }
         };
 
+    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;
+        };
+    
     var display_meanings = {
             state0: {
 	            title: 'Znaczenia',
@@ -272,8 +286,7 @@ function displayMeanings() {
             },
             state1: {
 	            title: 'Dodawanie znaczenia',
-	            html: '<label>Zwrotny <input type="checkbox" name="refl" value="true"></label><br />'+
-			          '<label>Glossa <input type="text" name="glossa" value=""></label><br />',
+	            html: addMeaningsHtml(),
 	            buttons: { "Anuluj": -1, "Potwierdź": 1 },
 	            focus: 1,
 	            submit:function(e,v,m,f){ 
@@ -529,7 +542,7 @@ function changeLexicalUnits() {
                                                   {
                                                       title: 'Znaczenia',
                                                       html: '<label>Glossa <input type="text" name="glossa" value="' + gloss + '" disabled></label><br />' + 
-                                                            getRelation(f) + "w stosunku do:<br />" + getSynsets(f.context, "czasownik"), 
+                                                            getRelation(f) + "w stosunku do:<br />" + getSynsets(f.context, part_of_speech), 
                                                       buttons: {Wstecz: -1, Anuluj: 0, Zatwierdź: 1}, 
                                                       focus: 1, 
                                                       submit: addPhraseology
diff --git a/semantics/views.py b/semantics/views.py
index 3e6df65..ac551c0 100644
--- a/semantics/views.py
+++ b/semantics/views.py
@@ -290,12 +290,23 @@ def ajax_units(request, lemma_id):
 
 def create_units_context(lemma_id):
     lemma = Lemma.objects.get(id=lemma_id)
+    pos_en = lemma.entry_obj.pos.tag
+    pos = 'brak'
+    if pos_en == 'adj':
+        pos = 'przymiotnik'
+    elif pos_en == 'noun':
+        pos = 'rzeczownik'
+    elif pos_en == 'adv':
+        pos = 'przysłówek'
+    elif pos_en == 'verb':
+        pos = 'czasownik'
     lexical_units = lemma.entry_obj.meanings.order_by('base', 'sense')
 #    lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ', pos="czasownik")|Q(base__contains=u' '+lemma.entry+u' ', pos="czasownik")|Q(base__endswith=u' '+lemma.entry, pos="czasownik")|Q(base=lemma.entry, pos="czasownik")).order_by('base', 'sense')
 
     context = {
                'lexical_units': [{"id": lu.id, "luid": lu.luid, "base": lu.base, "sense": lu.sense, "pos": lu.pos, "glossa": lu.glossa, "definition": lu.definition, "location": location(lu)} for lu in lexical_units],
-               'informations': {'base': lemma.entry, 'sense': max(['A'] + [chr(ord(lu.sense) + 1) for lu in lexical_units.filter(luid=-1)])}, # TODO: 2 different free senses for with/whthout 'się'
+               'informations': {'base': lemma.entry, 'sense': max(['A'] + [chr(ord(lu.sense) + 1) for lu in lexical_units.filter(luid=-1)]), # TODO: 2 different free senses for with/without 'się'
+                                'pos': pos}
               }
     return context
     
--
libgit2 0.22.2