0
0
Fork 0
mirror of https://github.com/kevinpapst/kimai2.git synced 2025-04-30 15:30:11 +00:00
kevinpapst_kimai2/assets/js/plugins/KimaiSortable.js
2025-03-12 16:45:05 +01:00

51 lines
1.1 KiB
JavaScript

/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*!
* [KIMAI] KimaiSortable: allow sorting of HTML elements
*/
import KimaiPlugin from "../KimaiPlugin";
import Sortable from 'sortablejs';
export default class KimaiSortable extends KimaiPlugin {
getId() {
return 'sortable';
}
/**
* Enable sorting on the given selector
*
* @param {HTMLElement} element
* @returns {true}
*/
toggle(element) {
if (!element instanceof HTMLElement) {
console.error('Given element is invalid');
return false;
}
let sortable = Sortable.get(element);
if (sortable === undefined || sortable === null) {
Sortable.create(element);
return true;
}
sortable.destroy();
return false;
}
toArray(element) {
let sortable = Sortable.get(element);
if (sortable === undefined || sortable === null) {
return null;
}
return sortable.toArray();
}
}