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 b0277f06461f6590f9b43f70fa8f54a6b0c203dd Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed May 30 15:20:40 2018 +0200 refs #199 : Il faut garder la possibilité de saisir les valeurs des choix comme sur la version 3.1.4 --- pollen-ui-riot-js/src/main/web/css/main.css | 6 ++ pollen-ui-riot-js/src/main/web/i18n/en.json | 4 + pollen-ui-riot-js/src/main/web/i18n/fr.json | 4 + pollen-ui-riot-js/src/main/web/js/Session.js | 8 ++ .../src/main/web/tag/poll/EditVote.tag.html | 114 +++++++++------------ .../src/main/web/tag/poll/EditVoteOrder.tag.html | 113 ++++++++------------ .../src/main/web/tag/poll/Votes.tag.html | 44 +++++++- .../pollen-votecounting-condorcet_en_GB.properties | 2 +- .../pollen-votecounting-condorcet_fr_FR.properties | 2 +- 9 files changed, 158 insertions(+), 139 deletions(-) diff --git a/pollen-ui-riot-js/src/main/web/css/main.css b/pollen-ui-riot-js/src/main/web/css/main.css index f2131bf1..7915e075 100644 --- a/pollen-ui-riot-js/src/main/web/css/main.css +++ b/pollen-ui-riot-js/src/main/web/css/main.css @@ -122,6 +122,12 @@ a { margin: 2px; } +.actions.c-input-group .c-button, +.actions-left.c-input-group .c-button, +.actions-right.c-input-group .c-button { + margin: 0; +} + .actions-left { padding: 5px 0; display: flex; diff --git a/pollen-ui-riot-js/src/main/web/i18n/en.json b/pollen-ui-riot-js/src/main/web/i18n/en.json index 3bc6e723..850209d5 100644 --- a/pollen-ui-riot-js/src/main/web/i18n/en.json +++ b/pollen-ui-riot-js/src/main/web/i18n/en.json @@ -173,10 +173,14 @@ "poll_votes_voteClosed": "Votes are closed", "poll_votes_ignored": "Ignored", "poll_votes_pointsDistribution": "Distribute {0} points among the proposed choices", + "poll_votes_voteByOrder": "Rank choices by preference order (1 = favorite)", + "poll_votes_voteByOrderWithMax": "Rank the {0} firsts choices by preference order (1 = favorite)", "poll_votes_remainPoints": "It remains {0} points to distribute", "poll_votes_remainPoint": "It remains {0} point to distribute", "poll_votes_tooManyPoints": "There are {0} points distributed too much", "poll_votes_tooManyPoint": "There is {0} point distributed too much", + "poll_votes_voteByClickAndDrop": "Vote by click and drop", + "poll_votes_voteByInput": "Vote by entry", "polls_createdPolls": "My polls", "polls_assignPollToMe": "Link a poll to my account", "polls_assignPollToMe_title": "Link the poll", diff --git a/pollen-ui-riot-js/src/main/web/i18n/fr.json b/pollen-ui-riot-js/src/main/web/i18n/fr.json index d20ebba6..3353992d 100644 --- a/pollen-ui-riot-js/src/main/web/i18n/fr.json +++ b/pollen-ui-riot-js/src/main/web/i18n/fr.json @@ -173,10 +173,14 @@ "poll_votes_voteClosed": "Les votes sont clos.", "poll_votes_ignored": "Ignoré", "poll_votes_pointsDistribution": "Distribuer {0} points parmis les choix proposés", + "poll_votes_voteByOrder": "Classer les choix par ordre de préférence (1 = préféré)", + "poll_votes_voteByOrderWithMax": "Classer vos {0} premiers choix par ordre de préférence (1 = préféré)", "poll_votes_remainPoints": "Il reste {0} points à distribuer", "poll_votes_remainPoint": "Il reste {0} point à distribuer", "poll_votes_tooManyPoints": "Il y a {0} points distribués en trop", "poll_votes_tooManyPoint": "Il y a {0} point distribué en trop", + "poll_votes_voteByClickAndDrop": "Vote par cliquer/glisser", + "poll_votes_voteByInput": "Vote par saisie", "polls_createdPolls": "Mes sondages", "polls_assignPollToMe": "Attacher le sondage", "polls_assignPollToMe_title": "Attacher un sondage à mon compte", diff --git a/pollen-ui-riot-js/src/main/web/js/Session.js b/pollen-ui-riot-js/src/main/web/js/Session.js index 980c3cb7..9385ac5e 100644 --- a/pollen-ui-riot-js/src/main/web/js/Session.js +++ b/pollen-ui-riot-js/src/main/web/js/Session.js @@ -146,6 +146,14 @@ class Session { bus.trigger("locale", this.locale); } + getUserSetting(key, defaultValue) { + return localStorage[key] || defaultValue; + } + + setUserSetting(key, value) { + localStorage[key] = value; + } + isConnected() { return document.cookie.indexOf("pollen-auth=") !== -1; } diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/EditVote.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/EditVote.tag.html index c0fb0de7..cee05efa 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/EditVote.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/EditVote.tag.html @@ -26,8 +26,16 @@ if={(poll.voteCountingType === 2)}> {_l("pointsDistribution", poll.voteCountingConfig.points)} </h3> + <h3 class="c-heading" + if={([3, 5, 6, 7].indexOf(poll.voteCountingType) >= 0) && !poll.voteCountingConfig.maxChoiceNumber}> + {_t.voteByOrder} + </h3> + <h3 class="c-heading" + if={(poll.voteCountingType === 5) && poll.voteCountingConfig.maxChoiceNumber}> + {_l("voteByOrderWithMax", poll.voteCountingConfig.maxChoiceNumber)} + </h3> <form id="voteForm" class="voter separator" ref="formAddVote"> - <HumanInput onsubmit="{voteInEdition ? updateVote : addVote}"></HumanInput> + <HumanInput onsubmit="{saveVote}"></HumanInput> <div class="header"> <div class="current-voter separator-right"> <div class="o-field o-field--icon-left o-field--icon-right" @@ -201,7 +209,9 @@ }; this.editVote = vote => { - this.voteInEdition = vote; + if (vote.id) { + this.voteInEdition = vote; + } this.error = null; this.update(); this.refs.voterName.value = vote.voterName; @@ -285,88 +295,62 @@ this.error = null; }; - this.addVote = (e) => { - e.preventDefault(); - e.stopPropagation(); + this.getVote = () => { - this.voting = true; - this.update(); + let vote; - let vote = { - id: null, - voterName: this.refs.voterName.value, - choice: [] - }; + if (this.voteInEdition) { + vote = Object.assign({}, this.voteInEdition); // don't modify original vote + vote.voterName = this.refs.voterName.value; - this.poll.choices.forEach(c => { - vote.choice.push({ - choiceId: c.id, - voteValue: this.getChoiceVoteValue(c.id + "_voteValue") + this.poll.choices.forEach(choice => { + let voteChoice = this.poll.getVoteChoice(vote, choice); + if (!voteChoice) { + voteChoice = { + choiceId: choice.id + }; + vote.choice.push(voteChoice); + } + voteChoice.voteValue = this.getChoiceVoteValue(choice.id + "_voteValue"); }); - }); - this.poll.addVote(vote).then(() => { - this.resetVoteForm(); - if (this.poll.resultIsVisible) { - this.poll.loadResults().then(() => { - this.voting = false; - this.update(); - }, () => { - this.voting = false; - this.update(); + } else { + + vote = { + id: null, + voterName: this.refs.voterName.value, + choice: [] + }; + + this.poll.choices.forEach(c => { + vote.choice.push({ + choiceId: c.id, + voteValue: this.getChoiceVoteValue(c.id + "_voteValue") }); - } else { - this.voting = false; - this.update(); - } - }, - (error) => { - this.error = error; - this.voting = false; - this.update(); - }); - }; + }); + } + + return vote; + } - this.updateVote = e => { + this.saveVote = e => { e.preventDefault(); e.stopPropagation(); this.voting = true; this.update(); - let updateVote = Object.assign({}, this.voteInEdition); // don't modify original vote - updateVote.voterName = this.refs.voterName.value; + let vote = this.getVote(); - this.poll.choices.forEach(choice => { - let voteChoice = this.poll.getVoteChoice(updateVote, choice); - if (!voteChoice) { - voteChoice = { - choiceId: choice.id - }; - updateVote.choice.push(voteChoice); - } - voteChoice.voteValue = this.getChoiceVoteValue(choice.id + "_voteValue"); - }); - - this.poll.updateVote(updateVote).then(() => { + this.opts.onSaveVote(vote).then(() => { + this.voting = false; this.voteInEdition = null; this.resetVoteForm(); - if (this.poll.resultIsVisible) { - this.poll.loadResults().then(() => { - this.voting = false; - this.update(); - }, () => { - this.voting = false; - this.update(); - }); - } else { - this.voting = false; - this.update(); - } + this.update(); }, (error) => { - this.voting = false; this.error = error; + this.voting = false; this.update(); }); }; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/EditVoteOrder.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/EditVoteOrder.tag.html index 3846cb59..7e108c81 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/EditVoteOrder.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/EditVoteOrder.tag.html @@ -23,7 +23,7 @@ <div class="form-wrapper"> <form id="voteForm" class="voter" ref="formAddVote"> - <HumanInput onsubmit="{voteInEdition ? updateVote : addVote}"></HumanInput> + <HumanInput onsubmit="{saveVote}"></HumanInput> <div class="current-voter"> <div class="o-field o-field--icon-left o-field--icon-right" if={poll.canVote || voteInEdition} > @@ -328,106 +328,81 @@ this.resetVoteForm(); }; - this.editVote = vote => { - this.voteInEdition = vote; + this.editVote = (vote, noAnim) => { + if (vote.id) { + this.voteInEdition = vote; + } this.update(); this.refs.voterName.value = vote.voterName; this.refs.choices.forEach(choiceElt => { let choice = vote.choice.find(c => c.choiceId === choiceElt.choice.id); - if (this.maxChoiceNumber && !choice.voteValue) { + if (!choice.voteValue) { choiceElt.voteOrder = undefined; - choiceElt.stashed = true; + choiceElt.stashed = this.maxChoiceNumber; } else { choiceElt.voteOrder = choice && choice.voteValue; choiceElt.stashed = false; } }); this.compactVoteOrders(); - this.placeChoices(); + this.placeChoices(noAnim); }; - this.addVote = e => { - e.preventDefault(); - e.stopPropagation(); + this.getVote = () => { - this.voting = true; - this.update(); + let vote; - let vote = { - id: null, - voterName: this.refs.voterName.value, - choice: [] - }; + if (this.voteInEdition) { + vote = Object.assign({}, this.voteInEdition); // don't modify original vote + vote.voterName = this.refs.voterName.value; - this.refs.choices.forEach(c => { - vote.choice.push({ - choiceId: c.choice.id, - voteValue: c.voteOrder + 1 + this.refs.choices.forEach(c => { + let voteChoice = this.poll.getVoteChoice(vote, c.choice); + if (!voteChoice) { + voteChoice = { + choiceId: c.choice.id + }; + vote.choice.push(voteChoice); + } + voteChoice.voteValue = c.voteOrder + 1; }); - }); - - this.poll.addVote(vote).then(() => { - //this.resetVoteForm(); - if (this.poll.resultIsVisible) { - this.poll.loadResults().then(() => { - this.voting = false; - this.update(); - }, () => { - this.voting = false; - this.update(); + } else { + vote = { + id: null, + voterName: this.refs.voterName.value, + choice: [] + }; + + this.refs.choices.forEach(c => { + vote.choice.push({ + choiceId: c.choice.id, + voteValue: c.voteOrder + 1 }); - } else { - this.voting = false; - this.update(); - } - }, - (error) => { - this.error = error; - this.voting = false; - this.update(); - }); + }); + } + + return vote; + }; - this.updateVote = e => { + this.saveVote = e => { e.preventDefault(); e.stopPropagation(); this.voting = true; this.update(); - let updateVote = Object.assign({}, this.voteInEdition); // don't modify original vote - updateVote.voterName = this.refs.voterName.value; - - this.refs.choices.forEach(c => { - let voteChoice = this.poll.getVoteChoice(updateVote, c.choice); - if (!voteChoice) { - voteChoice = { - choiceId: c.choice.id - }; - updateVote.choice.push(voteChoice); - } - voteChoice.voteValue = c.voteOrder + 1; - }); + let vote = this.getVote(); - this.poll.updateVote(updateVote).then(() => { + this.opts.onSaveVote(vote).then(() => { + this.voting = false; this.voteInEdition = null; this.resetVoteForm(); - if (this.poll.resultIsVisible) { - this.poll.loadResults().then(() => { - this.voting = false; - this.update(); - }, () => { - this.voting = false; - this.update(); - }); - } else { - this.voting = false; - this.update(); - } + this.update(); }, (error) => { - this.voting = false; this.error = error; + this.voting = false; this.update(); }); }; 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 f308b600..425c8ddb 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 @@ -21,10 +21,24 @@ <Votes> <div class="container" show="{loaded}"> + <span class="c-input-group actions-right" + if={isVoteByOrder}> + <button class="c-button c-button--info {c-button--ghost-info: !voteClickAndDrop, c-button--info: voteClickAndDrop}" + onclick={voteClickAndDropChange(true)} + title={_t.voteByClickAndDrop} + type="button"><i class="fa fa-list-ol"></i></button> + <button class="c-button c-button--info {c-button--ghost-info: voteClickAndDrop, c-button--info: !voteClickAndDrop}" + onclick={voteClickAndDropChange(false)} + title={_t.voteByInput} + type="button"><i class="fa fa-i-cursor"></i></button> + </span> + <EditVote ref="editVote" - if={!isVoteByOrder}/> + show={!isVoteByOrder || !voteClickAndDrop} + on-save-vote={saveVote}/> <EditVoteOrder ref="editVoteOrder" - if={isVoteByOrder}/> + show={isVoteByOrder && voteClickAndDrop} + on-save-vote={saveVote}/> <!-- Form to vote --> <p class="warning-label warning" if="{loaded && !poll.canVote}"> @@ -78,6 +92,7 @@ this.installBundle(session, "poll_votes"); this.addingChoice = false; this.isVoteByOrder = false; + this.voteClickAndDrop = false; this.poll = poll; @@ -87,16 +102,39 @@ this.loaded = poll2.choices !== undefined; this.poll = poll2; this.isVoteByOrder = [3, 5, 6, 7].indexOf(poll2.voteCountingType) >= 0; + this.voteClickAndDrop = this.isVoteByOrder && session.getUserSetting("voteClickAndDrop", "true") === "true"; this.update(); }; this.listen("poll", this.onPollChange); this.editVote = (vote) => { - let editor = this.isVoteByOrder ? this.refs.editVoteOrder : this.refs.editVote; + let editor = this.voteClickAndDrop ? this.refs.editVoteOrder : this.refs.editVote; editor.editVote(vote); }; + this.saveVote = (vote) => { + let promise = vote.id ? this.poll.updateVote(vote) : this.poll.addVote(vote); + + return promise.then(result => { + if (this.poll.resultIsVisible) { + return this.poll.loadResults().then(() => result); + } + return result; + }); + }; + + this.voteClickAndDropChange = value => () => { + if (this.isVoteByOrder && this.voteClickAndDrop !== value) { + session.setUserSetting("voteClickAndDrop", value); + let oldEditor = this.voteClickAndDrop ? this.refs.editVoteOrder : this.refs.editVote; + this.voteClickAndDrop = value; + let newEditor = this.voteClickAndDrop ? this.refs.editVoteOrder : this.refs.editVote; + let vote = oldEditor.getVote(); + newEditor.editVote(vote, true); + } + }; + this.addChoice = (e) => { e.preventDefault(); e.stopPropagation(); diff --git a/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_en_GB.properties b/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_en_GB.properties index 06afd681..6fd2e4da 100644 --- a/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_en_GB.properties +++ b/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_en_GB.properties @@ -1,5 +1,5 @@ pollen.voteCountingType.condorcet=Condorcet -pollen.voteCountingType.condorcet.help=Rank choices by preference order from 1 to N (1\=favorite).<br/>Only the rank is taken into account, not the values. Two choices can have the same value.<br/>In this method, the winner is the choice which wins the most duels against the other choices.<br/>More about this method\: <a href\='http\://en.wikipedia.org/wiki/Condorcet_method' target\='\#doc'>http\://en.wikipedia.org/wiki/Condorcet_method</a> +pollen.voteCountingType.condorcet.help=Rank choices by preference order from 1 to N (1=favorite).<br/>Only the rank is taken into account, not the values. Two choices can have the same value.<br/>In this method, the winner is the choice which wins the most duels against the other choices.<br/>More about this method: <a href='http://en.wikipedia.org/wiki/Condorcet_method' target='#doc'>http://en.wikipedia.org/wiki/Condorcet_method</a> pollen.voteCountingType.condorcet.shortHelp=Rank choices by preference order from 1 to N (1\=favorite). pollen.voteCountingType.condorcet.voteValue.error.positive=The value %1$s must be positive. pollen.voteCountingType.condorcet.voteValue.error.required=The value is required. diff --git a/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_fr_FR.properties b/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_fr_FR.properties index b748948c..b790dbb8 100644 --- a/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_fr_FR.properties +++ b/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_fr_FR.properties @@ -1,5 +1,5 @@ pollen.voteCountingType.condorcet=Condorcet -pollen.voteCountingType.condorcet.help=Classer les choix par ordre de préférence de 1 à N (1\=préféré).<br/>Seul l'ordre des choix compte, peu importe les valeurs. Deux choix peuvent avoir la même valeur.<br/>Dans cette méthode, le gagnant est celui qui remporte le plus de duels par rapport aux autres choix.<br/>Pour en savoir plus \: <a href\='http\://fr.wikipedia.org/wiki/M%C3%A9thode_Condorcet' target\='\#doc'>http\://fr.wikipedia.org/wiki/Méthode_Condorcet</a> +pollen.voteCountingType.condorcet.help=Classer les choix par ordre de préférence de 1 à N (1=préféré).<br/>Seul l'ordre des choix compte, peu importe les valeurs. Deux choix peuvent avoir la même valeur.<br/>Dans cette méthode, le gagnant est celui qui remporte le plus de duels par rapport aux autres choix.<br/>Pour en savoir plus : <a href='http://fr.wikipedia.org/wiki/M%C3%A9thode_Condorcet' target='#doc'>http://fr.wikipedia.org/wiki/Méthode_Condorcet</a> pollen.voteCountingType.condorcet.shortHelp=Classer les choix par ordre de préférence de 1 à N (1\=préféré). pollen.voteCountingType.condorcet.voteValue.error.positive=La valeur du vote %1$s doit être positive. pollen.voteCountingType.condorcet.voteValue.error.required=La valeur du vote est obligatoire. -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.