Skip to content

Commit

Permalink
#1268: Added Orientation Change to phonology fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
susanodd committed Jul 16, 2024
1 parent e44e1b6 commit 0e2178b
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 @@ -286,6 +286,23 @@ function toggle_relOriLoc(data) {
buttonCell.attr('value', button_contents);
}

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

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

function toggle_create_sense(data) {
if ($.isEmptyObject(data)) {
return;
Expand Down Expand Up @@ -645,6 +662,20 @@ $(document).ready(function() {
});
});

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

$('.quick_create_sense').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', 'movDir', 'repeat', 'altern', 'relOriMov', 'relOriLoc']
'contType', 'movSh', 'movDir', 'repeat', 'altern', 'relOriMov', 'relOriLoc', 'oriCh']
context['similar_gloss_fields'] = json.dumps(similar_gloss_fields)
similar_gloss_fields_labels = {}
for field in similar_gloss_fields:
Expand Down Expand Up @@ -6614,6 +6614,12 @@ def get_context_data(self, **kwargs):
field='RelOriLoc', machine_value__gt=1).order_by('name')]
context['available_relOriLoc'] = available_relOriLoc

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

context['query_parameters'] = json.dumps(self.query_parameters)
query_parameters_keys = list(self.query_parameters.keys())
context['query_parameters_keys'] = json.dumps(query_parameters_keys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,14 @@ <h3>{% trans "Batch Edit" %}</h3>
</div>
</td>
</tr>
<tr style="height:26px;">
<th>{% trans "Orientation Change" %}</th>
<td class="field_oriCh" style="width:100px;">
<div class="oriCh-cell"
id="oriCh_cell_{{gloss.id}}"><span class='oriCh'>{% if gloss.oriCh %}{{gloss.oriCh.name}}{% endif %}</span>
</div>
</td>
</tr>
</table>
</div>
</div>
Expand Down Expand Up @@ -885,6 +893,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_{{gloss.id}}"
data-target='#toggle_oriCh_panel_{{gloss.id}}'>{% trans "Orientation Change" %}
</div>
<div id='toggle_oriCh_panel_{{gloss.id}}' class="panel-collapse collapse">
<div class="panel-body" style="display:inline-block;">
<p>
{% for wc in available_oriCh %}
<button id='quick_oriCh_btn_{{gloss.id}}' class="quick_oriCh btn actionButton"
name='quick_oriCh_{{gloss.id}}'
value='{{gloss.id}}' data-oriCh='{{wc.machine_value}}' style="height:36px;"
type="submit" >{{wc.name}}
</button>
{% endfor %}
</p>
</div>
</div>
</div>

</div>

</div>
Expand Down
13 changes: 13 additions & 0 deletions signbank/dictionary/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3711,6 +3711,19 @@ def toggle_relOriLoc(request, glossid, relOriLoc):
return JsonResponse(result)


@permission_required('dictionary.change_gloss')
def toggle_oriCh(request, glossid, oriCh):

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

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

result = mapping_toggle_oriCh(request, gloss, oriCh)

return JsonResponse(result)


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

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 @@ -626,6 +626,44 @@ def mapping_toggle_relOriLoc(request, gloss, relOriLoc):
return result


@permission_required('dictionary.change_gloss')
def mapping_toggle_oriCh(request, gloss, oriCh):

try:
oriCh_machine_value = int(oriCh)
except TypeError:
return {}

empty_oriCh = FieldChoice.objects.get(field='OriChange', machine_value=0)
new_oriCh = FieldChoice.objects.filter(field='OriChange', machine_value=oriCh_machine_value).first()

if not new_oriCh:
# if the word class does not exist, set it to empty
oriCh_machine_value = 0
new_oriCh = empty_oriCh

original_oriCh = gloss.oriCh.name if gloss.oriCh else '-'

with atomic():
if not gloss.oriCh:
gloss.oriCh = new_oriCh
elif gloss.oriCh.machine_value != oriCh_machine_value:
gloss.oriCh = new_oriCh
else:
gloss.oriCh = empty_oriCh
new_oriCh = empty_oriCh
gloss.save()

add_gloss_update_to_revision_history(request.user, gloss, 'oriCh', original_oriCh, new_oriCh.name)

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

return result


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

Expand Down
3 changes: 3 additions & 0 deletions signbank/dictionary/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
re_path(r'^update/toggle_relOriLoc/(?P<glossid>\d+)/(?P<relOriLoc>.*)$',
signbank.dictionary.update.toggle_relOriLoc,
name='toggle_relOriLoc'),
re_path(r'^update/toggle_oriCh/(?P<glossid>\d+)/(?P<oriCh>.*)$',
signbank.dictionary.update.toggle_oriCh,
name='toggle_oriCh'),

re_path(r'^update/quick_create_sense/(?P<glossid>\d+)$',
signbank.dictionary.update.quick_create_sense,
Expand Down

0 comments on commit 0e2178b

Please sign in to comment.