Commit edba6ee3 authored by Fatih Acet's avatar Fatih Acet

Toggle individual task list group while requesting

parent 968e35a6
...@@ -10,6 +10,7 @@ export default class TaskList { ...@@ -10,6 +10,7 @@ export default class TaskList {
this.fieldName = options.fieldName; this.fieldName = options.fieldName;
this.lockVersion = options.lockVersion; this.lockVersion = options.lockVersion;
this.onSuccess = options.onSuccess || (() => {}); this.onSuccess = options.onSuccess || (() => {});
this.taskListContainerSelector = `${this.selector} .js-task-list-container`;
this.onError = this.onError =
options.onError || options.onError ||
function showFlash(e) { function showFlash(e) {
...@@ -28,25 +29,31 @@ export default class TaskList { ...@@ -28,25 +29,31 @@ export default class TaskList {
init() { init() {
// Prevent duplicate event bindings // Prevent duplicate event bindings
this.disable(); this.disable();
$(`${this.selector} .js-task-list-container`).taskList('enable'); $(this.taskListContainerSelector).taskList('enable');
$(document).on( $(document).on(
'tasklist:changed', 'tasklist:changed',
`${this.selector} .js-task-list-container`, this.taskListContainerSelector,
this.update.bind(this), this.update.bind(this),
); );
} }
disableTaskListItems() { getTaskListTarget(e = {}) {
$(`${this.selector} .js-task-list-container`).taskList('disable'); const $currentTarget = $(e.currentTarget);
return $currentTarget.taskList ? $currentTarget : $(this.taskListContainerSelector);
}
disableTaskListItems(e) {
this.getTaskListTarget(e).taskList('disable');
} }
enableTaskListItems() { enableTaskListItems(e) {
$(`${this.selector} .js-task-list-container`).taskList('enable'); this.getTaskListTarget(e).taskList('enable');
} }
disable() { disable() {
this.disableTaskListItems(); this.disableTaskListItems();
$(document).off('tasklist:changed', `${this.selector} .js-task-list-container`); $(document).off('tasklist:changed', this.taskListContainerSelector);
} }
update(e) { update(e) {
...@@ -65,18 +72,18 @@ export default class TaskList { ...@@ -65,18 +72,18 @@ export default class TaskList {
}, },
}; };
this.disableTaskListItems(); this.disableTaskListItems(e);
return axios return axios
.patch($target.data('updateUrl') || $('form.js-issuable-update').attr('action'), patchData) .patch($target.data('updateUrl') || $('form.js-issuable-update').attr('action'), patchData)
.then(({ data }) => { .then(({ data }) => {
this.lockVersion = data.lock_version; this.lockVersion = data.lock_version;
this.enableTaskListItems(); this.enableTaskListItems(e);
return this.onSuccess(data); return this.onSuccess(data);
}) })
.catch(({ response }) => { .catch(({ response }) => {
this.enableTaskListItems(); this.enableTaskListItems(e);
return this.onError(response.data); return this.onError(response.data);
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment