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 d653e813bc1c076567bd023b818ab3b31704139d Author: Tony CHEMIT <dev@tchemit.fr> Date: Tue Jan 17 22:38:32 2017 +0100 Suppression EmitterService (tout est dans la session), enfin on peut créer un sondage --- pollen-persistence/src/main/xmi/pollen.zargo | Bin 20954 -> 21037 bytes pollen-rest-api/src/main/resources/mapping | 2 +- .../org/chorem/pollen/services/bean/PollBean.java | 17 ++ pollen-ui-riot-js/src/main/web/conf.json | 3 +- pollen-ui-riot-js/src/main/web/i18n.json | 194 ++++++++++++++--- pollen-ui-riot-js/src/main/web/js/AuthService.js | 10 +- pollen-ui-riot-js/src/main/web/js/ChoiceText.js | 5 +- .../src/main/web/js/EmitterService.js | 49 ----- pollen-ui-riot-js/src/main/web/js/FetchService.js | 12 +- pollen-ui-riot-js/src/main/web/js/I18nHelper.js | 18 +- pollen-ui-riot-js/src/main/web/js/PollForm.js | 63 ++++-- pollen-ui-riot-js/src/main/web/js/PollService.js | 16 ++ pollen-ui-riot-js/src/main/web/js/Session.js | 65 +++++- pollen-ui-riot-js/src/main/web/tag/Footer.tag | 5 +- pollen-ui-riot-js/src/main/web/tag/Header.tag | 15 +- pollen-ui-riot-js/src/main/web/tag/HeaderI18n.tag | 13 +- pollen-ui-riot-js/src/main/web/tag/Home.tag | 18 +- pollen-ui-riot-js/src/main/web/tag/Pollen.tag | 17 +- pollen-ui-riot-js/src/main/web/tag/SignCheck.tag | 8 +- pollen-ui-riot-js/src/main/web/tag/SignIn.tag | 11 +- pollen-ui-riot-js/src/main/web/tag/SignUp.tag | 9 +- .../src/main/web/tag/poll/CreatePoll.tag | 130 ++++++++++-- .../src/main/web/tag/poll/PollChoiceText.tag | 23 +- .../src/main/web/tag/poll/PollChoiceTextGroup.tag | 13 +- .../src/main/web/tag/poll/PollChoicesText.tag | 24 ++- .../src/main/web/tag/poll/PollCreated.tag | 40 ++++ .../src/main/web/tag/poll/PollDescription.tag | 27 +-- .../src/main/web/tag/poll/PollSettings.tag | 236 ++++++++++++++------- .../src/main/web/tag/poll/PollVoters.tag | 173 +++++++++++++-- .../src/main/web/tag/popup/AccountCreated.tag | 8 +- .../src/main/web/tag/popup/NewPassword.tag | 8 +- .../src/main/web/tag/popup/ResendValidation.tag | 9 +- 32 files changed, 891 insertions(+), 350 deletions(-) diff --git a/pollen-persistence/src/main/xmi/pollen.zargo b/pollen-persistence/src/main/xmi/pollen.zargo index b32f5a8..e3d4cad 100644 Binary files a/pollen-persistence/src/main/xmi/pollen.zargo and b/pollen-persistence/src/main/xmi/pollen.zargo differ diff --git a/pollen-rest-api/src/main/resources/mapping b/pollen-rest-api/src/main/resources/mapping index 83822b2..0bb0f7e 100644 --- a/pollen-rest-api/src/main/resources/mapping +++ b/pollen-rest-api/src/main/resources/mapping @@ -101,7 +101,7 @@ GET /v1/polls/created PollApi.getCreatedPolls GET /v1/polls/invited PollApi.getInvitedPolls GET /v1/polls/participated PollApi.getParticipatedPolls POST /v1/polls PollApi.createPoll -GET /v1/polls/create PollApi.createPoll +POST,GET /v1/polls/create PollApi.createPoll GET /v1/polls/edit PollApi.editPoll #fix me diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java index ac7f99f..80c7099 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java @@ -21,6 +21,7 @@ package org.chorem.pollen.services.bean; * #L% */ +import com.google.common.base.Joiner; import org.chorem.pollen.persistence.entity.CommentVisibility; import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.persistence.entity.PollImpl; @@ -30,8 +31,12 @@ import org.chorem.pollen.persistence.entity.PollenPrincipalImpl; import org.chorem.pollen.persistence.entity.ResultVisibility; import org.chorem.pollen.persistence.entity.VoteVisibility; +import java.util.Arrays; +import java.util.Collections; import java.util.Date; +import java.util.LinkedHashSet; import java.util.Objects; +import java.util.Set; /** * Created on 5/15/14. @@ -105,6 +110,8 @@ public class PollBean extends PollenBean<Poll> { protected long commentCount; + protected Set<String> participants; + @Override public void fromEntity(Poll entity) { @@ -143,6 +150,7 @@ public class PollBean extends PollenBean<Poll> { setCommentVisibility(entity.getCommentVisibility()); setResultVisibility(entity.getResultVisibility()); setClosed(entity.isClosed()); + setParticipants(new LinkedHashSet<>(entity.getParticipants() == null ? Collections.emptyList() : Arrays.asList(entity.getParticipants().split("\\s")))); } @Override @@ -173,6 +181,7 @@ public class PollBean extends PollenBean<Poll> { entity.setCommentVisibility(getCommentVisibility()); entity.setResultVisibility(getResultVisibility()); entity.setClosed(isClosed()); + entity.setParticipants(Joiner.on(' ').join(getParticipants())); return entity; @@ -369,4 +378,12 @@ public class PollBean extends PollenBean<Poll> { public void setCommentCount(long commentCount) { this.commentCount = commentCount; } + + public Set<String> getParticipants() { + return participants; + } + + public void setParticipants(Set<String> participants) { + this.participants = participants; + } } diff --git a/pollen-ui-riot-js/src/main/web/conf.json b/pollen-ui-riot-js/src/main/web/conf.json index 78dd34b..73eb556 100644 --- a/pollen-ui-riot-js/src/main/web/conf.json +++ b/pollen-ui-riot-js/src/main/web/conf.json @@ -10,5 +10,6 @@ "defaultAlertTimeError": -1, "defaultDateFormat": "shortDate", "defaultTimeFormat": "shortTime", - "defaultDateTimeFormat": "short" + "defaultDateTimeFormat": "short", + "debugI18n":false } \ No newline at end of file diff --git a/pollen-ui-riot-js/src/main/web/i18n.json b/pollen-ui-riot-js/src/main/web/i18n.json index f54d573..c999419 100644 --- a/pollen-ui-riot-js/src/main/web/i18n.json +++ b/pollen-ui-riot-js/src/main/web/i18n.json @@ -17,13 +17,13 @@ "resendvalidation_placeholder": "Entrer votre courriel", "resendvalidation_sent": "Un nouveau courriel d'invitation a été envoyé", "resendvalidation_error_emailNotFound": "Le courriel n'a pas été trouvé", - "signcheck_title":"Validation de votre compte", - "signcheck_signin":"Vous connecter", - "signcheck_resendValidation":"Envoyer une nouvelle invitation", - "signcheck_message":"Votre compte doit être validé afin de pouvoir vous connecter.", - "signcheck_validating":"Votre compte est en cour de validation...", - "signcheck_validating_error":"Votre compte n'a pas pu être validé, essayer de renvoyer une invitation.", - "signcheck_validating_success":"Votre compte a été validé. Vous pouvez vous connecter.", + "signcheck_title": "Validation de votre compte", + "signcheck_signin": "Vous connecter", + "signcheck_resendValidation": "Envoyer une nouvelle invitation", + "signcheck_message": "Votre compte doit être validé afin de pouvoir vous connecter.", + "signcheck_validating": "Votre compte est en cour de validation...", + "signcheck_validating_error": "Votre compte n'a pas pu être validé, essayer de renvoyer une invitation.", + "signcheck_validating_success": "Votre compte a été validé. Vous pouvez vous connecter.", "signin_title": "Déjà membre ?", "signin_login": "Email", "signin_login_placeholder": "Entrer l'email", @@ -53,14 +53,81 @@ "home_createTextPoll": "Créer un sondage de type text", "home_createImagePoll": "Créer un sondage de type image", "home_createDatePoll": "Créer un sondage de type date", - "poll_settings_basic_usage":"Pour un sondage simple, vous pouvez passer cette étape.", - "poll_settings_previous":"Précédent", - "poll_settings_next":"Continuer", - "poll_settings_skip":"Passer", - "poll_header_general":"Description", - "poll_header_choices":"Choix", - "poll_header_options":"Options", - "poll_header_voters":"Participants", + "poll_description_cancel": "Annuler", + "poll_description_next": "Suivant", + "poll_description_title": "Titre", + "poll_description_titlePlaceHolder": "Renseigner le titre du sondage", + "poll_description_description": "Description", + "poll_description_descriptionPlaceHolder": "Renseigner la description du sondage", + "poll_description_name": "Votre nom", + "poll_description_namePlaceHolder": "Renseigner votre nom", + "poll_description_email": "Votre courriel", + "poll_description_emailPlaceHolder": "Renseigner votre courriel", + "poll_settings_basic_usage": "Pour un sondage simple, vous pouvez passer cette étape.", + "poll_settings_previous": "Précédent", + "poll_settings_next": "Continuer", + "poll_settings_skip": "Passer", + "poll_settings_showOptions": "Voir les options avancées", + "poll_settings_hideOptions": "Masquer les options avancées", + "poll_settings_resultVisibility": "Qui peut voir les résultats ?", + "poll_settings_resultVisibility_creator": "Uniquement le créateur", + "poll_settings_resultVisibility_everybody": "Tout le monde", + "poll_settings_resultVisibility_voter": "Les participants", + "poll_settings_commentVisibility": "Qui peut voir les commentaires ?", + "poll_settings_commentVisibility_creator": "Uniquement le créateur", + "poll_settings_commentVisibility_everybody": "Tout le monde", + "poll_settings_commentVisibility_voter": "Les participants", + "poll_settings_voteVisibility": "Qui peut voir les votes ?", + "poll_settings_voteVisibility_creator": "Uniquement le créateur", + "poll_settings_voteVisibility_everybody": "Tout le monde", + "poll_settings_voteVisibility_voter": "Les participants", + "poll_settings_nav_poll": "Sondage", + "poll_settings_nav_voteBeginDate": "Date de début", + "poll_settings_nav_voteEndDate": "Date de fin", + "poll_settings_nav_resultVisibility": "Visibilité des résultats", + "poll_settings_nav_continiousResult": "Résultats continus", + "poll_settings_nav_choices": "Choix", + "poll_settings_nav_addChoices": "Ajouter des choix", + "poll_settings_nav_limitChoices": "Limiter les choix", + "poll_settings_nav_votes": "Votes", + "poll_settings_nav_voteCountingType": "Type de scrutin", + "poll_settings_nav_voteVisibility": "Visibilité", + "poll_settings_nav_anonymousVote": "Anonimisation", + "poll_settings_nav_comments": "Commentaires", + "poll_settings_nav_commentVisibility": "Visiblité", + "poll_settings_poll_configuration": "Configuration du sondage", + "poll_settings_continiousResult": "Voir les résultats en continue", + "poll_settings_choicesConfiguration": "Configuration des choix", + "poll_settings_addChoices": "Est-ce que les participants peuvent ajouter des choix ?", + "poll_settings_limitChoices": "Limiter le nombre de choix par vote", + "poll_settings_votesConfiguration": "Configuration des votes", + "poll_settings_voteCountingType": "Type de scrutin pour effecter le dépouillement du sondage", + "poll_settings_voteCountingType_normal": "Normal", + "poll_settings_voteCountingType_pourcentage": "Pourcentage", + "poll_settings_voteCountingType_condorcet": "Condorcet", + "poll_settings_anonymousVote": "Rendre les votes anonymes", + "poll_settings_commentsConfiguration": "Configuration des commentaires", + "poll_settings_voteBeginDate": "Quand les participants peuvent commencer à voter ?", + "poll_settings_voteEndDate": "Date de fin des votes", + "poll_choices_label": "Choix", + "poll_choices_description": "Description", + "poll_choices_previous": "Précédent", + "poll_choices_next": "Suivant", + "poll_choices_moreChoices": "Ajouter des choix", + "poll_header_general": "Description", + "poll_header_choices": "Choix", + "poll_header_options": "Options", + "poll_header_voters": "Participants", + "poll_header_summary": "Résumé", + "poll_voters_description": "Qui peut voter ?", + "poll_voters_previous": "Précédent", + "poll_voters_save": "Enregistrer", + "poll_voters_freePoll": "Tout le monde peut voter (Sondage public)", + "poll_voters_restrictedPoll": "Seul les invités peuvent voter (Sondage privé)", + "poll_voters_restrictedPoll_withMe": "Je participe au sondage", + "poll_voters_restrictedPoll_withGroup": "Organiser les invités dans des groupes", + "poll_voters_invite": "Inviter des participants", + "poll_voters_invite_label": "Renseigner le courriel des participants (séparé par un espace)", "": "" }, "en": { @@ -73,13 +140,13 @@ "signup_resendValidation": "Already member, but account never validated ?", "signup_error": "Could not register account.", "signup_error_email": "This email is already used.", - "signcheck_title":"Validate your account", - "signcheck_signin":"Sign in", - "signcheck_resendValidation":"Send a new invitation", - "signcheck_message":"Your account must be validate before you can connect.", - "signcheck_validating":"Your account is validating...", - "signcheck_validating_error":"Your account could not be validated, try to send a new invitation.", - "signcheck_validating_success":"Your account was validated! You can now sign in. Enjoy!", + "signcheck_title": "Validate your account", + "signcheck_signin": "Sign in", + "signcheck_resendValidation": "Send a new invitation", + "signcheck_message": "Your account must be validate before you can connect.", + "signcheck_validating": "Your account is validating...", + "signcheck_validating_error": "Your account could not be validated, try to send a new invitation.", + "signcheck_validating_success": "Your account was validated! You can now sign in. Enjoy!", "createdaccount_title": "Your account was created", "createdaccount_description": "We sent you an email with the account validation process and your authentication data.", "createdaccount_action": "Continue", @@ -117,14 +184,81 @@ "home_createTextPoll": "Create a text poll", "home_createImagePoll": "Create a image poll", "home_createDatePoll": "Create a date poll", - "poll_settings_basic_usage":"For a basic poll, you can skip this step.", - "poll_settings_previous":"Previous", - "poll_settings_next":"Continue", - "poll_settings_skip":"Skip", - "poll_header_general":"General", - "poll_header_choices":"Choices", - "poll_header_options":"Options", - "poll_header_voters":"Voters", + "poll_description_cancel": "Cancel", + "poll_description_next": "Next", + "poll_description_title": "Title", + "poll_description_titlePlaceHolder": "Enter poll title", + "poll_description_description": "Description", + "poll_description_descriptionPlaceHolder": "Enter poll description", + "poll_description_name": "Your name", + "poll_description_namePlaceHolder": "Enter your name", + "poll_description_email": "Your email", + "poll_description_emailPlaceHolder": "Enter your email", + "poll_settings_basic_usage": "For a basic poll, you can skip this step.", + "poll_settings_previous": "Previous", + "poll_settings_next": "Continue", + "poll_settings_skip": "Skip", + "poll_settings_showOptions": "Show options", + "poll_settings_hideOptions": "Hide options", + "poll_settings_resultVisibility": "Who can see results?", + "poll_settings_resultVisibility_creator": "Only creator", + "poll_settings_resultVisibility_everybody": "Everybody", + "poll_settings_resultVisibility_voter": "Only voters", + "poll_settings_commentVisibility": "Who can see comments?", + "poll_settings_commentVisibility_creator": "Only creator", + "poll_settings_commentVisibility_everybody": "Everybody", + "poll_settings_commentVisibility_voter": "Only voters", + "poll_settings_voteVisibility": "Who can see votes?", + "poll_settings_voteVisibility_creator": "Only creator", + "poll_settings_voteVisibility_everybody": "Everybody", + "poll_settings_voteVisibility_voter": "Only voters", + "poll_settings_nav_poll": "Poll", + "poll_settings_nav_voteBeginDate": "Begin date", + "poll_settings_nav_voteEndDate": "End date", + "poll_settings_nav_resultVisibility": "Results visibility", + "poll_settings_nav_continiousResult": "Continious results", + "poll_settings_nav_choices": "Choices", + "poll_settings_nav_addChoices": "Add choices", + "poll_settings_nav_limitChoices": "Limit choices", + "poll_settings_nav_votes": "Votes", + "poll_settings_nav_voteCountingType": "Vote counting type", + "poll_settings_nav_voteVisibility": "Visibility", + "poll_settings_nav_anonymousVote": "Anomize", + "poll_settings_nav_comments": "Comments", + "poll_settings_nav_commentVisibility": "Visibility", + "poll_settings_poll_configuration": "Poll configuration", + "poll_settings_continiousResult": "Use continious results", + "poll_settings_choicesConfiguration": "Choices configuration", + "poll_settings_addChoices": "Can user add choices?", + "poll_settings_limitChoices": "Limit number of choices to use on a vote", + "poll_settings_votesConfiguration": "Votes configuration", + "poll_settings_voteCountingType": "Vote counting type used to compute poll's results.", + "poll_settings_voteCountingType_normal": "Normal", + "poll_settings_voteCountingType_pourcentage": "Pourcentage", + "poll_settings_voteCountingType_condorcet": "Condorcet", + "poll_settings_anonymousVote": "Anonymize votes", + "poll_settings_commentsConfiguration": "Comments configuration", + "poll_settings_voteBeginDate": "When users can start to vote?", + "poll_settings_voteEndDate": "When poll is ending?", + "poll_choices_label": "Choice", + "poll_choices_description": "Description", + "poll_choices_previous": "Previous", + "poll_choices_next": "Next", + "poll_choices_moreChoices": "Add more choices", + "poll_header_general": "General", + "poll_header_choices": "Choices", + "poll_header_options": "Options", + "poll_header_voters": "Voters", + "poll_header_summary": "Summary", + "poll_voters_description": "Who can vote?", + "poll_voters_previous": "Previous", + "poll_voters_save": "Save", + "poll_voters_freePoll": "Everybody can vote (Public poll)", + "poll_voters_restrictedPoll": "Only invited people can vote (Private poll)", + "poll_voters_restrictedPoll_withMe": "I also want to participate", + "poll_voters_restrictedPoll_withGroup": "Organize participants in groups", + "poll_voters_invite": "Invite people to vote", + "poll_voters_invite_label": "Type participants emails separated by space", "": "" } } \ No newline at end of file diff --git a/pollen-ui-riot-js/src/main/web/js/AuthService.js b/pollen-ui-riot-js/src/main/web/js/AuthService.js index 1aca463..3052652 100644 --- a/pollen-ui-riot-js/src/main/web/js/AuthService.js +++ b/pollen-ui-riot-js/src/main/web/js/AuthService.js @@ -1,10 +1,12 @@ let singleton = require("./Singleton"); -let emitter = require("./EmitterService"); -let session = require("./Session"); let FetchService = require("./FetchService"); class AuthService extends FetchService { + constructor() { + super(); + } + signIn(login, password) { return this.fetch("/v1/login", "POST", { Authorization: "Basic " + btoa(login + ":" + password) @@ -12,7 +14,7 @@ class AuthService extends FetchService { if (!auth) { return Promise.reject(false); } - session.signIn(auth, this); + this.session.signIn(auth, this); return true; }); } @@ -22,7 +24,7 @@ class AuthService extends FetchService { } signOut() { - session.signOut(); + this.session.signOut(); return this.get("/v1/logout"); } diff --git a/pollen-ui-riot-js/src/main/web/js/ChoiceText.js b/pollen-ui-riot-js/src/main/web/js/ChoiceText.js index d0e64d7..ed1bce3 100644 --- a/pollen-ui-riot-js/src/main/web/js/ChoiceText.js +++ b/pollen-ui-riot-js/src/main/web/js/ChoiceText.js @@ -1,8 +1,9 @@ class ChoiceText { - constructor(text, description) { - this.text = text; + constructor(name, description) { + this.choiceValue = name; this.description = description; + this.choiceType = 'TEXT'; } } diff --git a/pollen-ui-riot-js/src/main/web/js/EmitterService.js b/pollen-ui-riot-js/src/main/web/js/EmitterService.js deleted file mode 100644 index 490fe83..0000000 --- a/pollen-ui-riot-js/src/main/web/js/EmitterService.js +++ /dev/null @@ -1,49 +0,0 @@ -let singleton = require("./Singleton"); - -class EmitterService { - - constructor() { - riot.observable(this); - } - emitUnauthorize() { - this.trigger("unauthorized"); - } - - onUnauthorize(fn) { - this.on("unauthorized", fn); - } - - emitConnected(user) { - this.trigger("connected", user); - } - - onConnected(fn) { - this.on("connected", fn); - } - - emitDisconnected(user) { - this.trigger("disconnected", user); - } - - onDisconnected(fn) { - this.on("disconnected", fn); - } - - emitError() { - this.trigger("error"); - } - - onError(fn) { - this.on("error", fn); - } - - emitLocaleChanged(locale) { - this.trigger("localeChanged", locale); - } - - onLocaleChanged(fn) { - this.on("localeChanged", fn); - } -} - -module.exports = singleton(EmitterService); diff --git a/pollen-ui-riot-js/src/main/web/js/FetchService.js b/pollen-ui-riot-js/src/main/web/js/FetchService.js index 5225eb1..ba33dc3 100644 --- a/pollen-ui-riot-js/src/main/web/js/FetchService.js +++ b/pollen-ui-riot-js/src/main/web/js/FetchService.js @@ -1,8 +1,10 @@ -let emitter = require("./EmitterService"); -let session = require("./Session"); - class FetchService { + constructor() { + this.session = require("./Session"); + this.endPoint = this.session.configuration.endPoint; + } + fetch(url, method, headers, body) { headers = headers || {}; if (!(body instanceof FormData)) { @@ -10,7 +12,7 @@ class FetchService { } return fetch( - session.configuration.endPoint + url, { + this.endPoint + url, { headers, method, credentials: "include", @@ -30,7 +32,7 @@ class FetchService { return response.json(); } if (response.status === 503) { - emitter.emitUnauthorize(); + this.session.emitUnauthorize(); return Promise.reject(); } diff --git a/pollen-ui-riot-js/src/main/web/js/I18nHelper.js b/pollen-ui-riot-js/src/main/web/js/I18nHelper.js index 376f117..d6b04f1 100644 --- a/pollen-ui-riot-js/src/main/web/js/I18nHelper.js +++ b/pollen-ui-riot-js/src/main/web/js/I18nHelper.js @@ -1,12 +1,10 @@ module.exports = { - init() { - this.bundles = require("../i18n.json"); - }, - - installBundle(locale, value, emitter) { - this.generateBundle(locale, value); - emitter.onLocaleChanged((locale) => { + installBundle(session, value) { + this.bundle = session.i18n; + this.debug = session.configuration.debugI18n; + this.generateBundle(session.locale, value); + session.onLocaleChanged((locale) => { this.generateBundle(locale, value); try { this.update(); @@ -18,14 +16,16 @@ module.exports = { generateBundle(locale, value) { - let bundle = this.bundles[locale]; + let bundle = this.bundle[locale]; this.__ = {}; Object.keys(bundle).forEach((key) => { if (key.startsWith(value + "_")) { let realKey = key.substring(value.length + 1); this.__[realKey] = bundle[key]; - console.debug(realKey + " -> " + this.__[realKey]); + if (this.debug) { + console.debug(realKey + " -> " + this.__[realKey]); + } } }); }, 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 630c8bd..52934b8 100644 --- a/pollen-ui-riot-js/src/main/web/js/PollForm.js +++ b/pollen-ui-riot-js/src/main/web/js/PollForm.js @@ -5,14 +5,54 @@ let route = require("riot-route"); class PollForm { constructor() { + this.service = require('./PollService'); this.step = 0; + this.isInit = false; this.type = null; + this.showOptions = true; this.model = null; + this.choices = []; + } + + init() { + this.isInit = true; + console.info("init form"); + this.step = 0; + + return this.service.empty().then((poll) => { + this.model = poll; + console.info("empty poll"); + console.info(this.model); + + this.model.title = "Mon premier sondage"; + this.model.description = "Premier sondage!"; + this.model.name = "Dick Laurent"; + this.model.email = "user@pollen.org"; + this.model.participant = []; + this.choices = [ + new ChoiceText("Mozart", "Requiem is so powerfull"), + new ChoiceText("Schubert", "Truit is so nice"), + new ChoiceText("Malher", "So deep, so dark...")]; + }); + } + + create() { + return this.service.create(this.model, this.choices).then((result) => { + console.info("Poll created"); + console.info(result); + this.model.id = result.id; + this.model.permission = result.permission; + this.nextStep(); + }).catch((error) => { + console.error("Could not create poll"); + console.error(error); + return Promise.reject(error); + }); } previousStep() { - console.info("prevousStep:: "+this.step); + console.info("prevousStep:: " + this.step); this.setStep(this.step - 1); } @@ -20,25 +60,6 @@ class PollForm { this.setStep(this.step + 1); } - init(user) { - console.info("init form"); - this.step = 0; - this.model = { - title: "Mon premier sondage", - description: "", - name: "Tony Chemit", - email: "user@pollen.org", - textChoices: [new ChoiceText("Mozart", "Requiem is so powerfull"), - new ChoiceText("Schubert", "Truit is so nice"), new ChoiceText("Malher", "So deep, so dark...")], - imageChoices: [], - dateChoices: [] - }; - if (user) { - this.model.name = user.name; - this.model.email = user.email; - } - } - fromTextChoices(form) { let choices = []; @@ -63,7 +84,7 @@ class PollForm { } console.info("FromTextChoices"); console.info(choices); - this.model.textChoices = choices; + this.choices = choices; } setStep(step) { diff --git a/pollen-ui-riot-js/src/main/web/js/PollService.js b/pollen-ui-riot-js/src/main/web/js/PollService.js new file mode 100644 index 0000000..69fa890 --- /dev/null +++ b/pollen-ui-riot-js/src/main/web/js/PollService.js @@ -0,0 +1,16 @@ +let singleton = require("./Singleton"); +let FetchService = require("./FetchService"); + +class PollService extends FetchService { + + empty() { + return this.get("/v1/polls/new"); + } + + create(form, choices) { + return this.form("/v1/polls/create", {poll: form, choices:choices}); + } + +} + +module.exports = singleton(PollService); 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 6ae934f..bdb846d 100644 --- a/pollen-ui-riot-js/src/main/web/js/Session.js +++ b/pollen-ui-riot-js/src/main/web/js/Session.js @@ -1,13 +1,17 @@ let singleton = require("./Singleton"); -let emitter = require("./EmitterService"); class Session { constructor() { + + riot.observable(this); + // pour contenir la locale à utiliser this.locale = null; // pour contenir la configuration this.configuration = require('../conf.json'); + // pour contenir les traductions + this.i18n = require('../i18n.json'); // pour contenir l'utillisateur connecté this.user = null; @@ -17,18 +21,68 @@ class Session { } else { this.locale = 'fr'; } - emitter.onUnauthorize(() => { + + this.onUnauthorize(() => { this.user = null; }); } + start() { + if (this.isConnected()) { + return this.connect(require("./AuthService")); + }else { + return Promise.resolve(); + } + } + + emitUnauthorize() { + this.trigger("unauthorized"); + } + + onUnauthorize(fn) { + this.on("unauthorized", fn); + } + + emitConnected(user) { + this.trigger("connected", user); + } + + onConnected(fn) { + this.on("connected", fn); + } + + emitDisconnected(user) { + this.trigger("disconnected", user); + } + + onDisconnected(fn) { + this.on("disconnected", fn); + } + + emitError() { + this.trigger("error"); + } + + onError(fn) { + this.on("error", fn); + } + + onLocaleChanged(fn) { + this.on("localeChanged", fn); + } + + changeLocale(locale) { + this.locale = locale; + this.trigger("localeChanged", locale); + } + isConnected() { return document.cookie.indexOf("pollen-connected=true") !== -1; } connect(userService) { console.info("Connect::"); - userService.connectedUserPromise().then((user) => { + return userService.connectedUserPromise().then((user) => { if (!user) { console.info("Connect error"); this.user = null; @@ -37,8 +91,7 @@ class Session { console.info("Connect user::"); console.info(user); this.user = user; - emitter.emitConnected(user); - return user; + this.emitConnected(user); }); } @@ -54,7 +107,7 @@ class Session { console.info("SignIn user::"); console.info(user); this.user = user; - emitter.emitConnected(user); + this.emitConnected(user); return user; }); diff --git a/pollen-ui-riot-js/src/main/web/tag/Footer.tag b/pollen-ui-riot-js/src/main/web/tag/Footer.tag index d514deb..fbfada4 100644 --- a/pollen-ui-riot-js/src/main/web/tag/Footer.tag +++ b/pollen-ui-riot-js/src/main/web/tag/Footer.tag @@ -1,5 +1,3 @@ -let session = require("../js/Session"); -let emitter = require("../js/EmitterService"); <footer> <div class="links"> <a href="https://pollen.chorem.org/v/latest/index.html">{__.doc}</a> @@ -10,7 +8,8 @@ let emitter = require("../js/EmitterService"); <a href="http://www.codelutin.com/" target="_blank">Code Lutin</a> </div> <script> - this.installBundle(session.locale, "footer", emitter); + let session = require("../js/Session"); + this.installBundle(session, "footer"); </script> <style> diff --git a/pollen-ui-riot-js/src/main/web/tag/Header.tag b/pollen-ui-riot-js/src/main/web/tag/Header.tag index ff258f6..98e00a7 100644 --- a/pollen-ui-riot-js/src/main/web/tag/Header.tag +++ b/pollen-ui-riot-js/src/main/web/tag/Header.tag @@ -1,9 +1,4 @@ -let route = require("riot-route"); -let authService = require("../js/AuthService"); -let session = require("../js/Session"); -let emitter = require("../js/EmitterService"); require("./HeaderI18n.tag"); - <Header> <div class="header-home"> <a class="header-link" href="#home" target="_top">{__.home}</a> @@ -26,7 +21,11 @@ require("./HeaderI18n.tag"); <div class="header-separator"></div> <HeaderI18n></HeaderI18n> <script> - this.installBundle(session.locale, "header", emitter); + let route = require("riot-route"); + let authService = require("../js/AuthService"); + let session = require("../js/Session"); + + this.installBundle(session, "header"); this.signOut = () => { let callback = () => { @@ -43,12 +42,12 @@ require("./HeaderI18n.tag"); this.user = session.user; } - emitter.onConnected((user) => { + session.onConnected((user) => { this.user = user; this.update(); }); - emitter.onUnauthorize(() => { + session.onUnauthorize(() => { this.user = null; this.update(); }); diff --git a/pollen-ui-riot-js/src/main/web/tag/HeaderI18n.tag b/pollen-ui-riot-js/src/main/web/tag/HeaderI18n.tag index 4c5bec2..7a059af 100644 --- a/pollen-ui-riot-js/src/main/web/tag/HeaderI18n.tag +++ b/pollen-ui-riot-js/src/main/web/tag/HeaderI18n.tag @@ -1,6 +1,3 @@ -let session = require("../js/Session"); -let emitter = require("../js/EmitterService"); - <HeaderI18n> <div class="dropdown2"> @@ -13,22 +10,20 @@ let emitter = require("../js/EmitterService"); </div> <script> + let session = require("../js/Session"); this.locale = session.locale; - //FIXME Le traduction ne se fait pas - this.generateBundle(session.locale, "header_i18n"); + this.installBundle(session, "header_i18n"); this.toEnglish = () => { if ('en' != session.locale) { - session.locale = 'en'; + session.changeLocale('en'); this.locale = session.locale; - emitter.emitLocaleChanged(session.locale); this.update(); } }; this.toFrench = () => { if ('fr' != session.locale) { - session.locale = 'fr'; + session.changeLocale('fr'); this.locale = session.locale; - emitter.emitLocaleChanged(session.locale); this.update(); } }; 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 836f817..001827c 100644 --- a/pollen-ui-riot-js/src/main/web/tag/Home.tag +++ b/pollen-ui-riot-js/src/main/web/tag/Home.tag @@ -10,23 +10,25 @@ <script> let session = require("../js/Session"); - let emitter = require("../js/EmitterService"); let form = require("../js/PollForm"); let route = require("riot-route"); - this.installBundle(session.locale, "home", emitter); + this.installBundle(session, "home"); this.createText = () => { - form.init(session.user); - route("/poll/new/text/0"); + form.init(session.user).then(() => { + route("/poll/new/text/0"); + }); }; this.createImage = () => { - form.init(session.user); - route("/poll/new/image/0"); + form.init(session.user).then(() => { + route("/poll/new/image/0"); + }); }; this.createDate = () => { - form.init(session.user); - route("/poll/new/date/0"); + form.init(session.user).then(() => { + route("/poll/new/date/0"); + }); }; </script> diff --git a/pollen-ui-riot-js/src/main/web/tag/Pollen.tag b/pollen-ui-riot-js/src/main/web/tag/Pollen.tag index 19f89f0..e32a8e4 100644 --- a/pollen-ui-riot-js/src/main/web/tag/Pollen.tag +++ b/pollen-ui-riot-js/src/main/web/tag/Pollen.tag @@ -11,14 +11,8 @@ require("./poll/CreatePoll.tag"); <Footer></Footer> <script> - let emitter = require("../js/EmitterService"); - let session = require("../js/Session"); let route = require("riot-route"); - - if (session.isConnected()) { - session.connect(require("../js/AuthService")); - } - + let session = require("../js/Session"); route("/poll/create", () => { riot.mount(this.refs.content, "createpoll"); }); @@ -50,14 +44,15 @@ require("./poll/CreatePoll.tag"); riot.mount(this.refs.content, "userfavoritelists"); }); route("/poll/new/*/*", (type, step) => { - riot.mount(this.refs.content, "createpoll", {type: type, step:step}); + riot.mount(this.refs.content, "createpoll", {type: type, step: step}); }); - route( () => { + route(() => { riot.mount(this.refs.content, "home"); }); - emitter.onUnauthorize(() => { - route("/signin") + session.start().then(() => { + //console.info('session loaded'); }); + </script> </Pollen> diff --git a/pollen-ui-riot-js/src/main/web/tag/SignCheck.tag b/pollen-ui-riot-js/src/main/web/tag/SignCheck.tag index 1a67725..dda079a 100644 --- a/pollen-ui-riot-js/src/main/web/tag/SignCheck.tag +++ b/pollen-ui-riot-js/src/main/web/tag/SignCheck.tag @@ -1,7 +1,3 @@ -let authService = require("../js/AuthService"); -let session = require("../js/Session"); -let emitter = require("../js/EmitterService"); - <SignCheck> <div class="body-container"> <div class="body-container"> @@ -23,8 +19,10 @@ let emitter = require("../js/EmitterService"); </div> <script> + let authService = require("../js/AuthService"); + let session = require("../js/Session"); - this.installBundle(session.locale, "signcheck", emitter); + this.installBundle(session, "signcheck"); this.message = this.__.validating; this.error = false; authService.validateEmail(opts.id, opts.token) diff --git a/pollen-ui-riot-js/src/main/web/tag/SignIn.tag b/pollen-ui-riot-js/src/main/web/tag/SignIn.tag index c1a0863..c9b5117 100644 --- a/pollen-ui-riot-js/src/main/web/tag/SignIn.tag +++ b/pollen-ui-riot-js/src/main/web/tag/SignIn.tag @@ -1,9 +1,4 @@ -let authService = require("../js/AuthService"); -let session = require("../js/Session"); -let emitter = require("../js/EmitterService"); -let route = require("riot-route"); require("./popup/NewPassword.tag"); - <SignIn> <div class="body-container"> <form class="signin" method="post" onsubmit="{signIn}"> @@ -28,7 +23,11 @@ require("./popup/NewPassword.tag"); <NewPassword ref="newPassword"/> <script> - this.installBundle(session.locale, "signin", emitter); + let authService = require("../js/AuthService"); + let session = require("../js/Session"); + let route = require("riot-route"); + + this.installBundle(session, "signin"); this.message = ""; this.newPassword = () => { diff --git a/pollen-ui-riot-js/src/main/web/tag/SignUp.tag b/pollen-ui-riot-js/src/main/web/tag/SignUp.tag index 1dfa81c..2b6650f 100644 --- a/pollen-ui-riot-js/src/main/web/tag/SignUp.tag +++ b/pollen-ui-riot-js/src/main/web/tag/SignUp.tag @@ -1,7 +1,3 @@ -let authService = require("../js/AuthService"); -let session = require("../js/Session"); -let emitter = require("../js/EmitterService"); -let FormHelper = require("../js/FormHelper"); let route = require("riot-route"); require("./popup/ResendValidation.tag"); require("./popup/AccountCreated.tag"); @@ -28,6 +24,9 @@ require("./popup/AccountCreated.tag"); <AccountCreated ref="accountCreated"/> <script> + let authService = require("../js/AuthService"); + let session = require("../js/Session"); + let FormHelper = require("../js/FormHelper"); this.on('mount', () => { if (this.validate) { @@ -35,7 +34,7 @@ require("./popup/AccountCreated.tag"); } }); - this.installBundle(session.locale, "signup", emitter); + this.installBundle(session, "signup"); this.errors = ""; this.resendValidation = () => { 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 76dcb10..4220df5 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 @@ -4,66 +4,154 @@ require("./PollChoicesImage.tag"); require("./PollChoicesDate.tag"); require("./PollSettings.tag"); require("./PollVoters.tag"); +require("./PollCreated.tag"); <CreatePoll> <div> - <div class="header-container"> - <div class="{step == 0 ? 'header-selected-tab' : ''}"> + <div if="{form.step < 4}" class="header-container"> + <div class="{form.step == 0 ? 'header-selected-tab' : ''}"> + <span class="fa-stack fa-2x"> + <i class="fa fa-circle-o fa-stack-2x"></i> + <strong class="fa-stack-1x">1</strong> + </span> + <a if="{form.step > 0}" onclick="{goto0}"> + {__.header_general} + </a> + <span if="{form.step == 0}"> + {__.header_general} + </span> + </div> + <div class="{form.step == 1 ? 'header-selected-tab' : ''}"> + <span class="fa-stack fa-2x"> + <i class="fa fa-circle-o fa-stack-2x"></i> + <strong class="fa-stack-1x">2</strong> + </span> + <a if="{form.step > 1}" onclick="{goto1}"> + {__.header_choices} + </a> + <span if="{form.step <= 1}"> + {__.header_choices} + </span> + </div> + <div class="{form.step == 2 ? 'header-selected-tab' : ''}"> + <span class="fa-stack fa-2x"> + <i class="fa fa-circle-o fa-stack-2x"></i> + <strong class="fa-stack-1x">3</strong> + </span> + <a if="{form.step > 2}" onclick="{goto2}"> + {__.header_options} + </a> + <span if="{form.step <= 2}"> + {__.header_options} + </span> + </div> + <div class="{form.step == 3 ? 'header-selected-tab' : ''}"> + <span class="fa-stack fa-2x"> + <i class="fa fa-circle-o fa-stack-2x"></i> + <strong class="fa-stack-1x">4</strong> + </span> + {__.header_voters} + </div> + <div> + <span class="fa-stack fa-2x"> + <i class="fa fa-circle-o fa-stack-2x"></i> + <strong class="fa-stack-1x">5</strong> + </span> + {__.header_summary} + </div> + </div> + + <div if="{form.step==4}" class="header-container"> + <div> <span class="fa-stack fa-2x"> <i class="fa fa-circle-o fa-stack-2x"></i> <strong class="fa-stack-1x">1</strong> </span> {__.header_general} </div> - <div class="{step == 1 ? 'header-selected-tab' : ''}"> + <div> <span class="fa-stack fa-2x"> <i class="fa fa-circle-o fa-stack-2x"></i> <strong class="fa-stack-1x">2</strong> </span> {__.header_choices} </div> - <div class="{step == 2 ? 'header-selected-tab' : ''}"> + <div> <span class="fa-stack fa-2x"> <i class="fa fa-circle-o fa-stack-2x"></i> <strong class="fa-stack-1x">3</strong> </span> {__.header_options} </div> - <div class="{step == 3 ? 'header-selected-tab' : ''}"> + <div> <span class="fa-stack fa-2x"> <i class="fa fa-circle-o fa-stack-2x"></i> <strong class="fa-stack-1x">4</strong> </span> {__.header_voters} </div> + <div class="header-selected-tab"> + <span class="fa-stack fa-2x"> + <i class="fa fa-circle-o fa-stack-2x"></i> + <strong class="fa-stack-1x">5</strong> + </span> + {__.summary} + </div> </div> <div> - <PollDescription if="{step == 0}" form="{form}" session="{session}" emitter="{emitter}"/> - <PollChoicesText if="{step == 1 && type == 'text'}" form="{form}" session="{session}" emitter="{emitter}"/> - <PollChoicesImage if="{step == 1 && type == 'image'}" form="{form}" session="{session}" - emitter="{emitter}"/> - <PollChoicesDate if="{step == 1 && type == 'date'}" form="{form}" session="{session}" emitter="{emitter}"/> - <PollSettings if="{step == 2}" form="{form}" session="{session}" emitter="{emitter}"/> - <PollVoters if="{step == 3}" form="{form}" session="{session}" emitter="{emitter}"/> + <div ref="content"/> </div> </div> <script> + + console.info("Create poll"); this.type = opts.type; this.form = require("../../js/PollForm"); - this.emitter = require("../../js/EmitterService"); this.session = require("../../js/Session"); this.form.type = this.type; - this.installBundle(this.session.locale, "poll", this.emitter); + this.steps = { + 0: 'polldescription', + 1: 'pollchoices' + this.type, + 2: 'pollsettings', + 3: 'pollvoters', + 4: 'pollcreated' + }; + this.installBundle(this.session, "poll"); - if (!this.form.model) { - this.form.init(this.session.user); + this.goto0 = (e) => { this.form.setStep(0); - } else if (opts.step) { - this.form.step = parseInt(opts.step); + }; + this.goto1 = (e) => { + this.form.setStep(1); + }; + this.goto2 = (e) => { + this.form.setStep(2); + }; + + this.finalizeInit = () => { + let step = this.form.step; +// console.info("Current step!!!!!! " + step); + + riot.mount(this.refs.content, this.steps[step], {form: this.form, session: this.session}); + + }; + + if (!this.form.isInit) { + this.form.init().then(() => { + this.form.setStep(0); + this.finalizeInit(); + }); + + } else { + if (opts.step) { + this.form.step = parseInt(opts.step); + } + + this.on('mount', () => { + this.finalizeInit(); + }); } - this.step = this.form.step; - console.info("Current step!!!!!! " + this.step); </script> <style> @@ -83,7 +171,7 @@ require("./PollVoters.tag"); width: 160px; } - .header-selected-tab { + .header-selected-tab > span > i, .header-selected-tab > span > strong { color: #13a2ff; } diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/PollChoiceText.tag b/pollen-ui-riot-js/src/main/web/tag/poll/PollChoiceText.tag index a20c03d..2bd0ae3 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/PollChoiceText.tag +++ b/pollen-ui-riot-js/src/main/web/tag/poll/PollChoiceText.tag @@ -1,23 +1,24 @@ <PollChoiceText> <div class="container"> - <label class="wide" for="choice{number}">Choix {number}</label> - <label if="{number == 1 }">Description</label> + <label class="wide" for="choice{number}">{__.label} {number + 1}</label> + <label if="{number == 0 }">{__.description}</label> </div> <div class="container"> - - <input class="wide" if="{number == 1}" type="text" required ref="choice{number}" name="choice{number}" - id="choice{number}" - value="{(choices[0] || {text:''}).text}"> - <input class="wide" if="{number > 1}" type="text" ref="choice{number}" name="choice{number}" id="choice{number}" - value="{(choices[number - 1] || {text:''}).text}"> - <input class="wider" type="text" ref="description{number}" name="description{number}" id="description{number}" - value="{(choices[number - 1] || {description:''}).description}"> + <input class="wide" type="text" ref="choice" name="choice{number}" value="{choice.choiceValue}"> + <input class="wider" type="text" ref="description" name="description{number}" value="{choice.description}"> </div> <script> + this.installBundle(opts.session, "poll_choices"); this.number = opts.number; - this.choices = opts.choices; + this.choice = opts.choices[this.number] || {name: '', description: ''}; + this.on('mount', () => { + if (this.number == 0) { + this.refs.choice.required = "require"; + } + }); + </script> <style> diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/PollChoiceTextGroup.tag b/pollen-ui-riot-js/src/main/web/tag/poll/PollChoiceTextGroup.tag index 026cd3c..e4861da 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/PollChoiceTextGroup.tag +++ b/pollen-ui-riot-js/src/main/web/tag/poll/PollChoiceTextGroup.tag @@ -1,14 +1,13 @@ require('./PollChoiceText.tag'); <PollChoiceTextGroup> - <PollChoiceText number="{start}" choices="{choices}"/> - <PollChoiceText number="{start + 1}" choices="{choices}"/> - <PollChoiceText number="{start + 2}" choices="{choices}"/> - <PollChoiceText number="{start + 3}" choices="{choices}"/> - <PollChoiceText number="{start + 4}" choices="{choices}"/> - + <PollChoiceText number="{start}" choices="{choices}" session="{session}"/> + <PollChoiceText number="{start + 1}" choices="{choices}" session="{session}"/> + <PollChoiceText number="{start + 2}" choices="{choices}" session="{session}"/> + <PollChoiceText number="{start + 3}" choices="{choices}" session="{session}"/> + <PollChoiceText number="{start + 4}" choices="{choices}" session="{session}"/> <script> this.choices = opts.choices; - this.descriptions = opts.descriptions; this.start = parseInt(opts.start); + this.session = opts.session; </script> </PollChoiceTextGroup> \ No newline at end of file diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/PollChoicesText.tag b/pollen-ui-riot-js/src/main/web/tag/poll/PollChoicesText.tag index b35c603..ab42cf9 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/PollChoicesText.tag +++ b/pollen-ui-riot-js/src/main/web/tag/poll/PollChoicesText.tag @@ -2,25 +2,30 @@ require('./PollChoiceTextGroup.tag'); <PollChoicesText> <form ref="choices" onsubmit="{nextStep}"> <virtual each={item in counts}> - <PollChoiceTextGroup choices="{form.model.textChoices}" start="{item - 4}"/> + <PollChoiceTextGroup choices="{form.choices}" start="{item - 5}" session="{session}"/> </virtual> + <br/> <div class="actions"> - <a class="button" onclick="{addMoreChoices}"> <i class="fa fa-plus"/>Plus de choix</a> - <a class="button" onclick="{previousStep}">Précédent</a> - <input type="submit" class="button mainColorBackground" value="Suivant"> + <a class="button" onclick="{addMoreChoices}"> <i class="fa fa-plus"/>{__.moreChoices}</a> + </div> + <div class="actions"> + <a class="button" onclick="{previousStep}">{__.previous}</a> + <input type="submit" class="button mainColorBackground" value="{__.next}"> </div> </form> <script> + this.installBundle(opts.session, "poll_choices"); this.form = opts.form; + this.session = opts.session; this.on('mount', () => { this.choices = this.refs.choices; - let choices = this.form.model.textChoices; + let choices = this.form.choices; console.info("init step1 with " + choices.length + " choices"); console.info(choices); if (choices.length == 0) { - this.counts = []; - this.count = 0; + this.counts = [5]; + this.count = 5; } else { this.counts = []; this.count = 0; @@ -61,12 +66,15 @@ require('./PollChoiceTextGroup.tag'); </script> <style> + form { + margin-left: 20px; + } + a.button > i { margin-right: 10px; } .actions { - margin: 50px 10px 10px; display: flex; flex-direction: row; justify-content: flex-start; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/PollCreated.tag b/pollen-ui-riot-js/src/main/web/tag/poll/PollCreated.tag new file mode 100644 index 0000000..ee8a5bf --- /dev/null +++ b/pollen-ui-riot-js/src/main/web/tag/poll/PollCreated.tag @@ -0,0 +1,40 @@ +<PollCreated> + + <div class="container"> + + <div class="legend"> + Sondage créé. + </div> + <div> + Le sondage «{form.model.title}» vient d'être créé. Un courriel vous a été adressé ainsi qu'aux éventuels participants. + + <br/> + <a href="#poll/{form.model.id}/edit">Accéder au sondage</a>. + + </div> + </div> + + <script> + this.form = opts.form; + console.info("Created poll"); + console.info(this.form); + </script> + <style> + + .container { + margin-left: 20px; + } + + .legend { + width: 100%; + height: 70px; + border-bottom: 1px solid #b2c7d3; + display: flex; + justify-content: flex-start; + align-items: center; + margin-bottom: 20px; + font-size: 20px; + } + + </style> +</PollCreated> \ No newline at end of file diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/PollDescription.tag b/pollen-ui-riot-js/src/main/web/tag/poll/PollDescription.tag index 8b447dc..5209173 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/PollDescription.tag +++ b/pollen-ui-riot-js/src/main/web/tag/poll/PollDescription.tag @@ -1,20 +1,19 @@ <PollDescription> <form onsubmit="{nextStep}"> - <label for="title">Titre du sondage</label> - <input ref="title" type="text" required name="title" id="title" value="{model.title}" - placeholder="Enter le titre du sondage"> - <label for="name">Votre nom</label> - <input ref="name" type="text" required name="name" id="name" value="{model.name}" placeholder="Enter votre nom"> - <label for="email">Votre courriel</label> - <input ref="email" type="email" required name="email" id="email" value="{model.email}" - placeholder="Enter votre courriel"> - + <label for="title">{__.title}</label> + <input ref="title" type="text" required name="title" value="{model.title}" placeholder="{__.titlePlaceHolder}"> + <label for="name">{__.name}</label> + <input ref="name" type="text" required name="name" value="{model.name}" placeholder="{__.namePlaceHolder}"> + <label for="email">{__.email}</label> + <input ref="email" type="email" required name="email" value="{model.email}" placeholder="{__.emailPlaceHolder}"> + <br/> <div class="actions"> - <a class="button" onclick="{cancel}">Annuler</a> - <input type="submit" class="button mainColorBackground" value="Suivant"> + <a class="button" onclick="{cancel}">{__.cancel}</a> + <input type="submit" class="button mainColorBackground" value="{__.next}"> </div> </form> <script> + this.installBundle(opts.session, "poll_description", opts.emitter); this.form = opts.form; this.emitter = opts.emitter; this.session = opts.session; @@ -33,12 +32,16 @@ }; </script> <style> + form { + margin-left: 20px; + } + form > input { width: 440px; } .actions { - margin: 50px 10px 10px; + /*margin: 50px 10px 10px;*/ display: flex; flex-direction: row; justify-content: flex-start; 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 86422f2..a1a40ce 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 @@ -5,134 +5,199 @@ <a class="button skip mainColorBackground" onclick="{nextStep}">{__.skip}</a> </div> - <div id="navigation"> + <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> + + <div if="{showOptions}" id="navigation"> <nav class="bs-docs-sidebar"> <ul id="sidebar" class="nav nav-stacked"> <li> - <a onclick="{scrollTo}" href="#GlobalConfiguration">Poll</a> + <a onclick="{scrollTo}" href="#Poll">{__.nav_poll}</a> <ul class="nav nav-stacked"> - <li><a onclick="{scrollTo}" href="#GlobalConfiguration_beginDate">Begin date</a></li> - <li><a onclick="{scrollTo}" href="#GlobalConfiguration_endDate">End date</a></li> - <li><a onclick="{scrollTo}" href="#GlobalConfiguration_resultVisibility">Result visibility</a> + <li> + <a onclick="{scrollTo}" href="#Poll_beginDate">{__.nav_voteBeginDate}</a> + </li> + <li> + <a onclick="{scrollTo}" href="#Poll_endDate">{__.nav_voteEndDate}</a> + </li> + <li> + <a onclick="{scrollTo}" href="#Poll_resultVisibility">{__.nav_resultVisibility}</a> + </li> + <li> + <a onclick="{scrollTo}" href="#Poll_continiousVisibility">{__.nav_continiousResult}</a> </li> - <li><a onclick="{scrollTo}" href="#GlobalConfiguration_continiousVisibility">Continious - result</a></li> </ul> </li> <li> - <a onclick="{scrollTo}" href="#ChoiceConfiguration">Choices</a> + <a onclick="{scrollTo}" href="#Choice">{__.nav_choices}</a> <ul class="nav nav-stacked"> - <li><a onclick="{scrollTo}" href="#ChoiceConfigurationaddChoices">Add choices</a></li> - <li><a onclick="{scrollTo}" href="#ChoiceConfiguration_limitChoices">Limit choices</a></li> + <li> + <a onclick="{scrollTo}" href="#ChoiceaddChoices">{__.nav_addChoices}</a> + </li> + <li> + <a onclick="{scrollTo}" href="#Choice_limitChoices">{__.nav_limitChoices}</a> + </li> </ul> </li> <li> - <a onclick="{scrollTo}" href="#VoteConfiguration">Votes</a> + <a onclick="{scrollTo}" href="#Vote">{__.nav_votes}</a> <ul class="nav nav-stacked"> - <li><a onclick="{scrollTo}" href="#VoteConfiguration_countingType">Vote counting type</a></li> - <li><a onclick="{scrollTo}" href="#VoteConfiguration_visibility">Vote visibility</a></li> - <li><a onclick="{scrollTo}" href="#VoteConfiguration_anonymous">Anonymous vote</a></li> + <li> + <a onclick="{scrollTo}" href="#Vote_countingType">{__.nav_voteCountingType}</a> + </li> + <li> + <a onclick="{scrollTo}" href="#Vote_visibility">{__.nav_voteVisibility}</a> + </li> + <li> + <a onclick="{scrollTo}" href="#Vote_anonymous">{__.nav_anonymousVote}</a> + </li> </ul> </li> <li> - <a onclick="{scrollTo}" href="#CommentConfiguration">Comments</a> + <a onclick="{scrollTo}" href="#Comment">{__.nav_comments}</a> <ul class="nav nav-stacked"> - <li><a onclick="{scrollTo}" href="#CommentConfiguration_enabled">Use comments</a></li> - <li><a onclick="{scrollTo}" href="#CommentConfiguration_visibility">Comment visibility</a></li> + <li> + <a onclick="{scrollTo}" href="#Comment_visibility">{__.nav_commentVisibility}</a> + </li> </ul> </li> </ul> </nav> <div ref="content" class="content"> - <div class="config-group" id="GlobalConfiguration"> - <div class="config-header">Poll configuration</div> - <div id="GlobalConfiguration_beginDate" class="subgroup"> - <div class="config-subheader">Begin date</div> - <div class="config-description"> - When users can start to vote. + <div class="config-group" id="Poll"> + <div class="config-header">{__.poll_configuration}</div> + <div id="Poll_beginDate"> + <div class="config-subheader">{__.nav_voteBeginDate}</div> + <div class="config-description">{__.voteBeginDate} </div> </div> - <div id="GlobalConfiguration_endDate" class="subgroup"> - <div class="config-subheader">End date</div> - <div class="config-description"> - Limit date of voting. - </div> + <div id="Poll_endDate"> + <div class="config-subheader">{__.nav_voteEndDate}</div> + <div class="config-description">{__.voteEndDate}</div> </div> - <div id="GlobalConfiguration_resultVisibility" class="subgroup"> - <div class="config-subheader">Result visibility</div> + <div id="Poll_resultVisibility"> + <div class="config-subheader">{__.nav_resultVisibility}</div> <div class="config-description"> - Who can see results. + {__.resultVisibility} + </div> + <div class="config-form"> + <ul> + <li> + <input type="radio" name="resultVisibility">{__.resultVisibility_creator} + </li> + <li> + <input type="radio" name="resultVisibility">{__.resultVisibility_voter} + </li> + <li> + <input type="radio" name="resultVisibility">{__.resultVisibility_everybody} + </li> + </ul> </div> </div> - <div id="GlobalConfiguration_continiousVisibility" class="subgroup"> - <div class="config-subheader">Continious result</div> - <div class="config-description"> - Te see continious results. + <div id="Poll_continiousVisibility"> + <div class="config-subheader">{__.nav_continiousResult}</div> + <div class="config-description"> {__.continiousResult}</div> + <div class="config-form"> + <input type="checkbox" name="continiousResult" ref="continiousResult">{__.continiousResult} </div> </div> </div> - <div id="ChoiceConfiguration" class="config-group"> - <div class="config-header">Choices configuration</div> - <div id="ChoiceConfigurationaddChoices" class="subgroup"> - <div class="config-subheader">Can users add choices?</div> - <div class="config-description"> - Is users can add choices to poll? + <div id="Choice" class="config-group"> + <div class="config-header">{__.choicesConfiguration}</div> + <div id="Choice_addChoices"> + <div class="config-subheader">{__.nav_addChoices}</div> + <div class="config-description">{__.addChoices}</div> + <div class="config-form"> + <input type="checkbox" name="addChoices" ref="addChoices">{__.addChoices} </div> </div> - <div id="ChoiceConfiguration_limitChoices" class="subgroup"> - <div class="config-subheader">Limit number of choices</div> - <div class="config-description"> - To limit the number of choices what user can vote on. + <div id="Choice_limitChoices"> + <div class="config-subheader">{__.nav_limitChoices}</div> + <div class="config-description">{__.limitChoices}</div> + <div class="config-form"> + <input type="checkbox" name="limitChoices" ref="limitChoices">{__.limitChoices} </div> </div> </div> - <div id="VoteConfiguration" class="config-group"> - <div class="config-header">Votes configuration</div> - <div id="VoteConfiguration_countingType" class="subgroup"> - <div class="config-subheader">Vote counting type</div> - <div class="config-description"> - Defines the vote counting type. + <div id="Vote" class="config-group"> + <div class="config-header">{__.votesConfiguration}</div> + <div id="Vote_countingType"> + <div class="config-subheader">{__.nav_voteCountingType}</div> + <div class="config-description">{__.voteCountingType}</div> + <div class="config-form"> + <ul> + <li> + <input type="radio" name="voteCountingType">{__.voteCountingType_normal} + </li> + <li> + <input type="radio" name="voteCountingType">{__.voteCountingType_pourcentage} + </li> + <li> + <input type="radio" name="voteCountingType">{__.voteCountingType_condorcet} + </li> + </ul> </div> </div> - <div id="VoteConfiguration_visibility" class="subgroup"> - <div class="config-subheader">Vote visibility</div> - <div class="config-description"> - Who can see votes? + <div id="Vote_visibility"> + <div class="config-subheader">{__.nav_voteVisibility}</div> + <div class="config-description">{__.voteVisibility}</div> + <div class="config-form"> + <ul> + <li> + <input type="radio" name="voteVisibility" ref="voteVisibilityNobody">{__.voteVisibility_creator} + </li> + <li> + <input type="radio" name="voteVisibility" ref="voteVisibilityVoter">{__.voteVisibility_voter} + </li> + <li> + <input type="radio" name="voteVisibility" ref="voteVisibilityEverybody">{__.voteVisibility_everybody} + </li> + </ul> </div> </div> - <div id="VoteConfiguration_anonymous" class="subgroup"> - <div class="config-subheader">Anonymous votes</div> - <div class="config-description"> - Anonymze votes + <div id="Vote_anonymous"> + <div class="config-subheader">{__.nav_anonymousVote}</div> + <div class="config-description">{__.anonoymousVote}</div> + <div class="config-form"> + <input type="checkbox" name="anonymousVote" ref="anonymousVote">{__.anonymousVote} </div> </div> </div> - <div id="CommentConfiguration" class="config-group"> - <div class="config-header">Comments configuration</div> - <div id="CommentConfiguration_enabled" class="subgroup"> - <div class="config-subheader">Comment enabled?</div> - <div class="config-description"> - Can use comments on a poll? - </div> - </div> - <div id="CommentConfiguration_visibility" class="subgroup"> - <div class="config-subheader">Comment visibility</div> - <div class="config-description"> - Who can see comments. + <div id="Comment" class="config-group"> + <div class="config-header">{__.commentsConfiguration}</div> + <div id="Comment_visibility"> + <div class="config-subheader">{__.nav_commentVisibility}</div> + <div class="config-description">{__.commentVisibility}</div> + <div class="config-form"> + <ul> + <li> + <input type="radio" name="commentVisibility" ref="commentVisibilityCreator">{__.commentVisibility_creator} + </li> + <li> + <input type="radio" name="commentVisibility" ref="commentVisibilityVoter">{__.commentVisibility_voter} + </li> + <li> + <input type="radio" name="commentVisibility" ref="commentVisibilityEverybody">{__.commentVisibility_everybody} + </li> + </ul> </div> </div> </div> </div> </div> - <div class="actions"> + <div if="{showOptions}" class="actions"> <a class="button" onclick="{previousStep}">{__.previous}</a> <a class="button mainColorBackground" onclick="{nextStep}">{__.next}</a> </div> <script> this.form = opts.form; - this.installBundle(opts.session.locale, "poll_settings", opts.emitter); + this.showOptions = this.form.showOptions; + this.installBundle(opts.session, "poll_settings"); this.previousStep = (e) => { this.form.previousStep(); }; @@ -144,15 +209,31 @@ e.preventDefault(); e.stopPropagation(); let id = e.currentTarget.href.substring(e.currentTarget.href.indexOf('#') + 1); - if (id.indexOf('_')>-1) { + if (id.indexOf('_') > -1) { id = id.substring(0, id.indexOf('_')); } document.getElementById(id).scrollIntoView(); }; + this.toggleShowOptions = () => { + this.showOptions = this.form.showOptions = !this.showOptions; + } + </script> <style> + .config-form > ul > li > input, .config-form > input { + display: inline; + width: 50px; + margin: 0; + padding: 0; + height: 16px; + } + + .wide { + width: 250px; + } + .config-header { border-bottom: solid 2px #c8ccca; font-size: 20px; @@ -191,17 +272,16 @@ .legend { width: 100%; - height: 70px; border-bottom: 1px solid #b2c7d3; display: flex; - justify-content: center; + justify-content: flex-start; + margin-left: 20px; align-items: center; - margin-bottom: 30px; font-size: 20px; } .actions { - margin: 50px 10px 10px; + margin: 10px; display: flex; flex-direction: row; justify-content: flex-start; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/PollVoters.tag b/pollen-ui-riot-js/src/main/web/tag/poll/PollVoters.tag index b057aff..5f9c129 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/PollVoters.tag +++ b/pollen-ui-riot-js/src/main/web/tag/poll/PollVoters.tag @@ -1,42 +1,185 @@ <PollVoters> - <div> - Participants au sondage - </div> + <form onsubmit="{action}"> - <div class="actions"> - <a class="button" onclick="{previousStep}">Précédent</a> - <a class="button done" onclick="{validate}">Terminer</a> - </div> + <div class="legend"> + {__.description} + </div> + + <div class="mainOptions"> + <div class="mainOptionsDiv"> + <input type="radio" name="voteType" ref="publicType" onclick="{publicPoll}"> + {__.freePoll} + </div> + <div> + <div class="mainOptionsDiv"> + <input type="radio" ref="privateType" name="voteType" onclick="{privatePoll}"> + {__.restrictedPoll} + </div> + <div show="{$private}" class="privateOptions"> + <div> + <input type="checkbox" name="withMe" ref="withMe" onclick="{withMe}">{__.restrictedPoll_withMe} + </div> + </div> + </div> + </div> + <div class="legend"> + {__.invite} + </div> + + <div class="participants"> + <label for="paticipants">{__.invite_label}</label> + <textarea if="{!$private}" rows="5" ref="participants" name="participants" onchange="{participantsChanged}" + value="{participants}"/> + <textarea if="{$private}" required rows="5" ref="participants" name="participants" value="{participants}" + onchange="{participantsChanged}"/> + </div> + <div class="actions"> + <a class="button" onclick="{previousStep}">{__.previous}</a> + <input type="submit" class="button mainColorBackground" value="{__.save}"> + </div> + + </form> <script> + this.installBundle(opts.session, "poll_voters"); this.form = opts.form; + this.$private = this.form.model.pollType != 'FREE'; + this.participants = ""; this.previousStep = (e) => { this.form.previousStep(); }; - this.validate = (e) => { - this.form.save().then(poll => { - console.info("poll saved"); - console.info(poll); - }).catch(errors => { + this.on('mount', () => { + if (this.$private) { + this.refs.privateType.checked='checked'; + } else { + this.refs.publicType.checked='checked'; + } + if (this.form.model.withMe) { + this.refs.withMe.checked='checked'; + } + }); + this.action = (e) => { + e.preventDefault(); + e.stopPropagation(); + + this.form.model.participants = this.refs.participants.value.split(' '); + console.info('Poll form to save'); + console.info(this.form.model); + console.info('Poll choices to save'); + console.info(this.form.choices); + + this.form.create().catch(errors => { console.info("Can't save poll"); console.info(errors); }); + }; + this.publicPoll = () => { + if (this.form.model.pollType != 'FREE') { + this.form.model.pollType = 'FREE'; + this.form.model.withMe = false; + this.$private = false; + this.update(); + } + }; + this.privatePoll = () => { + if (this.form.model.pollType != 'RESTRICTED') { + this.form.model.pollType = 'RESTRICTED'; + this.$private = true; + this.update(); + } + }; + this.withMe = (e) => { + this.form.model.withMe = !this.form.model.withMe; + }; + this.participantsChanged = (e) => { + this.participants = e.target.value; + console.info(this.participants); } + </script> <style> + + form { + margin-left: 20px; + } + + textarea { + width: 80%; + } + + label { + width: 80%; + } + + .mainOptionsDiv > input, .privateOptions > div > input { + display: inline; + width: 50px; + margin: 0; + padding: 0; + height: 16px; + } + + .legend { + width: 100%; + height: 70px; + border-bottom: 1px solid #b2c7d3; + display: flex; + justify-content: flex-start; + align-items: center; + margin-bottom: 20px; + font-size: 20px; + } + + .participants { + margin-bottom: 5px; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: flex-start; + } + + .mainOptions { + margin-bottom: 5px; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: flex-start; + height: 80px; + } + + .mainOptionsDiv { + display: flex; + flex-direction: row; + justify-content: flex-start; + align-items: flex-start; + margin-bottom: 5px; + } + + .privateOptions { + margin-left: 20px; + margin-bottom: 5px; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: flex-start; + } + .actions { - margin: 50px 10px 10px; + /*margin: 50px 10px 10px;*/ display: flex; flex-direction: row; justify-content: flex-start; align-items: center; } + .actions > a { margin: 5px; } - .done { - background-color: #13a2ff; + + .actions > input { + margin: 5px; } + </style> </PollVoters> \ No newline at end of file diff --git a/pollen-ui-riot-js/src/main/web/tag/popup/AccountCreated.tag b/pollen-ui-riot-js/src/main/web/tag/popup/AccountCreated.tag index 9a8b5ef..28d41ce 100644 --- a/pollen-ui-riot-js/src/main/web/tag/popup/AccountCreated.tag +++ b/pollen-ui-riot-js/src/main/web/tag/popup/AccountCreated.tag @@ -1,7 +1,3 @@ -let session = require("../../js/Session"); -let emitter = require("../../js/EmitterService"); -let route = require("riot-route"); - <AccountCreated class="close"> <div class="popup-background"></div> @@ -18,8 +14,10 @@ let route = require("riot-route"); </div> <script> + let session = require("../../js/Session"); + let route = require("riot-route"); - this.installBundle(session.locale, "createdaccount", emitter); + this.installBundle(session, "createdaccount"); this.oldParent = this.parent.root; diff --git a/pollen-ui-riot-js/src/main/web/tag/popup/NewPassword.tag b/pollen-ui-riot-js/src/main/web/tag/popup/NewPassword.tag index af16ac7..03a37f1 100644 --- a/pollen-ui-riot-js/src/main/web/tag/popup/NewPassword.tag +++ b/pollen-ui-riot-js/src/main/web/tag/popup/NewPassword.tag @@ -1,7 +1,3 @@ -let session = require("../../js/Session"); -let emitter = require("../../js/EmitterService"); -let authService = require("../../js/AuthService"); - <NewPassword class="close"> <div class="popup-background"></div> @@ -23,8 +19,10 @@ let authService = require("../../js/AuthService"); </div> <script> + let session = require("../../js/Session"); + let authService = require("../../js/AuthService"); - this.installBundle(session.locale, "newpassword", emitter); + this.installBundle(session, "newpassword"); this.sent = false; this.error = ""; diff --git a/pollen-ui-riot-js/src/main/web/tag/popup/ResendValidation.tag b/pollen-ui-riot-js/src/main/web/tag/popup/ResendValidation.tag index 05bfdbf..cc9bd2f 100644 --- a/pollen-ui-riot-js/src/main/web/tag/popup/ResendValidation.tag +++ b/pollen-ui-riot-js/src/main/web/tag/popup/ResendValidation.tag @@ -1,7 +1,3 @@ -let session = require("../../js/Session"); -let emitter = require("../../js/EmitterService"); -let authService = require("../../js/AuthService"); - <ResendValidation class="close"> <div class="popup-background"></div> @@ -24,7 +20,10 @@ let authService = require("../../js/AuthService"); <script> - this.installBundle(session.locale, "resendvalidation", emitter); + let session = require("../../js/Session"); + let authService = require("../../js/AuthService"); + + this.installBundle(session, "resendvalidation"); this.oldParent = this.parent.root; -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.