Thêm nút Luôn mở + luôn đóng
This commit is contained in:
parent
41598c6225
commit
35de1bf6b0
|
@ -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
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<th>Tên cửa</th>
|
||||
<th>Thời gian mở cửa (giây)</th>
|
||||
<th>Sửa</th>
|
||||
<th style="width: 15%;">Mở cửa</th>
|
||||
<th>Mở cửa</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -35,8 +35,19 @@
|
|||
<button class="btn btn-primary" onclick="openDoor(this);" data-href="{yii\helpers\Url::to(['open-door', 'id' => $model->id, 'door' => $d->code])}">
|
||||
Mở
|
||||
</button>
|
||||
<button class="change-duration-{$d->id} btn btn-{if $d->duration==255}warning{else}default{/if}" onclick="changeDuration(this);" data-href="{yii\helpers\Url::to(['change-duration', 'id' => $d->id, 'duration' => 255])}">
|
||||
Luôn mở
|
||||
</button>
|
||||
<button class="change-duration-{$d->id} btn btn-{if $d->duration==0}warning{else}default{/if}" onclick="changeDuration(this);" data-href="{yii\helpers\Url::to(['change-duration', 'id' => $d->id, 'duration' => 0])}">
|
||||
Luôn đóng
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="text-right">
|
||||
<button class="btn btn-default" data-dismiss="modal" id="close-modal">
|
||||
<span class="fa fa-remove"></span> Đóng
|
||||
</button>
|
||||
</div>
|
|
@ -545,3 +545,24 @@ function editDoor(e) {
|
|||
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();
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user