Skip to content

Commit 4974053

Browse files
authored
Merge pull request #1391 from Signbank/trash_a_gloss
#1375: Trash button in Lemma Update for gloss deletion.
2 parents 0f3de77 + 2fc130f commit 4974053

File tree

3 files changed

+128
-5
lines changed

3 files changed

+128
-5
lines changed

signbank/dictionary/templates/dictionary/update_lemma.html

+92-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
{% load annotation_idgloss_translation %}
1111

1212
{% block extrajs %}
13+
<style>
14+
.trash_button:hover {
15+
color: red;
16+
}
17+
.trash_button.active {
18+
color: red;
19+
}
20+
</style>
1321
<script type='text/javascript'>
1422

1523
var csrf_token = '{{csrf_token}}';
@@ -19,6 +27,31 @@
1927
var url = '{{PREFIX_URL}}';
2028
var language_2chars = {{language_2chars|safe}};
2129

30+
function ready_videos(el) {
31+
$(el).find('video').hide();
32+
33+
$(el).mouseenter(function ()
34+
{
35+
var video = $(this).find('video');
36+
if(video.length > 0) {
37+
$(this).find('img').hide();
38+
video.show();
39+
video.get(0).play();
40+
}
41+
});
42+
43+
$(el).mouseleave(function ()
44+
{
45+
$(this).find('img').show();
46+
47+
var video = $(this).find('video');
48+
if(video.length > 0) {
49+
video.hide();
50+
video.get(0).pause();
51+
video.get(0).currentTime = 0;
52+
}
53+
});
54+
}
2255
function toggle_restore(data) {
2356
if ($.isEmptyObject(data)) {
2457
return;
@@ -69,6 +102,9 @@
69102
success : toggle_restore
70103
});
71104
});
105+
$('.hover-shows-video').each(function() {
106+
ready_videos(this);
107+
});
72108
});
73109

74110
var search_results_url = '{% url 'dictionary:lemma_ajax_search_results' %}';
@@ -116,25 +152,38 @@ <h3>{% trans "Update Lemma" %}</h3>
116152
<input type='hidden' id="gloss_id" name="gloss_id" value="{{gloss_id}}">
117153
<input class='btn btn-primary' type='submit' value='{% trans "Update" %}'>
118154
</form>
155+
<br>
119156
<div>
120157
{% if SHOW_DATASET_INTERFACE_OPTIONS %}
158+
{% url 'dictionary:protected_media' '' as protected_media_url %}
121159
{% csrf_token %}
122-
<table class='table' style='width: 800px;'>
160+
<table class='table' style='width: 1200px;'>
123161
<tr>
124162
<th>{% trans "Dataset" %}</th>
125163
<td><a href="{{PREFIX_URL}}/datasets/{{object.dataset.acronym}}" >{{ object.dataset.acronym }}</a></td>
126164
</tr>
127165
<tr>
128166
<th>{% trans "Glosses" %}</th>
129-
<th>{% trans "Signbank ID" %}</th>
167+
<th>{% trans "Video" %}</th>
168+
<th style="width:200px;">{% trans "Signbank ID" %}</th>
130169
{% for dataset_lang in dataset_languages %}
131-
<th>{% trans "Annotation ID Gloss" %} ({{dataset_lang.name}})</th>
170+
<th style="width:400px;">{% trans "Annotation ID Gloss" %} ({{dataset_lang.name}})</th>
132171
{% endfor %}
133172
<th></th>
134173
</tr>
135174
{% for gloss, annotation_idgloss_translations in lemma_group_list %}
136175
<tr><td></td>
137-
176+
<td>{% if gloss.get_image_path or gloss.has_video %}
177+
<div id='glossvideo_{{gloss.id}}' class="hover-shows-video">
178+
<img class="thumbnail" src="{{protected_media_url}}{{gloss.get_image_url}}">
179+
{% if gloss.has_video %}
180+
<video id="videoplayer" class="thumbnail-video"
181+
src="{{protected_media_url}}{{gloss.get_video_url}}"
182+
type="video/*" muted="muted"></video>
183+
{% endif %}
184+
</div>
185+
{% endif %}
186+
</td>
138187
<td id="signbank_id_{{gloss.id}}">{{gloss.id}} {% if gloss.archived %}({% trans "Archived" %}){% endif %}</td>
139188
{% for dataset_lang in dataset_languages %}
140189
{% with gloss|get_annotation_idgloss_translation:dataset_lang as annotation_translation %}
@@ -151,13 +200,51 @@ <h3>{% trans "Update Lemma" %}</h3>
151200
{% endfor %}
152201
<td id="restore_gloss_{{gloss.id}}">
153202
{% if gloss.archived and perms.dictionary.change_gloss %}
154-
<button id='quick_restore_btn_{{gloss.id}}' class="quick_restore btn btn-danger"
203+
<button id='quick_restore_btn_{{gloss.id}}' class="quick_restore btn btn-success"
155204
name='quick_restore_{{gloss.id}}'
156205
value='{{gloss.id}}' style="height:36px;"
157206
type="submit" >{% trans "Restore Gloss" %}</button>
158207

159208
{% endif %}
160209
</td>
210+
<td id="trash_gloss_{{gloss.id}}">
211+
{% if gloss.archived and perms.dictionary.change_gloss %}
212+
<button id='quick_trash_btn_{{gloss.id}}' class="quick_trash btn trash_button"
213+
name='quick_trash_{{gloss.id}}' data-toggle='modal' data-target='#delete_gloss_modal_{{gloss.id}}'
214+
value='{{gloss.id}}' style="font-size:20px;background-color:transparent;"
215+
type="submit" ><span class='glyphicon glyphicon-trash'></span></button>
216+
217+
<div class="modal fade" id="delete_gloss_modal_{{gloss.id}}" tabindex="-1" role="dialog" aria-labelledby="#modalTitleDelete" aria-hidden="true">
218+
<div class="modal-dialog modal-lg left-modal">
219+
<div class="modal-content">
220+
<div class='modal-header'>
221+
<h2 id='modalTitleDelete'>{% trans "Delete This Sign" %}</h2>
222+
<br>
223+
<h4>{% trans "Signbank ID" %}: {{gloss.id}}</h4>
224+
{% with gloss.get_annotationidglosstranslation_texts as annotations %}
225+
{% for lang in dataset_languages %}
226+
<p>{{lang.name}}: {{annotations|get_item:lang.language_code_2char}}</p>
227+
{% endfor %}
228+
{% endwith %}
229+
</div>
230+
<div class='modal-body'>
231+
<p>{% trans "This action will delete this sign and all associated records. It cannot be undone." %}</p>
232+
</div>
233+
<form action="{% url 'dictionary:trash_gloss' gloss.id %}" method='post'>
234+
{% csrf_token %}
235+
<input type='hidden' name='id' value='trash'>
236+
<input type='hidden' name='value' value='trash'>
237+
<div class="modal-footer">
238+
<button type="button" class="btn btn-primary" data-dismiss="modal">{% trans "Cancel" %}</button>
239+
<input type="submit" class="btn btn-danger" value='{% trans "Confirm Delete" %}'>
240+
</div>
241+
</form>
242+
243+
</div>
244+
</div>
245+
</div>
246+
{% endif %}
247+
</td>
161248
</tr>
162249
{% endfor %}
163250
</table>

signbank/dictionary/update.py

+34
Original file line numberDiff line numberDiff line change
@@ -3901,3 +3901,37 @@ def restore_gloss(request, glossid):
39013901
result['glossid'] = str(gloss.id)
39023902

39033903
return JsonResponse(result)
3904+
3905+
3906+
def trash_gloss(request, glossid):
3907+
"""View to update a gloss model from the jeditable jquery form
3908+
We are sent one field and value at a time, return the new value
3909+
once we've updated it."""
3910+
3911+
if not request.method == "POST":
3912+
return HttpResponseForbidden("Gloss deletion method must be POST")
3913+
3914+
if not request.user.has_perm('dictionary.change_gloss'):
3915+
return HttpResponseForbidden("Gloss update not allowed")
3916+
3917+
from django.contrib.auth.models import Group
3918+
group_manager = Group.objects.filter(name='Dataset_Manager').first()
3919+
groups_of_user = request.user.groups.all()
3920+
if group_manager not in groups_of_user:
3921+
return HttpResponseForbidden("You must be in group manager to delete a gloss.")
3922+
3923+
gloss = get_object_or_404(Gloss, id=glossid)
3924+
3925+
if not gloss.archived:
3926+
return HttpResponseForbidden("Gloss is not archived. Please archive the gloss before deleting.")
3927+
3928+
field = request.POST.get('id', '')
3929+
value = request.POST.get('value', '')
3930+
3931+
if value != 'trash' or field != 'trash':
3932+
return HttpResponseForbidden("Gloss Deletion not confirmed")
3933+
3934+
lemma_id = gloss.lemma.id
3935+
gloss.delete()
3936+
3937+
return HttpResponseRedirect(reverse('dictionary:change_lemma', kwargs={'pk': lemma_id}))

signbank/dictionary/urls.py

+2
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@
242242
re_path(r'restore_gloss/(?P<glossid>\d+)/$',
243243
signbank.dictionary.update.restore_gloss, name='restore_gloss'),
244244

245+
re_path(r'^trash_gloss/(?P<glossid>\d+)$', signbank.dictionary.update.trash_gloss, name='trash_gloss'),
246+
245247
re_path(r'info/$', signbank.dictionary.views.info),
246248
re_path(r'protected_media/(?P<filename>.*)$', signbank.dictionary.views.protected_media, name='protected_media'),
247249

0 commit comments

Comments
 (0)