-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write open and closed question components in octane
- Loading branch information
1 parent
2ea0d64
commit a90eb41
Showing
5 changed files
with
133 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.