diff --git a/entries/static/entries/js/components/LexicalUnitDisplay.js b/entries/static/entries/js/components/LexicalUnitDisplay.js index 8571e1f635be0562253fa9d7689c2a004a627eaf..498d6add868cfc73787faf888699fb8a610de0af 100644 --- a/entries/static/entries/js/components/LexicalUnitDisplay.js +++ b/entries/static/entries/js/components/LexicalUnitDisplay.js @@ -31,20 +31,47 @@ export default { goToEdit (unifiedFrameId, entryId, lexicalUnitId) { window.location = `/${lang}/entries/unification?unified_frame_id=${unifiedFrameId}&entry_id=${entryId}&lexical_unit_id=${lexicalUnitId}`; }, + hasWhiteSpace(s) { + return /\s/g.test(s); + }, take () { - $.ajax({ - type : 'post', - url : `/${lang}/unifier/frame_assign/${this.lexicalUnitId}/`, - dataType : 'json', - timeout : 60000, - success: function (response) { - show_info('Rama została stworzona oraz przypisana użytkownikowi.'); - this.goToEdit(response.unified_frame_id, this.entryId, this.lexicalUnitId); - }.bind(this), - error: function (request, errorType, errorMessage) { - show_error(errorType + ' (' + errorMessage + ')'); + const create_title_popup = { + state0: { + title: 'Wprowadź nazwę ramy', + html: '<input type="text" size="32" 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(); + const title = f.title; + if (this.hasWhiteSpace(title) || title.length === 0) { + alert(gettext("Nazwa zunifikowanej ramy nie może być pusta oraz nie może zawierać białych znaków.")); + } else { + const data = {'lu_id': this.lexicalUnitId, 'unified_frame_title': title}; + $.ajax({ + type : 'post', + url : `/${lang}/unifier/frame_assign/`, + dataType : 'json', + data: data, + timeout : 60000, + success: function (response) { + show_info('Rama została stworzona oraz przypisana użytkownikowi.'); + this.goToEdit(response.unified_frame_id, this.entryId, this.lexicalUnitId); + }.bind(this), + error: function (request, errorType, errorMessage) { + show_error(errorType + ' (' + errorMessage + ')'); + } + }); + } + } + }.bind(this) + } } - }); + $.prompt(create_title_popup); }, statusChange(api_method) { $.ajax({ diff --git a/unifier/urls.py b/unifier/urls.py index 5ae8ec00de3d6c7e75e1e85a258fbd9e92f5cf2f..899f02c912882ba96f0dd14226175829183474ac 100644 --- a/unifier/urls.py +++ b/unifier/urls.py @@ -22,7 +22,7 @@ urlpatterns = [ 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'), path('build_unified_frame_xml/', views.build_unified_frame_xml, name='build_unified_frame_xml'), - path('frame_assign/<int:lu_id>/', views.frame_assign, name='frame_assign'), + path('frame_assign/', views.frame_assign, name='frame_assign'), path('delete_unified_frame/<int:unified_frame_id>/', views.delete_unified_frame, name='delete_unified_frame'), ] diff --git a/unifier/views.py b/unifier/views.py index 45d7b4d1e9cdae5746fc1dc56f21cabadd343f97..c7f309075aef24fdd5189837172d058281d7baee 100644 --- a/unifier/views.py +++ b/unifier/views.py @@ -223,6 +223,7 @@ def get_unified_frame(request): return JsonResponse({}) @ajax_required +@transaction.atomic def extract_frames_to_new_frame(request): if request.method == 'POST': unified_frame_id = request.POST['unified_frame_id'] @@ -239,6 +240,7 @@ def extract_frames_to_new_frame(request): return JsonResponse({}) @ajax_required +@transaction.atomic def remove_selectional_preference(request): if request.method == 'POST': unified_frame_id = request.POST['unified_frame_id'] @@ -255,6 +257,7 @@ def remove_selectional_preference(request): return JsonResponse({}) @ajax_required +@transaction.atomic def duplicate_unified_frame(request): if request.method == 'POST': unified_frame_id = request.POST['unified_frame_id'] @@ -266,6 +269,7 @@ def duplicate_unified_frame(request): return JsonResponse({}) @ajax_required +@transaction.atomic def change_slowal2unified_fram_argument_mapping(request): if request.method == 'POST': unified_frame_id = request.POST['unified_frame_id'] @@ -302,6 +306,7 @@ def change_slowal2unified_fram_argument_mapping(request): return JsonResponse({}) @ajax_required +@transaction.atomic def change_slowal_frame_status(request): if request.method == 'POST': unified_frame_id = request.POST['unified_frame_id'] @@ -454,27 +459,48 @@ def build_unified_frame_xml(request): @ajax_required @transaction.atomic -def frame_assign(request, lu_id): +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'] - unified_frame_pk = create_unified_frame(lu_id) + unifiedFrame = UnifiedFrame.objects.get(id=unified_frame_id) - unifiedFrame = get_object_or_404( - UnifiedFrame.objects, - pk=unified_frame_pk, - ) + if unifiedFrame: + unifiedFrame.title = unified_frame_title + unifiedFrame.save() + return JsonResponse({}) - slowal_frames = [connection.slowal_frame for connection in unifiedFrame.unified_frame_2_slowal_frame.all()] +@ajax_required +@transaction.atomic +def frame_assign(request): + if request.method == 'POST': - for slowal_frame in slowal_frames: - slowal_frame.status = FrameStatus.PROCESSING - Assignment.assign(user=request.user, subject=slowal_frame) - slowal_frame.save() + lu_id = request.POST['lu_id'] + unified_frame_title = request.POST['unified_frame_title'] - ret = { - 'unified_frame_id': unified_frame_pk - } + unified_frame_pk = create_unified_frame(lu_id) + + unifiedFrame = get_object_or_404( + UnifiedFrame.objects, + pk=unified_frame_pk, + ) + unifiedFrame.title = unified_frame_title + unifiedFrame.save() - return JsonResponse(ret) + slowal_frames = [connection.slowal_frame for connection in unifiedFrame.unified_frame_2_slowal_frame.all()] + + for slowal_frame in slowal_frames: + slowal_frame.status = FrameStatus.PROCESSING + Assignment.assign(user=request.user, subject=slowal_frame) + slowal_frame.save() + + ret = { + 'unified_frame_id': unified_frame_pk + } + + return JsonResponse(ret) + return JsonResponse({}) def removeUnifiedFrameMappingsAndAssigments(unified_frame_id): #odpianie z ramy zunifikowanej