update sửa tên cửa
This commit is contained in:
parent
cd943030c6
commit
28f23530d0
|
@ -125,11 +125,6 @@ class DeviceController extends Controller {
|
|||
$model->area_id = $data["Area"];
|
||||
$model->modified_at = time();
|
||||
if ($model->save()) {
|
||||
$doors = Door::find()->andWhere(["device_id" => $id])->all();
|
||||
foreach ($doors as $key => $value) {
|
||||
$value->name = $data["Name"] . "-" . $value->code;
|
||||
$value->save();
|
||||
}
|
||||
common::insertSystemLogs(["action" => "update", "description" => "Chỉnh sửa thiết bị: " . $data["Name"], "type" => Yii::$app->controller->id]);
|
||||
return ["status" => true];
|
||||
} else
|
||||
|
@ -570,4 +565,30 @@ class DeviceController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
public function actionDoors($id) {
|
||||
if (Yii::$app->request->isAjax) {
|
||||
$model = $this->findModel($id);
|
||||
Yii::$app->response->format = "json";
|
||||
return [
|
||||
"title" => "Danh sách cửa: <b>" . $model->name . "</b>",
|
||||
"form" => $this->renderPartial("doors", [
|
||||
"model" => $model,
|
||||
"doors" => Door::find()->andWhere(["device_id" => $id])->all()
|
||||
])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function actionEditDoorName($id) {
|
||||
if (Yii::$app->request->post()) {
|
||||
$model = Door::findOne($id);
|
||||
if ($model) {
|
||||
$model->name = Yii::$app->request->post("name");
|
||||
$model->modified_at = time();
|
||||
$model->save();
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,17 +36,23 @@ class DeviceGrid extends CommonGrid {
|
|||
|
||||
public static function openDoor() {
|
||||
return function($model) {
|
||||
$doors = Door::find()->andWhere(["device_id" => $model->id])->all();
|
||||
$html = "";
|
||||
foreach ($doors as $key => $value) {
|
||||
$html .= Html::button($value->code, [
|
||||
'class' => 'btn btn-info',
|
||||
'data' => ['toggle' => 'tooltip', 'href' => Url::to(['open-door', 'id' => $model->id, 'door' => $value->code])],
|
||||
'title' => \Yii::t('app', 'Mở cửa'),
|
||||
'onclick' => "openDoor(this);"
|
||||
]) . " ";
|
||||
}
|
||||
return $html;
|
||||
$doors = Door::find()->andWhere(["device_id" => $model->id])->count();
|
||||
return Html::button("<i class='fa fa-list'></i> Danh sách cửa " . Html::label($doors, "", ["class" => "label label-danger"]), [
|
||||
'class' => 'btn btn-info',
|
||||
'data' => [
|
||||
'href' => Url::to(['doors', 'id' => $model->id])
|
||||
],
|
||||
'onclick' => "common.form(this, '');"
|
||||
]);
|
||||
// foreach ($doors as $key => $value) {
|
||||
// $html .= Html::button($value->code, [
|
||||
// 'class' => 'btn btn-info',
|
||||
// 'data' => ['toggle' => 'tooltip', 'href' => Url::to(['open-door', 'id' => $model->id, 'door' => $value->code])],
|
||||
// 'title' => \Yii::t('app', 'Mở cửa'),
|
||||
// 'onclick' => "openDoor(this);"
|
||||
// ]) . " ";
|
||||
// }
|
||||
// return $html;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ class Device extends \yii\db\ActiveRecord {
|
|||
'area_id' => 'Khu vực',
|
||||
'created_at' => 'Thời gian tạo',
|
||||
'modified_at' => 'Thời gian sửa',
|
||||
'door' => 'Quản lý cửa'
|
||||
];
|
||||
}
|
||||
|
||||
|
|
31
views/device/doors.tpl
Normal file
31
views/device/doors.tpl
Normal file
|
@ -0,0 +1,31 @@
|
|||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr class="info">
|
||||
<th style="width: 13%;">Mã cửa</th>
|
||||
<th>Tên cửa</th>
|
||||
<th style="width: 10%;">Sửa</th>
|
||||
<th style="width: 15%;">Mở cửa</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{foreach from=$doors item=d}
|
||||
<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])}">
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<button class="btn btn-success" data-stt="false" data="{$d->id}" onclick="openFormEditDoorName(this);" id="btn-edit-{$d->id}">
|
||||
<i class="fa fa-edit"></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])}">
|
||||
Mở
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
|
@ -100,8 +100,10 @@
|
|||
],
|
||||
'version',
|
||||
[
|
||||
'attribute' => 'door',
|
||||
'format' => 'raw',
|
||||
'headerOptions' => ['style' => 'width:10%'],
|
||||
'headerOptions' => ['style' => 'width:10%'],
|
||||
'contentOptions' => ['class' => 'text-center'],
|
||||
'value' => \app\helpers\DeviceGrid::openDoor()
|
||||
]
|
||||
],
|
||||
|
|
|
@ -497,3 +497,41 @@ function openDoor(e) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
function openFormEditDoorName(e) {
|
||||
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");
|
||||
} else {
|
||||
$("#name-text-" + id).removeClass("hidden");
|
||||
$("#name-input-" + id).addClass("hidden");
|
||||
$(e).attr("data-stt", "false");
|
||||
}
|
||||
}
|
||||
|
||||
function editDoorName(e) {
|
||||
common.modalBlock(true);
|
||||
$.ajax({
|
||||
url: $(e).attr('data-href'),
|
||||
type: 'POST',
|
||||
data: {
|
||||
name: $(e).val()
|
||||
},
|
||||
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");
|
||||
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