246 lines
7.9 KiB
JavaScript
246 lines
7.9 KiB
JavaScript
$(function () {
|
|
common.checkboxInit("device");
|
|
});
|
|
|
|
function validate() {
|
|
var error = 0;
|
|
var Name = $("input[name='Name']").val();
|
|
if (Name === "") {
|
|
common.error("name", "Tên thiết bị không được để trống");
|
|
error++;
|
|
} else {
|
|
common.success("name");
|
|
}
|
|
|
|
var Ip = $("input[name='Ip']").val();
|
|
if (Ip === "") {
|
|
common.error("ip", "Địa chỉ IP không được để trống");
|
|
error++;
|
|
} else if (!common.validateIp(Ip)) {
|
|
common.error("ip", "Định dạng địa chỉ IP không đúng");
|
|
error++;
|
|
} else {
|
|
common.success("ip");
|
|
}
|
|
return error == 0 ? true : false;
|
|
}
|
|
|
|
function checkConnection(e) {
|
|
var Ip = $("input[name='Ip']").val();
|
|
if (Ip === "") {
|
|
common.error("ip", "Địa chỉ IP không được để trống");
|
|
} else if (!common.validateIp(Ip)) {
|
|
common.error("ip", "Định dạng địa chỉ IP không đúng");
|
|
} else {
|
|
common.success("ip");
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr('href'),
|
|
type: 'POST',
|
|
data: {
|
|
Ip: $("input[name='Ip']").val()
|
|
},
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
$(".alert").addClass("hidden");
|
|
if (data.Status === "SUCCESS") {
|
|
$("#success").removeClass("hidden");
|
|
} else {
|
|
$("#error").removeClass("hidden");
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
alert("Có lỗi xảy ra! hãy kiểm tra lại service!");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function save(e) {
|
|
if (validate()) {
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr('data-href'),
|
|
type: 'POST',
|
|
data: {
|
|
Name: $("input[name='Name']").val(),
|
|
Area: $("select[name='Area']").val(),
|
|
Ip: $("input[name='Ip']").val()
|
|
},
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
if (data.status) {
|
|
notification.success("Đã lưu thông tin", 1000);
|
|
$.pjax.reload({container: '#device-list'});
|
|
$("#device-list").on('pjax:success', function () {
|
|
common.checkboxInit("device");
|
|
});
|
|
$("#myModal").modal("hide");
|
|
} else {
|
|
if (data.type === "ip") {
|
|
common.error("ip", "Địa chỉ ip đã tồn tại");
|
|
} else if (data.type === "connect") {
|
|
$(".alert").addClass("hidden");
|
|
$("#error").removeClass("hidden");
|
|
} else {
|
|
notification.danger("Có lỗi xảy ra, không lưu được dữ liệu!", 1000);
|
|
}
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
alert("Có lỗi xảy ra! hãy kiểm tra lại service!");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function _form(e) {
|
|
var lists = [];
|
|
$.each($("input[name='checkbox-device']:checked"), function () {
|
|
lists.push($(this).val());
|
|
});
|
|
if (lists.length == 0) {
|
|
alert("Vui lòng lựa chọn đối tượng để thay đổi!");
|
|
return;
|
|
}
|
|
if (lists.length > 1) {
|
|
alert("Tác vụ này không thể lựa chọn nhiều hơn một đối tượng!");
|
|
return;
|
|
}
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr('data-href') + "?id=" + lists[0],
|
|
type: 'POST',
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
common.modalOpen(data.form, false, data.title);
|
|
$('#Area').select2();
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
|
|
function _delete(e) {
|
|
var lists = [];
|
|
$.each($("input[name='checkbox-device']:checked"), function () {
|
|
lists.push($(this).val());
|
|
});
|
|
if (lists.length == 0) {
|
|
alert("Vui lòng lựa chọn đối tượng để xóa!");
|
|
return;
|
|
}
|
|
if (lists.length == 1 && lists[0] === "1") {
|
|
alert("Danh mục gốc không thể xóa!");
|
|
return;
|
|
}
|
|
if (confirm("Bạn có chắc chắn muốn xóa các đối tượng đã lựa chọn không?")) {
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr('data-href'),
|
|
type: 'POST',
|
|
data: {
|
|
lists: lists
|
|
},
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
notification.danger("Đã xóa dữ liệu", 1000);
|
|
$.pjax.reload({container: '#device-list'});
|
|
$("#device-list").on('pjax:success', function () {
|
|
common.checkboxInit("device");
|
|
});
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function _export(e) {
|
|
window.location = $(e).attr("data-href");
|
|
}
|
|
|
|
function _logs(e) {
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr('data-href'),
|
|
type: 'POST',
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
common.modalOpen(data.form, true, data.title);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
|
|
function validateChangeIP() {
|
|
var error = 0;
|
|
var Ip = $("input[name='IpNew']").val();
|
|
if (Ip === "") {
|
|
common.error("ip", "Địa chỉ IP mới không được để trống");
|
|
error++;
|
|
} else if (!common.validateIp(Ip)) {
|
|
common.error("ip", "Định dạng địa chỉ IP không đúng");
|
|
error++;
|
|
} else {
|
|
common.success("ip");
|
|
}
|
|
|
|
var SubnetMask = $("input[name='SubnetMask']").val();
|
|
if (SubnetMask === "") {
|
|
common.error("subnet_mask", "Subnet mask không được để trống");
|
|
error++;
|
|
} else if (!common.validateIp(SubnetMask)) {
|
|
common.error("subnet_mask", "Định dạng Subnet mask không đúng");
|
|
error++;
|
|
} else {
|
|
common.success("subnet_mask");
|
|
}
|
|
return error == 0 ? true : false;
|
|
}
|
|
|
|
function changeIP(e) {
|
|
if (validateChangeIP()) {
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr('data-href'),
|
|
type: 'POST',
|
|
data: {
|
|
Ip: $("input[name='IpNew']").val(),
|
|
SubnetMask: $("input[name='SubnetMask']").val()
|
|
},
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
console.log(data);
|
|
return;
|
|
if (data.status) {
|
|
notification.success("Đã lưu thông tin", 1000);
|
|
$.pjax.reload({container: '#device-list'});
|
|
$("#device-list").on('pjax:success', function () {
|
|
common.checkboxInit("device");
|
|
});
|
|
$("#myModal").modal("hide");
|
|
} else {
|
|
if (data.type === "ip") {
|
|
common.error("ip", "Địa chỉ ip đã tồn tại");
|
|
} else {
|
|
notification.danger("Có lỗi xảy ra, không lưu được dữ liệu!", 1000);
|
|
}
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
alert("Có lỗi xảy ra! hãy kiểm tra lại service!");
|
|
}
|
|
});
|
|
}
|
|
} |