remove ember-easy-form-extensions, finally

This commit is contained in:
jelhan 2015-11-19 21:51:49 +01:00
parent 3563e41913
commit f67381c6b9
12 changed files with 142 additions and 168 deletions

View file

@ -9,4 +9,8 @@ export default FmCheckboxComponent.reopen({
return this.fmconfig.errorClass;
}
}),
fieldWrapperClass: Ember.computed(function() {
return this.fmconfig.fieldWrapperClass;
})
});

View file

@ -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']
})
],

View file

@ -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, {
var Validations = buildValidations({
anonymousUser: validator('presence', true),
answerType: [
validator('presence', true),
validator('inclusion', {
in: ['YesNo', 'YesNoMaybe', 'FreeText']
})
],
forceAnswer: validator('presence', true)
});
export default Ember.Controller.extend(Validations, {
actions: {
save: function(){
// check if answer type is selected
if (this.get('model.answerType') === null) {
return;
}
// 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);
});
});
},
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
*/
@ -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')
});

View file

@ -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'
});
}
};

View file

@ -0,0 +1,20 @@
<div class='checkbox'>
<div class={{fieldWrapperClass}}>
<label>
{{input
type='checkbox'
checked=checked
disabled=disabled
name=name
tabindex=tabindex}}
{{label}}
</label>
{{#if errors}}
{{#if shouldShowErrors}}
{{fm-errortext errors=errors}}
{{/if}}
{{/if}}
</div>
</div>

View file

@ -11,6 +11,7 @@
<div class='col-sm-8 col-md-9 col-xs-10 {{if index 'col-sm-offset-2 col-md-offset-2'}}'>
{{fm-input
class='form-control'
step=step
type=type
value=element.value

View file

@ -21,28 +21,45 @@
{{else}}
<div id="datepicker">
{{bootstrap-datepicker-inline
value=optionsBootstrapDatepicker
multidate=true
calendarWeeks=true
todayHighlight=true
language=language.selected}}
</div>
{{#fm-form
action='submit'
isValid=validations.isValid
}}
<div class="form-group">
<label class="col-sm-2 control-label">
Tage
</label>
{{#form-wrapper}}
{{#input enoughOptions}}
{{#if view.showError}}
{{error-field enoughOptions}}
{{/if}}
{{/input}}
<div class="col-sm-10">
<div id="datepicker">
{{bootstrap-datepicker-inline
value=optionsBootstrapDatepicker
multidate=true
calendarWeeks=true
todayHighlight=true
language=language.selected
}}
</div>
{{input model.isDateTime as='checkbox'
labelTranslation="create.options.defineTimes.label"
{{#if showDatepickerErrors}}
{{#if validations.attrs.optionsBootstrapDatepicker.message}}
{{validations.attrs.optionsBootstrapDatepicker.message}}
{{/if}}
{{/if}}
</div>
</div>
{{fm-checkbox
checked=model.isDateTime
label=(t 'create.options.defineTimes.label')
fieldWrapperClass='col-sm-10 col-sm-offset-2'
}}
{{/form-wrapper}}
<button {{action "submit"}} class="btn btn-default btn-primary button-next"> {{t 'create.next'}} </button>
{{#fm-submit
fieldWrapperClass='col-sm-10 col-sm-offset-2'
}}
{{t 'create.next'}}
{{/fm-submit}}
{{/fm-form}}
{{/if}}
</div>

View file

@ -1,29 +1,43 @@
<div class="box">
{{#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}}
<button {{action "submit"}} class="btn btn-default btn-primary button-next"> {{t 'create.next'}} </button>
{{#fm-submit
fieldWrapperClass='col-sm-10 col-sm-offset-2'
}}
{{t 'create.next'}}
{{/fm-submit}}
{{/fm-form}}
</div>

View file

@ -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');
});

View file

@ -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",

View file

@ -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');

View file

@ -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');