Commit ab8e3a55 authored by Phil Hughes's avatar Phil Hughes

Converted notifications_form.js to axios

parent 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,24 +31,20 @@ export default class NotificationsForm { ...@@ -27,24 +31,20 @@ export default class NotificationsForm {
saveEvent($checkbox, $parent) { saveEvent($checkbox, $parent) {
const form = $parent.parents('form:first'); const form = $parent.parents('form:first');
return $.ajax({ this.showCheckboxLoadingSpinner($parent);
url: form.attr('action'),
method: form.attr('method'), axios[form.attr('method')](form.attr('action'), form.serialize())
dataType: 'json', .then(({ data }) => {
data: form.serialize(), $checkbox.enable();
beforeSend: () => { if (data.saved) {
this.showCheckboxLoadingSpinner($parent); $parent.find('.custom-notification-event-loading').toggleClass('fa-spin fa-spinner fa-check is-done');
}, setTimeout(() => {
}).done((data) => { $parent.removeClass('is-loading')
$checkbox.enable(); .find('.custom-notification-event-loading')
if (data.saved) { .toggleClass('fa-spin fa-spinner fa-check is-done');
$parent.find('.custom-notification-event-loading').toggleClass('fa-spin fa-spinner fa-check is-done'); }, 2000);
setTimeout(() => { }
$parent.removeClass('is-loading') })
.find('.custom-notification-event-loading') .catch(() => flash(__('There was an error saving your notification settings.')));
.toggleClass('fa-spin fa-spinner fa-check is-done');
}, 2000);
}
});
} }
} }
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