diff --git a/entries/static/entries/js/components/LexicalUnitEdit.js b/entries/static/entries/js/components/LexicalUnitEdit.js index 081c9e574da4536828b144410fe5ac25d43d0d8d..c59daa65d5339f5fc5fc628081a17009b91dbed4 100644 --- a/entries/static/entries/js/components/LexicalUnitEdit.js +++ b/entries/static/entries/js/components/LexicalUnitEdit.js @@ -9,6 +9,7 @@ export default { return { gettext: window.gettext, unified_frame: Object, + unified_frame_title: Object, unified_frame_arguments: [], active_unified_frame_argument: null, slowal_frames2selecional_preferencies_mapping: {}, @@ -38,13 +39,14 @@ export default { this.img_prefix = window.STATIC_URL; + this.lexical_units = frames2lexical_units(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; - this.lexical_units = frames2lexical_units(response.frames); - - $('#lexical-unit').html(this.unified_frame.title || lexical_units2dom(this.lexical_units)); + // $('#lexical-unit').html(this.unified_frame_title); this.slowal_frames2selecional_preferencies_mapping = slowal_frames2selecional_preferencies(this.unified_frame, response.frames); @@ -103,7 +105,45 @@ export default { } 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(); + } + if (v === 1) { + e.preventDefault(); + var title = f.title; + 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) + } + } + $.prompt(change_title_popup); + } }, mounted () { Split(['#semantics-frames-pane', '#semantics-schemata-pane'], { @@ -122,7 +162,7 @@ export default { <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;"> - <td id="change-title" style="padding: 10px 15px 10px 15px; color: #000000;">Zmień nazwę</td> + <td id="change-title" @click="changeTitle" style="padding: 10px 15px 10px 15px; color: #000000;">Zmień nazwę</td> <td id="add-arg" style="padding: 10px 15px 10px 15px; color: #000000;">Dodaj argum.</td> <td style="padding: 10px 15px 10px 15px; color: #000000;" @click="addSelectivePreference">Dodaj prefer.</td> <td id="merge" style="padding: 10px 15px 10px 15px; color: #000000;">Scal</td> @@ -137,7 +177,7 @@ export default { </tr> </table> <spinner /> - <div class="unifiedFrame mt-3" v-bind:data-frame_id="unified_frame.id" id="lexical-unit"></div> + <div class="unifiedFrame mt-3" v-bind:data-frame_id="unified_frame.id" id="lexical-unit" v-html="unified_frame_title"></div> <table v-if="unified_frame.id" id="unified-frame" class="table m-0 table-borderless border border-secondary text-dark"> <tbody> <tr> diff --git a/unifier/urls.py b/unifier/urls.py index 2f1276b65964eb414dc988f642c62b49f46bfa95..d761f5d6d20ac01855d3592c0d8cbf17a3361ca9 100644 --- a/unifier/urls.py +++ b/unifier/urls.py @@ -13,6 +13,6 @@ urlpatterns = [ path('extract_frames_to_new_frame/', views.extract_frames_to_new_frame, name='extract_frames_to_new_frame'), path('change_slowal2unified_fram_argument_mapping/', views.change_slowal2unified_fram_argument_mapping, name='change_slowal2unified_fram_argument_mapping'), path('change_slowal2unified_mapping_verification/', views.change_slowal2unified_mapping_verification, name='change_slowal2unified_mapping_verification'), - + path('save_unified_frame_title/', views.save_unified_frame_title, name='save_unified_frame_title'), ] diff --git a/unifier/views.py b/unifier/views.py index 16d49e656218f2466d8a3d209c3a9c208297338d..34ee7de4749c30238eeb7c31ab85373eb6522fd2 100644 --- a/unifier/views.py +++ b/unifier/views.py @@ -266,3 +266,17 @@ def change_slowal2unified_mapping_verification(request): unifiedFrame2SlowalFrameMapping.save() return JsonResponse({}) return JsonResponse({}) + +@ajax_required +@transaction.atomic +def save_unified_frame_title(request): + if request.method == 'POST': + unified_frame_id = request.POST['unified_frame_id'] + unified_frame_title = request.POST['unified_frame_title'] + + unifiedFrame = UnifiedFrame.objects.get(id=unified_frame_id) + + if unifiedFrame: + unifiedFrame.title = unified_frame_title + unifiedFrame.save() + return JsonResponse({})