Skip to content

Commit 3f085e0

Browse files
committed
fix: added missing fix on object, closes #2095
1 parent 4f39024 commit 3f085e0

File tree

2 files changed

+56
-63
lines changed

2 files changed

+56
-63
lines changed

phpmyfaq/admin/assets/src/content/category.js

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import Sortable from 'sortablejs';
1717
import { addElement } from '../../../../assets/src/utils';
1818

1919
export const handleCategories = () => {
20-
console.log('handleCategories');
21-
2220
const listGroupItems = document.querySelectorAll('.list-group-item');
2321
const sortableCategories = document.querySelector('.list-group.list-group-root');
2422

@@ -32,61 +30,63 @@ export const handleCategories = () => {
3230
});
3331
});
3432

35-
const sortable = Sortable.create(sortableCategories, {
36-
animation: 150,
37-
dataIdAttr: 'data-id',
38-
filter: '.pmf-category-not-sortable',
39-
group: 'pmf-category-order',
40-
store: {
41-
/**
42-
* Get the order of elements. Called once during initialization.
43-
* @param {Sortable} sortable
44-
* @returns {Array}
45-
*/
46-
get: (sortable) => {
47-
const order = localStorage.getItem(sortable.options.group.name);
48-
return order ? order.split('|') : [];
49-
},
33+
if (sortableCategories) {
34+
const sortable = Sortable.create(sortableCategories, {
35+
animation: 150,
36+
dataIdAttr: 'data-id',
37+
filter: '.pmf-category-not-sortable',
38+
group: 'pmf-category-order',
39+
store: {
40+
/**
41+
* Get the order of elements. Called once during initialization.
42+
* @param {Sortable} sortable
43+
* @returns {Array}
44+
*/
45+
get: (sortable) => {
46+
const order = localStorage.getItem(sortable.options.group.name);
47+
return order ? order.split('|') : [];
48+
},
5049

51-
/**
52-
* Save the order of elements. Called onEnd (when the item is dropped).
53-
* @param {Sortable} sortable
54-
*/
55-
set: (sortable) => {
56-
const order = sortable.toArray();
57-
const csrf = document.querySelector('input[name=csrf]').value;
58-
localStorage.setItem(sortable.options.group.name, order.join('|'));
50+
/**
51+
* Save the order of elements. Called onEnd (when the item is dropped).
52+
* @param {Sortable} sortable
53+
*/
54+
set: (sortable) => {
55+
const order = sortable.toArray();
56+
const csrf = document.querySelector('input[name=csrf]').value;
57+
localStorage.setItem(sortable.options.group.name, order.join('|'));
5958

60-
fetch('index.php?action=ajax&ajax=categories&ajaxaction=update-order', {
61-
method: 'POST',
62-
headers: {
63-
Accept: 'application/json, text/plain, */*',
64-
'Content-Type': 'application/json',
65-
},
66-
body: JSON.stringify({
67-
csrf: csrf,
68-
order: order,
69-
}),
70-
})
71-
.then(async (response) => {
72-
if (response.status === 200) {
73-
return response.json();
74-
}
75-
throw new Error('Network response was not ok.');
76-
})
77-
.then((response) => {
78-
sortableCategories.insertAdjacentElement(
79-
'beforebegin',
80-
addElement('div', { classList: 'alert alert-success', innerText: response.success })
81-
);
59+
fetch('index.php?action=ajax&ajax=categories&ajaxaction=update-order', {
60+
method: 'POST',
61+
headers: {
62+
Accept: 'application/json, text/plain, */*',
63+
'Content-Type': 'application/json',
64+
},
65+
body: JSON.stringify({
66+
csrf: csrf,
67+
order: order,
68+
}),
8269
})
83-
.catch((error) => {
84-
sortableCategories.insertAdjacentElement(
85-
'beforebegin',
86-
addElement('div', { classList: 'alert alert-danger', innerText: error })
87-
);
88-
});
70+
.then(async (response) => {
71+
if (response.status === 200) {
72+
return response.json();
73+
}
74+
throw new Error('Network response was not ok.');
75+
})
76+
.then((response) => {
77+
sortableCategories.insertAdjacentElement(
78+
'beforebegin',
79+
addElement('div', { classList: 'alert alert-success', innerText: response.success })
80+
);
81+
})
82+
.catch((error) => {
83+
sortableCategories.insertAdjacentElement(
84+
'beforebegin',
85+
addElement('div', { classList: 'alert alert-danger', innerText: error })
86+
);
87+
});
88+
},
8989
},
90-
},
91-
});
90+
});
91+
}
9292
};

yarn.lock

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,14 +2907,7 @@ jest-worker@^27.4.1:
29072907
merge-stream "^2.0.0"
29082908
supports-color "^8.0.0"
29092909

2910-
jquery-ui@^1.13.1:
2911-
version "1.13.1"
2912-
resolved "https://registry.yarnpkg.com/jquery-ui/-/jquery-ui-1.13.1.tgz#d0b7a42e73a04c31bb5706adf86f6f8942f64eaa"
2913-
integrity sha512-2VlU59N5P4HaumDK1Z3XEVjSvegFbEOQRgpHUBaB2Ak98Axl3hFhJ6RFcNQNuk9SfL6WxIbuLst8dW/U56NSiA==
2914-
dependencies:
2915-
jquery ">=1.8.0 <4.0.0"
2916-
2917-
"jquery@>=1.7.1 <4.0.0", "jquery@>=1.8.0 <4.0.0", jquery@^3.4.1:
2910+
"jquery@>=1.7.1 <4.0.0", jquery@^3.4.1:
29182911
version "3.6.0"
29192912
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.6.0.tgz#c72a09f15c1bdce142f49dbf1170bdf8adac2470"
29202913
integrity sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==

0 commit comments

Comments
 (0)