-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.js
163 lines (142 loc) · 6.18 KB
/
form.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
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
$(document).ready(function(){
$("#form").steps({
bodyTag: "fieldset",
labels: {
finish: "Завершить",
next: "Далее",
previous: "Назад",
loading: "Загрузка ..."
},
onStepChanging: function (event, currentIndex, newIndex)
{
// Always allow going backward even if the current step contains invalid fields!
if (currentIndex > newIndex)
{
return true;
}
var form = $(this);
// Clean up if user went backward before
if (currentIndex < newIndex)
{
// To remove error styles
$(".body:eq(" + newIndex + ") label.error", form).remove();
$(".body:eq(" + newIndex + ") .error", form).removeClass("error");
}
var dev_count = document.getElementById("device_count").innerHTML;
if (currentIndex > 0) {
if (dev_count === "Всего добавлено узлов: 0" || dev_count === "Всего добавлено узлов: 1") {
toastr.error("Добавьте хотя бы два узла!", "Ошибка!");
return false;
}
}
// Disable validation on fields that are disabled or hidden.
form.validate().settings.ignore = ":disabled,:hidden";
// Start validation; Prevent going forward if false
return form.valid();
},
onStepChanged: function (event, currentIndex, priorIndex)
{
var table = $("#all_dev_table tbody")[0],
names = d3.selectAll("text")[0],
links = d3.selectAll("path")[0],
html = "";
if (currentIndex === 1) {
$("#name_header")[0].innerHTML = "Добавление сервиса: " + $("#serviceName").val();
for (var i = 0; i < names.length; i += 1) {
names[i].innerHTML = names[i].innerHTML.replace(" (Узел доступа)","");
names[i].style.fontSize = 12;
names[i].style.fontWeight = "normal";
}
d3.selectAll("path")
.attr("class", "link");
}
if (currentIndex === 2 && priorIndex === 1)
{
$(".select2_demo_2").select2();
var divStyle = $('.back-change')[0].style;
d3.selectAll("text")
.style("font-size", 12)
.style("font-weight", "normal");
d3.selectAll("path")
.attr("class", "link");
for (var i = 0; i < names.length; i+= 1) {
for (var j = 1; j < table.rows.length; j += 1) {
if (table.rows[j].cells[1].innerHTML === names[i].innerHTML) {
names[i].innerHTML += " (Узел доступа)";
names[i].style.fontSize = 14;
names[i].style.fontWeight = "bold";
names[i].style.fontStyle = "italic";
}
}
}
for (var i = 0; i < names.length; i += 1) {
if (names[i].innerHTML.search("(Обязательно)") !== -1) {
names[i].style.fontSize = 12;
names[i].style.fontWeight = "bold";
names[i].style.fontStyle = "italic";
}
}
$("#link_list :selected").each(function () {
for (var i = 0; i < links.length; i += 1) {
if ($(this).val() === links[i].__data__.name) {
links[i].attributes[0].value = "active_link";
}
}
});
}
},
onFinishing: function (event, currentIndex)
{
var form = $(this);
form.validate().settings.ignore = ":disabled";
return form.valid();
},
onFinished: function (event, currentIndex)
{
var table = $("#all_dev_table tbody")[0],
i = 1;
result["name"] = $("#serviceName").val();
result["nodes"] = [];
for (i = 1; i < table.rows.length; i += 1) {
var node = {};
node["name"] = table.rows[i].cells[1].innerHTML;
if (table.rows[i].cells[2].innerHTML === '<i class="fa fa-times text-danger"></i>') {
node["physical"] = "";
} else {
node["physical"] = table.rows[i].cells[2].innerHTML;
}
if (table.rows[i].cells[3].innerHTML === '<i class="fa fa-times text-danger"></i>') {
node["ip"] = "";
} else {
node["ip"] = table.rows[i].cells[3].innerHTML;
}
if (table.rows[i].cells[4].innerHTML === '<i class="fa fa-times text-danger"></i>') {
node["port"] = "";
} else {
node["port"] = table.rows[i].cells[4].innerHTML;
}
result["nodes"].push(node);
}
result["bw"] = $("#bw_input").val();
result["req_nodes"] = [];
result["req_links"] = [];
$("#node_list :selected").each(function () {
result["req_nodes"].push($(this).val());
});
$("#link_list :selected").each(function () {
result["req_links"].push($(this).val());
});
console.log(result);
}
}).validate({
errorPlacement: function (error, element)
{
element.before(error);
},
rules: {
confirm: {
equalTo: "#password"
}
}
});
});