import { computed } from '@ember/object'; import { alias } from '@ember/object/computed'; import BasicComponent from './basic-component'; export default BasicComponent.extend({ 'col-width': 6, colWidth: alias('col-width'), classNameBindings: ['hasError:has-error'], model: alias('route.controller.model'), errors: alias('route.controller.errors'), hasError: computed('errors', function() { return this.get('errors.' + this.get('name')); }), 'error-msg': true, errorMsg: alias('error-msg'), 'label-class': 'col-xs-12 col-sm-3 col-md-3', labelClass: alias('label-class'), 'input-class': 'col-xs-12 col-sm-5 col-md-5', inputClass: alias('input-class'), 'data-scope': 'model', dataScope: alias('data-scope'), didReceiveAttrs() { let me = this; me._super(...arguments); let dataScope = me.get('data-scope'); if ('controller' === dataScope) { me.set('dataModel', me.get('route.controller')); } else if ('route' === dataScope) { me.set('dataModel', me.get('route')); } else { me.set('dataModel', me.get('model')); } }, getVal() { return this.get('dataModel.' + this.get('name')); }, setVal(val) { this.set('dataModel.' + this.get('name'), val); } });