{% extends "ndf/mis_base_create_edit.html" %} {% load i18n %} {% load ndf_tags %} {% load pagination_tags %} {% block title %} {% trans "Course Announcement "%} {% endblock %} {% block style %} {{block.super}} /* Resetting css-properties for fieldset (also legend, input) */ /* fieldset (padding-bottom) */ fieldset { padding: 0rem 1.25rem !important; } /* legend (background-color) */ fieldset legend { background-color: transparent !important; } /* input (margin) */ fieldset input { margin: 0 !important; } /* Setting css-properties for reveal-modal's paragraph */ div.reveal-modal > label, div#alertModalDiv > p { color: white; font-weight: bold; font-size: 1rem; } div#alertModalDiv > p > a { color: yellow; font-weight: bold; font-size: 1rem; } #announce-course.hide{ display: none; } {% endblock %} {% block body_content %}
×

{% if node %} {% blocktrans with title_var=title node_name=node.name %} Editing {{title_var}}: {{node_name}} {% endblocktrans %} {% else %} {% trans "Course Announcement "%} {% endif %}

{% csrf_token %}
{% html_widget groupid node.pk property_order_list.0.1.0 %}
{% html_widget groupid node.pk property_order_list.0.1.5 %}
{% if node %}
{% else %}
{% endif %}
{% if tiss_site %}
{% if node %} {% else %} * {% trans "Please select University" %} {% endif %}
{% endif %}
{% endblock %} {% block script %} {{block.super}} // Inputs reset functions function reset_college_fs() { if ($("#divcolg").children.length > 0) { $("#divcolg").empty(); } $("#already_announced_in_colg_list_div").addClass("hide"); $("#unassigned_PO_college_div").addClass("hide"); $("#univ_cur").prop("selectedIndex", 0); {% if not tiss_site %} $("#announce-course").removeClass("hide"); {% else %} $("#announce-course").addClass("hide"); {% endif %} } var announce_course_in_college = false; //Selct university------------------------------------------------------------------------------------------------------ $("select#univ_cur").change(function() { if ($(this).prop("selectedIndex") == 0) { reset_college_fs(); return; } is_all_courses_not_selected = $("input[name='unset-ac-options']:checked").size(); if (!(is_all_courses_not_selected) || $("#start_time").val() == "" || $("#end_time").val() == "") { $("#univ_cur").prop("selectedIndex", 0); $("#alertModalLabel").text("Either course is not selected or course period duration is not set properly!!!"); $("#alertModal").removeClass("success").removeClass("warning"); $("#alertModal").addClass("alert"); $("#alertModal").foundation('reveal', 'open'); return; } nussd_course_type = $("#nussd_course_type").val(); univ_id = $("select#univ_cur").val(); start_time = $("#start_time").val(); end_time = $("#end_time").val(); announce_course_in_college = false; dc_courses_id_list = []; $("input[name='unset-ac-options']:checked").each(function() { dc_course_id = $(this).val(); dc_courses_id_list.push(dc_course_id); }); $.ajax({ url: "{% url 'get_colleges' group_id app_id %}", data: { nussd_course_type: nussd_course_type, univ_id: univ_id, dc_courses_id_list: dc_courses_id_list, start_time: start_time, end_time: end_time }, type: "GET", dataType: "json", complete: function(data){ if (announce_course_in_college) { if ($("#announce-course").hasClass("hide")) { $("#announce-course").removeClass("hide"); } } else { if (!$("#announce-course").hasClass("hide")) { $("#announce-course").addClass("hide"); } } }, success: function(data){ success_state = data["success"]; if (data["success"]) { /* var dict_len = Object.keys(data["unset_nc"]).length; $.each(data["unset_nc"], function(k, val){ $("#unset_nc").append(val); }); */ // Fill already_announced_in_colg_list_div already_announced_in_colg_list = data["already_announced_in_colg_list"] if (already_announced_in_colg_list.length > 0) { $("#already_announced_in_colg_list_div").removeClass("hide"); if ($("#already_announced_in_colg_list_ol").children().length > 0) { $("#already_announced_in_colg_list_ol").empty(); } $.each(already_announced_in_colg_list, function(index, val){ $("#already_announced_in_colg_list_ol").append("
  • " + val + "
  • "); }); } else { if ($("#already_announced_in_colg_list_ol").children().length > 0) { $("#already_announced_in_colg_list_ol").empty(); } $("#already_announced_in_colg_list_div").addClass("hide"); } // Fill unassigned_PO_college_div unassigned_PO_colg_list = data["unassigned_PO_colg_list"] if (unassigned_PO_colg_list.length > 0) { $("#unassigned_PO_college_div").removeClass("hide"); if ($("#unassigned_PO_college_ol").children().length > 0) { $("#unassigned_PO_college_ol").empty(); } $.each(unassigned_PO_colg_list, function(index, val){ $("#unassigned_PO_college_ol").append("
  • " + val + "
  • "); }); } else { if ($("#unassigned_PO_college_ol").children().length > 0) { $("#unassigned_PO_college_ol").empty(); } $("#unassigned_PO_college_div").addClass("hide"); } // Fill divcolg if ($("#divcolg").children().length > 0) { $("#divcolg").empty(); } var text_head = "
    " + "" + "
    "; if (data.hasOwnProperty("drawer_widget")) { drawer_widget = data["drawer_widget"]; $("#divcolg").html(text_head + drawer_widget); announce_course_in_college = true; } else { $("#divcolg").html(text_head); } } else { $("select#univ_cur").prop("selectedIndex", 0); $("#alertModalDiv").html("

    " + data["message"] + "

    "); $("#alertModal").removeClass("success"); $("#alertModal").addClass("alert"); $("#alertModal").foundation('reveal', 'open'); } }//end of success block });//end of ajax call }); //For selecting Course type--------------------------------------------------------------------------------------- $("select#nussd_course_type").change(function() { success_state = false; var nussd_course_type = $("#nussd_course_type").val(); reset_college_fs(); $.ajax({ url: "{% url 'get_courses' group_id %}", data: { nussd_course_type: nussd_course_type }, type: "GET", dataType: "json", success: function(data){ success_state = data["success"]; if (data["success"]) { if ($("#unset-ac-options-div").children.length > 0) { $("#unset-ac-options-div").empty(); } var dict_len = Object.keys(data["unset_nc"]).length; $.each(data["unset_nc"], function(k, val){ input_chk = "" if (dict_len != 1) { input_chk += "
    " } else { input_chk += "
    " } input_type = "checkbox"; if (nussd_course_type != "Foundation Course") { input_type = "radio"; } v = k; input_chk += "" + "" + "
    "; $("#unset-ac-options-div").append(input_chk); dict_len = dict_len - 1; }); // If nussd_course_type is Foundation Course disable all checkboxes if (nussd_course_type == "Foundation Course") { $(".unsetOption").attr("disabled", "disabled"); } else { $(".unsetOption").removeAttr("disabled", "disabled"); $(".unsetOption:first").prop("checked", true); } // Fill divSt if ($("#divSt").children.length > 0) { $("#divSt").empty(); } drawer_widget = data["drawer_widget"] $("#divSt").html(drawer_widget); } else { $("select#nussd_course_type").prop("selectedIndex", 0); $("#alertModalDiv").html("

    " + data["message"] + "

    "); $("#alertModal").removeClass("success"); $("#alertModal").addClass("alert"); $("#alertModal").foundation('reveal', 'open'); } }, complete: function(){ if (success_state) { // Also toggle unset-ac fieldset if ($("#unset-ac").hasClass("hide")) { $("#unset-ac").removeClass("hide") } if ($("#course_dur").css("display") == "none") { $("#course_dur").toggle() } if ($("#fsCollege").hasClass("hide")) { $("#fsCollege").removeClass("hide") } } else { // Otherwise, hide button as well as fieldset if (!$("#announce-course").hasClass("hide")) { $("#announce-course").addClass("hide") } // Also toggle unset-ac fieldset if (!$("#unset-ac").hasClass("hide")) { if ($("#unset-ac-options-div").children.length > 0) { $("#unset-ac-options-div").empty(); } $("#unset-ac").addClass("hide") } } } }); }); // Tabs navigation: Enable and Disable tabs in sequential manner using Next & Previous buttons ------------------- $(".content").on('click', '.tab_next', function(event){ event.preventDefault(); // Forcefully blur all input elements, so that mandatory fields become data-invalid if not fill $(this).parents(".tab-nav").parents(".content").find(':input[required]').blur(); // Then check no. of data-invalid fields // if count == 0, then only proceed to next tab if($(this).parents(".tab-nav").parents(".content").find(':input[data-invalid]').length == 0) { // Valid, move to next step $('.active').removeClass('active').next().addClass('active'); } }); $(".content").on('click', '.tab_prev' ,function(event){ event.preventDefault(); $('.active').removeClass('active').prev().addClass('active'); }); // Only keeping month's & year's drop-down and hiding other datepicker's elements -------------------------------- $(document).on('focus click', '.date_month_day_year' ,function(){ $(".ui-datepicker-calendar").hide(); }); // Enable/Disable Announce (submit) button --------------------------- $(document).on("change click", ".unsetOption", function(){ optionState = $(this).prop("checked"); /* Reset University's drop down In order to check whether updated list of domain course(s) announced in given University */ reset_college_fs(); $("#fsCollege").removeClass("hide"); // Enable/Disable Announce (submit) button, if none of the checkbox is selected if ($("input[name='unset-ac-options']:checked").size() == 0) { $("#announce-course").attr("disabled", "disabled"); } else { // If any of the course of type "Domain Course" is selected // Then enable Announce (submit) button if (optionState) { $("#announce-course").attr("disabled", !optionState); } } }); // On click of Register/Update ----------------------------------------------------------------------------------- $(document).on("click", "#announce-course", function(event) { // Forcefully blur all input elements, so that mandatory fields become data-invalid if not fill $(this).parents(".tab-nav").parents(".content").find(':input[required]').blur(); // Then check no. of data-invalid fields // if count == 0, then only proceed to next tab if($(this).parents(".tab-nav").parents(".content").find(':input[data-invalid]').length == 0) { // Valid, move to next step var announce_to_colg_list = []; {% if not tiss_site %} var nussd_course_type = $("#nussd_course_type").val(); var nussd_course_type_list = [] nussd_course_type_list.push(nussd_course_type); announce_to_colg_list.push("{{group_id}}"); $("#announce_to_colg_list").val(announce_to_colg_list); $('article').block({ message: '

    Processing... Please wait!

    ', css: { border: 'none', padding: '15px', color: '#fff !important', backgroundColor: '#10c1cb !important', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: 1.0 } }); {% else %} {% if not node %} colg_in_rt_drawer = $("#announced_course_create_edit_drawer2 li input"); $.each(colg_in_rt_drawer,function(i, v){ // announce_to_colg_list.push(v.getAttribute('name')); announce_to_colg_list.push(v.getAttribute('value')); }); if (announce_to_colg_list.length > 0) { var nussd_course_type = $("#nussd_course_type").val(); var nussd_course_type_list = [] nussd_course_type_list.push(nussd_course_type); $("#announce_to_colg_list").val(announce_to_colg_list); if (announce_course_in_college) { $("input[name='ann_course_closure']").attr("disabled", false); $(".unsetOption").removeAttr("disabled", "disabled"); } $('article').block({ message: '

    Processing... Please wait!

    ', css: { border: 'none', padding: '15px', color: '#fff !important', backgroundColor: '#10c1cb !important', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: 1.0 } }); } else{ $("#alertModalLabel").text("Please select College!!!"); $("#alertModal").addClass("alert"); $("#alertModal").foundation('reveal', 'open'); // Disable only when "Foundation Course" selected as Course Type if ($("#nussd_course_type :selected").index() == 0) { $(".unsetOption").attr("disabled", "disabled"); } event.preventDefault(); } {% else %} // Fetch college objectid in which this Course is announced {% for col in node.acourse_for_college %} announce_to_colg_list.push("{{col.pk}}"); {% endfor %} if (announce_to_colg_list.length > 0) { $("#announce_to_colg_list").val(announce_to_colg_list); } // Enable Course Type $('#nussd_course_type').attr("disabled", false); // Enable Course duration $("#start_time").attr("disabled", false); $("#end_time").attr("disabled", false); $('article').block({ message: '

    Processing... Please wait!

    ', css: { border: 'none', padding: '15px', color: '#fff !important', backgroundColor: '#10c1cb !important', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', opacity: 1.0 } }); {% endif %} {% endif %} } else { event.preventDefault(); } }); {% endblock %} {% block document_ready %} {{block.super}} $("#nussd_course_type").prop("selectedIndex", 0); reset_college_fs(); {% if node %} $('#nussd_course_type').attr("disabled", true); $("#start_time").attr("disabled",true); $("#end_time").attr("disabled",true); $('#nussd_course_type').val("{{nussd_course_type}}"); if ($("#course_dur").css("display") == "none") { $("#course_dur").toggle(); } if ($("#fsCollege").hasClass("hide")) { $("#fsCollege").removeClass("hide") } $(".tab-nav").children(".for-next").append("") if($("#announce-course").hasClass("hide")) { $("#announce-course").removeClass("hide") } if ($("#announce-course").css("display") == "none") { $("#announce-course").toggle() } {% endif %} // Tabs: Adding Next and Previous buttons for navigation ----------------------------------------------------- $(".content").each(function(i) { totalTabs = $(".content").size() - 1 if (i != totalTabs) { // Not in last tab $(this).children(".tab-nav").children(".for-next") .append(""); } if (i == totalTabs) { // Only in last tab var is_existing_nussd_course = "{{node.pk|default_if_none:''}}"; var submit_btn_label = '{% trans "Announce" %}' // By default considering registering a new nussd_course if (is_existing_nussd_course) { // If value (ObjectId) found, it means updating existing nussd_course record submit_btn_label = '{% trans "Update" %}' } $(this).children(".tab-nav").children(".for-next") .append(""); } if (i != 0) { // Not in first tab $(this).children(".tab-nav").children(".for-prev") .append(""); } }); // Replace date format from DD/MM/YYYY HH:MM to MM/YYYY // For start_time & end_time $(".date_month_day_year").each(function(i) { // Below code is required because in validators "d/m/Y H:i" is set // In order to override that, below code is overwritten if ($(this).attr("id") == "start_time") { $(this).attr("placeholder", "MM/YYYY"); var st = "{{node.start_time|date:'m/Y'}}" $(this).val(st) } else if ($(this).attr("id") == "end_time") { $(this).attr("placeholder", "MM/YYYY"); var et = "{{node.end_time|date:'m/Y'}}" $(this).val(et) } }); // Course: start & end date-widgets -------------------------------------------------------------------------- var currentYear = (new Date()).getFullYear(); var currentMonth = (new Date()).getMonth(); lowerYearLimit = currentYear - 2; upperYearLimit = currentYear + 5; var startDtInput = $("#sc #start_time"); var endDtInput = $("#sc #end_time"); $(".date_month_day_year").datepicker({ changeMonth: true, changeYear: true, dateFormat: 'mm/yy', yearRange: lowerYearLimit + ":" + upperYearLimit, minDate: new Date(lowerYearLimit, currentMonth, 1), maxDate: new Date(upperYearLimit, currentMonth, 1), defaultDate: new Date(lowerYearLimit, currentMonth, 1), onClose: function(dateText, inst) { $(this).val(dateText); var month_year = $(this).val(); var month = 1 var year = lowerYearLimit if ($(this).attr('id') == "start_time") { if (month_year) { month_year = month_year.split("/") month = parseInt(month_year[0]) year = parseInt(month_year[1]) } if (endDtInput.val() != '') { var testStartDate = startDtInput.datepicker('getDate'); var testEndDate = endDtInput.datepicker('getDate'); if (testStartDate > testEndDate) { endDtInput.datepicker('setDate', testStartDate); } else { $(this).val(month+"/"+year); $(this).datepicker('setDate', new Date(year, (month-1), 1)); } } else { endDtInput.val(month+"/"+year); $(this).datepicker('setDate', new Date(year, (month-1), 1)); } $("#end_time.date_month_day_year").datepicker('option', 'minDate', new Date(year, (month-1), 1)); } else if ($(this).attr('id') == "end_time") { if (month_year) { month_year = month_year.split("/") month = parseInt(month_year[0]); year = parseInt(month_year[1]); } if (startDtInput.val() != '') { var testStartDate = startDtInput.datepicker('getDate'); var testEndDate = endDtInput.datepicker('getDate'); if (testStartDate > testEndDate) { startDtInput.datepicker('setDate', testEndDate); } else { $(this).val(month+"/"+year); $(this).datepicker('setDate', new Date(year, (month-1), 1)); } } else { startDtInput.val(month+"/"+year); $(this).datepicker('setDate', new Date(year, (month-1), 1)); } } }, beforeShow: function() { var month_year = $(this).val(); month = currentMonth; year = lowerYearLimit if (month_year) { month_year = month_year.split("/") month = parseInt(month_year[0]) year = parseInt(month_year[1]) } $(this).datepicker('option', 'defaultDate', new Date(year, (month-1), 1)); $(this).datepicker('setDate', new Date(year, (month-1), 1)); }, onChangeMonthYear: function(year, month, inst){ $(this).val(month+"/"+year); if ($(this).attr("id") == "start_date") { $("#end_date").val(month+"/"+year); } reset_college_fs(); } }); // Set Course status to "Open" // And Disable it only while announcing a course (creating and not while updating) {% if not node %} $("input#ann_course_closureOpen").prop("checked", true); $("input[name='ann_course_closure']").attr("disabled", true); {% else %} $("input#ann_course_closure" + "{{node.ann_course_closure}}").prop("checked", true); {% endif %} {% endblock %}