forked from cheekujodhpur/ipho2015
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_button.txt
60 lines (59 loc) · 3.01 KB
/
save_button.txt
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
$(".save_button").click(function(){
var type_question = $(this).attr('data-type');
if(type_question=='t1')
var data = $("#form_marks_T1").serializeArray();
else if(type_question=='t2')
var data = $("#form_marks_T2").serializeArray();
else if(type_question=='t3')
var data = $("#form_marks_T3").serializeArray();
else if(type_question=='e')
var data = $("#form_marks_E").serializeArray();
var ajaxData = {};
var maxMarks = []
//CAREFUL, hard coded line below
if(type_question=='t1')
var num_subparts = $("#mark_table_body_T1").find("tr:first td").length-2;
else if(type_question=='t2')
var num_subparts = $("#mark_table_body_T2").find("tr:first td").length-2;
else if(type_question=='t3')
var num_subparts = $("#mark_table_body_T3").find("tr:first td").length-2;
else if(type_question=='e')
var num_subparts = $("#mark_table_body_E").find("tr:first td").length-2;
for(var j = 0;j<num_subparts;j++)
{
maxMarks.push(parseFloat(data[j].value));
}
for(var i = 1;i<data.length/num_subparts;i++)
{
for(var j = 0;j<num_subparts;j++)
{
var tmp_mark = data[i*num_subparts+j].value;
if((tmp_mark.split('.')[1] || []).length > 1)
{
alert("Least count is 0.1");
return;
}
if(parseFloat(tmp_mark)>maxMarks[j])
{
alert("Marks should be less than max marks");
return;
}
ajaxData[(i-1)*num_subparts+j] = parseFloat(tmp_mark);
}
}
if(type_question=='t1')
var destination_url = 'save_mark_T1';
else if(type_question=='t2')
var destination_url = 'save_mark_T2';
else if(type_question=='t3')
var destination_url = 'save_mark_T3';
else if(type_question=='e')
var destination_url = 'save_mark_E';
$.ajax({
method:"POST",
timeout:4000,
url:destination_url,
data:ajaxData
}).
done(function(data){alert("saved!");});
});