diff --git a/entries/static/entries/js/components/LexicalUnitEdit.js b/entries/static/entries/js/components/LexicalUnitEdit.js index 93dc339e471cd232320f6f470b71ba44ec9c7d07..1cb53c019eea1fe75641fb4a6b73fd30841340d0 100644 --- a/entries/static/entries/js/components/LexicalUnitEdit.js +++ b/entries/static/entries/js/components/LexicalUnitEdit.js @@ -192,7 +192,7 @@ Object.assign(LexicalUnitEdit, { show_info(gettext('Kliknij, aby wybrać kolumnę do edycji.')); } }, - addSelectivePreference() { + addSelectivePreference () { if (!this.active_unified_frame_argument) { alert(gettext("Zaznacz argument, do którego chcesz dodać preferencję.")); } else { @@ -201,6 +201,58 @@ Object.assign(LexicalUnitEdit, { }.bind(this)); } }, + removeSelectionalPreference () { + if (!this.active_unified_frame_argument) { + alert(gettext("Zaznacz argument, do którego chcesz dodać preferencję.")); + } else { + var existingPreferencies = function () { + return this.active_unified_frame_argument.preferences.map(preference => { + return `<label><input type="checkbox" name="preference" value="${preference.id}" /> ${preference.str}</label><br />`; + }).join(""); + }.bind(this); + + var remove_preference_popup = { + state0: { + title: 'Wybierz preferencje do usunięcia', + html: existingPreferencies, + buttons: {Anuluj: 0, Usuń: 1}, + focus: -1, + submit: function (e, v, m, f) { + if (v == 0) { + e.preventDefault(); + $.prompt.close(); + } + if (v === 1) { + e.preventDefault(); + let preference_ids = normalizeFormData(f.preference); + var data = { + 'unified_frame_id': this.unified_frame.id, + 'argument_id': this.active_unified_frame_argument.id, + 'preference_ids': JSON.stringify(preference_ids) + }; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/remove_selectional_preference/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Wybrane preferencje zostału usunięte.'); + this.loadFrame(); + $.prompt.close(); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); + } + }); + } + }.bind(this) + } + } + $.prompt(remove_preference_popup); + } + }, changeTitle() { let title = this.unified_frame.title != null ? this.unified_frame.title : ''; var change_title_popup = { @@ -755,6 +807,7 @@ Object.assign(LexicalUnitEdit, { <tr style="background-color: white;"> <td id="change-role" @click="changeRole" style="padding: 10px 15px 10px 15px; color: #000000;">Zmień rolę</td> <td id="remove-arg" @click="removeArgument" style="padding: 10px 15px 10px 15px; color: #000000;">Usuń argum.</td> + <td id="change-windows" style="padding: 10px 15px 10px 15px; color: #000000;" @click="removeSelectionalPreference">Usuń prefer.</td> <td id="change-windows" style="padding: 10px 15px 10px 15px; color: #000000;" @click="swapUnifiedFrames">Zamień okna</td> <td id="duplicates" @click="duplicate" style="padding: 10px 15px 10px 15px; color: #000000;">Duplikuj</td> </tr> diff --git a/unifier/urls.py b/unifier/urls.py index 21fc47c814258c11a62b8b907c5b495dd3a842f8..3ea83f55aa2a8099ef12c9988a26254edf1aa1e0 100644 --- a/unifier/urls.py +++ b/unifier/urls.py @@ -20,5 +20,6 @@ urlpatterns = [ path('remove_argument/', views.remove_argument, name='remove_argument'), path('duplicate_unified_frame/', views.duplicate_unified_frame, name='duplicate_unified_frame'), path('change_unified_frame_status_to_ready/', views.change_unified_frame_status_to_ready, name='change_unified_frame_status_to_ready'), + path('remove_selectional_preference/', views.remove_selectional_preference, name='remove_selectional_preference'), ] diff --git a/unifier/views.py b/unifier/views.py index 015e3010a2d10ed0a31d792ae801f2c4afa13a0a..0b3fbd11348f36fb5df68c33baedea9b8ff10e4e 100644 --- a/unifier/views.py +++ b/unifier/views.py @@ -227,6 +227,22 @@ def extract_frames_to_new_frame(request): return JsonResponse(get_unified_frame_json(new_frame_fullfiled_and_saved, request)) return JsonResponse({}) +@ajax_required +def remove_selectional_preference(request): + if request.method == 'POST': + unified_frame_id = request.POST['unified_frame_id'] + argument_id = request.POST['argument_id'] + preference_ids = json.loads(request.POST['preference_ids']) + + unified_frame_argument = UnifiedFrameArgument.objects.get(id=argument_id, unified_frame=unified_frame_id) + unified_frame_argument.predefined.set(unified_frame_argument.predefined.exclude(id__in=preference_ids)) + unified_frame_argument.synsets.set(unified_frame_argument.synsets.exclude(id__in=preference_ids)) + unified_frame_argument.relations.set(unified_frame_argument.relations.exclude(id__in=preference_ids)) + unified_frame_argument.save() + + return JsonResponse({}) + return JsonResponse({}) + @ajax_required def duplicate_unified_frame(request): if request.method == 'POST':