2018-05-22 15:03:45 +00:00
|
|
|
import Mixin from '@ember/object/mixin';
|
2018-08-29 18:14:31 +00:00
|
|
|
import WithBlockingActions from 'consul-ui/mixins/with-blocking-actions';
|
2020-04-16 14:15:45 +00:00
|
|
|
import { get } from '@ember/object';
|
2018-05-22 15:03:45 +00:00
|
|
|
|
2018-06-12 13:09:47 +00:00
|
|
|
import { INTERNAL_SERVER_ERROR as HTTP_INTERNAL_SERVER_ERROR } from 'consul-ui/utils/http/status';
|
2018-08-29 18:14:31 +00:00
|
|
|
export default Mixin.create(WithBlockingActions, {
|
|
|
|
errorCreate: function(type, e) {
|
2018-09-12 19:41:43 +00:00
|
|
|
if (e && e.errors && e.errors[0]) {
|
2018-08-29 18:14:31 +00:00
|
|
|
const error = e.errors[0];
|
|
|
|
if (parseInt(error.status) === HTTP_INTERNAL_SERVER_ERROR) {
|
|
|
|
if (error.detail.indexOf('duplicate intention found:') === 0) {
|
|
|
|
return 'exists';
|
2018-06-12 13:09:47 +00:00
|
|
|
}
|
2018-08-29 18:14:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return type;
|
2018-05-22 15:03:45 +00:00
|
|
|
},
|
2020-04-16 14:15:45 +00:00
|
|
|
afterUpdate: function(item) {
|
|
|
|
if (get(this, 'history.length') > 0) {
|
|
|
|
return this.transitionTo(this.history[0].key, this.history[0].value);
|
|
|
|
}
|
|
|
|
return this._super(...arguments);
|
|
|
|
},
|
|
|
|
afterCreate: function(item) {
|
|
|
|
if (get(this, 'history.length') > 0) {
|
|
|
|
return this.transitionTo(this.history[0].key, this.history[0].value);
|
|
|
|
}
|
|
|
|
return this._super(...arguments);
|
|
|
|
},
|
|
|
|
afterDelete: function(item) {
|
|
|
|
if (get(this, 'history.length') > 0) {
|
|
|
|
return this.transitionTo(this.history[0].key, this.history[0].value);
|
|
|
|
}
|
|
|
|
if (this.routeName === 'dc.services.show') {
|
|
|
|
return this.transitionTo(this.routeName, this._router.currentRoute.params.name);
|
|
|
|
}
|
|
|
|
return this._super(...arguments);
|
|
|
|
},
|
2018-05-22 15:03:45 +00:00
|
|
|
});
|