Skip to content

Commit badaf8b

Browse files
committed
fix #309: JS error when using sortable inlines w/o sortable list view
1 parent 7d0b661 commit badaf8b

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

client/admin-sortable2.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,17 @@ import Sortable, { MultiDrag, SortableEvent } from 'sortablejs';
22

33
Sortable.mount(new MultiDrag());
44

5-
class SortableBase {
6-
protected readonly config: any;
7-
8-
constructor() {
9-
this.config = JSON.parse(document.getElementById('admin_sortable2_config')?.textContent ?? '');
10-
}
11-
}
12-
13-
14-
class ListSortable extends SortableBase {
5+
class ListSortable {
156
private readonly tableBody: HTMLTableSectionElement;
7+
private readonly config: any;
168
private readonly sortable: Sortable;
179
private readonly observer: MutationObserver;
1810
private firstOrder: number | undefined;
1911
private orderDirection: number | undefined;
2012

21-
constructor(table: HTMLTableElement) {
22-
super();
13+
constructor(table: HTMLTableElement, config: any) {
2314
this.tableBody = table.querySelector('tbody')!;
15+
this.config = config;
2416
this.sortable = Sortable.create(this.tableBody, {
2517
animation: 150,
2618
handle: '.handle',
@@ -163,15 +155,16 @@ class ListSortable extends SortableBase {
163155
}
164156

165157

166-
class ActionForm extends SortableBase {
158+
class ActionForm {
167159
private readonly selectElement: HTMLSelectElement;
160+
private readonly config: any;
168161
private readonly stepInput: HTMLInputElement;
169162
private readonly pageInput: HTMLInputElement;
170163

171-
constructor(formElement: HTMLElement) {
172-
super();
164+
constructor(formElement: HTMLElement, config: any) {
173165
formElement.setAttribute('novalidate', 'novalidate');
174166
this.selectElement = formElement.querySelector('select[name="action"]')!;
167+
this.config = config;
175168
this.selectElement.addEventListener('change', () => this.actionChanged());
176169

177170
this.stepInput = document.getElementById('changelist-form-step') as HTMLInputElement;
@@ -258,14 +251,19 @@ class InlineSortable {
258251

259252

260253
window.addEventListener('load', (event) => {
261-
const table = document.getElementById('result_list');
262-
if (table instanceof HTMLTableElement) {
263-
new ListSortable(table);
264-
}
254+
const configElem = document.getElementById('admin_sortable2_config');
255+
if (configElem instanceof HTMLScriptElement && configElem.textContent) {
256+
const adminSortableConfig = JSON.parse(configElem.textContent);
257+
258+
const table = document.getElementById('result_list');
259+
if (table instanceof HTMLTableElement) {
260+
new ListSortable(table, adminSortableConfig);
261+
}
265262

266-
const changelistForm = document.getElementById('changelist-form');
267-
if (changelistForm) {
268-
new ActionForm(changelistForm);
263+
const changelistForm = document.getElementById('changelist-form');
264+
if (changelistForm) {
265+
new ActionForm(changelistForm, adminSortableConfig);
266+
}
269267
}
270268

271269
for (let inlineFieldSet of document.querySelectorAll('fieldset.sortable')) {

0 commit comments

Comments
 (0)