1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
<!ATTLIST acourse_list_name scount CDATA #IMPLIED>
{% extends "ndf/base.html" %}
{% load i18n %}
{% load ndf_tags %}
{% block title %} {{title}} {% endblock %}
{% block head %}
{{block.super}}
<!-- DataTables -->
<script src="/static/ndf/bower_components/DataTables/media/js/jquery.dataTables.js"></script>
<script src="/static/ndf/bower_components/datatables-plugins/integration/foundation/dataTables.foundation.js"></script>
<!-- DataTables CSS -->
<link href="/static/ndf/bower_components/datatables-plugins/integration/foundation/dataTables.foundation.css" rel="stylesheet" type="text/css" />
{% endblock %}
{% block style %}
{{block.super}}
.divider-line { font-size: xx-large; color:lightgray; }
.line-height-2 { line-height:2; }
.line-height-2pt5 { line-height:2.5; }
.fontsize-x-large { font-size: x-large; }
.margin-0 {
margin: 0 !important;
}
tr:hover{
cursor:pointer;
}
.resource-drawer {
border-color: #D3D3D3; border-style: solid;
padding: 0 !important;
overflow-y: auto;
}
.resource-drawer li.bullet-item:hover{
background-color: #ecf0f1; cursor:pointer;
}
.target {
width:400px;
padding:10px;
margin:12px;
border:2px solid #bbb;
}
/* Setting css-properties for reveal-modal's label */
div.reveal-modal > label {
color: white;
font-weight: bold;
font-size: 1rem;
}
.existing_batch, .view_batch{
text-decoration: underline;
}
.posted-by{ color: #808080; font-size: small; }
.selected { background-color:lightgray !important ; }
.resource-type-image {
height:40px;
background-repeat:no-repeat; background-size: 48px 48px
/* Resetting css-properties for fieldset (also legend, input) */
/* fieldset (padding-bottom) */
fieldset {
padding: 0em !important;
margin: 0 !important;
}
/* legend (background-color) */
fieldset legend {
background-color: transparent !important;
}
/* input (margin) */
fieldset input {
padding: 0 !important;
}
/* Setting css-properties for small.error */
small.error {
padding: 0 0 0 0.5em !important;
margin: 3.3em 0em !important;
position: relative !important;
}
.batch_create_edit_table > tr {
border: 1px solid black;
}
{% endblock %}
{% block body_content %}
<div id="alertModal" class="reveal-modal small alert alert-box radius" data-reveal data-alert>
<label id="alertModalLabel"> </label>
<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">
<div class="small-2 columns">
<label class="right inline" for="nussd_course_type">{% trans "Course Type" %}</label>
</div>
<div class="small-4 columns end">
{% html_widget groupid "" ATs.0 %}
</div>
</div>
<div class="row">
<div class="small-2 columns">
<label class="right inline" for="acourse_list">{% trans "Name of Course" %}</label>
</div>
<div class="small-4 columns end">
<select id="acourse_list" name="acourse_list_name" disabled="disabled">
</select>
</div>
</div>
</fieldset>
<div class="small-2 columns end" align="center">
<br>
<label id="stud_count" style='display: none'></label>
<label id="lblstud" style='display: none'> {% trans "Student(s)" %}</label>
</div>
<div class="small-12 columns" align="center">
<input type="button" class="small button right inline" id="nextbtn" value="Proceed" disabled="disabled" style='display: none'/>
</div>
</div>
<br>
<div class="batch_div hide">
<div class="row">
<div style="text-align: center;">
<div class="small-4 columns end" style="display: inline-block; ">
<h4>{% trans 'Search Student by name : ' %}</h4>
</div>
<div class="small-4 columns end" style="display: inline-block; ">
<input type="text" class="ajax_input_name small-6 columns" value="" placeholder="Enter atleast 3 letters to search">
</div>
</div>
</div>
</div>
<div class="datatable_div"></div>
<div id="batch-details"></div>
<fieldset id="make_batch_fs" class="hide small-12 columns">
<table id="batch_create_edit_table">
<tbody>
</tbody>
</table>
<input type="button" class="create_batch_row button small" value="Create Batch" disabled="disabled">
<li style="color:red;">Batch once created CANNOT be deleted</li>
<li>Click on Batch name to add more students to the batch</li>
<li>Click on 'View' to display/remove batch members</li>
<div class="batch_create_div hide">
<input type="text" class="batch_name_inp" placeholder="Enter name of Batch">
<input type="button" class="save small round button" value="Save">
<input type="button" class="cancel small round button" value="Cancel">
</div>
<input type="hidden" name="batch_user_list_dict" id="batch_user_list_dict">
<input type="hidden" name="ac_id" id="ac_id">
</div>
</fieldset>
{% endblock %}
<script>
{% block script%}
//global variables
var ac_id=""
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 = {}
var scount_lbl = 0
var sce_dt_var;
//For selecting Course type
$("select#nussd_course_type").change(function() {
var nussd_course_type = $("#nussd_course_type").val();
success_state = false;
$.ajax({
url: "{% url 'get_announced_courses_with_ctype' group_id %}",
data: {
nussd_course_type: nussd_course_type
},
type: "GET",
dataType: "json",
complete: function () {
// Enable AC field
$("select#acourse_list").removeAttr('disabled')
{% if ac_node %}
$("select#acourse_list").val("{{ac_node.pk}}");
$("select#acourse_list").trigger("change");
{% endif %}
},
success: function(data){
success_state = data["success"]
if (success_state){
ac_data = data["acourse_ctype_list"]
ac_data = JSON.parse(ac_data)
$("select#acourse_list").empty();
$("select#acourse_list").append(
$("<option></option>")
.attr("value", "")
.text("{% trans ' - - - Select course - - - ' %}")
);
$.each(ac_data, function(i,v){
se = v["_id"];
ac_name = v["name"];
scount_lbl = v["enrolled_stud_count"]
$("select#acourse_list").append(
$("<option></option>")
.attr("value", se)
.text(ac_name)
.attr("scount", scount_lbl)
);
});
$("select#acourse_list").prop("selectedIndex", 0);
}
else {
$("#alertModalLabel").text(data["message"]);
$("#alertModal").foundation('reveal', 'open');
$("select#nussd_course_type").prop("selectedIndex", 0);
$("select#acourse_list").empty();
}
},
});//end of ajax
});//end of nussd_course_type.change function
// On close event of reveal-modal (alertModal) -------------------------------------------------------------
$(document).on('closed.fndtn.reveal', '#alertModal[data-reveal]', function () {
// Reset reveal-modal content & it's setting
$("#alertModalLabel").text("");
$("#alertModal").find("div.row").addClass("hide");
});
//For selecting Announced Course type
$("select#acourse_list").change(function() {
//ac_id = $("#acourse_list").val();
$("#stud_count").text("")
// sct = $(this).data("scount")
if ($("#nextbtn").css("display") == "none") {
$("#nextbtn").toggle()
}
if ($("#stud_count").css("display") == "none") {
$("#stud_count").toggle()
}
if ($("#lblstud").css("display") == "none") {
$("#lblstud").toggle()
}
scount_lbl = $("#acourse_list option:selected").attr("scount")
$("#stud_count").css("font-size", "53px");
$("#stud_count").text(scount_lbl)
if(scount_lbl>0){
$("#nextbtn").removeAttr("disabled")
}
else{
$("#nextbtn").attr("disabled","disabled")
}
{% if node %}
if ($("#stud_count").css("display") == "none") {
$("#stud_count").toggle()
}
if ($("#lblstud").css("display") == "none") {
$("#lblstud").toggle()
}
$("#nextbtn").trigger("click");
{% endif %}
});//end of acourse_list.change function
//Proceed to create batches for selected AC
$("#nextbtn").click(function(event) {
if ($("#nextbtn").css("display") != "none") {
$("#nextbtn").css("display", "none");
}
// $("#nussd_course_type").attr("disabled","disabled")
// $("#acourse_list").attr("disabled","disabled")
// Give a textbox to enter name
$(".batch_div").removeClass("hide");
$(".course_details_div").addClass("hide");
nc = $("#nussd_course_type").val();
ac = $("#acourse_list option:selected").text()
ac_id = $("#acourse_list").val();
$("aside.medium-2.columns").html("Batch creation for: <b>'"+ac+"'</b> ("+nc+")")
$.ajax({
url: "{% url 'get_possible_batches' groupid %}",
data: {
'ac_id': ac_id,
'create_new_batch':true,
'csrfmiddlewaretoken': "{{csrf_token}}"
},
type: "POST",
dataType: "json",
success: function(data){
success_state = data["success"]
if(success_state){
batch_data = data['old_batches']
if (batch_data!=""){
// batch_user_list_dict = batch_data
$("#make_batch_fs").removeClass("hide")
var table = document.getElementById("batch_create_edit_table");
$.each(batch_data, function(index){
$.each(batch_data[index], function(key,val){
batch_user_list_dict[key] = val[0]
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerHTML = "<span data-tooltip title='Click to view/edit'>View</span>";
cell1.className = "view_batch";
cell2.innerHTML = "<span data-tooltip title='Click to Add to this Batch'>"+key+"</span>";
cell2.className = "save";
cell2.className += " existing_batch";
cell2.id = val[1];
cell3.innerHTML = "<span data-tooltip title='Total students'>"+val[0].length+" student(s)<span>";
cell3.className = "stud_count_in_batch";
val.pop();
})
})
}
}
},
});//end of ajax
});//end of nextbtn.click()
// Click event: "Student data" Row of DataTable
$(document).on( 'click', '#student_data_table tbody tr', function () {
$(this).toggleClass('selected');
$("#make_batch_fs").removeClass("hide")
$(".create_batch_row").removeAttr("disabled")
});
// On click of create batch button
$(document).on( 'click', '.create_batch_row', function () {
$(".batch_create_div").removeClass("hide")
total_batches = Object.keys(batch_user_list_dict).length + 1
$(".batch_name_inp").val(ac + " - Batch " + total_batches)
.attr("disabled", true)
$(".create_batch_row").attr("disabled",true)
});
// Create batch and add selected students to it.
// Also hide batch_create_div from first row
// Add new row to batch create edit table with the batch name as inputted
$(document).on( 'click', '.save', function () {
arr = []
batch_id = null;
//do nothing
$(".create_batch_row").attr("disabled",true)
$(".batch_create_div").addClass("hide");
batch_name = $(".batch_name_inp").val();
sce_dt_var.$("tr.selected").each(function () {
$(this).removeClass('selected');
arr.push(this.id);
});
if (arr.length != 0){
if($(this).hasClass('existing_batch')){
batch_name = $(this).text()
if(batch_user_list_dict.hasOwnProperty(batch_name)){
old_arr = batch_user_list_dict[batch_name]
batch_user_list_dict[batch_name] = old_arr.concat(arr)
$(this).next('td').html(batch_user_list_dict[batch_name].length+ " student(s)")
arr = batch_user_list_dict[batch_name]
batch_id = $(this).attr('id')
}
}
$.ajax({
url: "{% url 'save_batch' groupid %}",
data: {
'ac_id': ac_id,
'batch_name': batch_name,
'batch_id': batch_id,
'user_list':arr,
'csrfmiddlewaretoken': "{{csrf_token}}"
},
type: "POST",
dataType: "json",
success: function(data){
new_batch_node = data
if(new_batch_node['new_batch_created']){
var table = document.getElementById("batch_create_edit_table");
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
batch_user_list_dict[batch_name] = arr;
cell2.innerHTML = "<span data-tooltip title='Click to Add to this Batch'>"+new_batch_node['new_batch_node_name']+"</span>";
cell2.className = "save";
cell2.className += " existing_batch";
cell2.id = new_batch_node['new_batch_node_id']
cell3.innerHTML = "<span data-tooltip title='Total students'>"+batch_user_list_dict[batch_name].length+" student(s)<span>";
cell3.className = "stud_count_in_batch";
cell1.innerHTML = "<span data-tooltip title='Click to view/edit'>View</span>";
cell1.className = "view_batch";
}
$(".batch_name_inp").val('');
$('.ajax_input_name').val('');
$(".datatable_div").html('');
},
});//end of ajax
}
else{
alert("Please select students");
}
})
//view batch members on click of 'View'
$(document).on( 'click', '.view_batch ', function () {
batch_id = $(this).next('.existing_batch').attr('id');
batch_name = $(this).next('.existing_batch').text();
$.ajax({
url: "{% url 'batch_detail' groupid %}",
data: {
'batch_id': batch_id,
},
type: "GET",
dataType: "json",
success: function(data){
$("#batch_info").html("")
if(data!=""){
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)
}
else{
$("#batch_info").html("No data to display")
}
$("#batch_info").append("<a class='close-reveal-modal'>×</a>")
$('#batch_info').foundation('reveal', 'open');
},
});//end of ajax
})
//remove batch members
$(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
var search_text_old = "";
$(document).on( 'keyup', '.ajax_input_name', function (e) {
var search_text = (this.value).toLowerCase();
var search_text_len = (search_text.length);
ac_id = $("#acourse_list").val();
// if (e.keyCode == 8) {
// // If backspace pressed, then do nothing
// search_text_len = 0;
// }
if (search_text_len > 2){
for(var key in batch_user_list_dict){
added_ids_list = added_ids_list.concat(batch_user_list_dict[key])
}
$.ajax({
type: "POST",
url: "{% url 'get_students_for_batches' groupid %}",
datatype: "json",
data:{
'search_text': search_text,
'ac_id': ac_id,
'added_ids_list':added_ids_list,
'csrfmiddlewaretoken': '{{ csrf_token }}'
},
success: function(data) {
data = JSON.parse(data)
success_state = data["success"];
search_text_old = search_text
// $("#alertModalLabel").text(data["message"]);
if (success_state) {
students_count = data["students_count"];
column_headers = data["column_headers"];
students_data_set = data["students_data_set"];
dataTable_columns_set = [];
if (parseInt(students_count) <= 0) {
c = '<div class="row">' +
'<div class="large-4 large-centered columns">' +
'<p class="alert-box alert radius text-center text-size-15">No records match the given criteria !!!</p>' +
'</div>' +
'</div>'
$(".datatable_div").html(c);
}
else {
// Define table
student_data_table = '<table cellpadding="0" cellspacing="0" border="0" class="display" id="student_data_table">' +
'<caption>' +
'<h6>No. of Students: <b>' + students_count + '</b></h6>' +
'<label>(Click on Name to select student)</label></caption>' +
'</table>';
$(".datatable_div").html(student_data_table);
// Prepare title & data headers used in dataTable
$.each(column_headers, function(index, v) {
d = {};
d["data"] = v[0];
d["title"] = v[1];
dataTable_columns_set.push(d);
});
// Set defintion dataTable
sce_dt_var = $("#student_data_table").dataTable({
"data": students_data_set,
"columns": dataTable_columns_set,
"columnDefs": [{ "width": "15%", "targets": 0 }],
"createdRow": function ( row, data, index ) {
// Attaching Student's ObjectId to each row (i.e., assigning to it's id attribute)
s_id = data["stud_id"];
$(row).attr("id", s_id);
}
});
}
}
else {
$("#alertModal").removeClass("success").removeClass("warning");
$("#alertModal").addClass("alert");
$("#alertModal").foundation('reveal', 'open');
}
},
});
}
})
//
$(document).on('click','.cancel',function(){
$(".batch_create_div").addClass("hide")
$(".batch_name_inp").val("");
$(".create_batch_row").removeAttr("disabled")
});
{% endblock %}
</script>
{% block document_ready %}
{% if nussd_course_name %}
$("select#nussd_course_type").val("{{nussd_course_name}}");
{% endif %}
if ($("select#nussd_course_type :selected").index() > 0) {
$("select#nussd_course_type").trigger("change");
}
{% endblock %}
|