update thu gọn danh sách cửa khi cấp quyền truy cập

This commit is contained in:
dongpd 2020-11-04 10:55:53 +07:00
parent 65aced8ccf
commit f306d207d3
4 changed files with 35 additions and 8 deletions

View File

@ -109,7 +109,7 @@ class AssignController extends Controller {
Yii::$app->response->format = "json"; Yii::$app->response->format = "json";
return [ return [
"schedule" => Schedule::findOne($post['schedule'])->name, "schedule" => Schedule::findOne($post['schedule'])->name,
"doors" => implode("<br>", $doors) "doors" => $doors
]; ];
} }
} }

View File

@ -86,14 +86,22 @@ class StaffGrid extends CommonGrid {
public static function doors($array) { public static function doors($array) {
return function($model) use ($array) { return function($model) use ($array) {
$doors = []; $doors = [];
$alert = $hidden = "";
if ($model->door_access) { if ($model->door_access) {
$ls = json_decode($model->door_access, true); $ls = json_decode($model->door_access, true);
foreach ($ls as $key => $value) { foreach ($ls as $key => $value) {
if (isset($array[$value])) if (isset($array[$value]))
$doors[] = $array[$value]; $doors[] = $array[$value];
} }
if (count($ls) <= 2) {
$alert = "<div id='short-{$model->id}'>" . implode("<br>", $doors) . "</div>";
} else {
$alert = "<div id='short-{$model->id}'>" . $doors[0] . "<br>" . $doors[1] . "<a href='#' onclick='openDoorList(this, true);return false;' data='{$model->id}'><i class='fa fa-chevron-down'></i> Xem thêm</a></div>";
$hidden = "<div id='full-{$model->id}' class='hidden'>" . implode("<br>", $doors) . "<a href='#' onclick='openDoorList(this, false);return false;' data='{$model->id}'><i class='fa fa-chevron-up'></i> Thu gọn</a></div>";
}
return $alert . $hidden;
} }
return implode("<br>", $doors); return "";
}; };
} }

View File

@ -3,9 +3,8 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/> <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2"> <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group> <group>
<file>file:/C:/xampp/htdocs/Server_AccessControl/views/device/doors.tpl</file> <file>file:/C:/xampp/htdocs/Server_AccessControl/helpers/StaffGrid.php</file>
<file>file:/C:/xampp/htdocs/Server_AccessControl/web/js/device.js</file> <file>file:/C:/xampp/htdocs/Server_AccessControl/views/assign/staff.tpl</file>
<file>file:/C:/xampp/htdocs/Server_AccessControl/controllers/DeviceController.php</file>
</group> </group>
</open-files> </open-files>
</project-private> </project-private>

View File

@ -92,8 +92,17 @@ schedule.setSchedule = function (e) {
notification.success("Đã lưu thông tin", 1000); notification.success("Đã lưu thông tin", 1000);
$.each($("input[name='checkbox-staff-schedule']:checked"), function () { $.each($("input[name='checkbox-staff-schedule']:checked"), function () {
if ($(this).val() !== "0") { if ($(this).val() !== "0") {
$("#schedule-staff-results-" + $(this).val()).html(data.schedule); var id = $(this).val();
$("#schedule-door-results-" + $(this).val()).html(data.doors); $("#schedule-staff-results-" + id).html(data.schedule);
var alert = "";
var hidden = "";
if (data.doors.length <= 2) {
alert = "<div id='short-{$model->id}'>" + data.doors.join("<br>") + "</div>";
} else {
alert = "<div id='short-" + id + "'>" + data.doors[0] + "<br>" + data.doors[1] + "<a href='#' onclick='openDoorList(this, true);return false;' data='" + id + "'><i class='fa fa-chevron-down'></i> Xem thêm</a></div>";
hidden = "<div id='full-" + id + "' class='hidden'>" + data.doors.join("<br>") + "<a href='#' onclick='openDoorList(this, false);return false;' data='" + id + "'><i class='fa fa-chevron-up'></i> Thu gọn</a></div>";
}
$("#schedule-door-results-" + id).html(alert + hidden);
} }
}); });
@ -103,4 +112,15 @@ schedule.setSchedule = function (e) {
common.ajaxError(); common.ajaxError();
} }
}); });
}; };
function openDoorList(e, stt) {
var id = $(e).attr("data");
if (stt) {
$("#short-" + id).addClass("hidden");
$("#full-" + id).removeClass("hidden");
} else {
$("#short-" + id).removeClass("hidden");
$("#full-" + id).addClass("hidden");
}
}