You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/ui-v2/app/services/feedback.js

36 lines
949 B

import Service from '@ember/service';
import { inject as service } from '@ember/service';
import { get } from '@ember/object';
export default Service.extend({
// TODO: Why can't I name this `notify`?
flashMessages: service('flashMessages'),
execute: function(handle, success, error) {
const controller = this.controller;
controller.set('isLoading', true);
return handle()
.then(() => {
get(this, 'flashMessages').add({
type: 'success',
message: success,
});
})
.catch(e => {
if (e.name === 'TransitionAborted') {
get(this, 'flashMessages').add({
type: 'success',
message: success,
});
} else {
get(this, 'flashMessages').add({
type: 'error',
message: error,
});
}
})
.finally(function() {
controller.set('isLoading', false);
});
},
});