From d8654a6ccb4d377fa9f77ced66ce812d3a4d34fe Mon Sep 17 00:00:00 2001 From: katkamrachana Date: Sat, 25 Apr 2015 11:05:23 +0530 Subject: Minor changes in Course Unit creation template flow --- .../ndf/templates/ndf/course_detail.html | 6 +- .../ndf/templates/ndf/course_units.html | 156 +++++++++++---------- gnowsys-ndf/gnowsys_ndf/ndf/urls/ajax-urls.py | 2 +- 3 files changed, 83 insertions(+), 81 deletions(-) (limited to 'gnowsys-ndf/gnowsys_ndf/ndf') diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_detail.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_detail.html index 4497285d..5c7792ef 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_detail.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_detail.html @@ -10,8 +10,6 @@ {% endblock %} - - {% block style %} {{block.super}} @@ -55,8 +53,8 @@

{{node.name}} - - + {% trans "Edit" %} + {% if node %} diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_units.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_units.html index 6618f1b0..733deaf2 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_units.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_units.html @@ -74,20 +74,9 @@ margin-left:0 !important; } - #add_res, #new_res{ - width:85%; - } - {% endblock %} {% block meta_content %} -

-
- -
-
- -
{% endblock %} @@ -96,32 +85,45 @@
- +
-
- +
+ {% if unit_node %} + + {% else %} + + {% endif %}
+
- + + {% if unit_node %} + + {% else %} + + {% endif %}
- -
+ +
+ + +
@@ -168,7 +170,6 @@
-



@@ -186,9 +187,9 @@ var res_name_flag = ""; - //save unit button click - $(document).on("click", "#create_unit", function(){ - unit_name_val = $("#unit_name").val(); + //create unit button click + $(document).on("click", ".create_unit", function(event){ + unit_name_val = $(".unit_name").val(); unit_node_id = $("#hidden_unit_node_id").val(); $.ajax({ @@ -215,23 +216,33 @@ }); }); + + //create unit button click + $(document).on("click", ".edit_unit", function(){ + name_input_filed = '' + $(".name-field").html(name_input_filed) + $(this).attr('value',"Update Unit") + .addClass("create_unit") + .removeClass("edit_unit") + }); + //Cancel button $(document).on("click", "#cancel_btn", function(){ $(".res-opt-div").find("#view_add_file, #view_add_page").addClass("hide"); - $(".res-option").removeClass("hide"); + $(".res-opt-btns").removeClass("hide") $(".name_id").val(""); }); //Create new page/ Upload file button - $(document).on("click", ".res-option", function(){ - $(this).addClass("hide") + $(document).on("click", "#new_res", function(){ + $(".res-opt-btns").addClass("hide") if(res_name_flag == "Page"){ $(".res-opt-div").find("#view_add_page").removeClass("hide"); $(".res-opt-div").find("#view_add_page .name_id").focus(); $(".res-opt-div").find("#view_add_file").addClass("hide"); } - else if(res_name_flag == "File" || res_name_flag == "Image" || res_name_flag == "Video" || res_name_flag == "Pandora"){ + else if(res_name_flag == "File" || res_name_flag == "Image" || res_name_flag == "Video"){ $(".res-opt-div").find("#view_add_file").removeClass("hide"); $(".res-opt-div").find("#view_add_page").addClass("hide"); } @@ -240,38 +251,33 @@ //Onclick of any resource type button function open_div(name,this1){ - {% if unit_node %} - res_name_flag = name - console.log(res_name_flag) - update_res_count(); - $(".button").removeClass("success"); - $(this1).addClass("success"); - $("#add_res,#new_res").removeAttr("disabled"); - {% else %} - alert("Please create Unit") - return false; - {% endif %} + res_name_flag = name + update_res_count(); + $(".button").removeClass("success"); + $(".save_units").addClass("hide") + + $(this1).addClass("success"); + $(".resources_drawer_div").html(""); + if(res_name_flag!="Quiz" && res_name_flag=="Page"){ + $("#new_res").val("Create new "+ res_name_flag) + $(".res-opt-btns").removeClass("hide") + } + else if(res_name_flag!="Quiz" && res_name_flag!="Page"){ + $("#new_res").val("Upload File") + $(".res-opt-btns").removeClass("hide") + } + else if(res_name_flag=="Quiz"){ + $(".res-opt-btns").addClass("hide"); + draw_drawer("Quiz") + } + $(".collection_details").html(""); }; - //create new resource - $(document).on('click','#new_res',function(){ - $(".collection_details").html("") - - if(res_name_flag=="Quiz" || res_name_flag=="Page"){ - $(".res-option").val("Create new "+ res_name_flag) - $(".res-option").removeClass("hide"); - } - else { - $(".res-option").removeClass("hide"); - $(".res-option").val("Upload File") - } - }) - + //add from existing resources $(document).on('click','#add_res',function(){ $(".collection_details").html("") - $(".res-option").addClass("hide"); draw_drawer(res_name_flag); }) @@ -308,9 +314,10 @@ //save page $("#add_page").click(function() { - unit_name = $("#unit_name").val(); + unit_node_id = "{{unit_node.pk}}" + unit_name = $(".unit_name").text(); page_name = $(".name_id").val(); - if(unit_name!="" && page_name!=""){ + if(unit_node_id && page_name!=""){ $.ajax({ type: "POST", url: "{% url 'add_page' groupid %}", @@ -331,20 +338,19 @@ alert("Page name "+ page +" already available, Please choose different name"); } else if (data["success"] == true) { - alert("Succesully added to Unit "+unit_name) + alert("Succesully added to '"+unit_name+"'") $(".name_id").val(""); $(".resources_drawer_div").html(""); + $(".res-opt-btns").addClass("hide"); $(".res-opt-div").find("#view_add_file, #view_add_page").addClass("hide"); $(".button").removeClass("success") - + location.reload(); } } }); - update_res_count(); } else{ - alert("Please enter name"); - $("#unit_name").focus(); + alert("You need to creat Unit first"); event.preventDefault(); } @@ -354,14 +360,13 @@ //Submit button for file $('#docPost input[type=submit]').click(function(){ //save file button, check wether unit name is entered - unit_name_val = $("#unit_name").val() + unit_name_val = $(".unit_name").text(); if($("#docFile").val() != ""){ if(unit_name_val!=""){ $("#unit_name_file").val(unit_name_val); $(".resources_drawer_div").html(""); $('#docPost').submit(); - unit_name_val = $("#unit_name").val() - alert("Succesully added to Unit "+unit_name_val) + alert("Succesully added to '"+unit_name_val+"'") } else{ alert("Please enter unit name"); @@ -378,13 +383,13 @@ // Save units $(document).on('click','.save_units',function(){ var resources_in_RHS = [] - unit_name_val = $("#unit_name").val() + unit_name_val = $(".unit_name").text() total_resources_in_RHS = $(".resources_drawer_div").find("#create_course_structure_drawer2").children("li") unit_node_id = $("#hidden_unit_node_id").val(); //check if right drawer has values // if(total_resources_in_RHS.length > 0){ - if(unit_name_val){ + if(unit_node_id){ //fetch right drawer values $.each(total_resources_in_RHS,function(i,v){ resources_in_RHS.push(v.getAttribute('value')) @@ -411,17 +416,16 @@ resp_dict = JSON.parse(data) $(".resources_drawer_div").html(""); $(".save_units").addClass("hide") - $(".res-option").addClass("hide") + $(".res-opt-btns").addClass("hide"); $(".button").removeClass("success") $(".done_units").removeClass("hide") $(".res-opt-div").find("#view_add_file, #view_add_page").addClass("hide"); - update_res_count(); + location.reload(); }, }); } else{ - alert("Please enter unit name"); - $("#unit_name").focus(); + alert("You need to create Unit first"); event.preventDefault(); } // } @@ -468,7 +472,9 @@ {% endif %} {% endfor %} {% else %} - $(".collection_details").html("You haven't added any resources to this unit yet"); + {% if unit_node %} + $(".collection_details").html("You haven't added any resources to this unit yet"); + {% endif %} {% endif %} if(dict_res){ @@ -485,12 +491,10 @@ {{block.super}} update_res_count() - // {% if unit_node %} - // $(".res-btn").removeAttr("disabled"); - // {% else %} - // $(".res-btn").attr("disabled",true); - // $(".res-btn").removeAttr("onclick"); - // {% endif %} + {% if unit_node %} + $(".unit-list-div").removeClass("hide") + {% endif %} + {% endblock %}