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()) {
|
if (Yii::$app->request->post()) {
|
||||||
|
$post = Yii::$app->request->post();
|
||||||
$model = Door::findOne($id);
|
$model = Door::findOne($id);
|
||||||
if ($model) {
|
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->modified_at = time();
|
||||||
$model->save();
|
$model->save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ class DeviceGrid extends CommonGrid {
|
||||||
'data' => [
|
'data' => [
|
||||||
'href' => Url::to(['doors', 'id' => $model->id])
|
'href' => Url::to(['doors', 'id' => $model->id])
|
||||||
],
|
],
|
||||||
'onclick' => "common.form(this, '');"
|
'onclick' => "common.form(this, '', true);"
|
||||||
]);
|
]);
|
||||||
// foreach ($doors as $key => $value) {
|
// foreach ($doors as $key => $value) {
|
||||||
// $html .= Html::button($value->code, [
|
// $html .= Html::button($value->code, [
|
||||||
|
|
|
@ -11,6 +11,7 @@ use Yii;
|
||||||
* @property int $device_id
|
* @property int $device_id
|
||||||
* @property string $name
|
* @property string $name
|
||||||
* @property int $code
|
* @property int $code
|
||||||
|
* @property int $duration
|
||||||
* @property int $created_at
|
* @property int $created_at
|
||||||
* @property int $modified_at
|
* @property int $modified_at
|
||||||
*/
|
*/
|
||||||
|
@ -29,7 +30,7 @@ class Door extends \yii\db\ActiveRecord {
|
||||||
public function rules() {
|
public function rules() {
|
||||||
return [
|
return [
|
||||||
[['device_id', 'name', 'code'], 'required'],
|
[['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],
|
[['name'], 'string', 'max' => 100],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -43,6 +44,7 @@ class Door extends \yii\db\ActiveRecord {
|
||||||
'device_id' => 'Device ID',
|
'device_id' => 'Device ID',
|
||||||
'name' => 'Name',
|
'name' => 'Name',
|
||||||
'code' => 'Code',
|
'code' => 'Code',
|
||||||
|
'duration' => 'Duration',
|
||||||
'created_at' => 'Created At',
|
'created_at' => 'Created At',
|
||||||
'modified_at' => 'Modified At',
|
'modified_at' => 'Modified At',
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
<table class="table table-bordered table-striped">
|
<table class="table table-bordered table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="info">
|
<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>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>
|
<th style="width: 15%;">Mở cửa</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -12,13 +13,23 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td class="text-center">{$d->code}</td>
|
<td class="text-center">{$d->code}</td>
|
||||||
<td>
|
<td>
|
||||||
<span id="name-text-{$d->id}">{$d->name}</span>
|
<span id="name-text-{$d->id}" class="real-{$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])}">
|
<input type="text" value="{$d->name}" class="hidden edit-{$d->id}" id="name-input-{$d->id}">
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<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>
|
<i class="fa fa-edit"></i>
|
||||||
</button>
|
</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>
|
||||||
<td class="text-center">
|
<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])}">
|
<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 id = $(e).attr("data");
|
||||||
var stt = $(e).attr("data-stt");
|
if (stt) {
|
||||||
if (stt === "false") {
|
$(".real-" + id).addClass("hidden");
|
||||||
$("#name-text-" + id).addClass("hidden");
|
$(".edit-" + id).removeClass("hidden");
|
||||||
$("#name-input-" + id).removeClass("hidden");
|
|
||||||
$(e).attr("data-stt", "true");
|
|
||||||
} else {
|
} else {
|
||||||
$("#name-text-" + id).removeClass("hidden");
|
$(".real-" + id).removeClass("hidden");
|
||||||
$("#name-input-" + id).addClass("hidden");
|
$(".edit-" + id).addClass("hidden");
|
||||||
$(e).attr("data-stt", "false");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
common.modalBlock(true);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: $(e).attr('data-href'),
|
url: $(e).attr('data-href'),
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {
|
data: {
|
||||||
name: $(e).val()
|
duration: duration,
|
||||||
|
name: name
|
||||||
},
|
},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
common.modalBlock(false);
|
common.modalBlock(false);
|
||||||
var id = parseInt(data);
|
var id = parseInt(data);
|
||||||
$("#name-text-" + id).html($(e).val());
|
$("#name-text-" + id).html(name);
|
||||||
$("#name-text-" + id).removeClass("hidden");
|
$("#duration-text-" + id).html(duration);
|
||||||
$("#name-input-" + id).addClass("hidden");
|
$(".real-" + id).removeClass("hidden");
|
||||||
$("#btn-edit-" + id).attr("data-stt", "false");
|
$(".edit-" + id).addClass("hidden");
|
||||||
notification.success("Đã lưu thông tin", 2000);
|
notification.success("Đã lưu thông tin", 2000);
|
||||||
},
|
},
|
||||||
error: function (jqXHR, textStatus, errorThrown) {
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
@ -534,4 +540,8 @@ function editDoorName(e) {
|
||||||
common.ajaxError();
|
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