From 9a13c5b6779e16fb194747522729c341e304bc69 Mon Sep 17 00:00:00 2001 From: dongpd Date: Thu, 10 Dec 2020 10:26:24 +0700 Subject: [PATCH] =?UTF-8?q?update=20filter=20d=E1=BB=AF=20li=E1=BB=87u=20c?= =?UTF-8?q?=E1=BB=ADa=20trong=20C=E1=BA=A5p=20quy=E1=BB=81n=20truy=20c?= =?UTF-8?q?=E1=BA=ADp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/web.php | 2 +- controllers/AssignController.php | 25 ++++++++++- models/Door.php | 4 ++ views/assign/device.tpl | 4 ++ views/assign/index.tpl | 30 +++++++++++--- web/js/assign.js | 71 +++++++++++++++++++++++++++++++- 6 files changed, 128 insertions(+), 8 deletions(-) create mode 100644 views/assign/device.tpl diff --git a/config/web.php b/config/web.php index 08b6c38b..8b142538 100644 --- a/config/web.php +++ b/config/web.php @@ -48,7 +48,7 @@ $config = [ ], 'assetManager' => [ 'class' => 'app\\components\\AssetManager', - 'appendVersion' => '1.0.11', + 'appendVersion' => '1.0.12', 'bundles' => [ 'dmstr\web\AdminLteAsset' => [ 'skin' => 'skin-blue', diff --git a/controllers/AssignController.php b/controllers/AssignController.php index daf65d1f..49c4510c 100644 --- a/controllers/AssignController.php +++ b/controllers/AssignController.php @@ -11,6 +11,7 @@ use app\models\Device; use yii\web\Controller; use yii\filters\VerbFilter; use app\models\StaffSearch; +use app\models\Area; /** * DeviceController implements the CRUD actions for Device model. @@ -48,7 +49,8 @@ class AssignController extends Controller { "company" => Department::findOne(1), "scheduleArray" => Schedule::scheduleArray(), "doorLists" => Door::find()->all(), - "deviceArray" => Device::deviceArray() + "deviceArray" => Device::deviceArray(), + "areaArray" => Area::areaArray() ]); } @@ -120,4 +122,25 @@ class AssignController extends Controller { } } + public function actionFilterArea() { + if (Yii::$app->request->post()) { + $lists = Device::find()->andWhere(['area_id' => Yii::$app->request->post('area')])->all(); + $deviceArray = []; + foreach ($lists as $key => $value) { + $deviceArray[$value->id] = $value->name; + } + return $this->renderPartial("device", [ + "deviceArray" => $deviceArray + ]); + } + } + + public function actionFilterAllDevice() { + if (Yii::$app->request->isAjax) { + return $this->renderPartial("device", [ + "deviceArray" => Device::deviceArray() + ]); + } + } + } diff --git a/models/Door.php b/models/Door.php index 01f95bda..dd734f57 100644 --- a/models/Door.php +++ b/models/Door.php @@ -67,4 +67,8 @@ class Door extends \yii\db\ActiveRecord { return $results; } + public function getDevice() { + return Device::findOne($this->device_id); + } + } diff --git a/views/assign/device.tpl b/views/assign/device.tpl new file mode 100644 index 00000000..2b0e890b --- /dev/null +++ b/views/assign/device.tpl @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/views/assign/index.tpl b/views/assign/index.tpl index 5a8348cd..a82fbb2b 100644 --- a/views/assign/index.tpl +++ b/views/assign/index.tpl @@ -24,7 +24,7 @@ overflow: scroll; } {*#schedule-search-staff::-webkit-scrollbar { - display: none; + display: none; }*} #create-schedule-main{ border-left: 1px solid #cecece; @@ -37,6 +37,7 @@ } +
@@ -94,7 +95,7 @@
-
+
Cấp quyền truy cập
Chọn lịch trình
@@ -108,7 +109,7 @@

- +
+ + + + + + + {foreach from=$doorLists item=door} - + {$device=$door->device} + - + + {/foreach} diff --git a/web/js/assign.js b/web/js/assign.js index d12b1e6e..646ee62f 100644 --- a/web/js/assign.js +++ b/web/js/assign.js @@ -1,7 +1,7 @@ $(function () { $("#schedule-department-tree").height($("#create-schedule-main").height() - 28); $("#schedule-door-lists").height($("#create-schedule-main").height() - 28); - common.checkboxInit("door-schedule"); + checkboxInit(); $('#checkbox-staff-schedule-all').iCheck({ checkboxClass: 'icheckbox_flat-red' }); @@ -143,4 +143,73 @@ function openDoorList(e, stt) { $("#short-" + id).removeClass("hidden"); $("#full-" + id).addClass("hidden"); } +} + +function filterDevice(e) { + var data = $(e).val(); + if (data === "") { + if ($("#FilterArea").val() !== "") { + $(".door-lists-" + $("#FilterArea").val()).removeClass("hidden"); + } else { + $(".door-lists").removeClass("hidden"); + } + } else { + $(".door-lists").addClass("hidden"); + $(".door-lists-" + data).removeClass("hidden"); + } +} + +function filterArea(e) { + $.ajax({ + url: $(e).attr("data-href"), + type: 'POST', + data: { + area: $(e).val() + }, + success: function (data) { + $("#deviceFilterForm").html(data); + var value = $(e).val(); + $("#FilterDevice").val(""); + if (value === "") { + $(".door-lists").removeClass("hidden"); + filterAllDevice(); + } else { + $(".door-lists").addClass("hidden"); + $(".door-lists-" + value).removeClass("hidden"); + } + }, + error: function (jqXHR, textStatus, errorThrown) { + common.ajaxError(); + } + }); +} + +function filterAllDevice() { + $.ajax({ + url: $("input[name='filter_all_device_url']").val(), + type: 'POST', + success: function (data) { + $("#deviceFilterForm").html(data); + }, + error: function (jqXHR, textStatus, errorThrown) { + common.ajaxError(); + } + }); +} + +function checkboxInit() { + $('.checkbox-door-schedule').iCheck({ + checkboxClass: 'icheckbox_flat-blue' + }); + $('#checkall-door-schedule').on('ifChanged', function (event) { + $.each($('.checkbox-door-schedule'), function () { + if (!$(this).closest("tr").hasClass("hidden")) { + if (event.target.checked) { + $(this).iCheck('check'); + } else { + $(this).iCheck('uncheck'); + } + } + }); + }); } \ No newline at end of file
@@ -116,16 +117,35 @@ Cửa Thiết bịKhu vực
+ + + +
{$door->name}{$deviceArray[$door->device_id]}{$device->name}{$areaArray[$device->area_id]|default:""}