diff options
author | katkamrachana <katkam.rachana@gmail.com> | 2015-06-23 01:36:33 +0530 |
---|---|---|
committer | katkamrachana <katkam.rachana@gmail.com> | 2015-06-23 01:36:33 +0530 |
commit | e5d8406e48f8da5521567c43384c8363831d44ad (patch) | |
tree | 492c1cfe37a62dffea6535e0a0003aae18a1359d | |
parent | 95343e8e67f1c2bc5314aa140af03a8ab5605179 (diff) | |
download | gnowsys-e5d8406e48f8da5521567c43384c8363831d44ad.tar.gz |
Batches in MIS
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/new_create_batch.html | 115 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/urls/batch.py | 2 | ||||
-rw-r--r-- | gnowsys-ndf/gnowsys_ndf/ndf/views/batch.py | 64 |
3 files changed, 153 insertions, 28 deletions
diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/new_create_batch.html b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/new_create_batch.html index 2cf1fe8..a21721f 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/new_create_batch.html +++ b/gnowsys-ndf/gnowsys_ndf/ndf/templates/ndf/new_create_batch.html @@ -99,6 +99,11 @@ <a class="close-reveal-modal">×</a> </div> + + <div id="batch_info" class="reveal-modal medium" data-reveal style="height:500px;overflow-y: auto !important;"> + <a class="close-reveal-modal">×</a> + </div> + <div class="course_details_div"> <fieldset id="stud-count" class="small-10 columns"> <div class="row"> @@ -174,6 +179,7 @@ var ac; var added_ids_list = [] var batch_name_index; + var batch_name; var ac_name_as_prefix; var batch_user_list_dict = {} var batch_user_list_list = {} @@ -339,6 +345,7 @@ cell2.className += " existing_batch"; cell2.id = val[1]; cell3.innerHTML = val[0].length+" student(s)"; + cell3.className = "stud_count_in_batch"; val.pop(); }) }) @@ -426,6 +433,7 @@ cell2.className += " existing_batch"; cell2.id = new_batch_node['new_batch_node_id'] cell3.innerHTML = batch_user_list_dict[batch_name].length+" student(s)"; + cell3.className = "stud_count_in_batch"; cell1.innerHTML = "View"; cell1.className = "view_batch"; } @@ -439,35 +447,86 @@ //view batch members on click of 'View' $(document).on( 'click', '.view_batch ', function () { - batch_name_from_table = $(this).next('.existing_batch').html(); - batch_member_list = [] - if(batch_user_list_dict.hasOwnProperty(batch_name_from_table)){ - batch_member_list = batch_user_list_dict[batch_name_from_table] - } + + batch_id = $(this).next('.existing_batch').attr('id'); + batch_name = $(this).next('.existing_batch').html(); + $.ajax({ + url: "{% url 'batch_detail' groupid %}", + + data: { + 'batch_id': batch_id, + }, + + type: "GET", + + dataType: "json", + + success: function(data){ + $("#batch_info").html("") + var table = document.createElement("TABLE"); + table.id = batch_id + table.className = "batch_table_id" + $.each(data, function(index){ + var row = table.insertRow(-1); + var cell1 = row.insertCell(0); + cell1.innerHTML = data[index]['name']; + var cell2 = row.insertCell(1); + cell2.innerHTML = "Remove from Batch"; + cell2.id = data[index]['_id']; + cell2.className = 'button alert remove_stud'; + }) + $("#batch_info").append(table) + $('#batch_info').foundation('reveal', 'open'); + + + }, + });//end of ajax + + + }) - // add to existing batch - // $(document).on( 'click', '.existing_batch', function () { - // arr = [] - // old_arr = [] - // sce_dt_var.$("tr.selected").each(function () { - // arr.push(this.id); - // $("#"+this.id).removeClass('selected'); - // }); - // v = $(this).html() - // if (arr.length>0){ - // if(batch_user_list_dict.hasOwnProperty(v)){ - // old_arr = batch_user_list_dict[v] - // batch_user_list_dict[v] = old_arr.concat(arr) - // } - // $(".batch_name_inp").val(''); - // $('.ajax_input_name').val(''); - // $(".datatable_div").html(''); - // $(this).next('td').html(batch_user_list_dict[v].length+ " student(s)") - // } - // $(".create_batch_row").attr("disabled",true) - // }) - + + //view batch members on click of 'View' + $(document).on( 'click', '.remove_stud ', function () { + + stud_id = $(this).attr('id'); + batch_id = $(".batch_table_id").attr('id') + $(this).closest("tr").remove() + $.ajax({ + url: "{% url 'remove_stud_from_batch' groupid %}", + + data: { + 'batch_id': batch_id, + 'stud_id': stud_id, + 'csrfmiddlewaretoken': "{{csrf_token}}" + }, + + type: "POST", + + dataType: "json", + + success: function(data){ + status = data + if(status=="success"){ + if(batch_user_list_dict.hasOwnProperty(batch_name)){ + old_arr = batch_user_list_dict[batch_name] + if(old_arr.indexOf(stud_id)>=0){ + i = old_arr.indexOf(stud_id) + old_arr.splice(i,1) + } + batch_user_list_dict[batch_name] = old_arr + + } + $("#batch_create_edit_table").find("#"+batch_id).next('.stud_count_in_batch').html(old_arr.length+ "student(s)") + } + }, + });//end of ajax + + + }) + + // Make an ajax call to search approved student // of the selected AC with entered name // ajax search student by name @@ -494,7 +553,7 @@ 'search_text': search_text, 'ac_id': ac_id, 'added_ids_list':added_ids_list, - csrfmiddlewaretoken: '{{ csrf_token }}' + 'csrfmiddlewaretoken': '{{ csrf_token }}' }, success: function(data) { data = JSON.parse(data) diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/urls/batch.py b/gnowsys-ndf/gnowsys_ndf/ndf/urls/batch.py index 274161a..2d8dc6d 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/urls/batch.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/urls/batch.py @@ -6,6 +6,8 @@ urlpatterns = patterns('gnowsys_ndf.ndf.views.batch', url(r'^/new_batch$', 'new_create_and_edit', name='new_batch'), url(r'^/save_batch_stud$', 'save_students_for_batches', name='save_batch_stud'), url(r'^/save_batch$', 'save_batch', name='save_batch'), + url(r'^/remove_stud_from_batch$', 'remove_stud_from_batch', name='remove_stud_from_batch'), + url(r'^/batch_detail$', 'batch_detail', name='batch_detail'), url(r'^/detail/(?P<_id>[\w-]+)$', 'detail', name='detail'), url(r'^/delete_batch/(?P<_id>[\w-]+)$', 'delete_batch', name='delete_batch'), url(r'^/get_possible_batches/$', 'get_possible_batches', name='get_possible_batches'), diff --git a/gnowsys-ndf/gnowsys_ndf/ndf/views/batch.py b/gnowsys-ndf/gnowsys_ndf/ndf/views/batch.py index 68ecb64..939c860 100644 --- a/gnowsys-ndf/gnowsys_ndf/ndf/views/batch.py +++ b/gnowsys-ndf/gnowsys_ndf/ndf/views/batch.py @@ -235,6 +235,70 @@ def detail(request, group_id, _id): return render_to_response(template, variable) +@get_execution_time +def remove_stud_from_batch(request, group_id): + group_name, group_id = get_group_name_id(group_id) + if request.is_ajax() and request.method == "POST": + batch_id = request.POST.get("batch_id", '') + stud_id = request.POST.get("stud_id", '') + rt_has_batch_member = node_collection.one({'_type':'RelationType','name':'has_batch_member'}) + grelation_node = triple_collection.one({'_type':'GRelation', + 'relation_type.$id':rt_has_batch_member._id, + 'subject':ObjectId(batch_id),'status':u'PUBLISHED', + 'right_subject': ObjectId(stud_id)}) + rel_name = grelation_node.relation_type.name + inv_rel_name = grelation_node.relation_type.inverse_name + subj = grelation_node.subject + right_subj = grelation_node.right_subject + + # Remove right-subject-node's ObjectId from the value + # corresponding to subject-node's "relation-name" key + # referenced in relation_set field + res = node_collection.collection.update({ + '_id': subj, + 'relation_set.' + rel_name: {'$exists': True} + }, { + '$pull': {'relation_set.$.' + rel_name: right_subj} + }, + upsert=False, multi=False + ) + # Remove subject-node's ObjectId from the value corresponding + # to right-subject-node's "inverse-relation-name" key + # referenced in relation_set field + res = node_collection.collection.update({ + '_id': right_subj, + 'relation_set.' + inv_rel_name: {'$exists': True} + }, { + '$pull': {'relation_set.$.' + inv_rel_name: subj} + }, + upsert=False, multi=False + ) + + grelation_node.status = u"DELETED" + grelation_node.save() + status = "success" + return HttpResponse(json.dumps(status, cls=NodeJSONEncoder)) + + +@get_execution_time +def batch_detail(request, group_id): + group_name, group_id = get_group_name_id(group_id) + new_batch_node = None + if request.is_ajax() and request.method == "GET": + batch_id = request.GET.get("batch_id", '') + + student_coll = [] + node = node_collection.one({'_id':ObjectId(batch_id)}) + rt_has_batch_member = node_collection.one({'_type':'RelationType','name':'has_batch_member'}) + relation_coll = triple_collection.find({'_type':'GRelation','relation_type.$id':rt_has_batch_member._id,'subject':node._id,'status':u'PUBLISHED'}) + + for each in relation_coll: + n = node_collection.one({'_id':ObjectId(each.right_subject)}) + student_coll.append(n) + return HttpResponse(json.dumps(student_coll, cls=NodeJSONEncoder)) + + + @login_required @get_execution_time def delete_batch(request, group_id, _id): |