update Device full CRUD
This commit is contained in:
@@ -252,10 +252,19 @@ table > tbody > tr.success >td>a {
|
||||
background: #b2d7ec;
|
||||
border: 1px solid #3c8dbc;
|
||||
}
|
||||
.action-button-disabled{
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
font-weight: inherit;
|
||||
border: 1px solid #ecf0f5;
|
||||
}
|
||||
.modal-header{
|
||||
padding: 10px;
|
||||
background: #b2d7ec;
|
||||
}
|
||||
.fa-1-5x {
|
||||
font-size: 1.3em !important;
|
||||
}
|
||||
.alert{
|
||||
padding: 5px;
|
||||
}
|
||||
@@ -242,6 +242,9 @@ common.form = function (e, obj, bigSize) {
|
||||
if (obj === 'card-register') {
|
||||
$('#Staff').select2();
|
||||
}
|
||||
if (obj === 'device') {
|
||||
$('#Area').select2();
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.modalBlock(false);
|
||||
@@ -287,7 +290,12 @@ common.validateEmail = function (Email) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
common.validateIp = function (Ip) {
|
||||
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(Ip)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* =========================
|
||||
*/
|
||||
|
||||
246
web/js/device.js
Normal file
246
web/js/device.js
Normal file
@@ -0,0 +1,246 @@
|
||||
$(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!");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
97
web/js/device_search.js
Normal file
97
web/js/device_search.js
Normal file
@@ -0,0 +1,97 @@
|
||||
$(function () {
|
||||
$('.checkbox-use-subnetmask').iCheck({
|
||||
checkboxClass: 'icheckbox_flat-red'
|
||||
});
|
||||
});
|
||||
|
||||
var progress = 0;
|
||||
var totals = 0;
|
||||
|
||||
function _search(e) {
|
||||
common.modalBlock(true);
|
||||
$.ajax({
|
||||
url: $(e).attr('data-href'),
|
||||
type: 'POST',
|
||||
data: {
|
||||
SubnetMask: $("input[name='SubnetMask']").val()
|
||||
},
|
||||
success: function (data) {
|
||||
common.modalBlock(false);
|
||||
$("#table-device").html(data.form);
|
||||
$("#totals").html(data.totals);
|
||||
$("#add-button-enabled").removeClass("hidden");
|
||||
$("#add-button-disabled").addClass("hidden");
|
||||
common.checkboxInit("device");
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.modalBlock(false);
|
||||
alert("Có lỗi xảy ra! hãy kiểm tra lại service!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function _process(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!");
|
||||
return;
|
||||
}
|
||||
common.modalBlock(true);
|
||||
$.ajax({
|
||||
url: $(e).attr('data-href'),
|
||||
type: 'POST',
|
||||
data: {
|
||||
lists: lists
|
||||
},
|
||||
success: function (data) {
|
||||
common.modalBlock(false);
|
||||
common.modalOpen(data.form, false, data.title);
|
||||
$("#close-modal").attr("disabled", true);
|
||||
$("#modalHeader").find("button").remove();
|
||||
totals = data.lists.length;
|
||||
for (var i = 0; i < totals; i++) {
|
||||
_import(data.lists[i]);
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.modalBlock(false);
|
||||
common.ajaxError();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function _import(data) {
|
||||
$.ajax({
|
||||
url: $("input[name='import_url']").val(),
|
||||
type: 'POST',
|
||||
data: {
|
||||
data: data
|
||||
},
|
||||
success: function (data) {
|
||||
var html = "";
|
||||
if (data.status) {
|
||||
html = "<span class='text-green'><i class='fa fa-check'></i> Thêm thiết bị <b>" + data.IP + "</b> thành công.</span><br>";
|
||||
} else {
|
||||
html = "<span class='text-red'><i class='fa fa-remove'></i> Thêm thiết bị <b>" + data.IP + "</b> thất bại.</span><br>";
|
||||
}
|
||||
$("#logs-response").append(html);
|
||||
$("#checkbox-" + data.SN).html("");
|
||||
$("#status-" + data.SN).find("label").removeClass("hidden");
|
||||
progress++;
|
||||
var percent = parseInt(progress / totals * 100);
|
||||
$("#progress").attr("aria-valuenow", percent);
|
||||
$("#progress").attr("style", "width: " + percent + "%");
|
||||
$("#progress").html(percent + "%");
|
||||
if (percent >= 100) {
|
||||
progress = 0;
|
||||
$("#close-modal").attr("disabled", false);
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.ajaxError();
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user