mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-27 06:01:54 +03:00
Upgraded app to Laravel 5.7
This commit is contained in:
45
resources/js/components/list-sort-control.js
Normal file
45
resources/js/components/list-sort-control.js
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* ListSortControl
|
||||
* Manages the logic for the control which provides list sorting options.
|
||||
*/
|
||||
class ListSortControl {
|
||||
|
||||
constructor(elem) {
|
||||
this.elem = elem;
|
||||
this.menu = elem.querySelector('ul');
|
||||
|
||||
this.sortInput = elem.querySelector('[name="sort"]');
|
||||
this.orderInput = elem.querySelector('[name="order"]');
|
||||
this.form = elem.querySelector('form');
|
||||
|
||||
this.menu.addEventListener('click', event => {
|
||||
if (event.target.closest('[data-sort-value]') !== null) {
|
||||
this.sortOptionClick(event);
|
||||
}
|
||||
});
|
||||
|
||||
this.elem.addEventListener('click', event => {
|
||||
if (event.target.closest('[data-sort-dir]') !== null) {
|
||||
this.sortDirectionClick(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
sortOptionClick(event) {
|
||||
const sortOption = event.target.closest('[data-sort-value]');
|
||||
this.sortInput.value = sortOption.getAttribute('data-sort-value');
|
||||
event.preventDefault();
|
||||
this.form.submit();
|
||||
}
|
||||
|
||||
sortDirectionClick(event) {
|
||||
const currentDir = this.orderInput.value;
|
||||
const newDir = (currentDir === 'asc') ? 'desc' : 'asc';
|
||||
this.orderInput.value = newDir;
|
||||
event.preventDefault();
|
||||
this.form.submit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ListSortControl;
|
Reference in New Issue
Block a user