Merge pull request #650 from MyIgel/persistent-hidden-filters

Shifts view: Persist hidden filters
This commit is contained in:
msquare 2019-10-08 19:14:37 +02:00 committed by GitHub
commit 503c479e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 8 deletions

View File

@ -16,7 +16,7 @@ global.checkAll = (id, checked) => {
* Sets the checkboxes according to the given type * Sets the checkboxes according to the given type
* *
* @param {string} id The elements ID * @param {string} id The elements ID
* @param {list} shifts_list A list of numbers * @param {list} shiftsList A list of numbers
*/ */
global.checkOwnTypes = (id, shiftsList) => { global.checkOwnTypes = (id, shiftsList) => {
$('#' + id + ' input[type="checkbox"]').each(function () { $('#' + id + ' input[type="checkbox"]').each(function () {
@ -144,10 +144,10 @@ $(function () {
elem.children('input').on('click', function (ev) { elem.children('input').on('click', function (ev) {
ev.stopImmediatePropagation(); ev.stopImmediatePropagation();
if (typeof elem.data('DateTimePicker') === 'undefined') { if (typeof elem.data('DateTimePicker') === 'undefined') {
elem.datetimepicker(opts); elem.datetimepicker(opts);
elem.data('DateTimePicker').show(); elem.data('DateTimePicker').show();
} else { } else {
elem.data('DateTimePicker').toggle(); elem.data('DateTimePicker').toggle();
} }
}); });
}); });
@ -173,3 +173,30 @@ $(function () {
}); });
}); });
}); });
/**
* Set the filter selects to latest state
*
* Uses DOMContentLoaded to prevent flickering
*/
window.addEventListener('DOMContentLoaded', () => {
const filter = document.getElementById('collapseShiftsFilterSelect');
if (!filter || localStorage.getItem('collapseShiftsFilterSelect') !== 'hidden') {
return;
}
filter.classList.remove('in');
});
$(() => {
if (typeof (localStorage) === 'undefined') {
return;
}
const onChange = (e) => {
localStorage.setItem('collapseShiftsFilterSelect', e.type);
};
$('#collapseShiftsFilterSelect')
.on('hidden.bs.collapse', onChange)
.on('shown.bs.collapse', onChange);
});

View File

@ -55,12 +55,12 @@
<div class="col-md-6"> <div class="col-md-6">
<button class="btn btn-info btn-sm hidden-print" style="margin-top: 20px; margin-bottom:10px" type="button" <button class="btn btn-info btn-sm hidden-print" style="margin-top: 20px; margin-bottom:10px" type="button"
data-toggle="collapse" data-toggle="collapse"
data-target="#collapseRoomSelect" aria-expanded="false" data-target="#collapseShiftsFilterSelect" aria-expanded="true"
aria-controls="collapseRoomSelect" aria-controls="collapseShiftsFilterSelect"
> >
collapse/show filters collapse/show filters
</button> </button>
<div class="collapse in" id="collapseRoomSelect"> <div class="collapse in" id="collapseShiftsFilterSelect">
<div class="row"> <div class="row">
<div class="col-xs-4 col-xxs-12">%room_select%</div> <div class="col-xs-4 col-xxs-12">%room_select%</div>
<div class="col-xs-4 col-xxs-12">%type_select%</div> <div class="col-xs-4 col-xxs-12">%type_select%</div>
@ -79,5 +79,5 @@
%shifts_table% %shifts_table%
<div class="hidden-print"> <div class="hidden-print">
%ical_text% %ical_text%
</div> </div>