diff --git a/controllers/DeviceController.php b/controllers/DeviceController.php index edb9d050..25c10262 100644 --- a/controllers/DeviceController.php +++ b/controllers/DeviceController.php @@ -635,22 +635,33 @@ class DeviceController extends Controller { 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 - ]); + $device = $this->findModel($model->device_id); + if ($duration === "0") { + if ($model->always_close) { + $duration = $model->duration; + $model->always_close = 0; } else { - common::requestToCardService("/ControlDevice", [ - "DeviceIP" => $device->ip_address, - "DoorID" => $model->code, - "Duration" => $duration - ]); + $duration = 0; + $model->always_close = 1; } - $model->duration = $duration; + common::requestToCardService("/SetDeviceData/DoorDriverTime", [ + "DeviceIP" => $device->ip_address, + "DoorID" => $model->code, + "DoorDriverTime" => $duration + ]); + } else { + if ($model->always_open) { + $duration = 0; + $model->always_open = 0; + } else { + $duration = 255; + $model->always_open = 1; + } + common::requestToCardService("/ControlDevice", [ + "DeviceIP" => $device->ip_address, + "DoorID" => $model->code, + "Duration" => $duration + ]); } $model->modified_at = time(); $model->save(); @@ -658,7 +669,9 @@ class DeviceController extends Controller { Yii::$app->response->format = "json"; return [ "id" => $id, - "duration" => $duration + "duration" => $duration, + "always_close" => $model->always_close, + "always_open" => $model->always_open ]; } } diff --git a/models/Door.php b/models/Door.php index 55c03734..01f95bda 100644 --- a/models/Door.php +++ b/models/Door.php @@ -12,6 +12,8 @@ use Yii; * @property string $name * @property int $code * @property int $duration + * @property int $always_open + * @property int $always_close * @property int $created_at * @property int $modified_at */ @@ -30,7 +32,7 @@ class Door extends \yii\db\ActiveRecord { public function rules() { return [ [['device_id', 'name', 'code'], 'required'], - [['device_id', 'code', 'created_at', 'modified_at', 'duration'], 'integer'], + [['device_id', 'code', 'created_at', 'modified_at', 'duration', 'always_open', 'always_close'], 'integer'], [['name'], 'string', 'max' => 100], ]; } diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 640fdffc..0928d03a 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -3,10 +3,9 @@ - file:/C:/xampp/htdocs/Server_AccessControl/views/auth-item/form.tpl - file:/C:/xampp/htdocs/Server_AccessControl/controllers/AuthItemController.php - file:/C:/xampp/htdocs/Server_AccessControl/web/js/auth_item.js - file:/C:/xampp/htdocs/Server_AccessControl/models/AuthItem.php + file:/C:/xampp/htdocs/Server_AccessControl/views/device/doors.tpl + file:/C:/xampp/htdocs/Server_AccessControl/web/js/device.js + file:/C:/xampp/htdocs/Server_AccessControl/controllers/DeviceController.php diff --git a/views/device/doors.tpl b/views/device/doors.tpl index ad8423ce..a7322231 100644 --- a/views/device/doors.tpl +++ b/views/device/doors.tpl @@ -35,10 +35,10 @@ - - diff --git a/web/js/device.js b/web/js/device.js index 5a05ada5..394d4cca 100644 --- a/web/js/device.js +++ b/web/js/device.js @@ -555,9 +555,9 @@ function changeDuration(e) { 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); + if (data.always_close || data.always_open) { + $(e).removeClass("btn-default").addClass("btn-warning"); + } notification.success("Đã lưu thông tin", 2000); }, error: function (jqXHR, textStatus, errorThrown) {