diff options
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_detail.html | 41 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py | 3 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/views/course.py | 19 |
3 files changed, 57 insertions, 6 deletions
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 4d9b964..0d14977 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_detail.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/course_detail.html @@ -13,6 +13,10 @@ {% block style %} {{block.super}} + .fi-trash:hover{ + color:red; + } + .name-section{ height:80px; } @@ -60,6 +64,18 @@ {% block body_content %} {% get_group_name groupid as group_name_tag %} + <div id="alertModal" class="reveal-modal medium alert-box radius" data-reveal data-alert> + <p id="alertModalLabel"></p> + <div class="row deletion"> + <div class="small-3 small-offset-3 columns"> + <input type="button" id="btnConfirmYes" class="button tiny expand" value="Yes"> + </div> + <div class="small-3 columns end"> + <input type="button" id="btnConfirmNo" class="button tiny expand " value="No"> + </div> + </div> + <a class="close-reveal-modal">×</a> + </div> <header class="row page"> <section class="medium-8 columns name-section" > @@ -160,6 +176,29 @@ });//end of ajax }) + // Click on delete button + $(document).on('click','.fi-trash',function(){ + lbl_msg = "Are you sure you want to delete '{{node.name}}' course?" + $("#alertModalLabel").text(lbl_msg); + $("#alertModal") + .removeClass("medium").addClass("small") + .addClass("alert") + $("#alertModal").foundation('reveal', 'open'); + }); + + + //Confirm or Cancel Deletion + $(document).on("click", "#btnConfirmYes", function() { + $("#alertModal").foundation('reveal', 'close'); + turl = "{% url 'del_course' group_id node.pk %}" + $(".fi-trash").attr("href",turl) + location.href = $(".fi-trash").attr('href'); + }); + + $(document).on("click", "#btnConfirmNo", function() { + $("#alertModal").foundation('reveal', 'close'); + }); + {% endblock %} @@ -193,7 +232,7 @@ $("#view_page").append("<label>{% trans 'You have not added any content to this course yet' %}</label>") {% endif %} {% endif %} - $("#view_collection").find("b.current").after(' <span><a class="fi-pencil" href="{% url 'create_edit' group_id node.pk %}">{% trans "Edit" %}</a></span>') + $("#view_collection").find("b.current").after(' <span><a class="fi-pencil" href="{% url 'create_edit' group_id node.pk %}">{% trans "Edit" %}</a></span> <span><a class="fi-trash">{% trans "Delete" %}</a></span>') {% endif %} {% endblock %} diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py b/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py index 499572c..1a5d1e8 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/urls/course.py @@ -23,6 +23,7 @@ urlpatterns = patterns('gnowsys_ndf.ndf.views.course', url(r'^/create_edit_unit/', 'create_edit_unit', name='create_edit_unit'), url(r'^/change_node_name/$', 'change_node_name', name='change_node_name'), url(r'^/change_order/$', 'change_order', name='change_order'), - url(r'^/delete/$', 'delete_from_course_structure', name='delete_from_cs'), + url(r'^/delete_from_structure/$', 'delete_from_course_structure', name='delete_from_cs'), + url(r'^/delete/(?P<node_id>[\w-]+)$', 'delete_course', name='del_course'), url(r'^/enroll/$', 'enroll_generic', name='course_enroll'), ) diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py index 2a2e119..dd61831 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/course.py @@ -77,10 +77,10 @@ def course(request, group_id, course_id=None): title = GST_COURSE.name if request.user.id: - course_coll = node_collection.find({'member_of': GST_COURSE._id,'group_set': ObjectId(group_id)}) + course_coll = node_collection.find({'member_of': GST_COURSE._id,'group_set': ObjectId(group_id),'status':u"DRAFT"}) all_course_coll = node_collection.find({'member_of': {'$in': [GST_COURSE._id,GST_ACOURSE._id]}, - 'group_set': ObjectId(group_id)}) + 'group_set': ObjectId(group_id),'status':{'$in':[u"PUBLISHED",u"DRAFT"]}}) auth_node = node_collection.one({'_type': "Author", 'created_by': int(request.user.id)}) @@ -92,7 +92,7 @@ def course(request, group_id, course_id=None): course_enrollment_status = [ObjectId(each) for each in course_enrollment_dict] enrolled_course_coll = node_collection.find({'_id': {'$in': course_enrollment_status}}) - ann_course_coll = node_collection.find({'member_of': GST_ACOURSE._id, 'group_set': ObjectId(group_id)}) + ann_course_coll = node_collection.find({'member_of': GST_ACOURSE._id, 'group_set': ObjectId(group_id),'status':u"PUBLISHED"}) return render_to_response("ndf/course.html", @@ -135,7 +135,7 @@ def create_edit(request, group_id, node_id=None): else: course_node = node_collection.collection.GSystem() - available_nodes = node_collection.find({'_type': u'GSystem', 'member_of': ObjectId(GST_COURSE._id),'group_set': ObjectId(group_id) }) + available_nodes = node_collection.find({'_type': u'GSystem', 'member_of': ObjectId(GST_COURSE._id),'group_set': ObjectId(group_id),'status':{"$in":[u"DRAFT",u"PUBLISHED"]}}) nodes_list = [] for each in available_nodes: @@ -1344,6 +1344,14 @@ def create_edit_unit(request, group_id): return HttpResponse(json.dumps(response_dict)) + +@login_required +def delete_course(request, group_id, node_id): + del_stat = delete_item(node_id) + if del_stat: + return HttpResponseRedirect(reverse('course', kwargs={'group_id': ObjectId(group_id)})) + + @login_required def delete_from_course_structure(request, group_id): ''' @@ -1362,8 +1370,10 @@ def delete_from_course_structure(request, group_id): if request.is_ajax() and request.method == "POST": oid = request.POST.get("oid", '') del_stat = delete_item(oid) + if del_stat: response_dict["success"] = True + return HttpResponse(json.dumps(response_dict)) @@ -1378,6 +1388,7 @@ def delete_item(item): node_id=node_item._id, deletion_type=0 ) + return del_status |