diff --git a/controllers/DeviceController.php b/controllers/DeviceController.php index afec7c5d..ecaa391e 100644 --- a/controllers/DeviceController.php +++ b/controllers/DeviceController.php @@ -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: " . $model->name . "", + "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; + } + } + } diff --git a/helpers/DeviceGrid.php b/helpers/DeviceGrid.php index a30f5426..d15a8371 100644 --- a/helpers/DeviceGrid.php +++ b/helpers/DeviceGrid.php @@ -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(" 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; }; } diff --git a/models/Device.php b/models/Device.php index adfecad5..9d1ce0f5 100644 --- a/models/Device.php +++ b/models/Device.php @@ -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' ]; } diff --git a/views/device/doors.tpl b/views/device/doors.tpl new file mode 100644 index 00000000..c04aa7d6 --- /dev/null +++ b/views/device/doors.tpl @@ -0,0 +1,31 @@ +
Mã cửa | +Tên cửa | +Sửa | +Mở cửa | +
---|---|---|---|
{$d->code} | ++ {$d->name} + $d->id])}"> + | ++ + | ++ + | +