Author: garandel Date: 2014-04-28 11:56:29 +0200 (Mon, 28 Apr 2014) New Revision: 3882 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3882 Log: add gobal poll controller. Added: trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html Modified: trunk/pollen-ui-angular/src/main/webapp/css/style.css trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js trunk/pollen-ui-angular/src/main/webapp/partials/poll.html Modified: trunk/pollen-ui-angular/src/main/webapp/css/style.css =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/css/style.css 2014-04-27 17:12:24 UTC (rev 3881) +++ trunk/pollen-ui-angular/src/main/webapp/css/style.css 2014-04-28 09:56:29 UTC (rev 3882) @@ -164,4 +164,9 @@ right: 30px; top:10px; pointer-events: none; +} + +.fixe-input .ng-hide { + display:inline-block !important; + visibility:hidden; } \ No newline at end of file Modified: trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-04-27 17:12:24 UTC (rev 3881) +++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-04-28 09:56:29 UTC (rev 3882) @@ -21,7 +21,26 @@ angular.module('pollenControllers', []).controller('HomeCtrl', ['$scope', '$http', function ($scope, $http) { }]) -.controller('PollCreateCtrl', ['$scope', '$http', '$sce', '$modal', '$filter', '$timeout', 'pollStorage', function ($scope, $http, $sce, $modal, $filter, $timeout, pollStorage) { + +.controller('PollCtrl', ['$scope', '$sce', '$timeout', 'pollStorage', function ($scope, $sce, $timeout, pollStorage) { + $scope.gvar = {saved:false}; + $scope.$watch('gvar.saved', function() { + $timeout(function () { + $scope.gvar.saved = false; + }, 5000); + }); + + $scope.poll = pollStorage.get(); + + $scope.toHTML = function (data) { + return $sce.trustAsHtml(data); + } + +}]) + +.controller('PollCreateCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', 'pollStorage', function ($scope, $controller, $modal, $filter, $timeout, pollStorage) { + $controller('PollCtrl', {$scope:$scope}); + function initPoll() { return { title :'', @@ -37,14 +56,8 @@ }; } - $scope.gvar = {saved:false, editMode:true}; - $scope.$watch('gvar.saved', function() { - $timeout(function () { - $scope.gvar.saved = false; - }, 5000); - }) + $scope.gvar.editMode = true; - $scope.poll = pollStorage.get(); if (JSON.stringify($scope.poll) == "{}") { $scope.poll = initPoll(); } @@ -54,33 +67,12 @@ $scope.addChoice = function () { var index = $scope.poll.choices.push(initChoice()); var choice = $scope.poll.choices[index-1]; - var modalInstance = $modal.open({ - templateUrl : 'popupChoice.html', - controller : PollPopChoiceCtrl, - resolve : { - title : function () { return 'Add Choice';}, - choice : function () { return choice; } - } - }); - modalInstance.result.then(function (ch) { - deleteChoice(ch); - }); + popupChoice(choice, 'Add Choice'); } $scope.editChoice = function (choice) { - var modalInstance = $modal.open({ - templateUrl : 'popupChoice.html', - controller : PollPopChoiceCtrl, - resolve : { - title : function () { return 'Edit Choice';}, - choice : function () { return choice; } - } - }); - - modalInstance.result.then(function (ch) { - deleteChoice(ch); - }); + popupChoice(choice, 'Edit Choice'); } var deleteChoice = function (ch) { @@ -90,6 +82,21 @@ } } + var popupChoice = function (choice, title) { + var modalInstance = $modal.open({ + templateUrl : 'partials/poll-popupChoice.html', + controller : PollPopChoiceCtrl, + resolve : { + title : function () { return title;}, + choice : function () { return choice; } + } + }); + + modalInstance.result.then(function (ch) { + deleteChoice(ch); + }); + } + $scope.save = function () { pollStorage.put($scope.poll); $scope.gvar.saved = true; @@ -97,21 +104,24 @@ $scope.reset = function () { $scope.poll = initPoll(); + $scope.voteChoices = $scope.poll.choices; pollStorage.put({}); } - $scope.toHTML = function (data) { - return $sce.trustAsHtml(data); - } - var PollPopChoiceCtrl = function ($scope, $filter, $modalInstance, title, choice) { $scope.title = title; $scope.choice = choice; + var oldChoice = angular.copy(choice); $scope.saveChoice = function () { $modalInstance.close(); } + $scope.cancelChoice = function () { + angular.copy(oldChoice, $scope.choice); + $modalInstance.close(); + } + $scope.deleteChoice = function (ch) { $modalInstance.close(ch); } @@ -119,24 +129,24 @@ } }]) -.controller('PollVoteCtrl', ['$scope', '$filter', '$sce', '$timeout', 'pollStorage', function ($scope, $filter, $sce, $timeout, pollStorage) { - $scope.gvar = {saved:false, editMode:false}; - $scope.$watch('gvar.saved', function() { - $timeout(function () { - $scope.gvar.saved = false; - }, 5000); - }) - $scope.poll = pollStorage.get(); - $scope.voteName = ""; - $scope.voteChoices = []; - for (var i = 0; i < $scope.poll.choices.length; ++i) { - if ($scope.poll.choices[i].type == 'text') { - $scope.voteChoices.push({name:$scope.poll.choices[i].name, value:false}); - } - else if ($scope.poll.choices[i].type == 'date') { - $scope.voteChoices.push({name: $filter('date')($scope.poll.choices[i].date,'dd/MM/yyyy') , value:false}); - } +.controller('PollVoteCtrl', ['$scope', '$filter', '$controller', 'pollStorage', function ($scope, $filter, $controller, pollStorage) { + $controller('PollCtrl', {$scope:$scope}); + + $scope.gvar.editMode = false; + + var initVote = function () { + $scope.voteName = ""; + $scope.voteChoices = []; + for (var i = 0; i < $scope.poll.choices.length; ++i) { + if ($scope.poll.choices[i].type == 'text') { + $scope.voteChoices.push({name:$scope.poll.choices[i].name, value:false}); + } + else if ($scope.poll.choices[i].type == 'date') { + $scope.voteChoices.push({name: $filter('date')($scope.poll.choices[i].date,'dd/MM/yyyy') , value:false}); + } + } } + initVote(); $scope.vote = function () { var data = {}; @@ -148,10 +158,7 @@ $scope.poll.votants.push(data); pollStorage.put($scope.poll); $scope.gvar.saved = true; + initVote(); } - - $scope.toHTML = function (data) { - return $sce.trustAsHtml(data); - } }]) ; \ No newline at end of file Added: trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html (rev 0) +++ trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html 2014-04-28 09:56:29 UTC (rev 3882) @@ -0,0 +1,49 @@ +<form class="form-horizontal"> + <div class="modal-header"> + <h4 class="modal-title">{{title}}</h4> + {{oldChoice}} + </div> + <div class="modal-body"> + + <div class="form-group"> + <label class="col-sm-4 control-label">Type de choix :</label> + + <div class="col-sm-8 btn-group"> + <button type="button" class="btn btn-default" ng-model="choice.type" btn-radio="'text'">Text</button> + <button type="button" class="btn btn-default" ng-model="choice.type" btn-radio="'date'">Date</button> + <button type="button" class="btn btn-default" ng-model="choice.type" btn-radio="'picture'" disabled>Image</button> + </div> + </div> + + <div class="form-group" ng-if="choice.type == 'text'"> + <label for="popNameChoiceCheck" class="col-sm-4 control-label">Nom du Choix : </label> + + <div class="col-sm-6"> + <input id="popNameChoiceCheck" type="text" ng-model="choice.name" class="form-control" /> + </div> + </div> + + <div class="form-group" ng-if="choice.type == 'date'"> + <label for="popNameChoiceDate" class="col-sm-4 control-label">Date : </label> + + <div class="col-sm-6"> + <div class="right-inner-addon "> + <i class="glyphicon glyphicon-calendar glyphicon-input"></i> + <input id="popNameChoiceDate" class="form-control" datepicker-popup="dd/MM/yyyy" type="text" ng-model="choice.date" is-open="opened"/> + </div> + </div> + </div> + <div class="form-group"> + <label for="popDescChoice" class="col-sm-4 control-label">Description : </label> + + <div class="col-sm-6"> + <textarea id="popDescChoice" type="text" ng-model="choice.description" class="form-control"></textarea> + </div> + </div> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-danger" ng-click="deleteChoice(choice)">Delete</button> + <button type="button" class="btn btn-default" ng-click="cancelChoice()">Cancel</button> + <button type="button" class="btn btn-primary" ng-click="saveChoice()">Save</button> + </div> +</form> \ No newline at end of file Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-04-27 17:12:24 UTC (rev 3881) +++ trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-04-28 09:56:29 UTC (rev 3882) @@ -46,15 +46,15 @@ <td class="pollChoice"></td> <td ng-repeat="choice in poll.choices" class="pollChoice pollAnim" edit-me="showEdit" ng-mouseenter="showEditHover = true" ng-mouseleave="showEditHover = false"> <div ng-show="choice.type == 'text'"> - <div ng-hide="showEdit" title="{{choice.description}}">{{choice.name}} <input type="button" class="btn btn-default" data-toggle="modal" data-target="#popupAddChoice" ng-show="gvar.editMode && showEditHover" ng-click="editChoice(choice)" value="..."/></div> + <div ng-hide="showEdit" class="fixe-input" title="{{choice.description}}">{{choice.name}} <input type="button" class="btn btn-default" ng-if="gvar.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/></div> <div ng-show="showEdit"> <input type="text" class="form-control" ng-model="choice.name" focus-me="showEdit" ng-exit="showEdit = false"/> <input type="button" class="btn btn-default" data-toggle="modal" data-target="#popupAddChoice" ng-click="editChoice(choice)" value="..."/> </div> </div> <div ng-show="choice.type == 'date'"> - <div ng-hide="showEdit || isOpen" title="{{choice.description}}">{{choice.date | date:'dd/MM/yyyy'}} <input type="button" class="btn btn-default" data-toggle="modal" data-target="#popupAddChoice" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/></div> - <div ng-show="showEdit || isOpen"> + <div ng-hide="showEdit || isOpen" class="fixe-input" title="{{choice.description}}">{{choice.date | date:'dd/MM/yyyy'}} <input type="button" class="btn btn-default" ng-if="gvar.editMode" ng-show="showEditHover" ng-click="editChoice(choice)" value="..."/></div> + <div ng-show="showEdit || isOpen" > <input type="text" class="form-control" ng-model="choice.date" focus-me="showEdit" datepicker-popup="dd/MM/yyyy" is-open="isOpen" ng-exit="showEdit = false" /> <input type="button" class="btn btn-default" data-toggle="modal" data-target="#popupAddChoice" ng-click="editChoice(choice)" value="..."/> </div> @@ -91,52 +91,3 @@ </div> </form> -<script type="text/ng-template" id="popupChoice.html"> - <form class="form-horizontal"> - <div class="modal-header"> - <h4 class="modal-title">{{title}}</h4> - </div> - <div class="modal-body"> - - <div class="form-group"> - <label class="col-sm-4 control-label">Type de choix :</label> - - <div class="col-sm-8 btn-group"> - <button type="button" class="btn btn-default" ng-model="choice.type" btn-radio="'text'">Text</button> - <button type="button" class="btn btn-default" ng-model="choice.type" btn-radio="'date'">Date</button> - <button type="button" class="btn btn-default" ng-model="choice.type" btn-radio="'picture'" disabled>Image</button> - </div> - </div> - - <div class="form-group" ng-if="choice.type == 'text'"> - <label for="popNameChoiceCheck" class="col-sm-4 control-label">Nom du Choix : </label> - - <div class="col-sm-6"> - <input id="popNameChoiceCheck" type="text" ng-model="choice.name" class="form-control" /> - </div> - </div> - - <div class="form-group" ng-if="choice.type == 'date'"> - <label for="popNameChoiceDate" class="col-sm-4 control-label">Date : </label> - - <div class="col-sm-6"> - <div class="right-inner-addon "> - <i class="glyphicon glyphicon-calendar glyphicon-input"></i> - <input id="popNameChoiceDate" class="form-control" datepicker-popup="dd/MM/yyyy" type="text" ng-model="choice.date" is-open="opened"/> - </div> - </div> - </div> - <div class="form-group"> - <label for="popDescChoice" class="col-sm-4 control-label">Description : </label> - - <div class="col-sm-6"> - <textarea id="popDescChoice" type="text" ng-model="choice.description" class="form-control"></textarea> - </div> - </div> - </div> - <div class="modal-footer"> - <button type="button" class="btn btn-danger" data-dismiss="modal" ng-click="deleteChoice(choice)">delete</button> - <button type="button" class="btn btn-primary" ng-click="saveChoice()">Save</button> - </div> - </form> -</script>