Skip to content

Commit

Permalink
#1268: Added Movement Direction to phonology fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
susanodd committed Jul 12, 2024
1 parent 2fc2a71 commit 6ec8b0f
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 @@ -201,6 +201,23 @@ function toggle_movSh(data) {
buttonCell.attr('value', button_contents);
}

function toggle_movDir(data) {
if ($.isEmptyObject(data)) {
return;
};
var glossid = data.glossid;
var movDir = data.movDir;
var hCell = $("#movDir_cell_"+glossid);
$(hCell).empty();
var cell = "<span class='movDir'>"+movDir+"</span>";
hCell.html(cell);

var button_lookup = '#button_' + glossid + '_movDir';
var buttonCell = $(button_lookup);
var button_contents = similar_gloss_fields_labels['movDir'] + ': ' + movDir;
buttonCell.attr('value', button_contents);
}

function toggle_repeat(data) {
if ($.isEmptyObject(data)) {
return;
Expand Down Expand Up @@ -524,6 +541,20 @@ $(document).ready(function() {
});
});

$('.quick_movDir').click(function(e)
{
e.preventDefault();
var glossid = $(this).attr('value');
var movDir = $(this).attr("data-movDir");
$.ajax({
url : url + "/dictionary/update/toggle_movDir/" + glossid + "/" + movDir,
type: 'POST',
data: { 'csrfmiddlewaretoken': csrf_token },
datatype: "json",
success : toggle_movDir
});
});

$('.quick_repeat').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',
'contType', 'movSh', 'repeat', 'altern']
'contType', 'movSh', 'movDir', '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 @@ -6592,6 +6592,12 @@ def get_context_data(self, **kwargs):
field='MovementShape', machine_value__gt=1).order_by('name')]
context['available_movSh'] = available_movSh

available_movDir = [fc for fc in FieldChoice.objects.filter(
field='MovementDir', machine_value__in=[0, 1]).order_by('machine_value')]
available_movDir += [fc for fc in FieldChoice.objects.filter(
field='MovementDir', machine_value__gt=1).order_by('name')]
context['available_movDir'] = available_movDir

available_boolean = [{'machine_value': 1, 'name': gettext("Yes")},
{'machine_value': 0, 'name': gettext("No")}]
context['available_boolean'] = available_boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ <h3>{% trans "Batch Edit" %}</h3>
</div>
</td>
</tr>
<tr style="height:26px;">
<th>{% trans "Movement Direction" %}</th>
<td class="field_movDir" style="width:100px;">
<div class="movDir-cell"
id="movDir_cell_{{gloss.id}}"><span class='movDir'>{% if gloss.movDir %}{{gloss.movDir.name}}{% endif %}</span>
</div>
</td>
</tr>
<tr style="height:26px;">
<th>{% trans "Repeated Movement" %}</th>
<td class="field_repeat" style="width:100px;">
Expand Down Expand Up @@ -758,6 +766,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_movDir_panel_{{gloss.id}}'>{% trans "Movement Direction" %}
</div>
<div id='toggle_movDir_panel_{{gloss.id}}' class="panel-collapse collapse">
<div class="panel-body" style="display:inline-block;">
<p>
{% for wc in available_movDir %}
<button id='quick_movDir_btn_{{gloss.id}}' class="quick_movDir btn actionButton"
name='quick_movDir_{{gloss.id}}'
value='{{gloss.id}}' data-movDir='{{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_repeat_panel_{{gloss.id}}'>{% trans "Repeated Movement" %}
Expand Down
13 changes: 13 additions & 0 deletions signbank/dictionary/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3629,6 +3629,19 @@ def toggle_movSh(request, glossid, movSh):
return JsonResponse(result)


@permission_required('dictionary.change_gloss')
def toggle_movDir(request, glossid, movDir):

gloss = Gloss.objects.filter(id=glossid).first()

if not okay_to_update_gloss(request, gloss):
return JsonResponse({})

result = mapping_toggle_movDir(request, gloss, movDir)

return JsonResponse(result)


@permission_required('dictionary.change_gloss')
def toggle_repeat(request, glossid, repeat):

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 @@ -460,6 +460,44 @@ def mapping_toggle_movSh(request, gloss, movSh):
return result


@permission_required('dictionary.change_gloss')
def mapping_toggle_movDir(request, gloss, movDir):

try:
movDir_machine_value = int(movDir)
except TypeError:
return {}

empty_movDir = FieldChoice.objects.get(field='MovementDir', machine_value=0)
new_movDir = FieldChoice.objects.filter(field='MovementDir', machine_value=movDir_machine_value).first()

if not new_movDir:
# if the word class does not exist, set it to empty
movDir_machine_value = 0
new_movDir = empty_movDir

original_movDir = gloss.movDir.name if gloss.movDir else '-'

with atomic():
if not gloss.movDir:
gloss.movDir = new_movDir
elif gloss.movDir.machine_value != movDir_machine_value:
gloss.movDir = new_movDir
else:
gloss.movDir = empty_movDir
new_movDir = empty_movDir
gloss.save()

add_gloss_update_to_revision_history(request.user, gloss, 'movDir', original_movDir, new_movDir.name)

result = dict()
result['glossid'] = str(gloss.id)
newvalue = gloss.movDir.name
result['movDir'] = newvalue

return result


@permission_required('dictionary.change_gloss')
def mapping_toggle_repeat(request, gloss, repeat):
# repeat is 0 or 1
Expand Down
3 changes: 3 additions & 0 deletions signbank/dictionary/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@
re_path(r'^update/toggle_movSh/(?P<glossid>\d+)/(?P<movSh>.*)$',
signbank.dictionary.update.toggle_movSh,
name='toggle_movSh'),
re_path(r'^update/toggle_movDir/(?P<glossid>\d+)/(?P<movDir>.*)$',
signbank.dictionary.update.toggle_movDir,
name='toggle_movDir'),
re_path(r'^update/toggle_repeat/(?P<glossid>\d+)/(?P<repeat>.*)$',
signbank.dictionary.update.toggle_repeat,
name='toggle_repeat'),
Expand Down

0 comments on commit 6ec8b0f

Please sign in to comment.