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";
return [
"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) {
return function($model) use ($array) {
$doors = [];
$alert = $hidden = "";
if ($model->door_access) {
$ls = json_decode($model->door_access, true);
foreach ($ls as $key => $value) {
if (isset($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"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/xampp/htdocs/Server_AccessControl/views/device/doors.tpl</file>
<file>file:/C:/xampp/htdocs/Server_AccessControl/web/js/device.js</file>
<file>file:/C:/xampp/htdocs/Server_AccessControl/controllers/DeviceController.php</file>
<file>file:/C:/xampp/htdocs/Server_AccessControl/helpers/StaffGrid.php</file>
<file>file:/C:/xampp/htdocs/Server_AccessControl/views/assign/staff.tpl</file>
</group>
</open-files>
</project-private>

View File

@ -92,8 +92,17 @@ schedule.setSchedule = function (e) {
notification.success("Đã lưu thông tin", 1000);
$.each($("input[name='checkbox-staff-schedule']:checked"), function () {
if ($(this).val() !== "0") {
$("#schedule-staff-results-" + $(this).val()).html(data.schedule);
$("#schedule-door-results-" + $(this).val()).html(data.doors);
var id = $(this).val();
$("#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);
}
});
@ -104,3 +113,14 @@ schedule.setSchedule = function (e) {
}
});
};
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");
}
}