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 c968dc0c67aa552e1889c34f8bae233f143f05fb Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue Mar 14 11:36:53 2017 +0100 Ajout de choix et des info du sondage dans l'écran de vote, --- pollen-ui-riot-js/src/main/web/i18n.json | 2 + pollen-ui-riot-js/src/main/web/js/Poll.js | 22 ++++++ pollen-ui-riot-js/src/main/web/js/PollForm.js | 17 +++-- .../src/main/web/tag/poll/Choice.tag.html | 6 ++ .../src/main/web/tag/poll/Poll.tag.html | 11 ++- .../src/main/web/tag/poll/Votes.tag.html | 82 ++++++++++++++++------ 6 files changed, 110 insertions(+), 30 deletions(-) diff --git a/pollen-ui-riot-js/src/main/web/i18n.json b/pollen-ui-riot-js/src/main/web/i18n.json index 99f4f4b..0283763 100644 --- a/pollen-ui-riot-js/src/main/web/i18n.json +++ b/pollen-ui-riot-js/src/main/web/i18n.json @@ -30,6 +30,7 @@ "poll_votes_deleteVote": "Supprimer le vote ?", "poll_votes_authorPlaceHolder": "Renseigner votre nom", "poll_votes_vote": "Voter", + "poll_votes_addChoice": "Ajouter un choix", "poll_votes_delete": "Supprimer le vote ?", "poll_votes_voteNotOpen": "Les votes ne sont pas encore ouverts.", "polls_createdPolls": "Mes sondages", @@ -265,6 +266,7 @@ "poll_votes_deleteVote": "Delete vote?", "poll_votes_authorPlaceHolder": "Fill your name", "poll_votes_vote": "Vote", + "poll_votes_addChoice": "Add choice", "poll_votes_delete": "Delete vote?", "poll_votes_voteNotOpen": "Votes are not open.", "polls_title": "My polls", 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 73c5a29..677623c 100644 --- a/pollen-ui-riot-js/src/main/web/js/Poll.js +++ b/pollen-ui-riot-js/src/main/web/js/Poll.js @@ -6,6 +6,7 @@ let voteCountingTypeService = require("./VoteCountingTypeService"); let resultService = require("./ResultService"); let commentService = require("./CommentService"); let Pagination = require("./Pagination"); +let resourceService = require("./ResourceService"); class Poll { @@ -51,6 +52,27 @@ class Poll { return Promise.reject("Init poll after load choices"); } + addChoice(choice) { + if (this.id) { + let promise; + if (choice.choiceType === "RESOURCE" && choice.choiceValue.type) { + promise = resourceService.create(choice.choiceValue) + .then((result) => { + choice.choiceValue = result.id; + return Promise.resolve(choice); + }); + } else { + promise = Promise.resolve(choice); + } + return promise.then(choice2 => { + return choiceService.addChoice(this.id, choice2, this.permission).then(() => { + return this.loadChoices(); + }); + }); + } + return Promise.reject("Init poll after add choice"); + } + loadVotes() { if (this.id) { return voteService.getVotes(this.id, this.permission) 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 62897c1..1e02149 100644 --- a/pollen-ui-riot-js/src/main/web/js/PollForm.js +++ b/pollen-ui-riot-js/src/main/web/js/PollForm.js @@ -23,6 +23,10 @@ let Choice = require("./Choice"); let route = require("riot-route"); let voteCountingTypeService = require("./VoteCountingTypeService"); let choiceService = require("./ChoiceService"); +let resourceService = require("./ResourceService"); +let pollService = require("./PollService"); + + class PollForm { constructor() { @@ -33,7 +37,6 @@ class PollForm { "voters" ]; this.pollService = require("./PollService"); - this.resourceService = require("./ResourceService"); this.FormHelper = require("./FormHelper"); this.step = -1; this.isInit = false; @@ -51,7 +54,7 @@ class PollForm { loadPoll(pollId, permission) { return Promise.all([ - this.pollService.getPoll(pollId, permission), + pollService.getPoll(pollId, permission), choiceService.getChoices(pollId, permission) ]).then(results => { Object.assign(this.model, results[0]); @@ -71,7 +74,7 @@ class PollForm { this.creation = true; console.info("init form"); - return this.pollService.empty(this.choiceType).then((poll) => { + return pollService.empty(this.choiceType).then((poll) => { this.model = poll; console.info("empty poll"); console.info(this.model); @@ -125,7 +128,7 @@ class PollForm { this.choices.forEach((choice, index) => { if (choice.choiceType === "RESOURCE") { let promise = new Promise((resolve, reject) => { - this.resourceService.create(choice.choiceValue).then((result) => { + resourceService.create(choice.choiceValue).then((result) => { choice.choiceValue = result.id; resolve(result.id); }); @@ -134,7 +137,7 @@ class PollForm { } }); Promise.all(fileUploadPromises).then(() => { - this.pollService.create(this.model, this.choices).then((result) => { + pollService.create(this.model, this.choices).then((result) => { console.info("Poll created"); console.info(result); this.model.id = result.id; @@ -154,7 +157,7 @@ class PollForm { let choicesPromises = this.choices.map(choice=> { let promise; if (choice.choiceType === "RESOURCE" && choice.choiceValue.type) { - promise = this.resourceService.create(choice.choiceValue) + promise = resourceService.create(choice.choiceValue) .then((result) => { choice.choiceValue = result.id; return Promise.resolve(choice); @@ -181,7 +184,7 @@ class PollForm { save() { return Promise.all([ - this.pollService.save(this.model), + pollService.save(this.model), this._saveChoices() ]); } 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 ff122b5..772d458 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 @@ -153,6 +153,12 @@ require("../components/time-picker.tag.html"); this.choice.choiceValue = choiceValue; }; + this.clear = () => { + this.setTextType(); + delete this.choice.choiceValue; + this.refs.choiceResource.value = ""; + }; + </script> <style> diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag.html index f6c2fc7..572de88 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag.html @@ -23,6 +23,7 @@ require("./Settings.tag.html"); <i class="fa fa-comments-o fa-15x"></i> {__.comments} ({poll.commentCount}) </a> </div> + <div if="{poll.permission}" class="poll-options dropdown"> <a class="header-link"><i class="fa fa-bars"/></a> @@ -46,6 +47,10 @@ require("./Settings.tag.html"); </div> <div class="container"> + <h1 class="center">{poll.title}<h1> + + <h3 class="center">{poll.description}</h3> + <Votes if={selectedTab === "votes"} poll-promise={pollPromise}/> @@ -96,11 +101,15 @@ require("./Settings.tag.html"); route("/home"); }); } - } + }; </script> <style> + .center { + text-align: center; + } + .tabs { border-bottom: 1px solid #b2c7d3; display: flex; 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 9058916..2ecaba0 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 @@ -1,3 +1,4 @@ +require("./Choice.tag.html"); <Votes> <div class="container"> <div show="{loaded}"> @@ -5,7 +6,8 @@ <div if="{!voting}">{__.voteNotOpen}</div> <div if="{voting}" class="voters"> - <form ref="formAddVote" onsubmit="{addVote}" class="fix"> + + <form ref="formAddVote" onsubmit="{addVote}" class="fix"> <div class="current-voter"> <div class="o-field o-field--icon-left o-field--icon-right" if={poll.canVote} > @@ -55,7 +57,7 @@ </form> <div class="window"> <div class="frame"> - <form each={vote in poll.votes.reverse()} class="vote" onsubmit="{updateVote(vote)}"> + <form each={vote in poll.votes} class="vote" onsubmit="{updateVote(vote)}"> <div class="voter"> <span class="voter-name" if={vote.id !== voteId}> @@ -79,23 +81,23 @@ {error['voter.name']} </div> </div> - <div each={choice in poll.choices} class="vote-choice" > - <input if={poll.voteCountingTypeValue.renderType==='checkbox'} - ref="vote_{vote.id}_{choice.id}" - name="vote_{vote.id}_{choice.id}" - class="check" - type="checkbox" - checked={poll.getVoteValue(vote, choice) == 1} - disabled={voteId !== vote.id}> - <input if={poll.voteCountingTypeValue.renderType === 'text'} - ref="vote_{vote.id}_{choice.id}" - class="text c-field" - name="vote_{vote.id}_{choice.id}" - type="number" - required={vote.id === voteId} - min="1" - disabled={voteId !== vote.id} - value={poll.getVoteValue(vote, choice)}> + <div each={choice in poll.choices} class="vote-choice {choice-resource: choice.choiceType === 'RESOURCE'}" > + <input if={poll.voteCountingTypeValue.renderType==='checkbox' && (poll.getVoteValue(vote, choice) || voteId === vote.id)} + ref="vote_{vote.id}_{choice.id}" + name="vote_{vote.id}_{choice.id}" + class="check" + type="checkbox" + checked={poll.getVoteValue(vote, choice) == 1} + disabled={voteId !== vote.id}> + <input if={poll.voteCountingTypeValue.renderType === 'text' && (poll.getVoteValue(vote, choice) || voteId === vote.id)} + ref="vote_{vote.id}_{choice.id}" + class="text c-field" + name="vote_{vote.id}_{choice.id}" + type="number" + required={vote.id === voteId} + min="1" + disabled={voteId !== vote.id} + value={poll.getVoteValue(vote, choice)}> </div> <div class="vote-actions"> <span class="c-input-group" @@ -129,6 +131,28 @@ </div> </div> </div> + + <form ref="formAddChoice" + if={poll.status === "ADDING_CHOICES"} + onsubmit="{addChoice}"> + <div class="o-form-element"> + <label class="c-label" for="choice">{__.addChoice}</label> + <div class="c-input-group"> + <div class="o-field"> + <Choice ref="choice" + class="c-field" + name="choice" + choice="{choiceToAdd}"/> + </div> + <button type="submit" + class="c-button c-button--success" + tooltips="{__.addChoice}"> + <i class="fa fa-plus"/> + </button> + </div> + </div> + + </form> </div> </div> @@ -136,6 +160,7 @@ this.loaded = false; let session = require("../../js/Session"); let Remarkable = require("remarkable"); + let Choice = require("../../js/Choice"); this.md = new Remarkable(); this.moment = require("moment"); this.moment.locale(session.locale); @@ -150,7 +175,8 @@ this.poll = {}; this.opts.pollPromise.then(poll => { this.poll = poll; - this.voting = poll.status === "VOTING" || poll.status === "CLOSED"; + this.voting = poll.canVote || poll.status === "VOTING" || poll.status === "CLOSED"; + this.choiceToAdd = new Choice("TEXT"); return Promise.all([ poll.loadChoices(), poll.loadVotes(), @@ -256,7 +282,7 @@ }; updateVote.choice.push(voteChoice); } - updateVote.voteValue = this.getChoiceVoteValue("vote_" + vote.id + "_" + choice.id); + voteChoice.voteValue = this.getChoiceVoteValue("vote_" + vote.id + "_" + choice.id); }); this.poll.updateVote(updateVote).then(() => { this.voteId = null; @@ -281,6 +307,17 @@ } }; + this.addChoice = (e) => { + e.preventDefault(); + e.stopPropagation(); + this.refs.choice.submit(); + this.poll.addChoice(this.choiceToAdd).then(() => { + this.refs.choice.clear(); + this.update(); + this.updateChoices(); + }); + }; + </script> <style> @@ -350,7 +387,8 @@ justify-content: center; } - .voters .fix .choice.choice-resource { + .voters .fix .choice.choice-resource, + .voters .window .frame .vote .vote-choice.choice-resource { height: 200px; } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.