BiFace_Server_Lite/web/js/config.js
2020-06-10 13:54:51 +07:00

89 lines
2.7 KiB
JavaScript

$(function () {
});
function saveStep1(e) {
var servermqtt = $("input[name='servermqtt']").val();
if (servermqtt === "") {
alert("Hãy nhập thông tin!");
return;
}
var url = $("input[name='url']").val();
if (url === "") {
alert("Hãy nhập thông tin!");
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("Box chưa được đăng kí trên CMS!");
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("Đã lưu cấu hình!", 2000);
} else {
notification.success("Lưu cấu hình thất bại!", 2000);
}
common.modalBlock(false);
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}