summaryrefslogtreecommitdiff
path: root/gnowsys-ndf
diff options
context:
space:
mode:
Diffstat (limited to 'gnowsys-ndf')
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_units.html195
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_course_structure.html114
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py3
-rw-r--r--gnowsys-ndf/gnowsys_ndf/ndf/views/course.py127
4 files changed, 321 insertions, 118 deletions
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_units.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_units.html
new file mode 100644
index 00000000..35457470
--- /dev/null
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_units.html
@@ -0,0 +1,195 @@
+{% extends "ndf/base.html" %}
+{% load i18n %}
+{% load ndf_tags %}
+{% block title %} {{title}} {% endblock %}
+{% load pagination_tags %}
+{% block style %}
+
+ {{block.super}}
+
+ .td_cell{
+ background-color:#0b8a91 !important;
+ font-size:19px;
+ text-align:center;
+ vertical-align:middle;
+ color: white !important;
+ }
+
+ .td_cell:hover{
+ cursor:pointer;
+ }
+
+ table, th, td {
+ border: 1px solid white;
+ }
+
+ .resource-drawer {
+ border-color: #D3D3D3; border-style: solid;
+ padding: 0 !important;
+ overflow-y: auto;
+ }
+
+ div.resources_drawer_div div{
+ padding:1px;
+ }
+ .resource-drawer li.bullet-item:hover{
+ background-color: #ecf0f1; cursor:pointer;
+ }
+
+ .posted-by{ color: #808080; font-size: small; }
+
+ .selected-resource { background-color:lightgray !important ; }
+
+ .resource-type-image {
+ height:40px;
+ background-repeat:no-repeat; background-size: 48px 48px;
+ width:16.667%;
+ }
+
+ .resource-type-image + div {
+ width:83.33333%%;
+ }
+
+
+ .resource_icon{
+ color:#0b8a91 !important;
+ }
+ .pricing-table .bullet-item {
+ padding:0 !important;
+ }
+
+ ul.no-bullet li ul, ul.no-bullet li ol{
+ margin-left:0 !important;
+ }
+
+{% endblock %}
+
+{% block body_content %}
+ {% block collection %}
+ <div class="collection_block_div">
+ <div class="choose">
+ <table width="400" align="center">
+ <tr class="row">
+ <td class="small-4 columns td_cell fi-page-filled">
+ {% trans "Page" %}
+ </td>
+ <td class="small-4 columns td_cell fi-book">
+ {% trans "File" %}
+ </td>
+
+ <td class="small-4 columns td_cell fi-photo">
+ {% trans "Image" %}
+ </td>
+ </tr>
+ <tr class="row">
+ <td class="small-4 columns td_cell fi-video">
+ {% trans "Video" %}
+ </td>
+ <td class="small-4 columns td_cell fi-video">
+ {% trans "Pandora" %}
+ </td>
+ <td class="small-4 columns td_cell fi-pencil">
+ {% trans "Quiz" %}
+ </td>
+ </tr>
+ </table>
+
+ </div>
+ <div class="resources_drawer_div row"></div>
+ <input type="button" value="Save Units" class="save_units small button round hide">
+ <a href="{% url 'create_course_struct' group_id course_node.pk %}?app_id={{app_id}}&app_set_id={{app_set_id}}" class="done_units small button round hide">Done with Units</a>
+ </div>
+
+ {% endblock %}
+{% endblock %}
+
+<script>
+{% block script %}
+ {{block.super}}
+
+ $('td').click(function (event){
+ var resource_type_name = $(this).html()
+ var existing_resources;
+ resp_dict = {}
+ $.ajax({
+
+ type: "POST",
+
+ url: "{% url 'get_resources' groupid %}",
+
+ datatype: "json",
+
+ data:{
+ resource_type: resource_type_name,
+ css_node_id : "{{css_node.pk}}",
+ widget_for: "create_course_structure",
+ csrfmiddlewaretoken: '{{ csrf_token }}'
+ },
+
+ success: function (data) {
+ resp_dict = data
+ $(".resources_drawer_div").html("");
+ $(".save_units").removeClass("hide")
+ $(".done_units").removeClass("hide")
+ $(".resources_drawer_div").html(resp_dict);
+ },
+ });
+
+ });
+
+ // Save units
+ $(document).on('click','.save_units',function(){
+ var resources_in_RHS = []
+ total_resources_in_RHS = $(".resources_drawer_div").find("#create_course_structure_drawer2").children("li")
+
+ //check if right drawer has values
+ if(total_resources_in_RHS.length > 0){
+ //fetch right drawer values
+ $.each(total_resources_in_RHS,function(i,v){
+ resources_in_RHS.push(v.getAttribute('value'))
+ });
+
+ existing_list = JSON.stringify(resources_in_RHS)
+ $.ajax({
+
+ type: "POST",
+
+ url: "{% url 'save_resources' groupid %}",
+
+ datatype: "json",
+
+ data:{
+ list_of_res: existing_list,
+ css_node: "{{css_node.pk}}",
+ csrfmiddlewaretoken: '{{ csrf_token }}'
+ },
+
+ success: function (data) {
+ resp_dict = data
+ $(".resources_drawer_div").html("");
+ $(".save_units").removeClass("hide")
+ $(".done_units").removeClass("hide")
+ },
+ });
+
+ // $("#"+corr_resource_div).html("")
+ // $("#"+corr_resource_div).next().css("display", "none");
+ // $(".choose").css("display", "none");
+ // $(".units-btn").removeClass("hide")
+ // $(".course-sec-btn").removeAttr("disabled")
+ // $(".units-btn").removeAttr("disabled")
+ // $(".sub-section-btn").removeAttr("disabled")
+ // $(".close-units-btn").addClass("hide")
+ }
+ else{
+ alert("Please select any resource")
+ event.preventDefault();
+ }
+ });
+
+
+ $(document).on('click','.done_units',function(){
+
+ })
+{% endblock %}
+</script \ No newline at end of file
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_course_structure.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_course_structure.html
index 71fa843e..8d77911e 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_course_structure.html
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/create_course_structure.html
@@ -35,11 +35,12 @@
font-size: 1rem;
}
- form .row .row .columns {
+ li .row .row .columns {
padding:0 !important;
padding-left:0 !important;
}
+
i:hover{
cursor:pointer;
}
@@ -156,8 +157,6 @@
<a class="close-reveal-modal">&#215;</a>
</div>
- <form data-abide id="form_course_structure" method="POST" action="">
- {% csrf_token %}
<li class="hide course-section-class" id="course-section">
<div class="row input-cs-row">
<div class="small-2 columns">
@@ -197,55 +196,12 @@
</div>
</div>
<div class="row">
- <div class="small-10 small-centered columns units-btn-div">
- <input type="button" class="button round expand hoverstyle units-btn" value="Add Units">
- <a class="hide close-units-btn" style="float:right;">&#215; Add Units Later</a>
+ <div class="small-10 small-centered columns units-btn-div">
+ <a class="button round expand hoverstyle units-btn"> Add Units</a>
</div>
</div>
- {% block collection %}
- <div class="collection_block_div">
- <div class="choose" style="display:none;">
-
- <table width="400" align="center">
- <tr class="row">
- <td class="small-4 columns ">
- <span class="fontsize-x-large subheader"><input type="radio" name="col" value="Page"/>
- {% trans "Page" %} <i class="resource_icon fi-page-filled"></i></span>
- </td>
- <td class="small-4 columns ">
- <span class="fontsize-x-large subheader"><input type="radio" name="col" value="File" />
- {% trans "File" %} <i class="resource_icon fi-book"></i></span>
- </td>
-
- <td class="small-4 columns ">
- <span class="fontsize-x-large subheader"><input type="radio" name="col" value="Image" />
- {% trans "Image" %} <i class="resource_icon fi-photo"></i>
- </td>
- </tr>
- <tr class="row">
- <td class="small-4 columns ">
- <span class="fontsize-x-large subheader"><input type="radio" name="col" value="Video" />
- {% trans "Video" %} <i class="resource_icon fi-video"></i>
- </td>
- <td class="small-4 columns ">
- <span class="fontsize-x-large subheader"><input type="radio" name="col" value="Pandora Video" />
- {% trans "Pandora" %} <i class="resource_icon fi-video"></i>
- </td>
- <td class="small-4 columns ">
- <span class="fontsize-x-large subheader"><input type="radio" name="col" value="QuizObj" />
- {% trans "Quiz" %} <i class="resource_icon fi-pencil"></i>
- </td>
- </tr>
- </table>
-
- </div>
- <div class="resources_drawer_div row"></div>
- <input type="button" value="Save Units" class="save_units small button round" style="display:none">
- </div>
</li>
- {% endblock %}
-
<ul class="ul-course-section no-bullet">
<input type="button" class="button expand round hoverstyle course-sec-btn" value="Add Course Section">
</ul>
@@ -319,7 +275,6 @@
<input type="hidden" id="course_node" name="course_node" value="{{cnode.pk}}">
<input type="hidden" id="app_set_id" name="app_set_id" value="{{app_set_id}}">
<input type="hidden" id="app_id" name="app_id" value="{{app_id}}">
- </form>
{% endblock %}
<script>
{% block script %}
@@ -332,9 +287,7 @@
$("#min_marks").addClass("min_marks_class")
$("#max_marks").addClass("max_marks_class")
-
// Adding Course Section--------------------------------------------------------------------------------
-
$(document).on('click','.course-sec-btn',function(){
$(".course-sec-btn").before($("#course-section").clone().attr('id',function(i,id){
cloned_ele_id = id+"_cloned"+cs_cloned_id;
@@ -349,7 +302,6 @@
$(this).before($("#course-subsection").clone().attr('id',function(i,id){
cloned_ss_ele_id = id+"_cloned"+css_cloned_id;
return cloned_ss_ele_id}).removeClass("hide"));
- $("#"+cloned_ss_ele_id).find("div.resources_drawer_div").attr('id','resources_drawer_for_'+cloned_ss_ele_id)
$("#"+cloned_ss_ele_id).find("input[id=name]").focus()
css_cloned_id+=1
});
@@ -458,6 +410,7 @@
$("#"+curr_css_li_id).parents("li").find("input.sub-section-btn").removeAttr("disabled");
$("#"+curr_css_li_id).find("div.input-cs-row").replaceWith(str_btn+str_lbl+str_prop)
$("#"+curr_css_li_id).attr("value",css_new_id);
+ $("#"+curr_css_li_id).find(".units-btn").attr("data-css-id",css_new_id)
},
});//end of ajax
@@ -555,7 +508,6 @@
var lbl_text;
$(document).on('click','.edit_course_structure_name',function(){
node_id = $(this).prev().attr("id");
- console.log(node_id)
if($(this).hasClass("fi-pencil")){
//Only one course name can be renamed at once
node_for_edit = $(".ul-course-section").find(".fi-check").prev().attr('id')
@@ -619,7 +571,6 @@
$("#"+parent_id).find("li").addClass("hide");
$("#"+parent_id).addClass("hidden_children");
}
-
});
// Set label name and mins in reveal modal with respective course name---------------------------------
@@ -640,8 +591,6 @@
success: function(data){
success_state = data["success"]
- console.log(data)
- console.log(success_state)
if(success_state){
$.each(data, function(key,value){
if (key == "course_structure_minutes"){
@@ -666,9 +615,9 @@
})
}
else{
- $("#course_structure_minutes").val("")
- $("#max_marks").val("");
- $("#min_marks").val("");
+ $(".css_mins_class").val("");
+ $(".max_marks_class").val("");
+ $(".min_marks_class").val("");
$("input[name='course_structure_assignment'][value='No']").prop("checked","checked");
$("input[name='course_structure_assessment'][value='No']").prop("checked","checked");
$(".marks_div").addClass("hide");
@@ -699,7 +648,6 @@
var assessment_chk;
var assignment_chk;
css_node_id = $("#css_reveal_id").val()
- console.log(css_node_id)
prop_dict = {}
course_min_value = $(".css_mins_class").val();
@@ -734,6 +682,7 @@
data: {
css_node_id: css_node_id,
prop_dict: prop_dict,
+ assessment_chk: assessment_chk,
'csrfmiddlewaretoken': "{{csrf_token}}"
},
@@ -743,10 +692,10 @@
success: function(data){
success_state = data["success"]
- console.log(success_state)
},
complete: function(){
$('#course_prop').foundation('reveal', 'close');
+ location.reload(true);
}
});//end of ajax
}
@@ -758,43 +707,9 @@
//On click of 'Add Units' button-----------------------------------------------------------------------
$(document).on('click','.units-btn',function(){
- // $(".choose").css("display", "block");
- parent_li_css = $(this).parents("li.course-sub-section-class").not(".hide").attr('id')
- corr_resource_div = "resources_drawer_for_"+parent_li_css
- $("#"+corr_resource_div).prev().css("display", "block");
- $(this).addClass('hide')
- $(".sub-section-btn").attr("disabled",true)
- $(".units-btn").attr("disabled",true)
- $(".course-sec-btn").attr("disabled",true)
- $("input[type='radio'][name='col']:checked").removeAttr("checked");
- $(this).next(".close-units-btn").removeClass("hide")
- //add a close button here to skip adding resources
- });
-
- // Close units div. This is same as skipping adding units now in other words
- //units will be added later
-
- $(document).on('click',".close-units-btn",function(){
- // $(this).prev().removeClass("hide")// this is for close btns prev btn 'Add Units' btn
- $("#"+corr_resource_div).html("")
- $("#"+corr_resource_div).next().css("display", "none");
- $("#"+corr_resource_div).prev().css("display", "none"); //for choose div
- $(".course-sec-btn").removeAttr("disabled")
- $(".units-btn").removeAttr("disabled")
- $(".units-btn").removeClass("hide")
- $(".sub-section-btn").removeAttr("disabled")
- $(this).addClass("hide")
-
- })
-
- // Ajax call for units
- $(document).on('click',"input[type='radio'][name='col']",function(){
- console.log("B")
- });
-
- // Save units
- $(document).on('click','.save_units',function(){
- console.log("B")
+ css_node = $(this).data("cssId");
+ turl = "{% url 'add_units' groupid %}?node_id="+ css_node+"&app_id={{app_id}}&app_set_id={{app_set_id}}&course_node={{cnode.pk}}"
+ $(this).attr("href",turl)
});
{% endblock %}
@@ -822,8 +737,7 @@
$("#"+cloned_ele_id).find(".sub-section-btn").before($("#course-subsection").clone().attr('id',function(i,id){
cloned_ss_ele_id = id+"_cloned"+css_cloned_id;
return cloned_ss_ele_id}).removeClass("hide").attr("value","{{css_node.pk}}"));
-
- $("#"+cloned_ss_ele_id).find("div.resources_drawer_div").attr('id','resources_drawer_for_'+cloned_ss_ele_id);
+ $("#"+cloned_ss_ele_id).find(".units-btn").attr("data-css-id","{{css_node.pk}}")
var str_btn1="<div class='row'><div class='small-1 columns text-center'><i class='fi-page largesize'></i></div>"
var str_lbl1="<span data-tooltip title='{{css_node.name}}'><div class='small-8 columns left inline div_lbl'><label name='lbl_name' class='lbl_of_css' id='{{css_node.pk}}' style='float:left;'>{{css_node.name}}</label><i class='fi-pencil css_setting largesize edit_course_structure_name' style='float:left;'></i></div></span>"
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py b/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py
index 6040f2da..5b92bbe9 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py
@@ -7,6 +7,9 @@ urlpatterns = patterns('gnowsys_ndf.ndf.views.course',
url(r'^/edit/(?P<node_id>[\w-]+)$', 'create_edit', name='create_edit'),
url(r'^/structure/create/(?P<node_id>[\w-]+)$', 'create_course_struct', name='create_course_struct'),
url(r'^/change_node_name/$', 'change_node_name', name='change_node_name'),
+ url(r'^resources/', 'get_resources', name='get_resources'),
+ url(r'^save_units/', 'save_resources', name='save_resources'),
+ url(r'^add_units/', 'add_units', name='add_units'),
url(r'^/course_sub_section_prop/$', 'course_sub_section_prop', name='course_sub_section_prop'),
url(r'^/change_order/$', 'change_order', name='change_order'),
url(r'^/create_cs/$', 'save_course_section', name='save_course_section'),
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py
index 6fd6a93e..9fe7d1d4 100644
--- a/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py
+++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py
@@ -10,6 +10,7 @@ from django.http import Http404
from django.shortcuts import render_to_response #, render uncomment when to use
from django.template import RequestContext
from django.template import TemplateDoesNotExist
+from django.template.loader import render_to_string
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
@@ -26,6 +27,7 @@ from gnowsys_ndf.ndf.models import NodeJSONEncoder
from gnowsys_ndf.ndf.models import Node, AttributeType, RelationType
from gnowsys_ndf.ndf.models import node_collection, triple_collection
from gnowsys_ndf.ndf.views.file import save_file
+from gnowsys_ndf.ndf.templatetags.ndf_tags import edit_drawer_widget
from gnowsys_ndf.ndf.views.methods import get_node_common_fields, parse_template_data,get_execution_time
from gnowsys_ndf.ndf.views.notify import set_notif_val
from gnowsys_ndf.ndf.views.methods import get_property_order_with_value
@@ -1125,12 +1127,6 @@ def create_course_struct(request, group_id,node_id):
)
@login_required
-def add_units(request,group_id):
- return render_to_response("ndf/course_units.html",
- context_instance = RequestContext(request)
- )
-
-@login_required
def save_course_section(request,group_id):
'''
This ajax function takes the nussd course node id and to be created_by
@@ -1235,10 +1231,12 @@ def course_sub_section_prop(request,group_id):
if request.method == "POST":
css_node_id = request.POST.get("css_node_id", '')
prop_dict = request.POST.get("prop_dict", '')
+
prop_dict = json.loads(prop_dict)
+
+ assessment_chk = json.loads(request.POST.get("assessment_chk", ''))
assessment_flag = False
- print "\n\n css_node_id", css_node_id
- print "\n\n\nprop_dict",prop_dict
+
css_node = node_collection.one({"_id": ObjectId(css_node_id)})
at_cs_hours = node_collection.one({'_type': 'AttributeType', 'name': 'course_structure_minutes'})
@@ -1247,24 +1245,20 @@ def course_sub_section_prop(request,group_id):
at_cs_min_marks = node_collection.one({'_type': 'AttributeType', 'name': 'min_marks'})
at_cs_max_marks = node_collection.one({'_type': 'AttributeType', 'name': 'max_marks'})
+ if(assessment_chk == True):
+ create_gattribute(css_node._id, at_cs_assessment, True)
+ assessment_flag = True
+
for propk, propv in prop_dict.items():
- print "\n\n propk", propk
# add attributes to css gs
if(propk == "course_structure_minutes"):
create_gattribute(css_node._id, at_cs_hours, int(propv))
elif(propk == "course_structure_assignment"):
create_gattribute(css_node._id, at_cs_assignment, propv)
- elif(propk == "course_structure_assessment"):
- create_gattribute(css_node._id, at_cs_assessment, propv)
- if propv == True:
- assessment_flag = True
- print "\n\n assessment_flag--", assessment_flag
if assessment_flag:
if(propk == "min_marks"):
- print "\n\n min marks"
create_gattribute(css_node._id, at_cs_min_marks, int(propv))
- elif(propk == "max_marks"):
- print "\n\n max marks"
+ if(propk == "max_marks"):
create_gattribute(css_node._id, at_cs_max_marks, int(propv))
css_node.reload()
response_dict["success"] = True
@@ -1277,10 +1271,107 @@ def course_sub_section_prop(request,group_id):
for each in css_node.attribute_set:
for k, v in each.items():
response_dict[k] = v
- print "\n\n response_dict--", response_dict
response_dict["success"] = True
else:
response_dict["success"] = False
return HttpResponse(json.dumps(response_dict))
+
+def add_units(request,group_id):
+
+ print "\n\n\n coming in add_units"
+ variable = None
+ css_node_hidden = request.GET.get('node_id', '')
+ course_node_id = request.GET.get('course_node', '')
+ print "\n\n\ncss_node_hidden", css_node_hidden
+ css_node = node_collection.one({"_id": ObjectId(css_node_hidden)})
+ course_node = node_collection.one({"_id": ObjectId(course_node_id)})
+ variable = RequestContext(request, {
+ 'group_id': group_id, 'groupid': group_id,
+ 'css_node': css_node,
+ 'course_node':course_node
+ })
+
+ template = "ndf/course_units.html"
+ return render_to_response(template, variable)
+
+
+
+def get_resources(request, group_id):
+ """
+ This view is for adding units to MIS Course Structure
+ Arguments:
+ group_id - ObjectId of the currently selected group
+ resource_type - name of GSystemType
+
+ Returns:
+ Drawer with resources
+ """
+ response_dict = {'success': False, 'message': ""}
+ try:
+ if request.is_ajax() and request.method == "POST":
+ resource_type = request.POST.get('resource_type', "")
+ css_node_id = request.POST.get('css_node_id', "")
+ resource_type = resource_type.strip()
+ print "\n\n\n resource_type", css_node_id
+ widget_for = request.POST.get('widget_for', "")
+ list_resources = []
+ css_node = node_collection.one({"_id": ObjectId(css_node_id)})
+ if resource_type:
+
+ if resource_type == "Pandora":
+ resource_type = "Pandora_video"
+
+ resource_gst = node_collection.one({'_type': "GSystemType", 'name': resource_type})
+ res = node_collection.find(
+ {
+ 'member_of': resource_gst._id,
+ 'group_set': ObjectId(group_id),
+ 'status': u"PUBLISHED"
+ }
+
+ )
+
+ print "\n\n res----", res.count()
+ for each in res:
+ list_resources.append(each)
+
+ drawer_template_context = edit_drawer_widget("CourseUnits", group_id, css_node, None, checked="collection_set", left_drawer_content=list_resources)
+ drawer_template_context["widget_for"] = widget_for
+ drawer_widget = render_to_string(
+ 'ndf/drawer_widget.html',
+ drawer_template_context,
+ context_instance = RequestContext(request)
+ )
+
+ return HttpResponse(drawer_widget)
+ else:
+ error_message = "Resource Drawer: Either not an ajax call or not a POST request!!!"
+ response_dict["message"] = error_message
+ return HttpResponse(json.dumps(response_dict))
+
+ except Exception as e:
+ error_message = "Resource Drawer: " + str(e) + "!!!"
+ response_dict["message"] = error_message
+ return HttpResponse(json.dumps(response_dict))
+
+
+
+def save_resources(request,group_id):
+ '''
+ This ajax function changes order of nodes in collection_set.
+ Basically it swaps the two node ids this function gets.
+ A node here can be either a course section or a course sub section.
+ '''
+ response_dict = {"success": False}
+ if request.is_ajax() and request.method == "POST":
+ list_of_res = json.loads(request.POST.get('list_of_res', ""))
+ css_node_id = request.POST.get('css_node', "")
+ css_node = node_collection.one({"_id": ObjectId(css_node_id)})
+
+ list_of_res_objIds = [ObjectId(each_res) for each_res in list_of_res]
+ node_collection.collection.update({'_id': css_node._id}, {'$set': {'collection_set':list_of_res_objIds}},upsert=False,multi=False)
+ css_node.reload()
+ response_dict["success"] = True
+ return HttpResponse(json.dumps(response_dict))