open-vault/ui/app/components/message-error.js

37 lines
901 B
JavaScript
Raw Normal View History

import { computed } from '@ember/object';
import Component from '@ember/component';
2018-04-03 14:16:57 +00:00
export default Component.extend({
2018-04-03 14:16:57 +00:00
model: null,
errors: computed(function() {
return [];
}),
2018-04-03 14:16:57 +00:00
errorMessage: null,
displayErrors: computed(
2018-04-03 14:16:57 +00:00
'errorMessage',
'model.{isError,adapterError.message,adapterError.errors.@each}',
2018-04-03 14:16:57 +00:00
'errors',
'errors.@each',
function() {
const errorMessage = this.get('errorMessage');
const errors = this.get('errors');
const modelIsError = this.get('model.isError');
if (errorMessage) {
return [errorMessage];
}
if (errors && errors.length > 0) {
return errors;
}
if (modelIsError) {
if (this.get('model.adapterError.errors.length') > 0) {
return this.get('model.adapterError.errors');
}
return [this.get('model.adapterError.message')];
2018-04-03 14:16:57 +00:00
}
}
),
});