未验证 提交 ab8e3a55 编写于 作者: P Phil Hughes

Converted notifications_form.js to axios

上级 1c8553f2
import { __ } from './locale';
import axios from './lib/utils/axios_utils';
import flash from './flash';
export default class NotificationsForm { export default class NotificationsForm {
constructor() { constructor() {
this.toggleCheckbox = this.toggleCheckbox.bind(this); this.toggleCheckbox = this.toggleCheckbox.bind(this);
...@@ -27,15 +31,10 @@ export default class NotificationsForm { ...@@ -27,15 +31,10 @@ export default class NotificationsForm {
saveEvent($checkbox, $parent) { saveEvent($checkbox, $parent) {
const form = $parent.parents('form:first'); const form = $parent.parents('form:first');
return $.ajax({
url: form.attr('action'),
method: form.attr('method'),
dataType: 'json',
data: form.serialize(),
beforeSend: () => {
this.showCheckboxLoadingSpinner($parent); this.showCheckboxLoadingSpinner($parent);
},
}).done((data) => { axios[form.attr('method')](form.attr('action'), form.serialize())
.then(({ data }) => {
$checkbox.enable(); $checkbox.enable();
if (data.saved) { if (data.saved) {
$parent.find('.custom-notification-event-loading').toggleClass('fa-spin fa-spinner fa-check is-done'); $parent.find('.custom-notification-event-loading').toggleClass('fa-spin fa-spinner fa-check is-done');
...@@ -45,6 +44,7 @@ export default class NotificationsForm { ...@@ -45,6 +44,7 @@ export default class NotificationsForm {
.toggleClass('fa-spin fa-spinner fa-check is-done'); .toggleClass('fa-spin fa-spinner fa-check is-done');
}, 2000); }, 2000);
} }
}); })
.catch(() => flash(__('There was an error saving your notification settings.')));
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册