Skip to content

Commit

Permalink
fix: handle ACP category enable/disable states after call success
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Oct 29, 2020
1 parent a6a5243 commit bff53de
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions public/src/admin/manage/categories.js
Expand Up @@ -27,11 +27,6 @@ define('admin/manage/categories', [
return $(this).attr('data-cid');
}).get();

parentEl.toggleClass('disabled', !disabled);
childrenEls.toggleClass('disabled', !disabled);
$this.translateText(!disabled ? '[[admin/manage/categories:enable]]' : '[[admin/manage/categories:disable]]');
childrenEls.find('li a[data-action="toggle"]').translateText(!disabled ? '[[admin/manage/categories:enable]]' : '[[admin/manage/categories:disable]]');

Categories.toggle([cid].concat(childrenCids), !disabled);
});

Expand Down Expand Up @@ -196,8 +191,13 @@ define('admin/manage/categories', [
};

Categories.toggle = function (cids, disabled) {
const listEl = document.querySelector('.categories ul');
Promise.all(cids.map(cid => api.put('/categories/' + cid, {
disabled: disabled ? 1 : 0,
}).then(() => {
const categoryEl = listEl.querySelector(`li[data-cid="${cid}"]`);
categoryEl.classList[disabled ? 'add' : 'remove']('disabled');
$(categoryEl).find('li a[data-action="toggle"]').first().translateText(disabled ? '[[admin/manage/categories:enable]]' : '[[admin/manage/categories:disable]]');
})));
};

Expand Down

0 comments on commit bff53de

Please sign in to comment.