From cd9643ca771529d767f176ef56944927402ce244 Mon Sep 17 00:00:00 2001 From: dcz2 <dcz@ipipan.waw.pl> Date: Tue, 28 Jun 2022 21:28:23 +0200 Subject: [PATCH] Fix tabs in the edit view --- .../entries/js/components/LexicalUnitEdit.js | 1087 ++++++++--------- 1 file changed, 542 insertions(+), 545 deletions(-) diff --git a/entries/static/entries/js/components/LexicalUnitEdit.js b/entries/static/entries/js/components/LexicalUnitEdit.js index a8aeeb8..4ea184b 100644 --- a/entries/static/entries/js/components/LexicalUnitEdit.js +++ b/entries/static/entries/js/components/LexicalUnitEdit.js @@ -2,567 +2,573 @@ import InfoTooltip from "./InfoTooltip.js"; import Spinner from "./Spinner.js"; export default { - props: { - unifiedFrameId: Number + props: { + unifiedFrameId: Number + }, + data() { + return { + gettext: window.gettext, + unified_frame: Object, + unified_frame_title: Object, + unified_frame_arguments: [], + active_unified_frame_argument: null, + slowal_frames2selecional_preferencies_mapping: {}, + lexical_units: [], + img_prefix: String, + frames: [], + right_pane_tabs: [ + {id: 'schemata', label: gettext('Schematy')}, + {id: 'frame_preview', label: gettext('Podgląd ram')}, + {id: 'notes', label: gettext('Notatki')}, + ], + right_pane_tab: 'schemata' + } + }, + components: {InfoTooltip, Spinner}, + emits: ['goToDisplay', 'refresh'], + watch: { + unifiedFrameId: function () { + this.loadFrame(); + } + }, + methods: { + hasWhiteSpace(s) { + return /\s/g.test(s); }, - data() { - return { - gettext: window.gettext, - unified_frame: Object, - unified_frame_title: Object, - unified_frame_arguments: [], - active_unified_frame_argument: null, - slowal_frames2selecional_preferencies_mapping: {}, - lexical_units: [], - img_prefix: String, - frames: [] - } + slowal_frame_html(frame) { + let ret = frame2dom(frame); + return ret.outerHTML; }, - components: {InfoTooltip, Spinner}, - emits: ['goToDisplay', 'refresh'], - watch: { - unifiedFrameId: function () { - this.loadFrame(); - } + show_semantics_unified_view(frames, subentries) { + $('#semantics-no-examples').hide(); + var schemata_dom = subentries2dom(subentries); + $('#semantics-schemata').append($(schemata_dom)); }, - methods: { - hasWhiteSpace(s) { - return /\s/g.test(s); - }, - slowal_frame_html(frame) { - let ret = frame2dom(frame); - return ret.outerHTML; - }, - show_semantics_unified_view(frames, subentries) { - $('#semantics-no-examples').hide(); - var schemata_dom = subentries2dom(subentries); - $('#semantics-schemata').append($(schemata_dom)); - }, - async loadFrame() { - try { - var data = {'unified_frame_id': this.unifiedFrameId}; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/get_unified_frame/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - - this.img_prefix = window.STATIC_URL; - - this.lexical_units = frames2lexical_units(response.frames); + async loadFrame() { + try { + var data = {'unified_frame_id': this.unifiedFrameId}; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/get_unified_frame/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { - this.unified_frame = response.unified_frame; - this.unified_frame_title = this.unified_frame.title || lexical_units2dom(this.lexical_units) - this.unified_frame_arguments = this.unified_frame.arguments; - this.frames = response.frames; + this.img_prefix = window.STATIC_URL; - // $('#lexical-unit').html(this.unified_frame_title); + this.lexical_units = frames2lexical_units(response.frames); - this.slowal_frames2selecional_preferencies_mapping = slowal_frames2selecional_preferencies(this.unified_frame, response.frames); + this.unified_frame = response.unified_frame; + this.unified_frame_title = this.unified_frame.title || lexical_units2dom(this.lexical_units) + this.unified_frame_arguments = this.unified_frame.arguments; + this.frames = response.frames; - // unified_view_frame_content = response.frames - curr_entry = this.unifiedFrameId; - // curr_no_filters = related; - clear_info(); - curr_alternations = response.alternations; - curr_realisation_phrases = response.realisation_phrases; - curr_realisation_descriptions = response.realisation_descriptions; - curr_examples = response.examples; - curr_examples_by_id = Object(); - for (var i in curr_examples) { - curr_examples_by_id[curr_examples[i].id] = curr_examples[i]; - } - // show_unified_frame_lexical_units(response.frames) - fulfill_slowal_frames_arguments_with_empty_elems(response.unified_frame, response.frames) - this.show_semantics_unified_view(response.frames, response.subentries); - // show_unmatched_examples(); + // $('#lexical-unit').html(this.unified_frame_title); - // tooltips with meaning gloss - activate_tooltips($('#semantics-frames-pane')); - update_last_visited(response.last_visited); - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - } - }); + this.slowal_frames2selecional_preferencies_mapping = slowal_frames2selecional_preferencies(this.unified_frame, response.frames); - } catch (error) { - console.log(error); - } - }, - unifiedFrameArgumentSelected(argument) { - if (this.active_unified_frame_argument === argument) { - this.active_unified_frame_argument = null; - } else { - this.active_unified_frame_argument = argument; - } - this.unifiedFrameArgumentHovered(argument); - }, - unifiedFrameArgumentHovered(argument) { + // unified_view_frame_content = response.frames + curr_entry = this.unifiedFrameId; + // curr_no_filters = related; clear_info(); - if (argument && this.active_unified_frame_argument === argument) { - show_info(gettext('Kliknij, aby cofnąć wybór kolumny do edycji.')); - } - if (argument && this.active_unified_frame_argument !== argument) { - show_info(gettext('Kliknij, aby wybrać kolumnę do edycji.')); + curr_alternations = response.alternations; + curr_realisation_phrases = response.realisation_phrases; + curr_realisation_descriptions = response.realisation_descriptions; + curr_examples = response.examples; + curr_examples_by_id = Object(); + for (var i in curr_examples) { + curr_examples_by_id[curr_examples[i].id] = curr_examples[i]; } - }, - addSelectivePreference() { - if (!this.active_unified_frame_argument) { - alert(gettext("Zaznacz argument, do którego chcesz dodać preferencję.")); - } else { - window.addSelectivePreference(this.unified_frame, this.active_unified_frame_argument.id, this.frames); + // show_unified_frame_lexical_units(response.frames) + fulfill_slowal_frames_arguments_with_empty_elems(response.unified_frame, response.frames) + this.show_semantics_unified_view(response.frames, response.subentries); + // show_unmatched_examples(); + + // tooltips with meaning gloss + activate_tooltips($('#semantics-frames-pane')); + update_last_visited(response.last_visited); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + } + }); + + } catch (error) { + console.log(error); + } + }, + unifiedFrameArgumentSelected(argument) { + if (this.active_unified_frame_argument === argument) { + this.active_unified_frame_argument = null; + } else { + this.active_unified_frame_argument = argument; + } + this.unifiedFrameArgumentHovered(argument); + }, + unifiedFrameArgumentHovered(argument) { + clear_info(); + if (argument && this.active_unified_frame_argument === argument) { + show_info(gettext('Kliknij, aby cofnąć wybór kolumny do edycji.')); + } + if (argument && this.active_unified_frame_argument !== argument) { + show_info(gettext('Kliknij, aby wybrać kolumnę do edycji.')); + } + }, + addSelectivePreference() { + if (!this.active_unified_frame_argument) { + alert(gettext("Zaznacz argument, do którego chcesz dodać preferencję.")); + } else { + window.addSelectivePreference(this.unified_frame, this.active_unified_frame_argument.id, this.frames); + } + }, + changeTitle() { + let title = this.unified_frame.title != null ? this.unified_frame.title : ''; + var change_title_popup = { + state0: { + title: 'Zmiana nazwy ramy', + html: '<input type="text" size="32" value="' + title + '" name="title" />', + buttons: {Anuluj: 0, Zapisz: 1}, + focus: -1, + submit: function (e, v, m, f) { + if (v == 0) { + $.prompt.close(); } - }, - changeTitle() { - let title = this.unified_frame.title != null ? this.unified_frame.title : ''; - var change_title_popup = { - state0: { - title: 'Zmiana nazwy ramy', - html: '<input type="text" size="32" value="' + title + '" name="title" />', - buttons: {Anuluj: 0, Zapisz: 1}, - focus: -1, - submit: function (e, v, m, f) { - if (v == 0) { - $.prompt.close(); - } - if (v === 1) { - e.preventDefault(); - var title = f.title; + if (v === 1) { + e.preventDefault(); + var title = f.title; - if (this.hasWhiteSpace(title)) { - alert(gettext("Nazwa zunifikowanej ramy nie może zawierać białych znaków.")); - } else { - var data = {'unified_frame_id': this.unified_frame.id, 'unified_frame_title': title}; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/save_unified_frame_title/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - show_info('Tytuł ramy zosał zapisany'); - $.prompt.close(); - this.loadFrame(); - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - $.prompt.close(); - } - }); - } - } - }.bind(this) - } + if (this.hasWhiteSpace(title)) { + alert(gettext("Nazwa zunifikowanej ramy nie może zawierać białych znaków.")); + } else { + var data = {'unified_frame_id': this.unified_frame.id, 'unified_frame_title': title}; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/save_unified_frame_title/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Tytuł ramy zosał zapisany'); + $.prompt.close(); + this.loadFrame(); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); + } + }); + } } - $.prompt(change_title_popup); - }, - changeRole() { - if (!this.active_unified_frame_argument) { - alert(gettext("Zaznacz argument, dla którego chcesz wybrać rolę.")); - } else { - var existingSelect = function () { - let selected_unified_frame_argument = this.unified_frame_arguments.find(o => o.id === this.active_unified_frame_argument.id); - if (!selected_unified_frame_argument.proposed_roles) { - return gettext('Brak ról do wyboru.') - } - return selected_unified_frame_argument.proposed_roles.map(role => { - return `<label><input type="radio" name="roles" value="${role.id}" /> ${role.str}</label><br />`; - }).join(""); - }.bind(this); + }.bind(this) + } + } + $.prompt(change_title_popup); + }, + changeRole() { + if (!this.active_unified_frame_argument) { + alert(gettext("Zaznacz argument, dla którego chcesz wybrać rolę.")); + } else { + var existingSelect = function () { + let selected_unified_frame_argument = this.unified_frame_arguments.find(o => o.id === this.active_unified_frame_argument.id); + if (!selected_unified_frame_argument.proposed_roles) { + return gettext('Brak ról do wyboru.') + } + return selected_unified_frame_argument.proposed_roles.map(role => { + return `<label><input type="radio" name="roles" value="${role.id}" /> ${role.str}</label><br />`; + }).join(""); + }.bind(this); - var newSelect = function () { - let rolesHTML = roles.map(role => { - return `<label><input type="radio" name="role" value="${role.id}" /> ${role.role}</label><br />`; - }).join(""); - let attributesHTML = role_attributes.map(attribute => { - return `<label><input type="radio" name="attribute" value="${attribute.id}" /> ${attribute.attribute}</label><br />`; - }).join(""); - return '<div class="row"><div class="column"><div class="role_select_header">Role</div>' + rolesHTML + '</div><div class="column"><div class="role_select_header">Atrybuty</div>' + attributesHTML + '</div></div>'; - }.bind(this); + var newSelect = function () { + let rolesHTML = roles.map(role => { + return `<label><input type="radio" name="role" value="${role.id}" /> ${role.role}</label><br />`; + }).join(""); + let attributesHTML = role_attributes.map(attribute => { + return `<label><input type="radio" name="attribute" value="${attribute.id}" /> ${attribute.attribute}</label><br />`; + }).join(""); + return '<div class="row"><div class="column"><div class="role_select_header">Role</div>' + rolesHTML + '</div><div class="column"><div class="role_select_header">Atrybuty</div>' + attributesHTML + '</div></div>'; + }.bind(this); - let change_role_popup = { - state0: { - title: 'Wybór roli', - html: 'Wybierz lub dodaj rolę', - buttons: {Wybierz: 0, Dodaj: 1, Koniec: -1}, - focus: -1, - submit: function (e, v, m, f) { - if (v == -1) { - e.preventDefault(); + let change_role_popup = { + state0: { + title: 'Wybór roli', + html: 'Wybierz lub dodaj rolę', + buttons: {Wybierz: 0, Dodaj: 1, Koniec: -1}, + focus: -1, + submit: function (e, v, m, f) { + if (v == -1) { + e.preventDefault(); - this.loadFrame(); + this.loadFrame(); - $.prompt.close(); - } - if (v === 0) { - e.preventDefault(); - $.prompt.goToState('state1'); - } - if (v == 1) { - e.preventDefault(); - $.prompt.goToState('state2'); - } - }.bind(this) - }, - state1: { - title: 'Wybierz rolę', - html: existingSelect(), - buttons: {Anuluj: -1, Zatwierdź: 1}, - focus: -1, - submit: function (e, v, m, f) { - if (v == -1) { - e.preventDefault(); - $.prompt.goToState('state0'); - } - if (v == 1) { - e.preventDefault(); - normalizeFormData(f.roles).map(role_id => { - var data = { - 'unified_frame_id': this.unified_frame.id, - 'complement_id': this.active_unified_frame_argument.id, - 'role_id': role_id - }; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/save_selected_role/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - show_info('Wybrana rola zosała zapisana'); - $.prompt.goToState('state0'); - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - $.prompt.close(); - } - }); - }); - } - }.bind(this) - }, - state2: { - title: 'Dodaj rolę', - html: newSelect(), - buttons: {Anuluj: -1, Zatwierdź: 1}, - focus: -1, - submit: function (e, v, m, f) { - if (v == -1) { - e.preventDefault(); - $.prompt.goToState('state0'); - } - if (v == 1) { - e.preventDefault(); + $.prompt.close(); + } + if (v === 0) { + e.preventDefault(); + $.prompt.goToState('state1'); + } + if (v == 1) { + e.preventDefault(); + $.prompt.goToState('state2'); + } + }.bind(this) + }, + state1: { + title: 'Wybierz rolę', + html: existingSelect(), + buttons: {Anuluj: -1, Zatwierdź: 1}, + focus: -1, + submit: function (e, v, m, f) { + if (v == -1) { + e.preventDefault(); + $.prompt.goToState('state0'); + } + if (v == 1) { + e.preventDefault(); + normalizeFormData(f.roles).map(role_id => { + var data = { + 'unified_frame_id': this.unified_frame.id, + 'complement_id': this.active_unified_frame_argument.id, + 'role_id': role_id + }; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/save_selected_role/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Wybrana rola zosała zapisana'); + $.prompt.goToState('state0'); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); + } + }); + }); + } + }.bind(this) + }, + state2: { + title: 'Dodaj rolę', + html: newSelect(), + buttons: {Anuluj: -1, Zatwierdź: 1}, + focus: -1, + submit: function (e, v, m, f) { + if (v == -1) { + e.preventDefault(); + $.prompt.goToState('state0'); + } + if (v == 1) { + e.preventDefault(); - var role_id = normalizeFormData(f.role)[0]; + var role_id = normalizeFormData(f.role)[0]; - if (role_id != null) { - var attribute_id = normalizeFormData(f.attribute)[0]; + if (role_id != null) { + var attribute_id = normalizeFormData(f.attribute)[0]; - var data = { - 'unified_frame_id': this.unified_frame.id, - 'complement_id': this.active_unified_frame_argument.id, - 'role_id': role_id, - 'attribute_id': attribute_id - }; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/save_new_role/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - show_info('Nowa rola zosała zapisana'); - $.prompt.goToState('state0'); - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - $.prompt.close(); - } - }); - } else { - alert(gettext("Musisz wybrać pzynajmniej rolę.")); - } - } - }.bind(this) - } - }; - $.prompt(change_role_popup); - } - }, - addArgument() { - var data = {'unified_frame_id': this.unified_frame.id}; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/add_argument/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - show_info('Nowy argument zosał dodany'); - this.loadFrame(); - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - $.prompt.close(); - } - }); - }, - removeArgument() { - if (!this.active_unified_frame_argument) { - alert(gettext("Zaznacz argument, który chcesz usunąć.")); - } else { - let hasSlowalFrameArgumentMapping = false; - for (var i in this.unified_frame.slowal_frame_mapping) { - var slowal_frame_mapping = this.unified_frame.slowal_frame_mapping[i]; - for (var j in slowal_frame_mapping.slowal_frame_argument_mapping) { - var slowal_frame_argument_mapping = slowal_frame_mapping.slowal_frame_argument_mapping[j]; - if (slowal_frame_argument_mapping.unified_frame_agrument_id == this.active_unified_frame_argument.id) { - hasSlowalFrameArgumentMapping = true; - break; - } - } - } - if (hasSlowalFrameArgumentMapping) { - alert(gettext("Zaznaczony argument nie może zostać usunięty - podpięte ramy posiadają do niego dowiązania.")); - } else { - var data = { - 'unified_frame_id': this.unified_frame.id, - 'complement_id': this.active_unified_frame_argument.id - }; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/remove_argument/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - show_info('Wybrany argument zosał usunięty'); - this.loadFrame(); - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - $.prompt.close(); - } - }); - } - } - }, - duplicate() { - let title = this.unified_frame.title != null ? this.unified_frame.title : ''; - var duplicate_popup = { - state0: { - title: 'Podaj nazwę zduplikowanej ramy', - html: '<input type="text" size="32" value="KOPIA_' + title + '" name="title" />', - buttons: {Anuluj: 0, Zapisz: 1}, - focus: -1, - submit: function (e, v, m, f) { - if (v == 0) { - e.preventDefault(); - $.prompt.close(); - } - if (v === 1) { - e.preventDefault(); - var title = f.title; - - if (this.hasWhiteSpace(title)) { - alert(gettext("Nazwa zunifikowanej ramy nie może zawierać białych znaków.")); - } else { - var data = { - 'unified_frame_id': this.unified_frame.id, - 'target_unified_frame_title': title - }; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/duplicate_unified_frame/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - show_info('Zunifikowana rama została zduplikowana.'); - $.prompt.close(); - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - $.prompt.close(); - } - }); - } - } - }.bind(this) - } - } - $.prompt(duplicate_popup); - }, - changeUnifiedFrameStatusToReady() { - let foundNotVerifiedFrame = this.frames.find(frame => !frame.verified); - if (foundNotVerifiedFrame) { - alert(gettext("Wszystkie podpięte ramy powinny być zweryfikowane.")); - } else { - var data = {'unified_frame_id': this.unified_frame.id}; - $.ajax({ + var data = { + 'unified_frame_id': this.unified_frame.id, + 'complement_id': this.active_unified_frame_argument.id, + 'role_id': role_id, + 'attribute_id': attribute_id + }; + $.ajax({ type: 'post', - url: '/' + lang + '/unifier/change_unified_frame_status_to_ready/', + url: '/' + lang + '/unifier/save_new_role/', dataType: 'json', data: data, timeout: 60000, success: function (response) { - show_info('Status ramy został zmieniony'); - this.$emit('goToDisplay') + show_info('Nowa rola zosała zapisana'); + $.prompt.goToState('state0'); }.bind(this), error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); + show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); } - }); - } - }, - change_slowal2unified_frame_argument_mapping(slowal_frame_id) { - var argument_ids = []; - $('.argument.active').each(function() { - var id = $(this).data('argument_id').split('-')[1]; - if(id.startsWith('_')) { - id = -parseInt(id.split('_')[1]) - } else { - id = parseInt(id) - } - argument_ids.push(id); - }); - var choosed_slowal_frame_id = null; - $('.frame.active').each(function() { - choosed_slowal_frame_id = $(this).data('frame_id'); - }); - if(choosed_slowal_frame_id == slowal_frame_id && argument_ids.length == 2) { - var data = { - 'unified_frame_id': this.unified_frame.id, - 'slowal_frame_id': choosed_slowal_frame_id, - 'slowal_frame_selected_arguments': JSON.stringify(argument_ids) - }; - $.ajax({ - type: 'post', - url: '/' + lang + '/unifier/change_slowal2unified_fram_argument_mapping/', - dataType: 'json', - data: data, - timeout: 60000, - success: function (response) { - show_info('Argumenty w ramie zostały zmienione'); - this.loadFrame(); - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); + }); + } else { + alert(gettext("Musisz wybrać pzynajmniej rolę.")); + } } - }); + }.bind(this) } - }, - change_slowal2unified_mapping_verification(slowal_frame_id, verified) { + }; + $.prompt(change_role_popup); + } + }, + addArgument() { + var data = {'unified_frame_id': this.unified_frame.id}; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/add_argument/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Nowy argument zosał dodany'); + this.loadFrame(); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); + } + }); + }, + removeArgument() { + if (!this.active_unified_frame_argument) { + alert(gettext("Zaznacz argument, który chcesz usunąć.")); + } else { + let hasSlowalFrameArgumentMapping = false; + for (var i in this.unified_frame.slowal_frame_mapping) { + var slowal_frame_mapping = this.unified_frame.slowal_frame_mapping[i]; + for (var j in slowal_frame_mapping.slowal_frame_argument_mapping) { + var slowal_frame_argument_mapping = slowal_frame_mapping.slowal_frame_argument_mapping[j]; + if (slowal_frame_argument_mapping.unified_frame_agrument_id == this.active_unified_frame_argument.id) { + hasSlowalFrameArgumentMapping = true; + break; + } + } + } + if (hasSlowalFrameArgumentMapping) { + alert(gettext("Zaznaczony argument nie może zostać usunięty - podpięte ramy posiadają do niego dowiązania.")); + } else { var data = { 'unified_frame_id': this.unified_frame.id, - 'slowal_frame_id': slowal_frame_id, - 'verified': verified + 'complement_id': this.active_unified_frame_argument.id }; $.ajax({ type: 'post', - url: '/' + lang + '/unifier/change_slowal2unified_mapping_verification/', + url: '/' + lang + '/unifier/remove_argument/', dataType: 'json', data: data, timeout: 60000, success: function (response) { - show_info('Status ramy został zmieniony'); - this.loadFrame(); + show_info('Wybrany argument zosał usunięty'); + this.loadFrame(); }.bind(this), error: function (request, errorType, errorMessage) { show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); } }); - }, - slowalFrameSelected(frame) { - if (this.active_slowal_frame === frame) { - this.active_slowal_frame = null; - } else { - this.active_slowal_frame = frame; + } + } + }, + duplicate() { + let title = this.unified_frame.title != null ? this.unified_frame.title : ''; + var duplicate_popup = { + state0: { + title: 'Podaj nazwę zduplikowanej ramy', + html: '<input type="text" size="32" value="KOPIA_' + title + '" name="title" />', + buttons: {Anuluj: 0, Zapisz: 1}, + focus: -1, + submit: function (e, v, m, f) { + if (v == 0) { + e.preventDefault(); + $.prompt.close(); } - }, - extract_frames_to_new_frame() { + if (v === 1) { + e.preventDefault(); + var title = f.title; - var existingSelect = function () { - return this.frames.map(frame => { - return `<label><input type="checkbox" name="frames" value="${frame.id}" /> ${lexical_units2dom(frame.lexical_units)}</label><br />`; - }).join(""); - }.bind(this); + if (this.hasWhiteSpace(title)) { + alert(gettext("Nazwa zunifikowanej ramy nie może zawierać białych znaków.")); + } else { + var data = { + 'unified_frame_id': this.unified_frame.id, + 'target_unified_frame_title': title + }; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/duplicate_unified_frame/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Zunifikowana rama została zduplikowana.'); + $.prompt.close(); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); + } + }); + } + } + }.bind(this) + } + } + $.prompt(duplicate_popup); + }, + changeUnifiedFrameStatusToReady() { + let foundNotVerifiedFrame = this.frames.find(frame => !frame.verified); + if (foundNotVerifiedFrame) { + alert(gettext("Wszystkie podpięte ramy powinny być zweryfikowane.")); + } else { + var data = {'unified_frame_id': this.unified_frame.id}; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/change_unified_frame_status_to_ready/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Status ramy został zmieniony'); + this.$emit('goToDisplay') + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + } + }); + } + }, + change_slowal2unified_frame_argument_mapping(slowal_frame_id) { + var argument_ids = []; + $('.argument.active').each(function() { + var id = $(this).data('argument_id').split('-')[1]; + if(id.startsWith('_')) { + id = -parseInt(id.split('_')[1]) + } else { + id = parseInt(id) + } + argument_ids.push(id); + }); + var choosed_slowal_frame_id = null; + $('.frame.active').each(function() { + choosed_slowal_frame_id = $(this).data('frame_id'); + }); + if(choosed_slowal_frame_id == slowal_frame_id && argument_ids.length == 2) { + var data = { + 'unified_frame_id': this.unified_frame.id, + 'slowal_frame_id': choosed_slowal_frame_id, + 'slowal_frame_selected_arguments': JSON.stringify(argument_ids) + }; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/change_slowal2unified_fram_argument_mapping/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Argumenty w ramie zostały zmienione'); + this.loadFrame(); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + } + }); + } + }, + change_slowal2unified_mapping_verification(slowal_frame_id, verified) { + var data = { + 'unified_frame_id': this.unified_frame.id, + 'slowal_frame_id': slowal_frame_id, + 'verified': verified + }; + $.ajax({ + type: 'post', + url: '/' + lang + '/unifier/change_slowal2unified_mapping_verification/', + dataType: 'json', + data: data, + timeout: 60000, + success: function (response) { + show_info('Status ramy został zmieniony'); + this.loadFrame(); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + } + }); + }, + slowalFrameSelected(frame) { + if (this.active_slowal_frame === frame) { + this.active_slowal_frame = null; + } else { + this.active_slowal_frame = frame; + } + }, + extract_frames_to_new_frame() { - var extract_frames_to_new_frame_popup = { - state0: { - title: 'Podaj nazwę zduplikowanej ramy', - html: existingSelect, - buttons: {Anuluj: 0, Wydziel: 1}, - focus: -1, - submit: function (e, v, m, f) { - if (v == 0) { - e.preventDefault(); - $.prompt.close(); - } - if (v === 1) { - e.preventDefault(); - let frame_ids = normalizeFormData(f.frames); - var data = { 'unified_frame_id' : this.unified_frame.id, 'slowal_frame_ids' : JSON.stringify(frame_ids), - 'target_unified_frame_id': ''}; - $.ajax({ - type : 'post', - url : '/' + lang + '/unifier/extract_frames_to_new_frame/', - dataType : 'json', - data : data, - timeout : 60000, - success : function(response) { - show_info('Ramy zostały wydzielone do nowej ramy zunifikowanej.'); - this.loadFrame(); - $.prompt.close(); - }.bind(this), - error: function(request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); - $.prompt.close(); - } - }); - } - }.bind(this) - } + var existingSelect = function () { + return this.frames.map(frame => { + return `<label><input type="checkbox" name="frames" value="${frame.id}" /> ${lexical_units2dom(frame.lexical_units)}</label><br />`; + }).join(""); + }.bind(this); + + var extract_frames_to_new_frame_popup = { + state0: { + title: 'Podaj nazwę zduplikowanej ramy', + html: existingSelect, + buttons: {Anuluj: 0, Wydziel: 1}, + focus: -1, + submit: function (e, v, m, f) { + if (v == 0) { + e.preventDefault(); + $.prompt.close(); } - $.prompt(extract_frames_to_new_frame_popup); - }, - extract_frames_to_frame(target_unified_frame_id) { - var data = { 'unified_frame_id' : this.unified_frame.id, 'slowal_frame_ids' : JSON.stringify([this.active_slowal_frame.id]), - 'target_unified_frame_id': target_unified_frame_id }; - $.ajax({ + if (v === 1) { + e.preventDefault(); + let frame_ids = normalizeFormData(f.frames); + var data = { 'unified_frame_id' : this.unified_frame.id, 'slowal_frame_ids' : JSON.stringify(frame_ids), + 'target_unified_frame_id': ''}; + $.ajax({ type : 'post', url : '/' + lang + '/unifier/extract_frames_to_new_frame/', dataType : 'json', data : data, timeout : 60000, success : function(response) { - show_info('Zaznaczona rama została przeniosiona.'); - this.loadFrame(); - }, + show_info('Ramy zostały wydzielone do nowej ramy zunifikowanej.'); + this.loadFrame(); + $.prompt.close(); + }.bind(this), error: function(request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); + show_error(errorType + ' (' + errorMessage + ')'); + $.prompt.close(); } - }); + }); + } + }.bind(this) } + } + $.prompt(extract_frames_to_new_frame_popup); }, - mounted() { - Split(['#semantics-frames-pane', '#semantics-schemata-pane'], { - sizes: [40, 60], - minSize: 400, - gutterSize: 4, - elementStyle: (dimension, size, gutterSize) => { - return { - 'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)' - } - }, - }); - this.loadFrame(); - }, - template: ` + extract_frames_to_frame(target_unified_frame_id) { + var data = { 'unified_frame_id' : this.unified_frame.id, 'slowal_frame_ids' : JSON.stringify([this.active_slowal_frame.id]), + 'target_unified_frame_id': target_unified_frame_id }; + $.ajax({ + type : 'post', + url : '/' + lang + '/unifier/extract_frames_to_new_frame/', + dataType : 'json', + data : data, + timeout : 60000, + success : function(response) { + show_info('Zaznaczona rama została przeniosiona.'); + this.loadFrame(); + }, + error: function(request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + } + }); + } + }, + mounted() { + Split(['#semantics-frames-pane', '#semantics-schemata-pane'], { + sizes: [40, 60], + minSize: 400, + gutterSize: 4, + elementStyle: (dimension, size, gutterSize) => { + return { + 'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)' + } + }, + }); + this.loadFrame(); + }, + template: ` <div class="col h-100 px-1 pt-0 pb-0 overflow-auto" id="semantics-frames-pane"> <table class="table-button-menu" cellspacing="1"> <tr style="background-color: white;"> @@ -693,60 +699,51 @@ export default { </tr> </table> <div id="semantics-frames"> - <table class="table m-0 table-borderless border border-secondary text-dark" v-for="frame in frames" :key="frame.id" > - <tbody> - <tr> - <th scope="row"> - <div v-html="slowal_frame_html(frame)" @click="slowalFrameSelected(frame)"></div> - </th> - <th scope="row"> - <div> - - <label v-bind:for="frame.id"> - <div><input - :id="frame.id" - type="checkbox" - - v-model="frame.verified" - :checked="frame.verified" - class="custom-control custom-checkbox" - @change="change_slowal2unified_mapping_verification(frame.id, frame.verified)" - > - <span>Zweryfikowane</span></div> - </label> - <br><br> <a href="#" class="btn btn-sm btn-dark" role="button" - @click="change_slowal2unified_frame_argument_mapping(frame.id)">Z</a> - </div> - </th> - </tr> - </tbody> + <tbody> + <tr> + <th scope="row"> + <div v-html="slowal_frame_html(frame)" @click="slowalFrameSelected(frame)"></div> + </th> + <th scope="row"> + <div> + <label v-bind:for="frame.id"> + <div><input + :id="frame.id" + type="checkbox" + v-model="frame.verified" + :checked="frame.verified" + class="custom-control custom-checkbox" + @change="change_slowal2unified_mapping_verification(frame.id, frame.verified)" + > + <span>Zweryfikowane</span></div> + </label> + <br><br> + <a href="#" class="btn btn-sm btn-dark" role="button" @click="change_slowal2unified_frame_argument_mapping(frame.id)">Z</a> + </div> + </th> + </tr> + </tbody> </table> - </div> </div> <div class="col h-100 px-1 pt-0 pb-0 overflow-auto" id="semantics-schemata-pane"> <ul class="nav nav-pills nav-justified p-1" id="entryTabs" role="tablist"> - <li class="nav-item mr-1"> - <a class="btn btn-sm btn-outline-dark nav-link active" id="unified-frame-semantics-tab" data-toggle="tab" href="#semantics" role="tab" aria-controls="semantics" aria-selected="true"> - {{ gettext('Schematy') }} - </a> - </li> - <li class="nav-item mr-1"> - <a class="btn btn-sm btn-outline-dark nav-link" id="unified-frame-view2-tab" data-toggle="tab" href="#syntax" role="tab" aria-controls="syntax" aria-selected="false"> - {{ gettext('Podgląd ram') }} - </a> - </li> - <li class="nav-item mr-0"> - <a class="btn btn-sm btn-outline-dark nav-link" id="unified-frame-notes-tab" data-toggle="tab" href="#examples" role="tab" aria-controls="examples" aria-selected="false"> - {{ gettext('Notatki') }} - </a> + <li + v-for="tab in right_pane_tabs" + class="btn btn-sm btn-outline-dark nav-link mx-1" + :class="right_pane_tab === tab.id && 'active'" + @click="right_pane_tab = tab.id" + > + {{ tab.label }} </li> </ul> - <div id="semantics-schemata"></div> + <div :class="right_pane_tab !== 'schemata' && 'd-none'" id="semantics-schemata"></div> + <div v-if="right_pane_tab === 'frame_preview'">drugi tab</div> + <div v-if="right_pane_tab === 'notes'">notateczki</div> </div> ` } -- GitLab