This is an automated email from the git hooks/post-receive script. New commit to branch feature/multi-ui in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 962c830556167d70e872cc17e7b859e04b7abac2 Author: jcouteau <couteau@codelutin.com> Date: Thu Oct 10 15:13:15 2019 +0200 Nice question editing workflow --- pollen-ui-riot-js/src/main/web/js/PollForm.js | 9 ++-- .../src/main/web/tag/poll/EditPoll.tag.html | 48 +++++++++++++++++----- .../src/main/web/tag/poll/EditQuestions.tag.html | 42 ++++++++++++------- 3 files changed, 71 insertions(+), 28 deletions(-) diff --git a/pollen-ui-riot-js/src/main/web/js/PollForm.js b/pollen-ui-riot-js/src/main/web/js/PollForm.js index 41152b4e..b4745dbc 100644 --- a/pollen-ui-riot-js/src/main/web/js/PollForm.js +++ b/pollen-ui-riot-js/src/main/web/js/PollForm.js @@ -227,12 +227,15 @@ class PollForm { this.setStep(this.step + 1); } - addNewQuestion() { + addNewQuestion(index) { let newQuestion = new Question("", "", ""); this.setQuestionDefaultSettings(newQuestion); this.setQuestionDefaultChoices(newQuestion); - this.questionEdited = this.questionEdited + 1; - this.model.questions.push(newQuestion); + this.model.questions.splice(index, 0, newQuestion); + } + + deleteQuestion() { + this.model.questions.splice(this.questionEdited, 1); } addNewChoice(questionId) { diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/EditPoll.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/EditPoll.tag.html index 3e743b30..5f78ba04 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/EditPoll.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/EditPoll.tag.html @@ -72,22 +72,39 @@ import "./CheckEmails.tag.html"; <GtuValidation if={!form.model.gtuValidated && !showSummary && (!form.creation || form.step === form.getSteps(form.multi).length - 1)} ref="gtuValidation"/> - <div class="actions" if={!showSummary && form.multi}> + <div class="actions" if={!showSummary && form.multi && form.step === 1}> - <button if={form.step === 1 && form.questionEdited !== 0} - type={form.creation || form.model.closed ? "button" : "submit"} - class="c-button c-button--info" - tabindex="1" - onclick={previousQuestion}> + <button type={form.creation || form.model.closed ? "button" : "submit"} + class="c-button c-button--info" + tabindex="1" + onclick={previousQuestion} + disabled={form.questionEdited === 0}> <i class="fa fa-chevron-left " aria-hidden="true"></i> {_t.previousQuestion} </button> - <button if={form.step === 1} - type="submit" - class="c-button c-button--info" - tabindex="1" - onclick={newQuestion}> + <button type={form.creation || form.model.closed ? "button" : "submit"} + class="c-button c-button--info" + tabindex="1" + onclick={deleteQuestion} + disabled={form.model.questions.length === 1}> + <i class="fa fa-trash " aria-hidden="true"></i> + {_t.deleteQuestion} + </button> + + <button type="submit" + class="c-button c-button--info" + tabindex="1" + onclick={newQuestion}> + <i class="fa fa-plus " aria-hidden="true"></i> + {_t.newQuestion} + </button> + + <button type="submit" + class="c-button c-button--info" + tabindex="1" + onclick={nextQuestion} + disabled={form.questionEdited === form.model.questions.length - 1}> {_t.nextQuestion} <i class="fa fa-chevron-right " aria-hidden="true"></i> </button> @@ -199,6 +216,15 @@ import "./CheckEmails.tag.html"; this.callAfterSubmit = () => this.refs.editQuestions.newQuestion(); }; + this.deleteQuestion = () => { + this.refs.editQuestions.deleteQuestion(); + }; + + this.nextQuestion = e => { + this.callAfterSubmit = () => this.refs.editQuestions.nextQuestion(); + this.submitStep(e); + }; + this.previousQuestion = (e) => { this.callAfterSubmit = () => this.refs.editQuestions.previousQuestion(); this.submitStep(e); diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/EditQuestions.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/EditQuestions.tag.html index a74c87b7..996138d2 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/EditQuestions.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/EditQuestions.tag.html @@ -59,17 +59,27 @@ import "./EditQuestionsSettings.tag.html"; this.newQuestion = () => { if (!this.form.hasVotes) { this.submit(); + this.form.addNewQuestion(this.form.questionEdited + 1); + this.form.questionEdited++; + this.reloadQuestion(); + } + }; - if (this.form.questionEdited === this.form.model.questions.length-1) { - this.form.addNewQuestion(); - } else { - this.form.questionEdited++; + this.deleteQuestion = () => { + if (!this.form.hasVotes) { + this.form.deleteQuestion(); + if (this.form.questionEdited >= this.form.model.questions.length) { + this.form.questionEdited = this.form.model.questions.length -1; } - this.question = this.form.model.questions[this.form.questionEdited]; - this.refs.title.value = this.question.title; - this.refs.description.value = this.question.description; - this.bus.trigger("questionEditedChanged", this.form.questionEdited); - this.update(); + this.reloadQuestion(); + } + }; + + this.nextQuestion = () => { + if (!this.form.hasVotes) { + this.submit(); + this.form.questionEdited++; + this.reloadQuestion(); } }; @@ -77,14 +87,18 @@ import "./EditQuestionsSettings.tag.html"; if (!this.form.hasVotes) { this.submit(); this.form.questionEdited = this.form.questionEdited - 1; - this.bus.trigger("questionEditedChanged", this.questionEdited); - this.question = this.form.model.questions[this.form.questionEdited]; - this.refs.title.value = this.question.title; - this.refs.description.value = this.question.description; - this.update(); + this.reloadQuestion(); } }; + this.reloadQuestion = () => { + this.question = this.form.model.questions[this.form.questionEdited]; + this.refs.title.value = this.question.title; + this.refs.description.value = this.question.description; + this.bus.trigger("questionEditedChanged", this.form.questionEdited); + this.update(); + } + this.submit = () => { this.refs.choices.submit(); this.refs.settings.submit(); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.