diff --git a/app/components/create-options-datetime.js b/app/components/create-options-datetime.js index b3f0b0ff1..e1d5c5325 100644 --- a/app/components/create-options-datetime.js +++ b/app/components/create-options-datetime.js @@ -2,16 +2,14 @@ import { inject as service } from '@ember/service'; import { readOnly, mapBy, filter } from '@ember/object/computed'; import Component from '@ember/component'; import { isPresent, isEmpty } from '@ember/utils'; -import { observer, computed, get } from '@ember/object'; +import { observer, get } from '@ember/object'; import { validator, buildValidations } from 'ember-cp-validations'; import { raw } from 'ember-awesome-macros'; import { groupBy } from 'ember-awesome-macros/array'; -import { next, scheduleOnce } from '@ember/runloop'; -import BsForm from 'ember-bootstrap/components/bs-form'; -import BsFormElement from 'ember-bootstrap/components/bs-form/element'; +import { next } from '@ember/runloop'; let modelValidations = buildValidations({ dates: [ @@ -101,10 +99,6 @@ export default Component.extend(modelValidations, { } }); } - - next(() => { - this.notifyPropertyChange('_nestedChildViews'); - }); }); }, @@ -153,73 +147,5 @@ export default Component.extend(modelValidations, { groupedDates: groupBy('dates', raw('day')), - childFormElements: computed('_nestedChildViews', function() { - let form = this.childViews.find((childView) => { - return childView instanceof BsForm; - }); - - if (!form) { - return []; - } - - return form.childViews.filter((childView) => { - return childView instanceof BsFormElement; - }); - }), - - // Can't use a computed property cause Ember Bootstrap seem to modify validation twice in a single render. - // Therefor we use the scheduleOnce trick. - // This is the same for {{create-options-text}} component. - daysValidationState: null, - updateDaysValidationState: observer('childFormElements.@each.validation', function() { - scheduleOnce('sync', () => { - this.set('daysValidationState', - this.childFormElements.reduce(function(daysValidationState, item) { - const day = item.get('model.day'); - const validation = item.get('validation'); - let currentValidationState; - - // there maybe form elements without model or validation - if (isEmpty(day) || validation === undefined) { - return daysValidationState; - } - - // if it's not existing initialize with current value - if (!daysValidationState.hasOwnProperty(day)) { - daysValidationState[day] = validation; - return daysValidationState; - } - - currentValidationState = daysValidationState[day]; - switch (currentValidationState) { - // error overrules all validation states - case 'error': - break; - - // null ist overruled by 'error' - case null: - if (validation === 'error') { - daysValidationState[day] = 'error'; - } - break; - - // success is overruled by anyother validation state - case 'success': - daysValidationState[day] = validation; - break; - } - - return daysValidationState; - }, {}) - ); - }); - }).on('init'), - store: service(), - - didInsertElement() { - // childViews is not observeable by default. Need to notify about a change manually. - // Lucky enough we know that child views will only be changed on init and if times are added / removed. - this.notifyPropertyChange('_nestedChildViews'); - } }); diff --git a/app/components/create-options-text.js b/app/components/create-options-text.js index 62a56e18f..2f50e1781 100644 --- a/app/components/create-options-text.js +++ b/app/components/create-options-text.js @@ -1,9 +1,6 @@ import { inject as service } from '@ember/service'; import Component from '@ember/component'; -import { observer, computed, get } from '@ember/object'; -import { run, next } from '@ember/runloop'; -import BsFormElement from 'ember-bootstrap/components/bs-form/element'; -import { any } from 'ember-awesome-macros/array'; +import { observer } from '@ember/object'; export default Component.extend({ actions: { @@ -15,76 +12,13 @@ export default Component.extend({ position, fragment ); - - next(() => { - this.notifyPropertyChange('_childViews'); - }); }, deleteOption(element) { let position = this.options.indexOf(element); this.options.removeAt(position); - - next(() => { - this.notifyPropertyChange('_childViews'); - }); } }, - anyElementHasFeedback: any('childFormElements.@each.hasFeedback', function(childFormElement) { - return get(childFormElement, 'hasFeedback'); - }), - - anyElementIsInvalid: any('childFormElements.@each.validation', function(childFormElement) { - return get(childFormElement, 'validation') === 'error'; - }), - - everyElementIsValid: computed('childFormElements.@each.validation', function() { - const anyElementIsInvalid = this.anyElementIsInvalid; - if (anyElementIsInvalid) { - return false; - } - - // childFormElements contains button wrapper element which should not be taken into account here - const childFormElements = this.childFormElements.filterBy('hasValidator'); - if (childFormElements) { - return childFormElements.every((childFormElement) => { - return childFormElement.get('hasFeedback') && childFormElement.get('validation') === 'success'; - }); - } else { - return false; - } - }), - - childFormElements: computed('_childViews', function() { - return this.childViews.filter((childView) => { - return childView instanceof BsFormElement; - }); - }), - - // Can't use a computed property cause Ember Bootstrap seem to modify validation twice in a single render. - // Therefor we use the scheduleOnce trick. - // This is the same for {{create-options-datetime}} component. - labelValidationClass: 'label-has-no-validation', - updateLabelValidationClass: observer('anyElementHasFeedback', 'anyElementIsInvalid', 'everyElementIsValid', function() { - run.scheduleOnce('sync', () => { - let validationClass; - - if (!this.anyElementHasFeedback) { - validationClass = 'label-has-no-validation'; - } else if (this.anyElementIsInvalid) { - validationClass = 'label-has-error'; - } else if (this.everyElementIsValid) { - validationClass = 'label-has-success'; - } else { - validationClass = 'label-has-no-validation'; - } - - this.set('labelValidationClass', validationClass); - }); - }).on('init'), - - classNameBindings: ['labelValidationClass'], - enforceMinimalOptionsAmount: observer('options', 'isMakeAPoll', function() { if (this.get('options.length') < 2) { let options = this.options; @@ -97,11 +31,4 @@ export default Component.extend({ }).on('init'), store: service('store'), - - didInsertElement() { - // childViews is not observeable by default. Need to notify about a change manually. - // Lucky enough we know that child views will only be changed on init and if times are added / removed. - // Use a custom variable to avoid any complications with framework. - this.notifyPropertyChange('_childViews'); - } }); diff --git a/app/components/form-navigation-buttons.js b/app/components/form-navigation-buttons.js index ada93f55d..6e196f20a 100644 --- a/app/components/form-navigation-buttons.js +++ b/app/components/form-navigation-buttons.js @@ -41,9 +41,9 @@ export default Component.extend({ let renderPrevButton = this.renderPrevButton; if (renderPrevButton) { - return ['col-xs-6', 'col-md-8']; + return ['col-6', 'col-md-8']; } else { - return ['col-md-8', 'col-md-offset-4']; + return ['col-md-8', 'offset-md-4']; } }), diff --git a/app/index.html b/app/index.html index df5e9af55..8aa9049c1 100644 --- a/app/index.html +++ b/app/index.html @@ -24,18 +24,18 @@ {{content-for "body-footer"}}