update điều chỉnh thời gian mở cửa
This commit is contained in:
parent
28f23530d0
commit
41598c6225
|
@ -579,11 +579,21 @@ class DeviceController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
public function actionEditDoorName($id) {
|
||||
public function actionEditDoor($id) {
|
||||
if (Yii::$app->request->post()) {
|
||||
$post = Yii::$app->request->post();
|
||||
$model = Door::findOne($id);
|
||||
if ($model) {
|
||||
$model->name = Yii::$app->request->post("name");
|
||||
$model->name = $post["name"];
|
||||
if ($model->duration !== $post["duration"]) {
|
||||
$device = $this->findModel($model->device_id);
|
||||
common::requestToCardService("/SetDeviceData/DoorDriverTime", [
|
||||
"DeviceIP" => $device->ip_address,
|
||||
"DoorID" => $model->code,
|
||||
"DoorDriverTime" => $post["duration"]
|
||||
]);
|
||||
$model->duration = $post["duration"];
|
||||
}
|
||||
$model->modified_at = time();
|
||||
$model->save();
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ class DeviceGrid extends CommonGrid {
|
|||
'data' => [
|
||||
'href' => Url::to(['doors', 'id' => $model->id])
|
||||
],
|
||||
'onclick' => "common.form(this, '');"
|
||||
'onclick' => "common.form(this, '', true);"
|
||||
]);
|
||||
// foreach ($doors as $key => $value) {
|
||||
// $html .= Html::button($value->code, [
|
||||
|
|
|
@ -11,6 +11,7 @@ use Yii;
|
|||
* @property int $device_id
|
||||
* @property string $name
|
||||
* @property int $code
|
||||
* @property int $duration
|
||||
* @property int $created_at
|
||||
* @property int $modified_at
|
||||
*/
|
||||
|
@ -29,7 +30,7 @@ class Door extends \yii\db\ActiveRecord {
|
|||
public function rules() {
|
||||
return [
|
||||
[['device_id', 'name', 'code'], 'required'],
|
||||
[['device_id', 'code', 'created_at', 'modified_at'], 'integer'],
|
||||
[['device_id', 'code', 'created_at', 'modified_at', 'duration'], 'integer'],
|
||||
[['name'], 'string', 'max' => 100],
|
||||
];
|
||||
}
|
||||
|
@ -43,6 +44,7 @@ class Door extends \yii\db\ActiveRecord {
|
|||
'device_id' => 'Device ID',
|
||||
'name' => 'Name',
|
||||
'code' => 'Code',
|
||||
'duration' => 'Duration',
|
||||
'created_at' => 'Created At',
|
||||
'modified_at' => 'Modified At',
|
||||
];
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr class="info">
|
||||
<th style="width: 13%;">Mã cửa</th>
|
||||
<th style="width: 10%;">Mã cửa</th>
|
||||
<th>Tên cửa</th>
|
||||
<th style="width: 10%;">Sửa</th>
|
||||
<th>Thời gian mở cửa (giây)</th>
|
||||
<th>Sửa</th>
|
||||
<th style="width: 15%;">Mở cửa</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -12,13 +13,23 @@
|
|||
<tr>
|
||||
<td class="text-center">{$d->code}</td>
|
||||
<td>
|
||||
<span id="name-text-{$d->id}">{$d->name}</span>
|
||||
<input type="text" value="{$d->name}" class="hidden" id="name-input-{$d->id}" onblur="editDoorName(this);" data-href="{yii\helpers\Url::to(["edit-door-name","id"=>$d->id])}">
|
||||
<span id="name-text-{$d->id}" class="real-{$d->id}">{$d->name}</span>
|
||||
<input type="text" value="{$d->name}" class="hidden edit-{$d->id}" id="name-input-{$d->id}">
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<button class="btn btn-success" data-stt="false" data="{$d->id}" onclick="openFormEditDoorName(this);" id="btn-edit-{$d->id}">
|
||||
<span id="duration-text-{$d->id}" class="real-{$d->id}">{$d->duration}</span>
|
||||
<input type="number" value="{$d->duration}" class="hidden edit-{$d->id}" id="duration-input-{$d->id}">
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<button class="btn btn-success real-{$d->id}" data="{$d->id}" onclick="openFormEditDoor(this, true);" id="btn-edit-{$d->id}">
|
||||
<i class="fa fa-edit"></i>
|
||||
</button>
|
||||
<button class="btn btn-primary hidden edit-{$d->id}" data="{$d->id}" onclick="editDoor(this);" id="btn-save-{$d->id}" data-href="{yii\helpers\Url::to(['edit-door', 'id' => $d->id])}">
|
||||
<i class="fa fa-floppy-o"></i>
|
||||
</button>
|
||||
<button class="btn btn-danger hidden edit-{$d->id}" data="{$d->id}" onclick="openFormEditDoor(this, false);" id="btn-close-{$d->id}">
|
||||
<i class="fa fa-remove"></i>
|
||||
</button>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<button class="btn btn-primary" onclick="openDoor(this);" data-href="{yii\helpers\Url::to(['open-door', 'id' => $model->id, 'door' => $d->code])}">
|
||||
|
|
|
@ -498,35 +498,41 @@ function openDoor(e) {
|
|||
});
|
||||
}
|
||||
|
||||
function openFormEditDoorName(e) {
|
||||
function openFormEditDoor(e, stt) {
|
||||
var id = $(e).attr("data");
|
||||
var stt = $(e).attr("data-stt");
|
||||
if (stt === "false") {
|
||||
$("#name-text-" + id).addClass("hidden");
|
||||
$("#name-input-" + id).removeClass("hidden");
|
||||
$(e).attr("data-stt", "true");
|
||||
if (stt) {
|
||||
$(".real-" + id).addClass("hidden");
|
||||
$(".edit-" + id).removeClass("hidden");
|
||||
} else {
|
||||
$("#name-text-" + id).removeClass("hidden");
|
||||
$("#name-input-" + id).addClass("hidden");
|
||||
$(e).attr("data-stt", "false");
|
||||
$(".real-" + id).removeClass("hidden");
|
||||
$(".edit-" + id).addClass("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
function editDoorName(e) {
|
||||
function editDoor(e) {
|
||||
var id = $(e).attr("data");
|
||||
var name = $("#name-input-" + id).val();
|
||||
if (name === "") {
|
||||
alert("Tên thiết bị không được để trống");
|
||||
return;
|
||||
}
|
||||
var duration = $("#duration-input-" + id).val();
|
||||
if (parseInt(duration) > 0 && parseInt(duration) < 255) {
|
||||
common.modalBlock(true);
|
||||
$.ajax({
|
||||
url: $(e).attr('data-href'),
|
||||
type: 'POST',
|
||||
data: {
|
||||
name: $(e).val()
|
||||
duration: duration,
|
||||
name: name
|
||||
},
|
||||
success: function (data) {
|
||||
common.modalBlock(false);
|
||||
var id = parseInt(data);
|
||||
$("#name-text-" + id).html($(e).val());
|
||||
$("#name-text-" + id).removeClass("hidden");
|
||||
$("#name-input-" + id).addClass("hidden");
|
||||
$("#btn-edit-" + id).attr("data-stt", "false");
|
||||
$("#name-text-" + id).html(name);
|
||||
$("#duration-text-" + id).html(duration);
|
||||
$(".real-" + id).removeClass("hidden");
|
||||
$(".edit-" + id).addClass("hidden");
|
||||
notification.success("Đã lưu thông tin", 2000);
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
|
@ -534,4 +540,8 @@ function editDoorName(e) {
|
|||
common.ajaxError();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
alert("Thời gian mở cửa phải từ 1-254 giây");
|
||||
return;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user