177 lines
5.5 KiB
JavaScript
177 lines
5.5 KiB
JavaScript
$(function () {
|
|
|
|
});
|
|
function saveStep1(e) {
|
|
var servermqtt = $("input[name='servermqtt']").val();
|
|
if (servermqtt === "") {
|
|
alert($("input[name='HAY_NHAP_THONG_TIN']").val());
|
|
return;
|
|
}
|
|
var url = $("input[name='url']").val();
|
|
if (url === "") {
|
|
alert($("input[name='HAY_NHAP_THONG_TIN']").val());
|
|
return;
|
|
}
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
data: {
|
|
servermqtt: servermqtt,
|
|
url: url
|
|
},
|
|
success: function (data) {
|
|
var c = 0;
|
|
setInterval(function () {
|
|
$.ajax({
|
|
url: data,
|
|
type: 'POST',
|
|
success: function (data) {
|
|
if (data.status) {
|
|
window.location = data.url;
|
|
} else {
|
|
if (data.text !== "") {
|
|
if (data.text === "error") {
|
|
c++;
|
|
if (c == 5) {
|
|
alert($("input[name='BOX_CHUA_DUOC_DANG_KI_TREN_CMS']").val());
|
|
window.location.reload(true);
|
|
}
|
|
} else {
|
|
alert(data.text);
|
|
window.location.reload(true);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}, 1000);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
|
|
function saveStep2(e) {
|
|
var cfgLists = $(".editform");
|
|
var cfg = [];
|
|
for (var i = 0; i < cfgLists.length; i++) {
|
|
cfg.push({
|
|
parent: $(cfgLists[i]).data("parent"),
|
|
key: $(cfgLists[i]).data("key"),
|
|
data: $(cfgLists[i]).html()
|
|
});
|
|
}
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
data: {
|
|
config: cfg
|
|
},
|
|
success: function (data) {
|
|
if (data)
|
|
notification.success($("input[name='DA_LUU_CAU_HINH']").val(), 2000);
|
|
else
|
|
notification.success($("input[name='LUU_CAU_HINH_THAT_BAI']").val(), 2000);
|
|
common.modalBlock(false);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
|
|
function SaveConfigDevice(e) {
|
|
var server_api = $("input[name='server_api']").val();
|
|
var device_id = $("input[name='device_id']").val();
|
|
if (server_api === "" || device_id === "") {
|
|
alert($("input[name='HAY_NHAP_THONG_TIN']").val());
|
|
return;
|
|
}
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
data: {
|
|
server_api: server_api,
|
|
device_id: device_id
|
|
},
|
|
success: function (data) {
|
|
if (data)
|
|
notification.success($("input[name='DA_LUU_CAU_HINH']").val(), 2000);
|
|
else
|
|
notification.success($("input[name='LUU_CAU_HINH_THAT_BAI']").val(), 2000);
|
|
common.modalBlock(false);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
|
|
function ValidateIPaddress(ipaddress) {
|
|
if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
function validData(inputName) {
|
|
var ip = $("input[name='" + inputName + "']").val();
|
|
if (!ValidateIPaddress(ip)) {
|
|
common.error(inputName, "");
|
|
return false;
|
|
} else {
|
|
common.success(inputName);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function validDNS(inputName) {
|
|
var dns = $("input[name='" + inputName + "']").val();
|
|
if (dns == "")
|
|
return true;
|
|
return validData(inputName);
|
|
}
|
|
|
|
function changeIP(e) {
|
|
var valid = validData("device_ip");
|
|
valid = validData("subnet_mask");
|
|
valid = validData("gateway");
|
|
valid = validDNS("dns1");
|
|
valid = validDNS("dns2");
|
|
if (!valid)
|
|
return;
|
|
if (confirm($("input[name='BAN_CO_CHAC_CHAN_MUON_DOI_IP_KHONG']").val())) {
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
data: {
|
|
device_ip: $("input[name='device_ip']").val(),
|
|
subnet_mask: $("input[name='subnet_mask']").val(),
|
|
gateway: $("input[name='gateway']").val(),
|
|
dns1: $("input[name='dns1']").val(),
|
|
dns2: $("input[name='dns2']").val(),
|
|
},
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
if (!data.status)
|
|
common.error("subnet_mask", "");
|
|
else
|
|
window.location = data.url;
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
} |