This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See http://git.chorem.org/pollen.git commit 4165b424fb94ffa4ff1cea0adad11be6411c8071 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Jul 2 12:17:49 2014 +0200 Implement type Date in choice --- .../chorem/pollen/services/bean/ChoiceBean.java | 52 +++++++++++++++++++++- .../pollen/services/service/ChoiceService.java | 31 +++++++++++-- .../i18n/pollen-services_en_GB.properties | 2 + .../i18n/pollen-services_fr_FR.properties | 2 + .../src/main/webapp/js/controllers/pollCtrl.js | 28 ++++++++++-- .../src/main/webapp/partials/inline-poll.html | 8 +++- .../src/main/webapp/partials/poll-popupChoice.html | 2 +- 7 files changed, 114 insertions(+), 11 deletions(-) diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java index c5ee22a..215498b 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java @@ -25,6 +25,8 @@ import org.chorem.pollen.persistence.entity.Choice; import org.chorem.pollen.persistence.entity.ChoiceImpl; import org.chorem.pollen.persistence.entity.ChoiceType; +import java.util.Date; + /** * Created on 5/15/14. * @@ -39,6 +41,8 @@ public class ChoiceBean extends PollenBean<Choice> { protected String name; + protected Date date; + protected ChoiceType choiceType; protected String description; @@ -61,7 +65,24 @@ public class ChoiceBean extends PollenBean<Choice> { } - setName(entity.getName()); + switch (entity.getChoiceType()) { + + case TEXT: + setName(entity.getName()); + setDate(null); + break; + + case DATE: + setName(null); + setDate(new Date(Long.parseLong(entity.getName()))); + break; + + case IMAGE: + + throw new IllegalStateException("Not implemented"); + //break; + } + setDescription(entity.getDescription()); setChoiceType(entity.getChoiceType()); setChoiceOrder(entity.getChoiceOrder()); @@ -74,7 +95,26 @@ public class ChoiceBean extends PollenBean<Choice> { Choice entity = new ChoiceImpl(); entity.setTopiaId(getEntityId()); - entity.setName(getName()); + + switch (getChoiceType()) { + case TEXT: + entity.setName(getName()); + + break; + + case DATE: + if (getDate() != null) { + entity.setName(String.valueOf(getDate().getTime())); + } + + break; + + case IMAGE: + + throw new IllegalStateException("Not implemented"); + //break; + } + entity.setDescription(getDescription()); entity.setChoiceType(getChoiceType()); entity.setChoiceOrder(getChoiceOrder()); @@ -99,6 +139,14 @@ public class ChoiceBean extends PollenBean<Choice> { this.name = name; } + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + public ChoiceType getChoiceType() { return choiceType; } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java index 3e6acc0..a6c9f2e 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java @@ -34,6 +34,7 @@ import org.chorem.pollen.services.bean.ChoiceBean; import org.chorem.pollen.services.bean.PollenEntityRef; import org.chorem.pollen.services.service.security.PermissionVerb; +import java.util.Date; import java.util.List; import java.util.Set; @@ -168,7 +169,7 @@ public class ChoiceService extends PollenServiceSupport { // can't delete this choice // will be the last one ErrorMap errors = new ErrorMap(); - errors.addError("choice", "need at least one choice"); + errors.addError("choice", l(getLocale(), "pollen.error.poll.choice.mandatory")); errors.failIfNotEmpty(); } @@ -230,6 +231,8 @@ public class ChoiceService extends PollenServiceSupport { } + toSave.setChoiceType(choice.getChoiceType()); + switch (toSave.getChoiceType()) { case TEXT: @@ -242,7 +245,11 @@ public class ChoiceService extends PollenServiceSupport { case DATE: - throw new IllegalStateException("Not implemented"); + toSave.setName(String.valueOf(choice.getDate().getTime())); + toSave.setDescription(choice.getDescription()); + toSave.setCreator(poll.getCreator()); + + break; case IMAGE: @@ -301,7 +308,25 @@ public class ChoiceService extends PollenServiceSupport { break; case DATE: - throw new IllegalStateException("Not implemented"); + Date choiceDate = choice.getDate(); + + boolean dateNotBlank; + if (choiceDate == null) { + dateNotBlank = checkNotBlank(errors, "date", null, l(getLocale(), "pollen.error.choice.choiceDateEmpty")); + } + else { + dateNotBlank = checkNotBlank(errors, + "date", + String.valueOf(choiceDate), + l(getLocale(), "pollen.error.choice.choiceDateEmpty")); + } + + if (dateNotBlank) { + boolean dateAdded = choiceNames.add(String.valueOf(choiceDate.getTime())); + check(errors, "date", dateAdded, l(getLocale(), "pollen.error.choice.choiceDateExist")); + } + + break; case IMAGE: diff --git a/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties b/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties index 24b79ec..2ec870f 100644 --- a/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties +++ b/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties @@ -11,6 +11,8 @@ pollen.configuration.defaultPollVoteVisibility=Default Poll vote visibility used pollen.configuration.defaultPollenUserPageSize= pollen.configuration.defaultVoteCountingType=Default vote counting type used when creating a new poll pollen.configuration.sessionTimeoutDelay=Inactivity delay before invalidate the session of a user (in seconds) +pollen.error.choice.choiceDateEmpty=choice date can not be empty +pollen.error.choice.choiceDateExist=choice date already used in this list pollen.error.choice.choiceNameEmpty=choice name can not be empty pollen.error.choice.choiceNameExist=choice name already used in this list pollen.error.choice.choiceTypeEmpty=choiceType can not be null diff --git a/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties b/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties index c7df00c..2685800 100644 --- a/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties +++ b/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties @@ -11,6 +11,8 @@ pollen.configuration.defaultPollVoteVisibility=Visibilité des votes par défaut pollen.configuration.defaultPollenUserPageSize= pollen.configuration.defaultVoteCountingType=Type de dépouillement par défaut lors de la création d'un nouveau sondage pollen.configuration.sessionTimeoutDelay=Temps autorisé d'inactivité avant d'invalider une session utilisateur (en secondes) +pollen.error.choice.choiceDateEmpty=La date ne peut pas être vide +pollen.error.choice.choiceDateExist=La date exist déjà utilisé sur ce sondage pollen.error.choice.choiceNameEmpty=Le nom du choix ne peut pas être vide pollen.error.choice.choiceNameExist=Le nom du choix est déjà utilisé sur ce sondage pollen.error.choice.choiceTypeEmpty=Le type du choix doit être défini diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js index fc54416..4f4637a 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js @@ -256,7 +256,7 @@ angular.module('pollControllers', []) $scope.globalVariables.editMode = true; $scope.globalVariables.voted = angular.isDefined($scope.data.votants); $scope.globalVariables.lastType = 'TEXT'; - $scope.globalVariables.lastDate = new Date(); + $scope.globalVariables.lastDate = null; $scope.restError = {}; //////////////////////////////// @@ -423,6 +423,12 @@ angular.module('pollControllers', []) var poll = angular.copy($scope.data.poll); poll.choice = angular.copy($scope.data.choices); + angular.forEach(poll.choice, function(choice) { + if (angular.isDate(choice.date)) { + choice.date = choice.date.getTime(); + } + }); + if (angular.isDate(poll.beginDate)) { poll.beginDate = poll.beginDate.getTime(); } @@ -446,6 +452,10 @@ angular.module('pollControllers', []) if (angular.isDefined(error.data['choice['+index+'].name'])) { choice.restError = {name:error.data['choice['+index+'].name']}; } + + if (angular.isDefined(error.data['choice['+index+'].date'])) { + choice.restError = {date:error.data['choice['+index+'].date']}; + } }); if (angular.isDefined(error.data.choice)) { @@ -471,7 +481,13 @@ angular.module('pollControllers', []) //////////////////////////////// $scope.callBackAddChoice = function (choice) { - PollChoice.add({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken}, choice, function (data) { + saveChoice = angular.copy(choice); + + if (angular.isDate(saveChoice.date)) { + saveChoice.date = saveChoice.date.getTime(); + } + + PollChoice.add({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken}, saveChoice, function (data) { delete choice.restError; choice.id = data.id; $rootScope.$broadcast('newSuccess', 'poll.saved'); @@ -481,7 +497,13 @@ angular.module('pollControllers', []) } $scope.callBackEditChoice = function (choice) { - PollChoice.update({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken}, choice, function() { + saveChoice = angular.copy(choice); + + if (angular.isDate(saveChoice.date)) { + saveChoice.date = saveChoice.date.getTime(); + } + + PollChoice.update({pollId:$routeParams.pollId, permission:$scope.globalVariables.pollToken}, saveChoice, function() { delete choice.restError; $rootScope.$broadcast('newSuccess', 'poll.saved'); }, function (error) { diff --git a/pollen-ui-angular/src/main/webapp/partials/inline-poll.html b/pollen-ui-angular/src/main/webapp/partials/inline-poll.html index e19b41e..87d801c 100644 --- a/pollen-ui-angular/src/main/webapp/partials/inline-poll.html +++ b/pollen-ui-angular/src/main/webapp/partials/inline-poll.html @@ -28,7 +28,7 @@ <td ng-repeat="choice in data.choices" class="pollChoice pollAnim" ng-mouseenter="showEditHover = true" ng-mouseleave="showEditHover = false"> <div ng-if="choice.choiceType == 'TEXT'" edit-me="showEdit" > <div ng-hide="showEdit && !globalVariables.voted" class="fixe-input" title="{{choice.description}}"> - {{choice.name || 'poll.edit' | translate}} + {{ choice.name || ('poll.edit' | translate) }} <info-error error="choice.restError.name[0]" data="choice.name"></info-error> <input type="button" class="btn btn-default" ng-if="!globalVariables.voted && globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/></div> <div ng-show="showEdit && !globalVariables.voted"> @@ -37,7 +37,11 @@ </div> </div> <div ng-if="choice.choiceType == 'DATE'" edit-me="showEdit" > - <div ng-hide="!globalVariables.voted && showEdit || isOpen" class="fixe-input" title="{{choice.description}}">{{choice.date | date:globalVariables.dateFormat}} <input type="button" class="btn btn-default" ng-if="!globalVariables.voted && globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/></div> + <div ng-hide="!globalVariables.voted && showEdit || isOpen" class="fixe-input" title="{{choice.description}}"> + {{ (choice.date | date:globalVariables.dateFormat) || ('poll.edit' | translate) }} + <info-error error="choice.restError.date[0]" data="choice.date"></info-error> + <input type="button" class="btn btn-default" ng-if="!globalVariables.voted && globalVariables.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/> + </div> <div ng-show="!globalVariables.voted && showEdit || isOpen" > <input type="text" class="form-control" ng-model="choice.date" focus-me="showEdit" datepicker-popup="{{globalVariables.dateFormat}}" is-open="isOpen" ng-exit="showEdit = false" ng-click="isOpen = true" auto-save="saveChoice(choice)" required/> <input type="button" class="btn btn-default" data-toggle="modal" data-target="#popupAddChoice" ng-click="editChoice(choice)" value="..."/> diff --git a/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html b/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html index f86dfca..3264210 100644 --- a/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html +++ b/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html @@ -30,7 +30,7 @@ <div class="col-sm-8 btn-group"> <button type="button" class="btn btn-default" ng-model="choice.choiceType" btn-radio="'TEXT'">Text</button> - <button type="button" class="btn btn-default" ng-model="choice.choiceType" btn-radio="'DATE'" disabled>Date</button> + <button type="button" class="btn btn-default" ng-model="choice.choiceType" btn-radio="'DATE'">Date</button> <button type="button" class="btn btn-default" ng-model="choice.choiceType" btn-radio="'IMAGE'" disabled>Image</button> </div> </div> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.