-
Notifications
You must be signed in to change notification settings - Fork 0
/
save.js
93 lines (88 loc) · 2.21 KB
/
save.js
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
$("span[id|='spnRank']").each(function (i, el) {
$(this).html('<input type="text" style="color:black;" class="prefRankByPP" value="'+i+'"></input>')
});
function save() {
len = $('.col-sm-12.item-blue').length
cnt = new Array(len).fill(0)
$('.col-sm-12.item-blue').each(function () {
rank = parseInt($(this).find('input.prefRankByPP').val())
cnt[rank] += 1
})
sum = 0
b = false
for(i in cnt) {
e = cnt[i]
sum += e
console.log(cnt[i])
if(e != 1) {
alert("Invalid value at index" + (parseInt(i)+1))
b = true
return
}
}
if(!b && sum!=len) {
alert('All ranks not available. values should be between 0-'+(len-1))
return
}
// check = ok
// now save
var accomo = "false";
var contistation = 1;
var i = 0;
jsondata = "";
jsonvalue = "";
jsondata = "[";
$('.col-sm-12.item-blue').each(function () {
spn = $(this).find('span.spanclass').attr('spn')
accomo = "false"
if ($('.accomo[chkaccomo="' + spn + '"]').is(':checked') == true) {
accomo = "true";
}
else {
accomo = "false";
}
rank = parseInt($(this).find('input.prefRankByPP').val()) + 1
jsondata += "{"
jsondata += "'isActive':'1',"
jsondata += "'PreferenceNo':'" + rank + "','StationId':'" + spn + "',"
jsondata += "'Accommodation':'" + accomo + "',"
jsondata += "},"
})
jsondata = jsondata.substr(0, jsondata.length - 1);
jsondata += "]";
if ($('#consta').is(":checked")) {
contistation = 1;
jsonvalue += "'isActive':'1',"
jsonvalue += "'ContinueStation':'"+ contistation+"',"
jsonvalue = jsonvalue.substr(0, jsonvalue.length - 1);
jsonvalue = '{' + jsonvalue + '}';
}
else {
contistation = 0;
}
saveprefdata(jsondata, jsonvalue, contistation);
}
$('#btnSave').one("click", save)
// swap preference numbers
$('.prefRankByPP').each(function () {
$(this).data('val', $(this).val())
})
$('.prefRankByPP').change(function () {
preVal = $(this).data('val')
curVal = $(this).val()
b = false
ct = this
$('.prefRankByPP').each(function () {
swapVal = $(this).val()
if(swapVal == curVal && this != ct) {
$(this).val(preVal)
$(this).data('val', preVal)
b = true
}
})
if(!b) {
$(this).val(preVal)
} else {
$(this).data('val', $(this).val())
}
})