Author: garandel Date: 2014-05-12 18:50:51 +0200 (Mon, 12 May 2014) New Revision: 3932 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3932 Log: test PUT by POST (edit poll) Modified: trunk/pollen-ui-angular/src/main/webapp/index.html trunk/pollen-ui-angular/src/main/webapp/js/app.js trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js trunk/pollen-ui-angular/src/main/webapp/js/services.js trunk/pollen-ui-angular/src/main/webapp/partials/big-poll.html trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html trunk/pollen-ui-angular/src/main/webapp/partials/poll.html Modified: trunk/pollen-ui-angular/src/main/webapp/index.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/index.html 2014-05-12 15:06:31 UTC (rev 3931) +++ trunk/pollen-ui-angular/src/main/webapp/index.html 2014-05-12 16:50:51 UTC (rev 3932) @@ -29,6 +29,7 @@ <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-route.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-resource.min.js"></script> + <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-cookies.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.11.0/ui-bootstrap-tpls.min.js"></script> <script src="js/libs/ckeditor/ckeditor.js"></script> Modified: trunk/pollen-ui-angular/src/main/webapp/js/app.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-05-12 15:06:31 UTC (rev 3931) +++ trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-05-12 16:50:51 UTC (rev 3932) @@ -18,9 +18,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'ui.bootstrap'], function($httpProvider) { +angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'ui.bootstrap', 'ngCookies'], function($httpProvider) { $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; - $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; + //$httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; }) Modified: trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-12 15:06:31 UTC (rev 3931) +++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-12 16:50:51 UTC (rev 3932) @@ -23,9 +23,11 @@ }]) -.controller('PollCtrl', ['$scope', '$sce', '$timeout', function ($scope, $sce, $timeout) { +.controller('PollCtrl', ['$scope', '$sce', '$timeout', '$cookieStore', function ($scope, $sce, $timeout, $cookieStore) { if (!angular.isDefined($scope.globalVariables)) { - $scope.globalVariables = {saved : false}; + $scope.globalVariables = {saved : $cookieStore.get('saved')}; + $cookieStore.put('saved', ''); + $scope.$watch('globalVariables.saved', function() { $timeout(function () { $scope.globalVariables.saved = false; @@ -217,7 +219,7 @@ }]) -.controller('PollCreateCtrl', ['$scope', '$controller', '$location', 'Poll', function ($scope, $controller, $location, Poll) { +.controller('PollCreateCtrl', ['$scope', '$controller', '$location', 'Poll', '$cookieStore', function ($scope, $controller, $location, Poll, $cookieStore) { $controller('PollAdminCtrl', {$scope:$scope}); $scope.globalVariables.create = true; @@ -238,9 +240,7 @@ var poll = angular.copy($scope.data.poll); poll.choice = angular.copy($scope.data.choices); Poll.add(poll, function (data) { - console.log(data); - $scope.globalVariables.saved = true; - $scope.globalVariables.restError = false; + $cookieStore.put('saved', true); $location.url('/poll/edit/'+data.topiaId+'?token='+data.permission); }, function (error) { $scope.globalVariables.restError = true; @@ -302,6 +302,7 @@ var initPoll = function () { Poll.get({pollId:$routeParams.pollId}).$promise.then(function (poll) { $scope.data.poll = poll; + $scope.$watchCollection('data.poll', $scope.autoSave); }); PollChoice.query({pollId:$routeParams.pollId}).$promise.then(function (choices) { $scope.data.choices = choices; @@ -314,8 +315,7 @@ $scope.save = function () { $timeout.cancel(timeout); if ($scope.formValid) { - var poll = angular.copy($scope.data.poll); - Poll.update({permission:$routeParams.token}, poll, function (data) { + $scope.data.poll.$update({permission:$routeParams.token}, function (data) { $scope.globalVariables.saved = true; }, function (error) { console.log(error); Modified: trunk/pollen-ui-angular/src/main/webapp/js/services.js =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-12 15:06:31 UTC (rev 3931) +++ trunk/pollen-ui-angular/src/main/webapp/js/services.js 2014-05-12 16:50:51 UTC (rev 3932) @@ -26,25 +26,23 @@ }) .factory('Poll', ['$resource', 'BaseUrl', function ($resource, BaseUrl) { - var transformParam = function (data) { - var poll = angular.copy(data); - delete poll.choice; - var choices = angular.copy(data.choice); - return 'poll='+encodeURIComponent(JSON.stringify(poll))+'&choices='+encodeURIComponent(JSON.stringify(choices)); - }; return $resource(BaseUrl+'/polls/:pollId/:cmd', {pollId:'@topiaId'}, { 'add' : { method : 'POST', transformRequest : function (data, headersGetter) { - return transformParam(data); + var poll = angular.copy(data); + delete poll.choice; + var choices = angular.copy(data.choice); + return 'poll='+encodeURIComponent(JSON.stringify(poll))+'&choices='+encodeURIComponent(JSON.stringify(choices)); } }, 'update' : { method : 'POST', transformRequest : function (data, headersGetter) { - return transformParam(data); + return 'poll='+encodeURIComponent(JSON.stringify(data)); } + ,headers : { 'X-HTTP-Method':'PUT'} } }); }]) Modified: trunk/pollen-ui-angular/src/main/webapp/partials/big-poll.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/big-poll.html 2014-05-12 15:06:31 UTC (rev 3931) +++ trunk/pollen-ui-angular/src/main/webapp/partials/big-poll.html 2014-05-12 16:50:51 UTC (rev 3932) @@ -31,7 +31,7 @@ {{choice.name}} </h3> <h3 ng-show="showEdit"> - <input type="text" ng-model="choice.name" focus-me="showEdit" ng-exit="showEdit = false" required/> + <input type="text" ng-model="choice.name" focus-me="showEdit" ng-exit="showEdit = false" auto-save="saveChoice(choice)" required/> </h3> </div> @@ -46,12 +46,13 @@ is-open="isOpen" focus-me="showEdit" ng-exit="showEdit = false" - ng-click="isOpen = true" required/> + ng-click="isOpen = true" + auto-save="saveChoice(choice)" required/> </h3> </div> </div> <p collapse="!globalVariables.editMode && !showChoiceDesc" edit-me="showEditChoiceDesc" ng-hide="showEditChoiceDesc">{{choice.description}}</p> - <p ng-show="globalVariables.editMode && showEditChoiceDesc"><textarea ng-model="choice.description" focus-me="showEditChoiceDesc" ng-exit="showEditChoiceDesc = false" cols="80" rows="8"></textarea></p> + <p ng-show="globalVariables.editMode && showEditChoiceDesc"><textarea ng-model="choice.description" focus-me="showEditChoiceDesc" ng-blur="showEditChoiceDesc = false" auto-save="saveChoice(choice)" cols="80" rows="8"></textarea></p> </div> <div class="col-sm-2 pollChoiceInput"> <input type="checkbox" ng-model="vote.choice[$index].value"/> Modified: trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html 2014-05-12 15:06:31 UTC (rev 3931) +++ trunk/pollen-ui-angular/src/main/webapp/partials/inline-poll.html 2014-05-12 16:50:51 UTC (rev 3932) @@ -36,7 +36,7 @@ <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:'dd/MM/yyyy'}} <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="dd/MM/yyyy" is-open="isOpen" ng-exit="showEdit = false" ng-click="isOpen = true" auto-save="saveChoice()" required/> + <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" 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="..."/> </div> </div> Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll.html =================================================================== --- trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-12 15:06:31 UTC (rev 3931) +++ trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-12 16:50:51 UTC (rev 3932) @@ -39,7 +39,7 @@ <div ng-bind-html="toHTML(data.poll.description || 'Description (Facultatif). Ce cadre disparait si aucune description n\'est mise')"></div> </div> <div ng-show="showEditDesc" class="pollDesc " ng-exit="showEditDesc = false;"> - <textarea id="descEditor" data-ck-editor ng-model="data.poll.description" auto-save="save()"></textarea> + <textarea id="descEditor" data-ck-editor ng-model="data.poll.description"></textarea> <input type="button" value="Return" class="btn btn-primary" ng-click="showEditDesc = false;"/> </div>