From a90eb41bf4465af280b94fd8ddf4ba8a3e31791d Mon Sep 17 00:00:00 2001 From: DrumsnChocolate Date: Sun, 3 Nov 2024 22:12:20 +0100 Subject: [PATCH] write open and closed question components in octane --- app/components/form/closed-question.hbs | 51 +++++++------ app/components/form/closed-question.js | 77 +++++++++---------- app/components/form/form-form.hbs | 4 +- app/components/form/open-question.hbs | 31 ++++---- app/components/form/open-question.js | 98 +++++++++++++------------ 5 files changed, 133 insertions(+), 128 deletions(-) diff --git a/app/components/form/closed-question.hbs b/app/components/form/closed-question.hbs index 44b10b7bc..bbbbf3e96 100644 --- a/app/components/form/closed-question.hbs +++ b/app/components/form/closed-question.hbs @@ -2,7 +2,7 @@ {{#unless question.form.hasResponses}}
- +
{{/unless}} @@ -13,8 +13,8 @@ aria-label='Vraag' name='question' placeholder='Vraag' - @value={{question.question}} - disabled={{question.form.hasResponses}} + @value={{@question.question}} + disabled={{@question.form.hasResponses}} /> @@ -25,11 +25,10 @@ @@ -38,22 +37,22 @@ class='form-check-input' @type='checkbox' name='required' - @checked={{question.required}} - disabled={{question.form.hasResponses}} - id="question-{{question.position}}-required-check" + @checked={{@question.required}} + disabled={{@question.form.hasResponses}} + id="question-{{@question.position}}-required-check" /> - + - {{#unless question.form.hasResponses}} + {{#unless @question.form.hasResponses}}
-{{#each question.sortedOptions as |opt|}} +{{#each @question.sortedOptions as |opt|}} {{#unless opt.isDeleted}}
- - - +
- {{#unless question.form.hasResponses}} + {{#unless @question.form.hasResponses}} @@ -119,8 +118,8 @@ {{/unless}} {{/each}} -{{#unless question.form.hasResponses}} - {{/unless}} \ No newline at end of file diff --git a/app/components/form/closed-question.js b/app/components/form/closed-question.js index c144b45a3..e3e1bcf8e 100644 --- a/app/components/form/closed-question.js +++ b/app/components/form/closed-question.js @@ -1,42 +1,43 @@ import { ClosedQuestionTypes } from 'amber-ui/constants'; import { inject as service } from '@ember/service'; import OpenQuestionComponent from './open-question'; +import { action } from '@ember/object'; -export default OpenQuestionComponent.extend({ - store: service(), - questionTypes: ClosedQuestionTypes, - init() { - this._super(); - }, - actions: { - addOption() { - const position = - this.question.get('sortedOptions.lastObject.position') + 1 || 0; - this.store.createRecord('form/closed-question-option', { - question: this.question, - position, - }); - }, - deleteOption(option) { - option.deleteRecord(); - }, - moveOptionUp(option) { - const index = this.question.get('sortedOptions').indexOf(option); - if (index > 0) { - const previousOption = this.question - .get('sortedOptions') - .objectAt(index - 1); - this.send('switchPositions', option, previousOption); - } - }, - moveOptionDown(option) { - const index = this.question.get('sortedOptions').indexOf(option); - if (index < this.question.get('sortedOptions.length') - 1) { - const nextOption = this.question - .get('sortedOptions') - .objectAt(index + 1); - this.send('switchPositions', option, nextOption); - } - }, - }, -}); +export default class ClosedQuestionComponent extends OpenQuestionComponent { + @service store; + questionTypes = ClosedQuestionTypes; + @action + addOption() { + const position = + this.question.get('sortedOptions.lastObject.position') + 1 || 0; + this.store.createRecord('form/closed-question-option', { + question: this.question, + position, + }); + } + + @action + deleteOption(option) { + option.deleteRecord(); + } + + @action + moveOptionUp(option) { + const index = this.question.get('sortedOptions').indexOf(option); + if (index > 0) { + const previousOption = this.question + .get('sortedOptions') + .objectAt(index - 1); + this.switchPositions(option, previousOption); + } + } + + @action + moveOptionDown(option) { + const index = this.question.get('sortedOptions').indexOf(option); + if (index < this.question.get('sortedOptions.length') - 1) { + const nextOption = this.question.get('sortedOptions').objectAt(index + 1); + this.switchPositions(option, nextOption); + } + } +} diff --git a/app/components/form/form-form.hbs b/app/components/form/form-form.hbs index 523d00171..e71284722 100644 --- a/app/components/form/form-form.hbs +++ b/app/components/form/form-form.hbs @@ -26,9 +26,9 @@
{{#if question.isOpenQuestion}} - {{form/open-question question form=model}} + {{else}} - {{form/closed-question question form=model}} + {{/if}}
diff --git a/app/components/form/open-question.hbs b/app/components/form/open-question.hbs index beeb6ae3e..f68d3883f 100644 --- a/app/components/form/open-question.hbs +++ b/app/components/form/open-question.hbs @@ -1,8 +1,8 @@ Open vraag -{{#unless question.form.hasResponses}} +{{#unless @question.form.hasResponses}}
- +
{{/unless}} @@ -13,8 +13,8 @@ aria-label='Vraag' name='question' placeholder='Vraag' - @value={{question.question}} - disabled={{question.form.hasResponses}} + @value={{@question.question}} + disabled={{@question.form.hasResponses}} />
@@ -25,11 +25,10 @@
@@ -38,22 +37,22 @@ class='form-check-input' @type='checkbox' name='required' - @checked={{question.required}} - disabled={{question.form.hasResponses}} - id="question-{{question.position}}-required-check" + @checked={{@question.required}} + disabled={{@question.form.hasResponses}} + id="question-{{@question.position}}-required-check" /> - +
- {{#unless question.form.hasResponses}} + {{#unless @question.form.hasResponses}}