model fragments for answers

This commit is contained in:
jelhan 2015-10-12 13:40:29 +02:00
parent a8a10ad42a
commit 3d4cf3f408
9 changed files with 54 additions and 26 deletions

View file

@ -41,13 +41,13 @@ export default Ember.Controller.extend(EmberValidations.Mixin, {
id : "YesNo",
labelTranslation : "answerTypes.yesNo.label",
answers : [
Ember.Object.extend(Ember.I18n.TranslateableProperties, {}).create({
id: "yes",
this.store.createFragment('answer', {
type: "yes",
labelTranslation: "answerTypes.yes.label",
icon: "glyphicon glyphicon-thumbs-up"
}),
Ember.Object.extend(Ember.I18n.TranslateableProperties, {}).create({
id: "no",
this.store.createFragment('answer', {
type: "no",
labelTranslation: "answerTypes.no.label",
icon: "glyphicon glyphicon-thumbs-down"
})
@ -57,18 +57,18 @@ export default Ember.Controller.extend(EmberValidations.Mixin, {
id : "YesNoMaybe",
labelTranslation : "answerTypes.yesNoMaybe.label",
answers : [
Ember.Object.extend(Ember.I18n.TranslateableProperties, {}).create({
id: "yes",
this.store.createFragment('answer', {
type: "yes",
labelTranslation: "answerTypes.yes.label",
icon: "glyphicon glyphicon-thumbs-up"
}),
Ember.Object.extend(Ember.I18n.TranslateableProperties, {}).create({
id: "maybe",
this.store.createFragment('answer', {
type: "maybe",
labelTranslation: "answerTypes.maybe.label",
icon: "glyphicon glyphicon-hand-right"
}),
Ember.Object.extend(Ember.I18n.TranslateableProperties, {}).create({
id: "no",
this.store.createFragment('answer', {
type: "no",
labelTranslation: "answerTypes.no.label",
icon: "glyphicon glyphicon-thumbs-down"
})
@ -124,7 +124,7 @@ export default Ember.Controller.extend(EmberValidations.Mixin, {
if (selectedAnswer !== null) {
for (var i=0; i < answerTypes.length; i++) {
if (answerTypes[i].id === selectedAnswer) {
answers = answerTypes[i].answers;
answers = answerTypes[i].answers.map(answer => Ember.copy(answer));
}
}

View file

@ -17,9 +17,21 @@ export default Ember.Controller.extend(EmberValidations.Mixin, {
// work-a-round cause value is not retrived otherwise
this.get('newUserSelections').forEach(function(selection) {
newUser.selections.push({
value: selection.get('value')
});
if(typeof selection.get('value') === 'string') {
newUser.selections.push({
value: selection.get('value')
});
}
else {
newUser.selections.push({
value: {
type: selection.get('value.type'),
label: selection.get('value.label'),
labelTranslation: selection.get('value.labelTranslation'),
icon: selection.get('value.icon')
}
});
}
});
// send new user to controller for saving

8
app/models/answer.js Normal file
View file

@ -0,0 +1,8 @@
import DS from 'ember-data';
export default DS.ModelFragment.extend({
type: DS.attr('string'),
label: DS.attr('string'),
labelTranslation: DS.attr('string'),
icon: DS.attr('string')
});

View file

@ -13,7 +13,7 @@ export default DS.Model.extend({
anonymousUser : DS.attr('boolean'),
// array of possible answers
answers : DS.attr('array'),
answers : DS.hasManyFragments('answer', { defaultValue: [] }),
// YesNo, YesNoMaybe or Freetext
answerType: DS.attr('string'),

View file

@ -0,0 +1,4 @@
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
});

View file

@ -82,9 +82,9 @@
{{#each answer in model.answers}}
<div class="radio">
{{#radio-button value=answer groupValue=newUserSelection.value}}
<span {{bind-attr class="answer.id"}}>
<span {{bind-attr class="answer.type"}}>
<span {{bind-attr class="answer.icon"}}></span>
{{answer.label}}
{{t answer.labelTranslation}}
</span>
{{/radio-button}}
</div>
@ -112,13 +112,15 @@
<td>{{user.name}}</td>
{{#each selection in user.selections}}
<td>
{{#if model.isFreeText}}
{{selection.value}}
{{else}}
<span {{bind-attr class="selection.value.id"}}>
{{#if selection.value}}
{{#if model.isFreeText}}
{{selection.value}}
{{else}}
<span {{bind-attr class="selection.value.type"}}>
<span {{bind-attr class="selection.value.icon"}}></span>
{{selection.value.label}}
</span>
{{t selection.value.labelTranslation}}
</span>
{{/if}}
{{/if}}
</td>
{{/each}}

View file

@ -23,6 +23,7 @@
"ember-cli-moment-shim": "~0.2.0",
"moment-timezone": ">= 0.1.0",
"pretender": "^0.6.0",
"moment": ">= 2.8.0"
"moment": ">= 2.8.0",
"ember-data.model-fragments": "0.3.3"
}
}

View file

@ -42,6 +42,7 @@
"ember-cli-sri": "1.0.3",
"ember-cli-uglify": "^1.0.1",
"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",

View file

@ -10,13 +10,13 @@ export default function (attr, key) {
answerType: 'YesNo',
answers: [
{
id: "yes",
type: "yes",
labelTranslation: "answerTypes.yes.label",
icon: "glyphicon glyphicon-thumbs-up",
label: "Ja"
},
{
id: "no",
type: "no",
labelTranslation: "answerTypes.no.label",
icon: "glyphicon glyphicon-thumbs-down",
label: "Nein"