diff --git a/app/components/fm-checkbox.js b/app/components/fm-checkbox.js
index 070514b..bccc119 100644
--- a/app/components/fm-checkbox.js
+++ b/app/components/fm-checkbox.js
@@ -9,4 +9,8 @@ export default FmCheckboxComponent.reopen({
return this.fmconfig.errorClass;
}
}),
+
+ fieldWrapperClass: Ember.computed(function() {
+ return this.fmconfig.fieldWrapperClass;
+ })
});
diff --git a/app/controllers/create/options.js b/app/controllers/create/options.js
index 25ad4f4..843071a 100644
--- a/app/controllers/create/options.js
+++ b/app/controllers/create/options.js
@@ -26,6 +26,9 @@ var Validations = buildValidations({
message: Ember.I18n.t('create.options.error.notEnoughOptions')
}),
validator('valid-collection', {
+ active() {
+ return this.get('model.isMakeAPoll');
+ },
dependentKeys: ['optionsTexts.@each.value']
})
],
diff --git a/app/controllers/create/settings.js b/app/controllers/create/settings.js
index d379f88..26f19a3 100644
--- a/app/controllers/create/settings.js
+++ b/app/controllers/create/settings.js
@@ -1,40 +1,38 @@
import Ember from "ember";
-import EmberValidations from 'ember-validations';
+import {
+ validator, buildValidations
+}
+from 'ember-cp-validations';
/* global moment */
-export default Ember.Controller.extend(EmberValidations.Mixin, {
- actions: {
- save: function(){
- // check if answer type is selected
- if (this.get('model.answerType') === null) {
- return;
- }
+var Validations = buildValidations({
+ anonymousUser: validator('presence', true),
+ answerType: [
+ validator('presence', true),
+ validator('inclusion', {
+ in: ['YesNo', 'YesNoMaybe', 'FreeText']
+ })
+ ],
+ forceAnswer: validator('presence', true)
+});
- // save poll
- var self = this;
- this.get('model').save().then(function(model){
- // reload as workaround for bug: duplicated records after save
- model.reload().then(function(model){
- // redirect to new poll
- self.get('target').send('transitionToPoll', model);
- });
- });
- },
-
+export default Ember.Controller.extend(Validations, {
+ actions: {
submit: function(){
- var self = this;
- this.validate().then(function() {
- self.send('save');
- }).catch(function(){
- Ember.$.each(Ember.View.views, function(id, view) {
- if(view.isEasyForm) {
- view.focusOut();
- }
+ // save poll
+ this.get('model').save().then((model) => {
+ // reload as workaround for bug: duplicated records after save
+ model.reload().then((model) => {
+ // redirect to new poll
+ this.get('target').send('transitionToPoll', model);
});
});
}
},
+ anonymousUser: Ember.computed.alias('model.anonymousUser'),
+ answerType: Ember.computed.alias('model.answerType'),
+
answerTypes: function() {
return [
Ember.Object.extend(Ember.I18n.TranslateableProperties, {}).create({
@@ -113,6 +111,8 @@ export default Ember.Controller.extend(EmberValidations.Mixin, {
];
}.property(),
+ forceAnswer: Ember.computed.alias('model.forceAnswer'),
+
/*
* set answers depending on selected answer type
*/
@@ -134,7 +134,7 @@ export default Ember.Controller.extend(EmberValidations.Mixin, {
updateExpirationDate: function() {
var expirationDuration = this.get('expirationDuration');
-
+
if(Ember.isEmpty(expirationDuration)) {
this.set('model.expirationDate', '');
}
@@ -145,20 +145,5 @@ export default Ember.Controller.extend(EmberValidations.Mixin, {
).toISOString()
);
}
- }.observes('expirationDuration'),
-
- validations: {
- 'model.anonymousUser': {
- presence: true
- },
- 'model.answerType': {
- presence: true,
- inclusion: {
- in: ["YesNo", "YesNoMaybe", "FreeText"]
- }
- },
- 'model.forceAnswer': {
- presence: true
- }
- }
+ }.observes('expirationDuration')
});
diff --git a/app/initializers/ember-easyForm.js b/app/initializers/ember-easyForm.js
deleted file mode 100644
index 751767c..0000000
--- a/app/initializers/ember-easyForm.js
+++ /dev/null
@@ -1,73 +0,0 @@
-import Ember from "ember";
-
-/*
- * make ember-easyForm support Bootstrap 3
- * https://github.com/dockyard/ember-easyForm/wiki/Bootstrap-3-and-Ember-Data-With-Server-Side-Validations
- */
-export default {
- name: 'easyForm',
- initialize: function() {
-
- Ember.EasyForm.Input.reopen({
- classNameBindings: ['wrapperConfig.inputClass', 'wrapperErrorClass'],
- isCheckbox: function() {
- if (this.get('inputOptionsValues.as') === 'checkbox') {
- return true;
- }
- else {
- return false;
- }
- }.property('inputOptionsValues'),
- divWrapperClass: function() {
- if (this.get('inputOptionsValues.as') === 'checkbox') {
- return 'checkbox';
- }
- else {
- return '';
- }
- }.property('inputOptionsValues'),
-
- isEasyForm: true
- });
-
- Ember.EasyForm.Error.reopen({
- errorText: function() {
- return this.get('errors.firstObject');
- }.property('errors.firstObject').cacheable(),
- updateParentView: function() {
- var parentView = this.get('parentView');
- if(this.get('errors.length') > 0) {
- parentView.set('wrapperErrorClass', 'has-error');
- }else{
- parentView.set('wrapperErrorClass', false);
- }
- }.observes('errors.firstObject')
- });
-
- Ember.EasyForm.Submit.reopen({
- disabled: function() {
- return this.get('formForModel.disableSubmit');
- }.property('formForModel.disableSubmit')
- });
-
- //-- Bootstrap 3 Class Names --------------------------------------------
- //-- https://github.com/dockyard/ember-easyForm/issues/47
- Ember.TextSupport.reopen({
- classNames: ['form-control']
- });
- // And add the same classes to Select inputs
- Ember.Select.reopen({
- classNames: ['form-control']
- });
-
- Ember.EasyForm.Config.registerWrapper('default', {
- inputTemplate: 'form-fields/input',
-
- labelClass: 'control-label',
- inputClass: 'form-group',
- buttonClass: 'btn btn-primary',
- fieldErrorClass: 'has-error',
- errorClass: 'help-block'
- });
- }
-};
\ No newline at end of file
diff --git a/app/templates/components/ember-form-master-2000/fm-checkbox.hbs b/app/templates/components/ember-form-master-2000/fm-checkbox.hbs
new file mode 100644
index 0000000..5889c2a
--- /dev/null
+++ b/app/templates/components/ember-form-master-2000/fm-checkbox.hbs
@@ -0,0 +1,20 @@
+
+
+
+
+
+ {{#if errors}}
+ {{#if shouldShowErrors}}
+ {{fm-errortext errors=errors}}
+ {{/if}}
+ {{/if}}
+
+
diff --git a/app/templates/components/fm-input-group.hbs b/app/templates/components/fm-input-group.hbs
index c255278..726741c 100644
--- a/app/templates/components/fm-input-group.hbs
+++ b/app/templates/components/fm-input-group.hbs
@@ -11,6 +11,7 @@
{{fm-input
+ class='form-control'
step=step
type=type
value=element.value
diff --git a/app/templates/create/options.hbs b/app/templates/create/options.hbs
index f88ad93..8641462 100644
--- a/app/templates/create/options.hbs
+++ b/app/templates/create/options.hbs
@@ -21,28 +21,45 @@
{{else}}
-
- {{bootstrap-datepicker-inline
- value=optionsBootstrapDatepicker
- multidate=true
- calendarWeeks=true
- todayHighlight=true
- language=language.selected}}
-
+ {{#fm-form
+ action='submit'
+ isValid=validations.isValid
+ }}
+
+
+ {{fm-checkbox
+ checked=model.isDateTime
+ label=(t 'create.options.defineTimes.label')
+ fieldWrapperClass='col-sm-10 col-sm-offset-2'
}}
- {{/form-wrapper}}
-
-
+ {{#fm-submit
+ fieldWrapperClass='col-sm-10 col-sm-offset-2'
+ }}
+ {{t 'create.next'}}
+ {{/fm-submit}}
+ {{/fm-form}}
{{/if}}
diff --git a/app/templates/create/settings.hbs b/app/templates/create/settings.hbs
index 0a2de0f..53aa700 100644
--- a/app/templates/create/settings.hbs
+++ b/app/templates/create/settings.hbs
@@ -1,29 +1,43 @@
- {{#form-wrapper}}
- {{input model.answerType as='select'
- collection="answerTypes"
- value="model.answerType"
- optionValuePath="content.id"
- optionLabelPath="content.label"
- labelTranslation="create.settings.answerType.label"
+ {{#fm-form action='submit'}}
+ {{fm-field
+ type='select'
+ content=answerTypes
+ value=answerType
+ optionValuePath='content.id'
+ optionLabelPath='content.label'
+ label=(t 'create.settings.answerType.label')
+ errors=validations.attrs.answerType.messages
+ class='answer-type'
}}
-
- {{input expirationDuration as='select'
- collection="expirationDurations"
- value="expirationDuration"
- optionValuePath="content.id"
- optionLabelPath="content.label"
- labelTranslation="create.settings.expirationDate.label"
+ {{fm-field
+ type='select'
+ content=expirationDurations
+ value=expirationDuration
+ optionValuePath='content.id'
+ optionLabelPath='content.label'
+ label=(t 'create.settings.expirationDate.label')
+ errors=validations.attrs.expirationDuration.messages
+ class='expiration-duration'
}}
-
- {{input model.anonymousUser as='checkbox'
- labelTranslation="create.settings.anonymousUser.label"
+ {{fm-checkbox
+ checked=anonymousUser
+ label=(t 'create.settings.anonymousUser.label')
+ errors=validations.attrs.anonymousUser.messages
+ class='anonymous-user'
+ fieldWrapperClass='col-sm-10 col-sm-offset-2'
}}
-
- {{input model.forceAnswer as='checkbox'
- labelTranslation="create.settings.forceAnswer.label"
+ {{fm-checkbox
+ checked=forceAnswer
+ label=(t 'create.settings.forceAnswer.label')
+ errors=validations.attrs.forceAnswer.messages
+ class='force-answer'
+ fieldWrapperClass='col-sm-10 col-sm-offset-2'
}}
- {{/form-wrapper}}
-
-
+ {{#fm-submit
+ fieldWrapperClass='col-sm-10 col-sm-offset-2'
+ }}
+ {{t 'create.next'}}
+ {{/fm-submit}}
+ {{/fm-form}}
diff --git a/app/validators/valid-collection.js b/app/validators/valid-collection.js
index 1529b0b..444d50f 100644
--- a/app/validators/valid-collection.js
+++ b/app/validators/valid-collection.js
@@ -1,7 +1,11 @@
import BaseValidator from 'ember-cp-validations/validators/base';
export default BaseValidator.extend({
- validate(value) {
+ validate(value, options) {
+ if (options.active === false) {
+ return true;
+ }
+
var valid = value.every((element) => {
return element.get('validations.isValid');
});
diff --git a/package.json b/package.json
index b09aa4c..1c1a9e5 100644
--- a/package.json
+++ b/package.json
@@ -46,7 +46,6 @@
"ember-data": "1.0.0-beta.18",
"ember-data-model-fragments": "0.3.3",
"ember-disable-proxy-controllers": "^1.0.0",
- "ember-easy-form-extensions": "0.2.8",
"ember-export-application-global": "^1.0.2",
"ember-form-master-2000": "0.2.0",
"ember-get-helper": "1.0.4",
diff --git a/tests/acceptance/create-a-poll-test.js b/tests/acceptance/create-a-poll-test.js
index f201a82..7baebdf 100644
--- a/tests/acceptance/create-a-poll-test.js
+++ b/tests/acceptance/create-a-poll-test.js
@@ -77,12 +77,12 @@ test("create a default poll", function(assert) {
dates
);
- click('.button-next');
+ click('button[type="submit"]');
andThen(function(){
assert.equal(currentPath(), 'create.settings');
- click('.button-next');
+ click('button[type="submit"]');
andThen(function(){
assert.equal(currentPath(), 'poll.participation');
@@ -158,7 +158,7 @@ test("create a poll for answering a question", function(assert) {
andThen(function(){
assert.equal(currentPath(), 'create.settings');
- click('.button-next');
+ click('button[type="submit"]');
andThen(function(){
assert.equal(currentPath(), 'poll.participation');
@@ -209,12 +209,12 @@ test("create a poll with description", function(assert) {
selectDates('#datepicker .ember-view', dates);
- click('.button-next');
+ click('button[type="submit"]');
andThen(function(){
assert.equal(currentPath(), 'create.settings');
- click('.button-next');
+ click('button[type="submit"]');
andThen(function(){
assert.equal(currentPath(), 'poll.participation');
diff --git a/tests/integration/create-a-poll-test.js b/tests/integration/create-a-poll-test.js
index 1fde2a3..7e41fee 100644
--- a/tests/integration/create-a-poll-test.js
+++ b/tests/integration/create-a-poll-test.js
@@ -48,12 +48,12 @@ test("create a default poll and participate", function(assert) {
selectDates('#datepicker .ember-view', dates);
- click('.button-next');
+ click('button[type="submit"]');
andThen(function(){
assert.equal(currentPath(), 'create.settings');
- click('.button-next');
+ click('button[type="submit"]');
andThen(function(){
assert.equal(currentPath(), 'poll.participation');