mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
3d6856614f
no issue - add ember-suave dependency - upgrade grunt-jscs dependency - add a new .jscsrc for the client's tests directory that extends from client's base .jscsrc - separate client tests in Gruntfile jscs task so they pick up the test's .jscsrc - standardize es6 usage across client
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
import Ember from 'ember';
|
|
|
|
const {Component, computed, isEmpty} = Ember;
|
|
|
|
/**
|
|
* 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: computed.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;
|
|
}
|
|
})
|
|
});
|