diff --git a/controllers/DeviceController.php b/controllers/DeviceController.php index dae80f9b..cb7ce2a2 100644 --- a/controllers/DeviceController.php +++ b/controllers/DeviceController.php @@ -601,4 +601,36 @@ class DeviceController extends Controller { } } + public function actionChangeDuration($id, $duration) { + if (Yii::$app->request->isAjax) { + $model = Door::findOne($id); + if ($model) { + if ($model->duration !== $duration) { + $device = $this->findModel($model->device_id); + if ($duration === "0") { + common::requestToCardService("/ControlDevice/ForceCloseDoor", [ + "DeviceIP" => $device->ip_address, + "DoorID" => $model->code, + "Duration" => $duration + ]); + } else { + common::requestToCardService("/ControlDevice", [ + "DeviceIP" => $device->ip_address, + "DoorID" => $model->code, + "Duration" => $duration + ]); + } + $model->duration = $duration; + } + $model->modified_at = time(); + $model->save(); + } + Yii::$app->response->format = "json"; + return [ + "id" => $id, + "duration" => $duration + ]; + } + } + } diff --git a/views/device/doors.tpl b/views/device/doors.tpl index 9501c213..ad8423ce 100644 --- a/views/device/doors.tpl +++ b/views/device/doors.tpl @@ -5,7 +5,7 @@ Tên cửa Thời gian mở cửa (giây) Sửa - Mở cửa + Mở cửa @@ -35,8 +35,19 @@ + + {/foreach} - \ No newline at end of file + +
+ +
\ No newline at end of file diff --git a/web/js/device.js b/web/js/device.js index 3ce06f1f..5a05ada5 100644 --- a/web/js/device.js +++ b/web/js/device.js @@ -544,4 +544,25 @@ function editDoor(e) { alert("Thời gian mở cửa phải từ 1-254 giây"); return; } +} + +function changeDuration(e) { + common.modalBlock(true); + $.ajax({ + url: $(e).attr('data-href'), + type: 'POST', + success: function (data) { + common.modalBlock(false); + var id = parseInt(data.id); + $(".change-duration-" + id).removeClass("btn-warning").addClass("btn-default"); + $(e).removeClass("btn-default").addClass("btn-warning"); + $("#duration-text-" + id).html(data.duration); + $("#duration-input-" + id).val(data.duration); + notification.success("Đã lưu thông tin", 2000); + }, + error: function (jqXHR, textStatus, errorThrown) { + common.modalBlock(false); + common.ajaxError(); + } + }); } \ No newline at end of file