From 9a7a65e2a13045108bce81e52e4a55f27e3f52b5 Mon Sep 17 00:00:00 2001 From: yleclanche Date: Fri, 9 Aug 2019 14:26:11 +0200 Subject: [PATCH] Users can now send messages to correctors. --- teleforma/templates/postman/base_write.html | 58 +++++++++++++++++++-- teleforma/templatetags/teleforma_tags.py | 22 ++++++++ 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/teleforma/templates/postman/base_write.html b/teleforma/templates/postman/base_write.html index f0be0752..f140e0a5 100644 --- a/teleforma/templates/postman/base_write.html +++ b/teleforma/templates/postman/base_write.html @@ -33,6 +33,8 @@ for="recipient_category-admin">A un administrateur +
@@ -65,6 +67,25 @@
+
+ + + + +
{% block pm_write_recipient %}{% endblock %} @@ -102,20 +123,30 @@ }); } + function update_corrector_recipient() { + $("#_correctorSelect").click(function () { + var htmlStr = $(this).val(); + $("#id_recipients").val(htmlStr); + }); + } function update_desk_messages(event) { // reset values if(event){ $target = $(event.target); - if($target.attr('id') === 'recipient_category-prof' || $target.attr('id') === 'recipient_category-admin') { + if($target.attr('id') === 'recipient_category-prof' || $target.attr('id') === 'recipient_category-admin' || $target.attr('id') === 'recipient_category-corrector') { $('#_professorSelect').val(''); + $('#_correctorSelect').val(''); + $('#_correctorCourseSelect').val(''); $('#_courseSelect').val(''); $('#_adminSelect').val(''); } if($target.attr('id') === '_courseSelect') $('#_professorSelect').val(''); + if($target.attr('id') === '_correctorCourseSelect') + $('#_professorSelect').val(''); } // show or hide field depending on what is selected @@ -123,10 +154,13 @@ $("#id_recipients").val(''); $('#category-admin').hide(); $('#category-prof').hide(); + $('#category-corrector').hide(); if (recipientCategory == 'admin') $('#category-admin').show(); else if (recipientCategory == 'prof') $('#category-prof').show(); + else if (recipientCategory == 'corrector') + $('#category-corrector').show(); var course = parseInt($('[name="course"]').val(), 10); if(!course) @@ -134,6 +168,13 @@ else $('#_professorSelect').show(); + var correctorCourse = parseInt($('[name="corrector_course"]').val(), 10); + console.log(correctorCourse) + if(!correctorCourse) + $('#_correctorSelect').hide(); + else + $('#_correctorSelect').show(); + $('#_professorSelect option').hide(); $('#_professorSelect option:first').show(); $('#_professorSelect option').each(function(){ @@ -142,9 +183,20 @@ if(courses && courses.indexOf(course) >= 0) $option.show(); }); + $('#_correctorSelect option').hide(); + $('#_correctorSelect option:first').show(); + $('#_correctorSelect option').each(function(){ + var $option = $(this); + var courses = $option.data('courses') + if(courses && courses.indexOf(correctorCourse) >= 0) + $option.show(); + }); + // fill the hidden field if($('#_professorSelect').val() && $('#_courseSelect').val() && recipientCategory === 'prof') $("#id_recipients").val($('#_professorSelect').val()); + if($('#_correctorSelect').val() && $('#_correctorCourseSelect').val() && recipientCategory === 'corrector') + $("#id_recipients").val($('#_correctorSelect').val()); if($('#_adminSelect').val() && recipientCategory === 'admin') $("#id_recipients").val($('#_adminSelect').val()); @@ -155,8 +207,8 @@ {#$('#id_course').parent().parent().hide();#} $('[name="recipient_category"]').bind('change', update_desk_messages); - $('[name="course"]').bind('change', update_desk_messages); - $('#_professorSelect, #_adminSelect').bind('change', update_desk_messages); + $('[name="course"], [name="corrector_course"]').bind('change', update_desk_messages); + $('#_professorSelect, #_correctorSelect, #_adminSelect').bind('change', update_desk_messages); update_desk_messages(); document.getElementById("id_subject").focus(); diff --git a/teleforma/templatetags/teleforma_tags.py b/teleforma/templatetags/teleforma_tags.py index 7cea5aa8..41742b3d 100644 --- a/teleforma/templatetags/teleforma_tags.py +++ b/teleforma/templatetags/teleforma_tags.py @@ -163,6 +163,28 @@ def get_all_professors_with_courses(): return professors +@register.assignment_tag +def get_all_correctors_with_courses(): + correctors = {} + + for quota in Quota.objects.all(): + if not quota.corrector: + continue + if quota.corrector not in correctors: + correctors[quota.corrector] = set() + correctors[quota.corrector].add(quota.course.id) + + result = [] + for corrector in correctors.keys(): + name = corrector.last_name + corrector.first_name + if name: + result.append({ + 'username':corrector.username, + 'name':corrector.last_name + " " + corrector.first_name, + 'courses':json.dumps(list(correctors[corrector])) + }) + return result + @register.assignment_tag def get_all_admins(): -- 2.39.5