Skip to content

Commit

Permalink
#1268: Added Contact Type to phonology fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
susanodd committed Jul 12, 2024
1 parent f8f2b5f commit 2fc2a71
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 1 deletion.
31 changes: 31 additions & 0 deletions media/js/glosses_toggle_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<span class='contType'>"+contType+"</span>";
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;
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion signbank/dictionary/adminviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,14 @@ <h3>{% trans "Batch Edit" %}</h3>
</div>
</td>
</tr>
<tr style="height:26px;">
<th>{% trans "Contact Type" %}</th>
<td class="field_contType" style="width:100px;">
<div class="contType-cell"
id="contType_cell_{{gloss.id}}"><span class='contType'>{% if gloss.contType %}{{gloss.contType.name}}{% endif %}</span>
</div>
</td>
</tr>
<tr style="height:26px;">
<th>{% trans "Movement Shape" %}</th>
<td class="field_movSh" style="width:100px;">
Expand Down Expand Up @@ -712,6 +720,25 @@ <h3>{% trans "Batch Edit" %}</h3>
</div>
</div>

<div class="panel panel-default panel-toggles">
<div class='panel-heading' data-toggle='collapse' data-parent="#phonology"
data-target='#toggle_contType_panel_{{gloss.id}}'>{% trans "Contact Type" %}
</div>
<div id='toggle_contType_panel_{{gloss.id}}' class="panel-collapse collapse">
<div class="panel-body" style="display:inline-block;">
<p>
{% for wc in available_contType %}
<button id='quick_contType_btn_{{gloss.id}}' class="quick_contType btn actionButton"
name='quick_contType_{{gloss.id}}'
value='{{gloss.id}}' data-contType='{{wc.machine_value}}' style="height:36px;"
type="submit" >{{wc.name}}
</button>
{% endfor %}
</p>
</div>
</div>
</div>

<div class="panel panel-default panel-toggles">
<div class='panel-heading' data-toggle='collapse' data-parent="#phonology"
data-target='#toggle_movSh_panel_{{gloss.id}}'>{% trans "Movement Shape" %}
Expand Down
13 changes: 13 additions & 0 deletions signbank/dictionary/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
38 changes: 38 additions & 0 deletions signbank/dictionary/update_glosses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
3 changes: 3 additions & 0 deletions signbank/dictionary/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
re_path(r'^update/toggle_locprim/(?P<glossid>\d+)/(?P<locprim>.*)$',
signbank.dictionary.update.toggle_locprim,
name='toggle_locprim'),
re_path(r'^update/toggle_contType/(?P<glossid>\d+)/(?P<contType>.*)$',
signbank.dictionary.update.toggle_contType,
name='toggle_contType'),
re_path(r'^update/toggle_movSh/(?P<glossid>\d+)/(?P<movSh>.*)$',
signbank.dictionary.update.toggle_movSh,
name='toggle_movSh'),
Expand Down

0 comments on commit 2fc2a71

Please sign in to comment.