Ghost/ghost/admin/app/components/gh-error-message.js
Kevin Ansfield 983110d931 Switched from ember-cli-shims to new module imports (#779)
no issue

- add eslint-plugin-ember, configure no-old-shims rule
- run `eslint --fix` on `app`, `lib`, `mirage`, and `tests` to move imports to the new module imports
- further cleanup of Ember globals usage
- remove event-dispatcher initializer now that `canDispatchToEventManager` is deprecated
2017-08-22 14:53:26 +07:00

38 lines
1.1 KiB
JavaScript

import Component from '@ember/component';
import {computed} from '@ember/object';
import {isEmpty} from '@ember/utils';
import {notEmpty} from '@ember/object/computed';
/**
* Renders one random error message when passed a DS.Errors object
* and a property name. The message will be one of the ones associated with
* that specific property. If there are no errors associated with the property,
* nothing will be rendered.
* @param {DS.Errors} errors The DS.Errors object
* @param {string} property The property name
*/
export default Component.extend({
tagName: 'p',
classNames: ['response'],
errors: null,
property: '',
isVisible: notEmpty('errors'),
message: computed('errors.[]', 'property', function () {
let property = this.get('property');
let errors = this.get('errors');
let messages = [];
let index;
if (!isEmpty(errors) && errors.get(property)) {
errors.get(property).forEach((error) => {
messages.push(error);
});
index = Math.floor(Math.random() * messages.length);
return messages[index].message;
}
})
});