diff --git a/media/js/glosses_toggle_edit.js b/media/js/glosses_toggle_edit.js index 460aff8ce..81d757b2e 100644 --- a/media/js/glosses_toggle_edit.js +++ b/media/js/glosses_toggle_edit.js @@ -167,6 +167,23 @@ function toggle_locprim(data) { buttonCell.attr('value', button_contents); } +function toggle_contType(data) { + if ($.isEmptyObject(data)) { + return; + }; + var glossid = data.glossid; + var contType = data.contType; + var hCell = $("#contType_cell_"+glossid); + $(hCell).empty(); + var cell = ""+contType+""; + hCell.html(cell); + + var button_lookup = '#button_' + glossid + '_contType'; + var buttonCell = $(button_lookup); + var button_contents = similar_gloss_fields_labels['contType'] + ': ' + contType; + buttonCell.attr('value', button_contents); +} + function toggle_movSh(data) { if ($.isEmptyObject(data)) { return; @@ -479,6 +496,20 @@ $(document).ready(function() { }); }); + $('.quick_contType').click(function(e) + { + e.preventDefault(); + var glossid = $(this).attr('value'); + var contType = $(this).attr("data-contType"); + $.ajax({ + url : url + "/dictionary/update/toggle_contType/" + glossid + "/" + contType, + type: 'POST', + data: { 'csrfmiddlewaretoken': csrf_token }, + datatype: "json", + success : toggle_contType + }); + }); + $('.quick_movSh').click(function(e) { e.preventDefault(); diff --git a/signbank/dictionary/adminviews.py b/signbank/dictionary/adminviews.py index 21e8d0121..9ec27a377 100755 --- a/signbank/dictionary/adminviews.py +++ b/signbank/dictionary/adminviews.py @@ -6540,7 +6540,7 @@ def get_context_data(self, **kwargs): context['available_tags'] = [tag for tag in Tag.objects.all()] similar_gloss_fields = ['handedness', 'domhndsh', 'subhndsh', 'handCh', 'relatArtic', 'locprim', - 'movSh', 'repeat', 'altern'] + 'contType', 'movSh', 'repeat', 'altern'] context['similar_gloss_fields'] = json.dumps(similar_gloss_fields) similar_gloss_fields_labels = {} for field in similar_gloss_fields: @@ -6580,6 +6580,12 @@ def get_context_data(self, **kwargs): field='Location', machine_value__gt=1).order_by('name')] context['available_locprim'] = available_locprim + available_contType = [fc for fc in FieldChoice.objects.filter( + field='ContactType', machine_value__in=[0, 1]).order_by('machine_value')] + available_contType += [fc for fc in FieldChoice.objects.filter( + field='ContactType', machine_value__gt=1).order_by('name')] + context['available_contType'] = available_contType + available_movSh = [fc for fc in FieldChoice.objects.filter( field='MovementShape', machine_value__in=[0, 1]).order_by('machine_value')] available_movSh += [fc for fc in FieldChoice.objects.filter( diff --git a/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html b/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html index fc8f3af45..d3eaa3088 100644 --- a/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html +++ b/signbank/dictionary/templates/dictionary/admin_batch_edit_view.html @@ -516,6 +516,14 @@

{% trans "Batch Edit" %}

+ + {% trans "Contact Type" %} + +
{% if gloss.contType %}{{gloss.contType.name}}{% endif %} +
+ + {% trans "Movement Shape" %} @@ -712,6 +720,25 @@

{% trans "Batch Edit" %}

+
+
{% trans "Contact Type" %} +
+
+
+

+ {% for wc in available_contType %} + + {% endfor %} +

+
+
+
+
{% trans "Movement Shape" %} diff --git a/signbank/dictionary/update.py b/signbank/dictionary/update.py index bdcde1342..eb1f4dcde 100755 --- a/signbank/dictionary/update.py +++ b/signbank/dictionary/update.py @@ -3603,6 +3603,19 @@ def toggle_locprim(request, glossid, locprim): return JsonResponse(result) +@permission_required('dictionary.change_gloss') +def toggle_contType(request, glossid, contType): + + gloss = Gloss.objects.filter(id=glossid).first() + + if not okay_to_update_gloss(request, gloss): + return JsonResponse({}) + + result = mapping_toggle_contType(request, gloss, contType) + + return JsonResponse(result) + + @permission_required('dictionary.change_gloss') def toggle_movSh(request, glossid, movSh): diff --git a/signbank/dictionary/update_glosses.py b/signbank/dictionary/update_glosses.py index b99a35c1b..756983aee 100644 --- a/signbank/dictionary/update_glosses.py +++ b/signbank/dictionary/update_glosses.py @@ -384,6 +384,44 @@ def mapping_toggle_locprim(request, gloss, locprim): return result +@permission_required('dictionary.change_gloss') +def mapping_toggle_contType(request, gloss, contType): + + try: + contType_machine_value = int(contType) + except TypeError: + return {} + + empty_contType = FieldChoice.objects.get(field='ContactType', machine_value=0) + new_contType = FieldChoice.objects.filter(field='ContactType', machine_value=contType_machine_value).first() + + if not new_contType: + # if the word class does not exist, set it to empty + contType_machine_value = 0 + new_contType = empty_contType + + original_contType = gloss.contType.name if gloss.contType else '-' + + with atomic(): + if not gloss.contType: + gloss.contType = new_contType + elif gloss.contType.machine_value != contType_machine_value: + gloss.contType = new_contType + else: + gloss.contType = empty_contType + new_contType = empty_contType + gloss.save() + + add_gloss_update_to_revision_history(request.user, gloss, 'contType', original_contType, new_contType.name) + + result = dict() + result['glossid'] = str(gloss.id) + newvalue = gloss.contType.name + result['contType'] = newvalue + + return result + + @permission_required('dictionary.change_gloss') def mapping_toggle_movSh(request, gloss, movSh): diff --git a/signbank/dictionary/urls.py b/signbank/dictionary/urls.py index 21d1365e0..5ded9b1a0 100755 --- a/signbank/dictionary/urls.py +++ b/signbank/dictionary/urls.py @@ -108,6 +108,9 @@ re_path(r'^update/toggle_locprim/(?P\d+)/(?P.*)$', signbank.dictionary.update.toggle_locprim, name='toggle_locprim'), + re_path(r'^update/toggle_contType/(?P\d+)/(?P.*)$', + signbank.dictionary.update.toggle_contType, + name='toggle_contType'), re_path(r'^update/toggle_movSh/(?P\d+)/(?P.*)$', signbank.dictionary.update.toggle_movSh, name='toggle_movSh'),