Commit 4cea24f8 authored by Phil Hughes's avatar Phil Hughes

Converted todos.js to axios

parent 43f1088f
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import UsersSelect from '~/users_select'; import UsersSelect from '~/users_select';
import { isMetaClick } from '~/lib/utils/common_utils'; import { isMetaClick } from '~/lib/utils/common_utils';
import { __ } from '../../../../locale';
import flash from '../../../../flash';
import axios from '../../../../lib/utils/axios_utils';
export default class Todos { export default class Todos {
constructor() { constructor() {
...@@ -59,18 +62,12 @@ export default class Todos { ...@@ -59,18 +62,12 @@ export default class Todos {
const target = e.target; const target = e.target;
target.setAttribute('disabled', true); target.setAttribute('disabled', true);
target.classList.add('disabled'); target.classList.add('disabled');
$.ajax({
type: 'POST', axios[target.dataset.method](target.dataset.href)
url: target.dataset.href, .then(({ data }) => {
dataType: 'json',
data: {
'_method': target.dataset.method,
},
success: (data) => {
this.updateRowState(target); this.updateRowState(target);
return this.updateBadges(data); this.updateBadges(data);
}, }).catch(() => flash(__('Error updating todo status.')));
});
} }
updateRowState(target) { updateRowState(target) {
...@@ -98,19 +95,15 @@ export default class Todos { ...@@ -98,19 +95,15 @@ export default class Todos {
e.preventDefault(); e.preventDefault();
const target = e.currentTarget; const target = e.currentTarget;
const requestData = { '_method': target.dataset.method, ids: this.todo_ids };
target.setAttribute('disabled', true); target.setAttribute('disabled', true);
target.classList.add('disabled'); target.classList.add('disabled');
$.ajax({
type: 'POST', axios[target.dataset.method](target.dataset.href, {
url: target.dataset.href, ids: this.todo_ids,
dataType: 'json', }).then(({ data }) => {
data: requestData,
success: (data) => {
this.updateAllState(target, data); this.updateAllState(target, data);
return this.updateBadges(data); this.updateBadges(data);
}, }).catch(() => flash(__('Error updating status for all todos.')));
});
} }
updateAllState(target, data) { updateAllState(target, 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