update filter dữ liệu cửa trong Cấp quyền truy cập

This commit is contained in:
dongpd 2020-12-10 10:26:24 +07:00
parent ecd76e6c58
commit 9a13c5b677
6 changed files with 128 additions and 8 deletions

View File

@ -48,7 +48,7 @@ $config = [
], ],
'assetManager' => [ 'assetManager' => [
'class' => 'app\\components\\AssetManager', 'class' => 'app\\components\\AssetManager',
'appendVersion' => '1.0.11', 'appendVersion' => '1.0.12',
'bundles' => [ 'bundles' => [
'dmstr\web\AdminLteAsset' => [ 'dmstr\web\AdminLteAsset' => [
'skin' => 'skin-blue', 'skin' => 'skin-blue',

View File

@ -11,6 +11,7 @@ use app\models\Device;
use yii\web\Controller; use yii\web\Controller;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use app\models\StaffSearch; use app\models\StaffSearch;
use app\models\Area;
/** /**
* DeviceController implements the CRUD actions for Device model. * DeviceController implements the CRUD actions for Device model.
@ -48,7 +49,8 @@ class AssignController extends Controller {
"company" => Department::findOne(1), "company" => Department::findOne(1),
"scheduleArray" => Schedule::scheduleArray(), "scheduleArray" => Schedule::scheduleArray(),
"doorLists" => Door::find()->all(), "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()
]);
}
}
} }

View File

@ -67,4 +67,8 @@ class Door extends \yii\db\ActiveRecord {
return $results; return $results;
} }
public function getDevice() {
return Device::findOne($this->device_id);
}
} }

4
views/assign/device.tpl Normal file
View File

@ -0,0 +1,4 @@
<select name="FilterDevice" id="FilterDevice" onchange="filterDevice(this);">
<option value=""></option>
{html_options options=$deviceArray}
</select>

View File

@ -24,7 +24,7 @@
overflow: scroll; overflow: scroll;
} }
{*#schedule-search-staff::-webkit-scrollbar { {*#schedule-search-staff::-webkit-scrollbar {
display: none; display: none;
}*} }*}
#create-schedule-main{ #create-schedule-main{
border-left: 1px solid #cecece; border-left: 1px solid #cecece;
@ -37,6 +37,7 @@
} }
</style> </style>
<input type="hidden" value="" name="currentDepartment"> <input type="hidden" value="" name="currentDepartment">
<input type="hidden" value="{Url::to(['filter-all-device'])}" name="filter_all_device_url">
<div class="assign-index"> <div class="assign-index">
<div class="row"> <div class="row">
<div class="col-md-3"> <div class="col-md-3">
@ -94,7 +95,7 @@
</fieldset> </fieldset>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<fieldset id='schedule-door-lists' style="overflow-y: scroll;"> <fieldset id='schedule-door-lists' style="overflow: scroll;">
<legend>Cấp quyền truy cập</legend> <legend>Cấp quyền truy cập</legend>
<div class="input-group"> <div class="input-group">
<div class="input-group-addon">Chọn lịch trình</div> <div class="input-group-addon">Chọn lịch trình</div>
@ -108,7 +109,7 @@
</div> </div>
</div> </div>
<br> <br>
<table class="table table-bordered table-striped table-staff-schedule" style="background: #fff;"> <table class="table table-bordered table-striped table-staff-schedule" style="background: #fff;width: 500px;">
<thead> <thead>
<tr class="info"> <tr class="info">
<th style="width: 10%;" class="text-center"> <th style="width: 10%;" class="text-center">
@ -116,16 +117,35 @@
</th> </th>
<th>Cửa</th> <th>Cửa</th>
<th>Thiết bị</th> <th>Thiết bị</th>
<th>Khu vực</th>
</tr>
<tr>
<td></td>
<td></td>
<td id="deviceFilterForm">
<select name="FilterDevice" id="FilterDevice" onchange="filterDevice(this);">
<option value=""></option>
{html_options options=$deviceArray}
</select>
</td>
<td>
<select name="FilterArea" id="FilterArea" onchange="filterArea(this);" data-href="{Url::to(['filter-area'])}">
<option value=""></option>
{html_options options=$areaArray}
</select>
</td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{foreach from=$doorLists item=door} {foreach from=$doorLists item=door}
<tr> {$device=$door->device}
<tr class="door-lists door-lists-{$device->area_id} door-lists-{$device->id}">
<td class="text-center"> <td class="text-center">
<input type='checkbox' value='{$door->id}' name='checkbox-door-schedule' class='checkbox-door-schedule'> <input type='checkbox' value='{$door->id}' name='checkbox-door-schedule' class='checkbox-door-schedule'>
</td> </td>
<td>{$door->name}</td> <td>{$door->name}</td>
<td>{$deviceArray[$door->device_id]}</td> <td>{$device->name}</td>
<td>{$areaArray[$device->area_id]|default:""}</td>
</tr> </tr>
{/foreach} {/foreach}
</tbody> </tbody>

View File

@ -1,7 +1,7 @@
$(function () { $(function () {
$("#schedule-department-tree").height($("#create-schedule-main").height() - 28); $("#schedule-department-tree").height($("#create-schedule-main").height() - 28);
$("#schedule-door-lists").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({ $('#checkbox-staff-schedule-all').iCheck({
checkboxClass: 'icheckbox_flat-red' checkboxClass: 'icheckbox_flat-red'
}); });
@ -144,3 +144,72 @@ function openDoorList(e, stt) {
$("#full-" + id).addClass("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');
}
}
});
});
}