diff --git a/controllers/DeviceController.php b/controllers/DeviceController.php index 4363bffb..c984e665 100644 --- a/controllers/DeviceController.php +++ b/controllers/DeviceController.php @@ -502,4 +502,38 @@ class DeviceController extends Controller { } } + public function actionChangeIpSearchForm() { + Yii::$app->response->format = "json"; + if (Yii::$app->request->post()) { + $data = json_decode(Yii::$app->request->post("data"), true); + return [ + "title" => Html::tag("i", "", ["class" => "fa fa-pencil"]) . " Thay đổi địa chỉ IP", + "form" => $this->renderPartial("change-ip-search", [ + "data" => $data, + "url" => Url::to(["change-ip-search"]) + ]) + ]; + } + } + + public function actionChangeIpSearch() { + Yii::$app->response->format = "json"; + if (Yii::$app->request->post()) { + $data = Yii::$app->request->post(); + if ($data["IpOld"] !== $data["IpNew"]) { + $res = common::requestToCardService("/ModifyIPAddress", [ + "OldIPAddress" => $data["IpOld"], + "NewIPAddress" => $data["IpNew"], + "NetMask" => $data["SubnetMask"], + "GATEIPAddress" => $data["Gateway"], + "MAC" => $data["MAC"] + ]); + if ($res == 0) { + return ["status" => true]; + } + } + return ["status" => true]; + } + } + } diff --git a/views/device/change-ip-search.tpl b/views/device/change-ip-search.tpl new file mode 100644 index 00000000..f41e8ace --- /dev/null +++ b/views/device/change-ip-search.tpl @@ -0,0 +1,52 @@ + +
+
+
Địa chỉ IP cũ
+ +
+ +
+
+
+
Địa chỉ IP mới
+ +
+ +
+
+
+
Subnet Mask
+ +
+ +
+
+
+
Gateway
+ +
+ +
+ + + + +
+ + +
\ No newline at end of file diff --git a/views/device/device-lists.tpl b/views/device/device-lists.tpl index efd952cd..6e07b335 100644 --- a/views/device/device-lists.tpl +++ b/views/device/device-lists.tpl @@ -20,9 +20,9 @@ {/if} {$d.MAC|default:""} - {$d.IP|default:""} - {$d.NetMask|default:""} - {$d.GATEIPAddress|default:""} + {$d.IP|default:""} + {$d.NetMask|default:""} + {$d.GATEIPAddress|default:""} {$d.SN|default:""} {$d.Device|default:""} diff --git a/views/device/search.tpl b/views/device/search.tpl index b2577ebb..37db5d30 100644 --- a/views/device/search.tpl +++ b/views/device/search.tpl @@ -16,6 +16,9 @@ +
diff --git a/web/js/device_search.js b/web/js/device_search.js index 1291eb38..d18a9dd4 100644 --- a/web/js/device_search.js +++ b/web/js/device_search.js @@ -94,4 +94,120 @@ function _import(data) { common.ajaxError(); } }); +} + +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'), + type: 'POST', + data: { + data: lists[0] + }, + success: function (data) { + common.modalBlock(false); + common.modalOpen(data.form, false, 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"); + } + + var Gateway = $("input[name='Gateway']").val(); + if (Gateway === "") { + common.error("gateway", "Gateway không được để trống"); + error++; + } else if (!common.validateIp(Gateway)) { + common.error("gateway", "Định dạng Gateway không đúng"); + error++; + } else { + common.success("gateway"); + } + return error == 0 ? true : false; +} + +function changeIP(e) { + if (validateChangeIP()) { + common.modalBlock(true); + $.ajax({ + url: $(e).attr('data-href'), + type: 'POST', + data: { + IpOld: $("input[name='IpOld']").val(), + IpNew: $("input[name='IpNew']").val(), + SubnetMask: $("input[name='SubnetMaskDevice']").val(), + Gateway: $("input[name='Gateway']").val(), + MAC: $("input[name='MAC']").val() + }, + success: function (data) { + common.modalBlock(false); + var SN = $("input[name='SN']").val(); + if (data.status) { + notification.success("Đổi IP thiết bị thành công", 1000); + $("#myModal").modal("hide"); + $("#ip-" + SN).html($("input[name='IpNew']").val()); + $("#subnet-mask-" + SN).html($("input[name='SubnetMaskDevice']").val()); + $("#gateway-" + SN).html($("input[name='Gateway']").val()); + var params = { + MAC: $("input[name='MAC']").val(), + IP: $("input[name='IpNew']").val(), + NetMask: $("input[name='SubnetMaskDevice']").val(), + GATEIPAddress: $("input[name='Gateway']").val(), + SN: $("input[name='SN']").val(), + Device: $("input[name='Device']").val(), + Ver: $("input[name='Ver']").val() + }; + $("#checkbox-" + SN).find("input").val(JSON.stringify(params)); + } 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!"); + } + }); + } } \ No newline at end of file