model fragments for answers
This commit is contained in:
parent
a8a10ad42a
commit
3d4cf3f408
9 changed files with 54 additions and 26 deletions
|
@ -41,13 +41,13 @@ export default Ember.Controller.extend(EmberValidations.Mixin, {
|
||||||
id : "YesNo",
|
id : "YesNo",
|
||||||
labelTranslation : "answerTypes.yesNo.label",
|
labelTranslation : "answerTypes.yesNo.label",
|
||||||
answers : [
|
answers : [
|
||||||
Ember.Object.extend(Ember.I18n.TranslateableProperties, {}).create({
|
this.store.createFragment('answer', {
|
||||||
id: "yes",
|
type: "yes",
|
||||||
labelTranslation: "answerTypes.yes.label",
|
labelTranslation: "answerTypes.yes.label",
|
||||||
icon: "glyphicon glyphicon-thumbs-up"
|
icon: "glyphicon glyphicon-thumbs-up"
|
||||||
}),
|
}),
|
||||||
Ember.Object.extend(Ember.I18n.TranslateableProperties, {}).create({
|
this.store.createFragment('answer', {
|
||||||
id: "no",
|
type: "no",
|
||||||
labelTranslation: "answerTypes.no.label",
|
labelTranslation: "answerTypes.no.label",
|
||||||
icon: "glyphicon glyphicon-thumbs-down"
|
icon: "glyphicon glyphicon-thumbs-down"
|
||||||
})
|
})
|
||||||
|
@ -57,18 +57,18 @@ export default Ember.Controller.extend(EmberValidations.Mixin, {
|
||||||
id : "YesNoMaybe",
|
id : "YesNoMaybe",
|
||||||
labelTranslation : "answerTypes.yesNoMaybe.label",
|
labelTranslation : "answerTypes.yesNoMaybe.label",
|
||||||
answers : [
|
answers : [
|
||||||
Ember.Object.extend(Ember.I18n.TranslateableProperties, {}).create({
|
this.store.createFragment('answer', {
|
||||||
id: "yes",
|
type: "yes",
|
||||||
labelTranslation: "answerTypes.yes.label",
|
labelTranslation: "answerTypes.yes.label",
|
||||||
icon: "glyphicon glyphicon-thumbs-up"
|
icon: "glyphicon glyphicon-thumbs-up"
|
||||||
}),
|
}),
|
||||||
Ember.Object.extend(Ember.I18n.TranslateableProperties, {}).create({
|
this.store.createFragment('answer', {
|
||||||
id: "maybe",
|
type: "maybe",
|
||||||
labelTranslation: "answerTypes.maybe.label",
|
labelTranslation: "answerTypes.maybe.label",
|
||||||
icon: "glyphicon glyphicon-hand-right"
|
icon: "glyphicon glyphicon-hand-right"
|
||||||
}),
|
}),
|
||||||
Ember.Object.extend(Ember.I18n.TranslateableProperties, {}).create({
|
this.store.createFragment('answer', {
|
||||||
id: "no",
|
type: "no",
|
||||||
labelTranslation: "answerTypes.no.label",
|
labelTranslation: "answerTypes.no.label",
|
||||||
icon: "glyphicon glyphicon-thumbs-down"
|
icon: "glyphicon glyphicon-thumbs-down"
|
||||||
})
|
})
|
||||||
|
@ -124,7 +124,7 @@ export default Ember.Controller.extend(EmberValidations.Mixin, {
|
||||||
if (selectedAnswer !== null) {
|
if (selectedAnswer !== null) {
|
||||||
for (var i=0; i < answerTypes.length; i++) {
|
for (var i=0; i < answerTypes.length; i++) {
|
||||||
if (answerTypes[i].id === selectedAnswer) {
|
if (answerTypes[i].id === selectedAnswer) {
|
||||||
answers = answerTypes[i].answers;
|
answers = answerTypes[i].answers.map(answer => Ember.copy(answer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,21 @@ export default Ember.Controller.extend(EmberValidations.Mixin, {
|
||||||
|
|
||||||
// work-a-round cause value is not retrived otherwise
|
// work-a-round cause value is not retrived otherwise
|
||||||
this.get('newUserSelections').forEach(function(selection) {
|
this.get('newUserSelections').forEach(function(selection) {
|
||||||
newUser.selections.push({
|
if(typeof selection.get('value') === 'string') {
|
||||||
value: selection.get('value')
|
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
|
// send new user to controller for saving
|
||||||
|
|
8
app/models/answer.js
Normal file
8
app/models/answer.js
Normal 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')
|
||||||
|
});
|
|
@ -13,7 +13,7 @@ export default DS.Model.extend({
|
||||||
anonymousUser : DS.attr('boolean'),
|
anonymousUser : DS.attr('boolean'),
|
||||||
|
|
||||||
// array of possible answers
|
// array of possible answers
|
||||||
answers : DS.attr('array'),
|
answers : DS.hasManyFragments('answer', { defaultValue: [] }),
|
||||||
|
|
||||||
// YesNo, YesNoMaybe or Freetext
|
// YesNo, YesNoMaybe or Freetext
|
||||||
answerType: DS.attr('string'),
|
answerType: DS.attr('string'),
|
||||||
|
|
4
app/serializers/answer.js
Normal file
4
app/serializers/answer.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import DS from 'ember-data';
|
||||||
|
|
||||||
|
export default DS.RESTSerializer.extend({
|
||||||
|
});
|
|
@ -82,9 +82,9 @@
|
||||||
{{#each answer in model.answers}}
|
{{#each answer in model.answers}}
|
||||||
<div class="radio">
|
<div class="radio">
|
||||||
{{#radio-button value=answer groupValue=newUserSelection.value}}
|
{{#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>
|
<span {{bind-attr class="answer.icon"}}></span>
|
||||||
{{answer.label}}
|
{{t answer.labelTranslation}}
|
||||||
</span>
|
</span>
|
||||||
{{/radio-button}}
|
{{/radio-button}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -112,13 +112,15 @@
|
||||||
<td>{{user.name}}</td>
|
<td>{{user.name}}</td>
|
||||||
{{#each selection in user.selections}}
|
{{#each selection in user.selections}}
|
||||||
<td>
|
<td>
|
||||||
{{#if model.isFreeText}}
|
{{#if selection.value}}
|
||||||
{{selection.value}}
|
{{#if model.isFreeText}}
|
||||||
{{else}}
|
{{selection.value}}
|
||||||
<span {{bind-attr class="selection.value.id"}}>
|
{{else}}
|
||||||
|
<span {{bind-attr class="selection.value.type"}}>
|
||||||
<span {{bind-attr class="selection.value.icon"}}></span>
|
<span {{bind-attr class="selection.value.icon"}}></span>
|
||||||
{{selection.value.label}}
|
{{t selection.value.labelTranslation}}
|
||||||
</span>
|
</span>
|
||||||
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</td>
|
</td>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
"ember-cli-moment-shim": "~0.2.0",
|
"ember-cli-moment-shim": "~0.2.0",
|
||||||
"moment-timezone": ">= 0.1.0",
|
"moment-timezone": ">= 0.1.0",
|
||||||
"pretender": "^0.6.0",
|
"pretender": "^0.6.0",
|
||||||
"moment": ">= 2.8.0"
|
"moment": ">= 2.8.0",
|
||||||
|
"ember-data.model-fragments": "0.3.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
"ember-cli-sri": "1.0.3",
|
"ember-cli-sri": "1.0.3",
|
||||||
"ember-cli-uglify": "^1.0.1",
|
"ember-cli-uglify": "^1.0.1",
|
||||||
"ember-data": "1.0.0-beta.18",
|
"ember-data": "1.0.0-beta.18",
|
||||||
|
"ember-data-model-fragments": "0.3.3",
|
||||||
"ember-disable-proxy-controllers": "^1.0.0",
|
"ember-disable-proxy-controllers": "^1.0.0",
|
||||||
"ember-easy-form-extensions": "0.2.8",
|
"ember-easy-form-extensions": "0.2.8",
|
||||||
"ember-export-application-global": "^1.0.2",
|
"ember-export-application-global": "^1.0.2",
|
||||||
|
|
|
@ -10,13 +10,13 @@ export default function (attr, key) {
|
||||||
answerType: 'YesNo',
|
answerType: 'YesNo',
|
||||||
answers: [
|
answers: [
|
||||||
{
|
{
|
||||||
id: "yes",
|
type: "yes",
|
||||||
labelTranslation: "answerTypes.yes.label",
|
labelTranslation: "answerTypes.yes.label",
|
||||||
icon: "glyphicon glyphicon-thumbs-up",
|
icon: "glyphicon glyphicon-thumbs-up",
|
||||||
label: "Ja"
|
label: "Ja"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "no",
|
type: "no",
|
||||||
labelTranslation: "answerTypes.no.label",
|
labelTranslation: "answerTypes.no.label",
|
||||||
icon: "glyphicon glyphicon-thumbs-down",
|
icon: "glyphicon glyphicon-thumbs-down",
|
||||||
label: "Nein"
|
label: "Nein"
|
||||||
|
|
Loading…
Reference in a new issue