From 815e6b04833c638fc9aa796e580a815e70978700 Mon Sep 17 00:00:00 2001 From: dcz2 <dcz@ipipan.waw.pl> Date: Thu, 9 Jun 2022 21:06:24 +0200 Subject: [PATCH] Existing preferences popup tab --- .../entries/js/selectional_preference.js | 26 ++++++++++++++++--- entries/static/entries/js/unification.js | 9 +++---- entries/views.py | 8 +++++- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/entries/static/entries/js/selectional_preference.js b/entries/static/entries/js/selectional_preference.js index 2d50564..a8ef088 100644 --- a/entries/static/entries/js/selectional_preference.js +++ b/entries/static/entries/js/selectional_preference.js @@ -3,6 +3,16 @@ var relations = []; var synsets = []; var change = false; +function existingSelect() { + let availablePreferencies = slowal_frames2selecional_preferencies(unified_frame_active_frame, unified_view_frame_content)[unified_frame_active_argument_id]; + if (!availablePreferencies) { + return gettext('Brak preferencji selekcyjnych do wyboru.') + } + return availablePreferencies.map(preference => { + return `<label><input type="checkbox" name="existing" value="${preference.type}:${preference.id}" /> ${preference.str}</label><br />`; + }).join(""); +} + function predefinedSelect() { var display = ""; @@ -251,7 +261,7 @@ function addSelectivePreferenceBase(unified_frame, frame, complement_id) { }, state4: { title: 'Wybierz z istniejących', - html: 'TODO', + html: existingSelect(), buttons: { Anuluj: -1, Zatwierdź: 1 }, focus: 1, submit: function(e,v,m,f){ @@ -261,9 +271,17 @@ function addSelectivePreferenceBase(unified_frame, frame, complement_id) { } if (v == 1) { e.preventDefault(); - - // TODO - + normalizeFormData(f.existing).map(choice => { + let [type, id] = choice.split(':'); + switch (type) { + case 'meanings.Synset': + saveSynsetPreference(unified_frame_id, complement_id, id); + case 'semantics.PredefinedSelectionalPreference': + savePredefinedPreference(unified_frame_id, complement_id, id); + case 'semantics.RelationalSelectionalPreference': + saveRelationalSelectionalPreference(unified_frame_id, complement_id, null, null); // TODO + } + }); $.prompt.goToState('state0'); } } diff --git a/entries/static/entries/js/unification.js b/entries/static/entries/js/unification.js index 2745f5e..b544445 100644 --- a/entries/static/entries/js/unification.js +++ b/entries/static/entries/js/unification.js @@ -298,8 +298,7 @@ function unifiedFrame2dom(unifiedFrame, slowal_frames) { let selecional_preferencies_poposition = slowal_frames2selecional_preferencies_mapping[argument.id] if(selecional_preferencies_poposition != null) { - let selectional_preference_proposition_html = create_selectional_preference_html(selecional_preferencies_poposition, ''); - preferences_html += selectional_preference_proposition_html; + preferences_html += create_selectional_preference_html(selecional_preferencies_poposition, ''); } // *** and we want to close the <td> here @@ -314,7 +313,7 @@ function unifiedFrame2dom(unifiedFrame, slowal_frames) { return div; } -function create_selectional_preference_html(preferences, additioan_css_class) { +function create_selectional_preference_html(preferences, additional_css_class) { let preferences_html_local = ''; for (var j in preferences) { var preference = preferences[j]; @@ -324,9 +323,9 @@ function create_selectional_preference_html(preferences, additioan_css_class) { } preferences_html_local += '<div class="preference py-2 px-1' + cls + '">'; if (preference.url) { - preferences_html_local += ' <a class="synset-plwn '+additioan_css_class+'" href="' + preference.url + '" target="_blank">' + preference.str + '</a>'; + preferences_html_local += ' <a class="synset-plwn '+additional_css_class+'" href="' + preference.url + '" target="_blank">' + preference.str + '</a>'; } else { - preferences_html_local += ' <span class="'+additioan_css_class+'">' + preference.str +'</span>'; + preferences_html_local += ' <span class="'+additional_css_class+'">' + preference.str +'</span>'; } if (preference.info) { preferences_html_local += ' ' + tooltipped_info(preference.info); diff --git a/entries/views.py b/entries/views.py index f238216..e8e75cf 100644 --- a/entries/views.py +++ b/entries/views.py @@ -516,11 +516,15 @@ def get_synset_def(synset): def get_prefs_list(argument): return sorted( ({ - 'str' : str(p), + 'id' : p.pk, + 'type' : p._meta.label, + 'str' : str(p), } for p in argument.predefined.all()), key=lambda x: x['str'] ) + sorted( ({ + 'id' : s.pk, + 'type' : s._meta.label, 'str' : str(s), # can be a new synset 'url' : None if s.id < 0 else 'http://plwordnet21.clarin-pl.eu/synset/{}'.format(s.id), @@ -529,6 +533,8 @@ def get_prefs_list(argument): key=lambda x: x['str'] ) + sorted( ({ + 'id' : r.pk, + 'type' : r._meta.label, 'str' : str(r), 'info' : get_rel_pref_desc(r), } for r in argument.relations.all()), -- GitLab