class UiSortableList {
protected readonly _options: SortableListOptions;
readonly #container: HTMLElement | null;
+ readonly #sortables = new Map<number, Sortable>();
/**
* Initializes the sortable list controller.
animation: 150,
swapThreshold: 0.65,
fallbackOnBody: true,
- dataIdAttr: "object-id",
+ dataIdAttr: "data-object-id",
chosenClass: "sortablePlaceholder",
ghostClass: "",
draggable: "li",
this._options.toleranceElement = undefined;
}
- new Sortable(sortableList, {
- direction: "vertical",
- ...this._options.options,
- });
+ this.#sortables.set(
+ 0,
+ new Sortable(sortableList, {
+ direction: "vertical",
+ ...this._options.options,
+ }),
+ );
} else {
this.#container.querySelectorAll(".sortableList").forEach((list: HTMLElement) => {
- new Sortable(list, {
- group: "nested",
- ...this._options.options,
- });
+ this.#sortables.set(
+ parseInt(list.dataset.objectId!, 10),
+ new Sortable(list, {
+ group: "nested",
+ ...this._options.options,
+ }),
+ );
});
}
+
+ if (this._options.className) {
+ let formSubmit = this.#container.querySelector(".formSubmit");
+ if (!formSubmit) {
+ formSubmit = this.#container.nextElementSibling;
+ }
+ if (!formSubmit) {
+ console.debug("[UiSortableList] Unable to find form submit for saving, aborting.");
+ return;
+ }
+
+ formSubmit.querySelector('button[data-type="submit"]')?.addEventListener("click", () => {
+ this.save();
+ });
+ }
+ }
+
+ public save(): void {
+ if (!this._options.className) {
+ return;
+ }
+
+ // TODO save postions and send them to server
}
}
class UiSortableList {
_options;
#container;
+ #sortables = new Map();
/**
* Initializes the sortable list controller.
*/
animation: 150,
swapThreshold: 0.65,
fallbackOnBody: true,
- dataIdAttr: "object-id",
+ dataIdAttr: "data-object-id",
chosenClass: "sortablePlaceholder",
ghostClass: "",
draggable: "li",
if (closest && sortablejs_1.default.utils.is(closest, ".sortableNoNesting")) {
return false;
}
- console.log(event.dragged);
const levelOfDraggedNode = Math.max(...Array.from(event.dragged.querySelectorAll(".sortableList")).map((list) => {
- console.log(list);
return getNestingLevel(list, event.dragged);
}));
if (getNestingLevel(event.to) + levelOfDraggedNode > this._options.maxNestingLevel) {
- console.log(`${getNestingLevel(event.to)} + ${levelOfDraggedNode} > ${this._options.maxNestingLevel}`);
return false;
}
return true;
this._options.options.draggable = "tr";
this._options.toleranceElement = undefined;
}
- new sortablejs_1.default(sortableList, {
+ this.#sortables.set(0, new sortablejs_1.default(sortableList, {
direction: "vertical",
...this._options.options,
- });
+ }));
}
else {
this.#container.querySelectorAll(".sortableList").forEach((list) => {
- new sortablejs_1.default(list, {
+ this.#sortables.set(parseInt(list.dataset.objectId, 10), new sortablejs_1.default(list, {
group: "nested",
...this._options.options,
- });
+ }));
});
}
+ if (this._options.className) {
+ let formSubmit = this.#container.querySelector(".formSubmit");
+ if (!formSubmit) {
+ formSubmit = this.#container.nextElementSibling;
+ }
+ if (!formSubmit) {
+ console.debug("[UiSortableList] Unable to find form submit for saving, aborting.");
+ return;
+ }
+ formSubmit.querySelector('button[data-type="submit"]')?.addEventListener("click", () => {
+ this.save();
+ });
+ }
+ }
+ save() {
+ if (!this._options.className) {
+ return;
+ }
+ // TODO save postions and send them to server
}
}
return UiSortableList;