This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 24255003e6098a7347756ea540e296206953109b Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue Mar 21 12:07:05 2017 +0100 initialiser un nouveaux choix avec les valeurs du dernier --- pollen-ui-riot-js/src/main/web/js/Choice.js | 6 +-- pollen-ui-riot-js/src/main/web/js/Poll.js | 20 ++++++++ pollen-ui-riot-js/src/main/web/js/PollForm.js | 12 ++++- .../src/main/web/tag/poll/Choice.tag.html | 58 +++++++++++----------- .../src/main/web/tag/poll/Choices.tag.html | 1 + .../src/main/web/tag/poll/Votes.tag.html | 4 +- 6 files changed, 67 insertions(+), 34 deletions(-) diff --git a/pollen-ui-riot-js/src/main/web/js/Choice.js b/pollen-ui-riot-js/src/main/web/js/Choice.js index adf0c35..cc5b223 100644 --- a/pollen-ui-riot-js/src/main/web/js/Choice.js +++ b/pollen-ui-riot-js/src/main/web/js/Choice.js @@ -20,10 +20,10 @@ */ class Choice { - constructor(type, name, description, id) { - this.choiceValue = name; - this.description = description; + constructor(type, value, description, id) { this.choiceType = type; + this.choiceValue = value; + this.description = description; this.id = id; } } diff --git a/pollen-ui-riot-js/src/main/web/js/Poll.js b/pollen-ui-riot-js/src/main/web/js/Poll.js index 244473f..83cedfe 100644 --- a/pollen-ui-riot-js/src/main/web/js/Poll.js +++ b/pollen-ui-riot-js/src/main/web/js/Poll.js @@ -1,6 +1,7 @@ let singleton = require("./Singleton"); let pollService = require("./PollService"); let voteService = require("./VoteService"); +let Choice = require("./Choice"); let choiceService = require("./ChoiceService"); let voteCountingTypeService = require("./VoteCountingTypeService"); let resultService = require("./ResultService"); @@ -52,6 +53,25 @@ class Poll { return Promise.reject("Init poll after load choices"); } + initChoice(choice) { + choice = choice || new Choice(); + choice.id = undefined; + if (this.choices.length > 0) { + let lastChoice = this.choices[this.choices.length - 1]; + choice.choiceType = lastChoice.choiceType; + if (lastChoice.choiceType.startsWith("DATE")) { + choice.choiceValue = lastChoice.choiceValue; + } else { + choice.choiceValue = undefined; + } + } else { + choice.choiceType = this.choiceType; + choice.choiceValue = undefined; + choice.description = undefined; + } + return choice; + } + addChoice(choice) { if (this.id) { let promise; 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 1bfb328..9e37024 100644 --- a/pollen-ui-riot-js/src/main/web/js/PollForm.js +++ b/pollen-ui-riot-js/src/main/web/js/PollForm.js @@ -179,7 +179,17 @@ class PollForm { } addNewChoice() { - let choice = new Choice(this.model.choiceType); + let choice; + if (this.choices.length > 0) { + let lastChoice = this.choices[this.choices.length - 1]; + if (lastChoice.choiceType.startsWith("DATE")) { + choice = new Choice(lastChoice.choiceType, lastChoice.choiceValue); + } else { + choice = new Choice(lastChoice.choiceType); + } + } else { + choice = new Choice(this.model.choiceType); + } this.choices.push(choice); } diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Choice.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Choice.tag.html index 401f59e..6a08fc9 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Choice.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Choice.tag.html @@ -12,10 +12,10 @@ require("../components/time-picker.tag.html"); </button> <input type="text" ref="choiceText" - class="{choice.choiceType === 'TEXT' ? 'selected' : 'hidden'}" + class={opts.choice.choiceType === 'TEXT' ? 'selected' : 'hidden'} disabled={opts.disabled} - value="{opts.choice.choiceType === 'TEXT' ? opts.choice.choiceValue : null}"/> - + value={valueText} + onchange={onTextChange}/> <button type="button" class="c-button" alt="resource" @@ -26,7 +26,7 @@ require("../components/time-picker.tag.html"); <i class="fa fa-image" aria-hidden="true"></i> </button> <span if="{originalFile}" - class="original-file {choice.choiceType === 'RESOURCE' ? 'selected' : 'hidden'}"> + class="original-file {opts.choice.choiceType === 'RESOURCE' ? 'selected' : 'hidden'}"> <span>{originalFile.name}</span> <i class="fa fa-remove" if={!opts.disabled} @@ -34,7 +34,7 @@ require("../components/time-picker.tag.html"); </span> <input type="file" ref="choiceResource" - class="{choice.choiceType === 'RESOURCE' ? 'selected' : 'hidden'}" + class="{opts.choice.choiceType === 'RESOURCE' ? 'selected' : 'hidden'}" disabled={opts.disabled} if="{!originalFile}"/> @@ -47,11 +47,11 @@ require("../components/time-picker.tag.html"); <i class="fa fa-calendar" aria-hidden="true"></i> </button> <date-picker ref="choiceDate" - class="{choice.choiceType.startsWith('DATE') ? 'selected' : 'hidden'}" + class="{opts.choice.choiceType.startsWith('DATE') ? 'selected' : 'hidden'}" date="{date}"/> <button type="button" - class="c-button {!choice.choiceType.startsWith('DATE') ? 'hidden' : ''}" + class="c-button {!opts.choice.choiceType.startsWith('DATE') ? 'hidden' : ''}" alt="heure" disabled={opts.disabled} onclick="{toggleTime}" @@ -59,7 +59,7 @@ require("../components/time-picker.tag.html"); <i class="fa fa-clock-o " aria-hidden="true"></i> </button> <time-picker ref="choiceTime" - class="{choice.choiceType === 'DATETIME' ? 'selected' : 'hidden'}" + class="{opts.choice.choiceType === 'DATETIME' ? 'selected' : 'hidden'}" time="{time}"/> <button type="button" @@ -73,7 +73,7 @@ require("../components/time-picker.tag.html"); <div show="{showDescription}"> <textarea ref="description" placeholder="{__.description_placeholder}" - value="{choice.description}"/> + value="{opts.choice.description}"/> </div> <script type="es6"> @@ -84,13 +84,11 @@ require("../components/time-picker.tag.html"); this.installBundle(session, "choice", locale => { moment.locale(locale); }); - - this.number = parseInt(this.opts.number, 10); this.originalFile = this.opts.choice.choiceType === "RESOURCE" ? this.opts.choice.choiceValue : null; + this.valueText = this.opts.choice.choiceType === "TEXT" ? this.opts.choice.choiceValue : null; this.showDescription = false; - this.choice = this.opts.choice; - if (this.choice.choiceType.startsWith("DATE")) { + if (this.opts.choice.choiceType.startsWith("DATE")) { this.date = { date: moment(parseInt(this.opts.choice.choiceValue, 10)) }; @@ -100,7 +98,7 @@ require("../components/time-picker.tag.html"); }; } - if (this.choice.choiceType === "DATETIME") { + if (this.opts.choice.choiceType === "DATETIME") { this.time = { time: moment(parseInt(this.opts.choice.choiceValue, 10)) }; @@ -111,24 +109,28 @@ require("../components/time-picker.tag.html"); } this.setTextType = () => { - this.choice.choiceType = "TEXT"; + this.opts.choice.choiceType = "TEXT"; + }; + + this.onTextChange = (e) => { + this.valueText = e.value; }; this.setImageType = () => { - this.choice.choiceType = "RESOURCE"; + this.opts.choice.choiceType = "RESOURCE"; }; this.setDateType = () => { - if (!this.choice.choiceType.startsWith("DATE")) { - this.choice.choiceType = "DATE"; + if (!this.opts.choice.choiceType.startsWith("DATE")) { + this.opts.choice.choiceType = "DATE"; } }; this.toggleTime = () => { - if (this.choice.choiceType === "DATE") { - this.choice.choiceType = "DATETIME"; - } else if (this.choice.choiceType === "DATETIME") { - this.choice.choiceType = "DATE"; + if (this.opts.choice.choiceType === "DATE") { + this.opts.choice.choiceType = "DATETIME"; + } else if (this.opts.choice.choiceType === "DATETIME") { + this.opts.choice.choiceType = "DATE"; } }; @@ -142,11 +144,11 @@ require("../components/time-picker.tag.html"); this.submit = () => { let choiceValue = {}; - if (this.choice.choiceType === "RESOURCE") { + if (this.opts.choice.choiceType === "RESOURCE") { choiceValue = this.originalFile ? this.originalFile : this.refs.choiceResource.files[0]; - } else if (this.choice.choiceType.startsWith("DATE")) { + } else if (this.opts.choice.choiceType.startsWith("DATE")) { let selectedMoment = this.date.date; - if (this.choice.choiceType === "DATETIME") { + if (this.opts.choice.choiceType === "DATETIME") { selectedMoment.set({hour: this.time.time.hour(), minute: this.time.time.minute()}); } choiceValue = selectedMoment.valueOf(); @@ -154,13 +156,13 @@ require("../components/time-picker.tag.html"); } else { choiceValue = this.refs.choiceText.value; } - this.choice.choiceValue = choiceValue; - this.choice.description = this.refs.description.value; + this.opts.choice.choiceValue = choiceValue; + this.opts.choice.description = this.refs.description.value; }; this.clear = () => { this.setTextType(); - delete this.choice.choiceValue; + delete this.opts.choice.choiceValue; this.refs.choiceResource.value = ""; }; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Choices.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Choices.tag.html index ab015e7..40521d2 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Choices.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Choices.tag.html @@ -38,6 +38,7 @@ require("./Choice.tag.html"); this.addOneChoice = () => { if (!this.form.hasVotes) { + this.submit(); this.form.addNewChoice(); } }; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Votes.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Votes.tag.html index d2f3901..10fcbee 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Votes.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Votes.tag.html @@ -214,7 +214,6 @@ require("./ChoiceView.tag.html"); this.opts.pollPromise.then(poll => { this.poll = poll; this.voting = poll.canVote || poll.status === "VOTING" || poll.status === "CLOSED"; - this.choiceToAdd = new Choice("TEXT"); let promises = [ poll.loadChoices(), poll.loadVotes(), @@ -227,6 +226,7 @@ require("./ChoiceView.tag.html"); return Promise.resolve(); }); }).then(() => { + this.choiceToAdd = this.poll.initChoice(); this.loaded = true; this.update(); }); @@ -350,7 +350,7 @@ require("./ChoiceView.tag.html"); e.stopPropagation(); this.refs.choice.submit(); this.poll.addChoice(this.choiceToAdd).then(() => { - this.refs.choice.clear(); + this.choiceToAdd = this.poll.initChoice(this.choiceToAdd); this.update(); }); }; -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.