branch feature/pollen-riot-js updated (a86254a -> 03ce02e)
This is an automated email from the git hooks/post-receive script. New change to branch feature/pollen-riot-js in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git from a86254a fix tests new 03ce02e Mise en place des différents types de scrutin + revue des éditeurs de votes The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 03ce02ebcb0101ed2d102044a5b8aa3eb185282d Author: Tony CHEMIT <dev@tchemit.fr> Date: Wed Feb 1 11:01:07 2017 +0100 Mise en place des différents types de scrutin + revue des éditeurs de votes Summary of changes: .../org/chorem/pollen/rest/api/JsonHelper.java | 19 ++++- .../rest/api/PollenRestApiApplicationListener.java | 4 ++ .../rest/api/converter/PollenEnumConverter.java | 54 ++++++++++++++ .../pollen/services/service/PollService.java | 28 ++++---- pollen-ui-riot-js/src/main/web/js/FormHelper.js | 24 +++---- pollen-ui-riot-js/src/main/web/js/PollForm.js | 5 +- ...ResultService.js => VoteCountingTypeService.js} | 18 ++--- pollen-ui-riot-js/src/main/web/tag/Home.tag | 56 ++++++++------- .../src/main/web/tag/poll/CreatePoll.tag | 2 +- pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag | 2 +- .../src/main/web/tag/poll/PollSettings.tag | 84 +++++++++++++--------- .../src/main/web/tag/poll/PollVotes.tag | 80 ++++++++++++++------- 12 files changed, 247 insertions(+), 129 deletions(-) create mode 100644 pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/PollenEnumConverter.java copy pollen-ui-riot-js/src/main/web/js/{ResultService.js => VoteCountingTypeService.js} (72%) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/pollen-riot-js in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 03ce02ebcb0101ed2d102044a5b8aa3eb185282d Author: Tony CHEMIT <dev@tchemit.fr> Date: Wed Feb 1 11:01:07 2017 +0100 Mise en place des différents types de scrutin + revue des éditeurs de votes --- .../org/chorem/pollen/rest/api/JsonHelper.java | 19 ++++- .../rest/api/PollenRestApiApplicationListener.java | 4 ++ .../rest/api/converter/PollenEnumConverter.java | 54 ++++++++++++++ .../pollen/services/service/PollService.java | 28 ++++---- pollen-ui-riot-js/src/main/web/js/FormHelper.js | 24 +++---- pollen-ui-riot-js/src/main/web/js/PollForm.js | 5 +- .../src/main/web/js/VoteCountingTypeService.js | 36 ++++++++++ pollen-ui-riot-js/src/main/web/tag/Home.tag | 56 ++++++++------- .../src/main/web/tag/poll/CreatePoll.tag | 2 +- pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag | 2 +- .../src/main/web/tag/poll/PollSettings.tag | 84 +++++++++++++--------- .../src/main/web/tag/poll/PollVotes.tag | 80 ++++++++++++++------- 12 files changed, 274 insertions(+), 120 deletions(-) diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/JsonHelper.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/JsonHelper.java index 85ab3c7..1afee10 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/JsonHelper.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/JsonHelper.java @@ -32,6 +32,8 @@ import com.google.gson.JsonNull; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializer; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.math.NumberUtils; import org.chorem.pollen.services.bean.PollenEntityId; import org.chorem.pollen.services.bean.PollenEntityRef; import org.chorem.pollen.services.service.FavoriteListImportException; @@ -39,6 +41,8 @@ import org.chorem.pollen.services.service.InvalidFormException; import org.nuiton.topia.persistence.TopiaIdFactory; import java.lang.reflect.Type; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -51,6 +55,7 @@ import java.util.Map; */ public class JsonHelper { + public static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm"); private final Gson gson; public JsonHelper(final TopiaIdFactory idFactory, boolean prettyPrint) { @@ -79,7 +84,7 @@ public class JsonHelper { } else { - result = new JsonPrimitive(src.getTime()); + result = new JsonPrimitive(SIMPLE_DATE_FORMAT.format(src)); } @@ -158,7 +163,17 @@ public class JsonHelper { }); - gsonBuilder.registerTypeAdapter(Date.class, (JsonDeserializer<Date>) (json, typeOfT, context) -> new Date(json.getAsLong())); + gsonBuilder.registerTypeAdapter(Date.class, (JsonDeserializer<Date>) (json, typeOfT, context) -> { + if (NumberUtils.isCreatable(json.getAsString())) { + return new Date(json.getAsLong()); + } + try { + return SIMPLE_DATE_FORMAT.parse(json.getAsString()); + } catch (ParseException e) { + return null; + } + + }); gsonBuilder.registerTypeAdapter(PollenEntityId.class, (JsonDeserializer<PollenEntityId>) (json, typeOfT, context) -> { diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java index 1d8d971..26cfea0 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java @@ -22,9 +22,11 @@ package org.chorem.pollen.rest.api; */ import com.google.common.collect.Sets; +import org.chorem.pollen.persistence.entity.ChoiceType; import org.chorem.pollen.rest.api.converter.DateConverter; import org.chorem.pollen.rest.api.converter.JsonArrayConverter; import org.chorem.pollen.rest.api.converter.JsonConverter; +import org.chorem.pollen.rest.api.converter.PollenEnumConverter; import org.chorem.pollen.rest.api.injector.PollenBeanIdInjector; import org.chorem.pollen.rest.api.injector.PollenRestApiRequestContextInjector; import org.chorem.pollen.rest.api.injector.PollenServiceInjector; @@ -42,6 +44,7 @@ import org.chorem.pollen.services.bean.VoterListMemberBean; import org.debux.webmotion.server.WebMotionServerListener; import org.debux.webmotion.server.call.ServerContext; import org.debux.webmotion.server.mapping.Mapping; +import org.nuiton.converter.EnumConverter; import org.nuiton.topia.persistence.TopiaIdFactory; import java.util.Date; @@ -86,6 +89,7 @@ public class PollenRestApiApplicationListener implements WebMotionServerListener // --- init converters --- // serverContext.addConverter(new DateConverter(), Date.class); + serverContext.addConverter(new PollenEnumConverter<>(ChoiceType.class), ChoiceType.class); for (Class<?> beanType : BEAN_TYPES) { diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/PollenEnumConverter.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/PollenEnumConverter.java new file mode 100644 index 0000000..8307709 --- /dev/null +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/converter/PollenEnumConverter.java @@ -0,0 +1,54 @@ +package org.chorem.pollen.rest.api.converter; + +import org.apache.commons.beanutils.ConversionException; +import org.nuiton.converter.EnumConverter; + +/** + * Created on 31/01/17. + * + * @author Tony Chemit - dev@tchemit.fr + * @since 2.0 + */ +public class PollenEnumConverter<E extends Enum> extends EnumConverter<E> { + + public PollenEnumConverter(Class<E> enumType, Object defaultValue) { + super(enumType, defaultValue); + } + + public PollenEnumConverter(Class<E> enumType) { + super(enumType); + } + + @Override + public <T> T convert(Class<T> aClass, Object value) { + if (value == null) { + return super.convert(aClass, value); + } + if (isEnabled(aClass, enumType)) { + Object result; + if (isEnabled(value.getClass(), enumType)) { + result = value; + return aClass.cast(result); + } + if (value.getClass().isArray()) { { + value = ((Object[])value)[0]; + }} + if (value instanceof String) { + try { + result = valueOf(aClass, value); + } catch (IllegalArgumentException e) { + // try an ordinal conversion + result = convertFromOrdinal(aClass, value); + } + return aClass.cast(result); + } + if (value instanceof Integer) { + // try a ordinal conversion + result = convertFromOrdinal(aClass, value); + return aClass.cast(result); + } + } + throw new ConversionException( + String.format("no convertor found for type %2$s and objet '%1$s'", aClass.getName(), value)); + } +} diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java index 8ed1754..61ae54f 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java @@ -42,6 +42,7 @@ import org.nuiton.util.pagination.PaginationResult; import java.io.File; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.function.Function; @@ -160,7 +161,7 @@ public class PollService extends PollenServiceSupport { pollBean.setVoteVisibility(getPollenServiceConfig().getDefaultVoteVisibility()); pollBean.setCommentVisibility(getPollenServiceConfig().getDefaultCommentVisibility()); pollBean.setResultVisibility(getPollenServiceConfig().getDefaultResultVisibility()); - pollBean.setBeginDate(serviceContext.getNow()); +// pollBean.setBeginDate(serviceContext.getNow()); // -- creator -- // @@ -381,25 +382,26 @@ public class PollService extends PollenServiceSupport { toSave.setMaxChoiceNumber(poll.getMaxChoiceNumber()); toSave.setTitle(poll.getTitle()); - if (poll.getBeginDate() == null) { - toSave.setBeginDate(getNow()); - } else { - toSave.setBeginDate(poll.getBeginDate()); - } - + toSave.setBeginDate(poll.getBeginDate()); toSave.setEndDate(poll.getEndDate()); toSave.setChoiceAddAllowed(poll.isChoiceAddAllowed()); if (poll.isChoiceAddAllowed()) { - if (poll.getBeginChoiceDate() == null || poll.getBeginChoiceDate().compareTo(toSave.getBeginDate()) == -1) { - // correction Date - toSave.setBeginChoiceDate(toSave.getBeginDate()); - } else { - toSave.setBeginChoiceDate(poll.getBeginChoiceDate()); + toSave.setBeginChoiceDate(poll.getBeginChoiceDate()); + toSave.setEndChoiceDate(poll.getEndChoiceDate()); + + if (toSave.getBeginDate() == null) { + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(poll.getEndChoiceDate()); + calendar.add(Calendar.MINUTE, 1); + toSave.setBeginDate(calendar.getTime()); } + } - toSave.setEndChoiceDate(poll.getEndChoiceDate()); + if (toSave.getBeginDate() == null) { + toSave.setBeginDate(getNow()); } // -- choice -- // diff --git a/pollen-ui-riot-js/src/main/web/js/FormHelper.js b/pollen-ui-riot-js/src/main/web/js/FormHelper.js index efc5bbc..6b13fc6 100644 --- a/pollen-ui-riot-js/src/main/web/js/FormHelper.js +++ b/pollen-ui-riot-js/src/main/web/js/FormHelper.js @@ -21,6 +21,9 @@ class FormHelper { static formToMap(form) { + + let moment = require('moment'); + let result = {}; Array.prototype.forEach.call(form.elements, (e) => { if (e.name) { @@ -28,15 +31,10 @@ class FormHelper { if (e.checked) { result[e.name] = true; } - } else if (e.type === "date") { - if (e.value !== "") { - result[e.name] = this.toISOTZString(e.value + "T12:00"); - } } else if (e.type === "datetime-local") { if (e.value !== "") { - // result[e.name] = this.toISOTZString(e.value); - result[e.name] = new Date(e.value).getTime(); - console.info('date: '+result[e.name]); + result[e.name] = moment(e.value).format('YYYY-MM-DDTHH:mm'); + console.info('date::: '+e.value+" -- "+result[e.name]); } } else if (e.type === "radio") { Array.prototype.forEach.call(form.elements[e.name], function(r) { @@ -62,6 +60,9 @@ class FormHelper { } static fillForm(form, context, defaults = {}) { + + let moment = require('moment'); + let formData = context._formData || context; Array.prototype.forEach.call(form.elements, (e) => { if (e.name) { @@ -75,7 +76,8 @@ class FormHelper { } else if (e.type === "datetime-local") { let d = new Date(value); if (!isNaN( d.getTime() )) { - e.value = new Date(+d - d.getTimezoneOffset() * 60 * 1000).toISOString().replace("Z", ""); + e.value = moment(d).format('YYYY-MM-DDThh:mm'); + //e.value = d.toISOString().replace("Z", ""); } } else if (e.type === "radio") { Array.prototype.forEach.call(form.elements[e.name], function(r) { @@ -99,12 +101,6 @@ class FormHelper { }); } - static toISOTZString(date) { - let d = new Date(date); - let tz = -d.getTimezoneOffset() * 60 * 1000; - return new Date(+d - 2 * tz).toISOString(); - } - } module.exports = FormHelper; 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 0836a66..4bfee2a 100644 --- a/pollen-ui-riot-js/src/main/web/js/PollForm.js +++ b/pollen-ui-riot-js/src/main/web/js/PollForm.js @@ -35,12 +35,13 @@ class PollForm { this.choices = []; } - init(user) { + init(choiceType, user) { this.isInit = true; + this.choiceType = choiceType; console.info("init form"); this.step = 0; - return this.service.empty().then((poll) => { + return this.service.empty(this.choiceType).then((poll) => { this.model = poll; console.info("empty poll"); console.info(this.model); diff --git a/pollen-ui-riot-js/src/main/web/js/VoteCountingTypeService.js b/pollen-ui-riot-js/src/main/web/js/VoteCountingTypeService.js new file mode 100644 index 0000000..5253c6c --- /dev/null +++ b/pollen-ui-riot-js/src/main/web/js/VoteCountingTypeService.js @@ -0,0 +1,36 @@ +/*- + * #%L + * Pollen :: UI (Riot Js) + * %% + * Copyright (C) 2009 - 2017 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +let singleton = require("./Singleton"); +let FetchService = require("./FetchService"); + +class VoteCountingTypeService extends FetchService { + + getVoteCountingType(voteCountingTypeId) { + return this.get("/v1/voteCountingTypes/"+voteCountingTypeId); + }; + + getVoteCountingTypes() { + return this.get("/v1/voteCountingTypes"); + }; + +} + +module.exports = singleton(VoteCountingTypeService); diff --git a/pollen-ui-riot-js/src/main/web/tag/Home.tag b/pollen-ui-riot-js/src/main/web/tag/Home.tag index 80be1ce..e79cbf6 100644 --- a/pollen-ui-riot-js/src/main/web/tag/Home.tag +++ b/pollen-ui-riot-js/src/main/web/tag/Home.tag @@ -1,23 +1,23 @@ /*- - * #%L - * Pollen :: UI (Riot Js) - * %% - * Copyright (C) 2009 - 2017 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ +* #%L +* Pollen :: UI (Riot Js) +* %% +* Copyright (C) 2009 - 2017 CodeLutin +* %% +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* #L% +*/ <Home> <div class="body-container"> @@ -36,27 +36,31 @@ this.installBundle(session, "home"); this.createText = () => { - session.getUser().then(user=> { - form.init(user).then(() => { + session.getUser().then(user => { + form.init('TEXT', user).then(() => { route("/poll/new/text/0"); }); }); }; this.createImage = () => { - form.init(session.getUser).then(() => { - route("/poll/new/image/0"); + session.getUser().then(user => { + form.init('RESOURCE', user).then(() => { + route("/poll/new/image/0"); + }); }); }; this.createDate = () => { - form.init(session.getUser).then(() => { - route("/poll/new/date/0"); + session.getUser().then(user => { + form.init('DATE', user).then(() => { + route("/poll/new/date/0"); + }); }); }; </script> - <style scoped> + <style> .body-container { display: flex; flex-flow: row wrap; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/CreatePoll.tag b/pollen-ui-riot-js/src/main/web/tag/poll/CreatePoll.tag index 512a272..975f6b6 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/CreatePoll.tag +++ b/pollen-ui-riot-js/src/main/web/tag/poll/CreatePoll.tag @@ -152,7 +152,7 @@ require("./PollCreated.tag"); if (!this.form.isInit) { this.session.getUser().then(user => { - this.form.init(user).then(() => { + this.form.init(opts.choiceType, user).then(() => { this.form.setStep(0); this.finalizeInit(); }); diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag b/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag index 43939d2..736e76f 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag @@ -71,7 +71,7 @@ require('./PollChoices.tag'); console.info("Poll::"); console.info(this.poll); if (!this.selectedTab) { - if (this.poll.status == 'VOTING') { + if (this.poll.status == 'VOTING' || this.poll.status == 'CREATED') { this.selectedTab = 'votes'; } else if (this.poll.status == 'ADDING_CHOICES') { this.selectedTab = 'choices'; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/PollSettings.tag b/pollen-ui-riot-js/src/main/web/tag/poll/PollSettings.tag index 9955a8d..b8048a5 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/PollSettings.tag +++ b/pollen-ui-riot-js/src/main/web/tag/poll/PollSettings.tag @@ -28,7 +28,6 @@ <div class="actions"> <a if="{!showOptions}" class="button" onclick="{previousStep}">{__.previous}</a> <a if="{!showOptions}" class="button wide" onclick="{toggleShowOptions}">{__.showOptions}</a> - <!--a if="{showOptions}" class="button wide" onclick="{toggleShowOptions}">{__.hideOptions}</a--> </div> <form show="{showOptions}" ref="form" onsubmit="{action}"> @@ -68,12 +67,12 @@ </ul> </li> <li> + <a onclick="{scrollTo}" href="#VoteCountingType">{__.nav_voteCountingType}</a> + </li> + <li> <a onclick="{scrollTo}" href="#Vote">{__.nav_votes}</a> <ul class="nav nav-stacked"> <li> - <a onclick="{scrollTo}" href="#Vote_countingType">{__.nav_voteCountingType}</a> - </li> - <li> <a onclick="{scrollTo}" href="#Vote_visibility">{__.nav_voteVisibility}</a> </li> <li> @@ -103,11 +102,11 @@ <div class="config-form config-period"> <div> <label for="beginDate">{__.beginDate}</label> - <input ref="beginDate" name="beginDate" type="datetime-local"> + <input ref="beginDate" name="beginDate" id="beginDate" type="datetime-local"> </div> <div> <label for="endDate">{__.endDate}</label> - <input ref="endDate" name="endDate" type="datetime-local"> + <input ref="endDate" name="endDate" id="endDate" type="datetime-local"> </div> </div> </div> @@ -160,11 +159,13 @@ <div if="{form.model.choiceAddAllowed}" class="config-period"> <div> <label for="beginChoiceDate">{__.beginChoiceDate}</label> - <input ref="beginChoiceDate" name="beginChoiceDate" type="datetime-local"> + <input ref="beginChoiceDate" name="beginChoiceDate" id="beginChoiceDate" + type="datetime-local"> </div> <div> - <label for="endDate">{__.endChoiceDate}</label> - <input ref="endChoiceDate" name="endChoiceDate" type="datetime-local"> + <label for="endChoiceDate">{__.endChoiceDate}</label> + <input ref="endChoiceDate" name="endChoiceDate" id="endChoiceDate" + type="datetime-local"> </div> </div> </div> @@ -188,26 +189,20 @@ </div> </div> </div> + <div id="VoteCountingType" class="config-group"> + <div class="config-header">{__.nav_voteCountingType}<i class="fa fa-info-circle" + onclick="{help}"></i></div> + <div class="config-description">{__.voteCountingType}</div> + <div class="config-form"> + <ul> + <li each="{type in voteCountingTypes}"> + <input type="radio" name="voteCountingType" value="{type.id}">{type.name} + </li> + </ul> + </div> + </div> <div id="Vote" class="config-group"> <div class="config-header">{__.votesConfiguration}</div> - <div id="Vote_countingType"> - <div class="config-subheader">{__.nav_voteCountingType}<i class="fa fa-info-circle" - onclick="{help}"></i></div> - <div class="config-description">{__.voteCountingType}</div> - <div class="config-form"> - <ul> - <li> - <input type="radio" name="voteCountingType" value="1">{__.voteCountingType_normal} - </li> - <li> - <input type="radio" name="voteCountingType" value="2">{__.voteCountingType_pourcentage} - </li> - <li> - <input type="radio" name="voteCountingType" value="3">{__.voteCountingType_condorcet} - </li> - </ul> - </div> - </div> <div id="Vote_visibility"> <div class="config-subheader">{__.nav_voteVisibility}<i class="fa fa-info-circle" onclick="{help}"></i></div> @@ -319,17 +314,37 @@ this.form.nextStep(); }; + let moment = require('moment'); + + this.formatDate = (date) => { + if (date) { + date = moment(date).format('YYYY-MM-DDThh:mm'); + } + return date; + }; this.on('mount', () => { let model = this.form.model; - let moment = require('moment'); - model.beginDate = moment(model.beginDate).format('YYYY-MM-DDTHH:mm'); - console.info(model.beginDate); - let form = this.refs.form; - console.info('fill form with model'); - console.info(model); - FormHelper.fillForm(form, model); + model.beginDate = this.formatDate(model.beginDate); + model.beginChoiceDate = this.formatDate(model.beginChoiceDate); + model.endDate = this.formatDate(model.endDate); + model.endChoiceDate = this.formatDate(model.endChoiceDate); + + let voteCountingTypeService = require('../../js/VoteCountingTypeService'); + + voteCountingTypeService.getVoteCountingTypes().then(result => { + this.voteCountingTypes = result; + this.update({voteCountingTypes: this.voteCountingTypes}); + console.info('voteCountingTypes'); + console.info(this.voteCountingTypes); + let form = this.refs.form; + console.info('fill form with model'); + console.info(model); + + FormHelper.fillForm(form, model); + }); + }); this.previousStep = (e) => { @@ -456,6 +471,7 @@ flex-direction: column; align-content: flex-start; } + .config-header { border-bottom: solid 2px #c8ccca; font-size: 20px; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/PollVotes.tag b/pollen-ui-riot-js/src/main/web/tag/poll/PollVotes.tag index a3a430e..2684fc3 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/PollVotes.tag +++ b/pollen-ui-riot-js/src/main/web/tag/poll/PollVotes.tag @@ -30,8 +30,10 @@ </td> <td class="vote-choice" each="{choice in choices}"> <div> - <input class="check" type="checkbox" name="{choice.id}.voteValue" - disabled="{voteId?'disabled':''}"> + <input if="{renderType==='checkbox'}" class="check" type="checkbox" + name="{choice.id}.voteValue" disabled="{voteId?'disabled':''}"> + <input if="{renderType==='text'}" class="text" type="number" + name="{choice.id}.voteValue" disabled="{voteId?'disabled':''}"> </div> </td> </tr> @@ -42,7 +44,7 @@ <i class="fa fa-user"/> {vote.voterName} </div> - <input ref="vote_{vote.id}_voter" class="voter" type="text" value="{vote.voterName}" + <input ref="vote_{vote.id}_voter" name="vote_{vote.id}_voter" class="voter" type="text" value="{vote.voterName}" required="{vote.id == voteId?'required':''}" show="{voteId == vote.id}" disabled="{vote.id == voteId?'':'disabled'}" placeholder="{__.authorPlaceHolder}"> @@ -66,9 +68,14 @@ </td> <td class="vote-choice" each="{choice in vote.choice}"> <div> - <input ref="vote_{vote.id}_{choice.choiceId}" class="check" type="checkbox" - checked="{choice.voteValue == 1?'checked':''}" + <input if="{renderType==='checkbox'}" ref="vote_{vote.id}_{choice.choiceId}" + name="vote_{vote.id}_{choice.choiceId}" + class="check" type="checkbox" checked="{choice.voteValue == 1?'checked':''}" disabled="{voteId == vote.id?'':'disabled'}"> + <input if="{renderType === 'text'}" ref="vote_{vote.id}_{choice.choiceId}" class="text" + name="vote_{vote.id}_{choice.choiceId}" + type="number" disabled="{voteId == vote.id?'':'disabled'}" + value="{choice.voteValue}"> </div> </td> </tr> @@ -95,23 +102,14 @@ if (this.votePeriod != '') { this.votePeriod = '( ' + this.votePeriod + ' )'; } - this.choicePeriod = ''; - if (this.poll.beginChoiceDate) { - this.choicePeriod += moment(this.poll.beginChoiceDate).format('LLL'); - } - if (this.poll.endChoiceDate) { - this.choicePeriod += ' - ' + moment(this.poll.endChoiceDate).format('LLL'); - } - if (this.choicePeriod != '') { - this.choicePeriod = '( ' + this.choicePeriod + ' )'; - } - this.update({votePeriod: this.votePeriod, choicePeriod: this.choicePeriod}); + this.update({votePeriod: this.votePeriod}); }; let session = require("../../js/Session"); this.installBundle(session, "poll_votes", this.i18nCallback); let voteService = require("../../js/VoteService"); let choiceService = require("../../js/ChoiceService"); + let voteCountingTypeService = require("../../js/VoteCountingTypeService"); let moment = require('moment'); this.pollId = opts.pollId; this.permission = opts.permission; @@ -119,7 +117,7 @@ this.i18nCallback(); - this.voting = this.poll.status != 'CREATED'; + this.voting = this.poll.status === 'VOTING' || this.poll.status === 'CLOSED'; this.votes = []; @@ -128,10 +126,18 @@ this.on('mount', () => { if (this.voting && session.isConnected() && this.poll.canVote) { session.getUser().then(user => { - this.refs.voterName.value = user.name; + this.form.voterName.value = user.name; }) - } + + voteCountingTypeService.getVoteCountingType(this.poll.voteCountingType).then(voteCountingType => { + console.info('voteCountingType'); + console.info(voteCountingType); + this.voteCountingType = voteCountingType; + this.renderType = voteCountingType.renderType; + this.update({renderType: this.renderType}); + }); + this.form = this.refs.form; }); @@ -147,7 +153,11 @@ this.votes.forEach(v => { if (previousVoteId == v.id) { v.choice.forEach(c => { - this.refs['vote_' + previousVoteId + "_" + c.choiceId].checked = c.voteValue == 1 ? 'checked' : ''; + if (this.renderType === 'text') { + this.form['vote_' + previousVoteId + "_" + c.choiceId].value = c.voteValue; + } else { + this.form['vote_' + previousVoteId + "_" + c.choiceId].checked = c.voteValue == 1 ? 'checked' : ''; + } }) } }); @@ -156,7 +166,7 @@ this.onEditVote = (e) => { if (this.voteId) { - let tr = this.refs['vote_' + this.voteId]; + let tr = this.form['vote_' + this.voteId]; tr.classList.remove("selected"); } this.voteId = e.target.parentNode.parentNode.id; @@ -164,11 +174,18 @@ tr.classList.add("selected"); this.votes.forEach(v => { if (this.voteId == v.id) { - this.refs['vote_' + this.voteId + "_voter"].value = v.voterName; + this.form['vote_' + this.voteId + "_voter"].value = v.voterName; } }); }; + this.getChoiceVoteValue = (t) => { + if (this.renderType === 'text') { + return this.form[t].value; + } + return this.form[t].checked ? 1 : 0; + }; + this.addOrEditVote = e => { e.preventDefault(); e.stopPropagation(); @@ -186,7 +203,7 @@ vote.choice.push({ choiceId: c.id, - voteValue: this.form[c.id + '.voteValue'].checked ? 1 : 0 + voteValue: this.getChoiceVoteValue(c.id + '.voteValue') }); }); @@ -194,7 +211,7 @@ } else { vote.id = this.voteId; - vote.voterName = this.refs['vote_' + this.voteId + '_voter'].value; + vote.voterName = this.form['vote_' + this.voteId + '_voter'].value; this.votes.forEach(v => { if (this.voteId == v.id) { @@ -202,7 +219,7 @@ vote.choice.push({ id: c.id, choiceId: c.choiceId, - voteValue: this.refs['vote_' + this.voteId + "_" + c.choiceId].checked ? 1 : 0 + voteValue: this.getChoiceVoteValue('vote_' + this.voteId + "_" + c.choiceId) }); }) } @@ -222,8 +239,11 @@ this.refs.voterName.value = null; let form = this.refs.form; this.choices.forEach(c => { - form[c.id + '.voteValue'].checked = ''; - + if (this.renderType === 'text') { + form[c.id + '.voteValue'].value = ''; + } else { + form[c.id + '.voteValue'].checked = ''; + } }); }); @@ -422,6 +442,12 @@ margin: 0 0 0 5px; } + .text { + width: 60px; + height: 30px; + margin: 0 0 0 5px; + } + .body { margin-top: 10px; } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm