Commit ce65011c2fa97545cb5d0d1f12b33e2ac767ef08

Authored by Caio Almeida
1 parent 717b5446

Tickets #9 and #10: avoid double comment submission and clear form after comment…

…, tag or proposal is submitted
ConfJuvApp/www/html/_create_comment.html
1 <div class="modal" id="create-comment"> 1 <div class="modal" id="create-comment">
2 <ion-content> 2 <ion-content>
3 - <form ng-submit="createComment(data)"> 3 + <form ng-submit="createComment(data)" onsubmit="createcomment.disabled = true">
4 <h1 class="title"> 4 <h1 class="title">
5 <span>Comentar</span> 5 <span>Comentar</span>
6 <a class="back icon-left ion-reply" ng-click="closeCommentModal()">Voltar</a> 6 <a class="back icon-left ion-reply" ng-click="closeCommentModal()">Voltar</a>
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 <label class="item item-input"><textarea placeholder="Comentário" ng-model="data.comment" rows="15"></textarea></label> 9 <label class="item item-input"><textarea placeholder="Comentário" ng-model="data.comment" rows="15"></textarea></label>
10 10
11 <p class="text-center"> 11 <p class="text-center">
12 - <button ripple class="button" type="submit">Enviar</button> 12 + <button ripple class="button" type="submit" name="createcomment" id="createcomment">Enviar</button>
13 </p> 13 </p>
14 </form> 14 </form>
15 </ion-content> 15 </ion-content>
ConfJuvApp/www/js/controllers.js
@@ -517,8 +517,8 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -517,8 +517,8 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
517 $scope.proposalList.push(proposal); 517 $scope.proposalList.push(proposal);
518 $scope.cards.push(proposal); 518 $scope.cards.push(proposal);
519 $scope.proposalsByTopic[data.topic_id].push(proposal); 519 $scope.proposalsByTopic[data.topic_id].push(proposal);
520 - data.title = data.description = data.topic_id = null;  
521 $scope.loading = false; 520 $scope.loading = false;
  521 + $scope.data.title = $scope.data.description = $scope.data.topic_id = null;
522 }); 522 });
523 }, function(err) { 523 }, function(err) {
524 $scope.closeProposalModal(); 524 $scope.closeProposalModal();
@@ -543,7 +543,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -543,7 +543,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
543 } 543 }
544 else { 544 else {
545 // Initiate the modal 545 // Initiate the modal
546 - $ionicModal.fromTemplateUrl('html/_create_comment.html?1', { 546 + $ionicModal.fromTemplateUrl('html/_create_comment.html?4', {
547 scope: $scope, 547 scope: $scope,
548 animation: 'slide-in-up' 548 animation: 'slide-in-up'
549 }).then(function(modal) { 549 }).then(function(modal) {
@@ -555,6 +555,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -555,6 +555,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
555 555
556 // Function to close the modal 556 // Function to close the modal
557 $scope.closeCommentModal = function() { 557 $scope.closeCommentModal = function() {
  558 + document.getElementById('createcomment').disabled = false;
558 $scope.commentModal.hide(); 559 $scope.commentModal.hide();
559 $scope.openProposal($scope.proposal); 560 $scope.openProposal($scope.proposal);
560 }; 561 };
@@ -600,6 +601,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -600,6 +601,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
600 .then(function(resp) { 601 .then(function(resp) {
601 $scope.closeCommentModal(); 602 $scope.closeCommentModal();
602 var popup = $ionicPopup.alert({ title: 'Comentar', template: 'Comentário criado com sucesso!' }); 603 var popup = $ionicPopup.alert({ title: 'Comentar', template: 'Comentário criado com sucesso!' });
  604 + $scope.data.comment = '';
603 if (!$scope.proposal.comments) { 605 if (!$scope.proposal.comments) {
604 $scope.proposal.comments = []; 606 $scope.proposal.comments = [];
605 } 607 }
@@ -764,14 +766,15 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -764,14 +766,15 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
764 $http.post(ConfJuvAppUtils.pathTo('articles/' + $scope.proposal.id + '/tags'), jQuery.param(params), config) 766 $http.post(ConfJuvAppUtils.pathTo('articles/' + $scope.proposal.id + '/tags'), jQuery.param(params), config)
765 .then(function(resp) { 767 .then(function(resp) {
766 $scope.closeTagModal(); 768 $scope.closeTagModal();
767 - var popup = $ionicPopup.alert({ title: 'Tag', template: 'Tag adicionada com sucesso!' }); 769 + var popup = $ionicPopup.alert({ title: 'Tags', template: 'Tags adicionadas com sucesso!' });
768 $scope.proposal.tag_list = data.tag.split(','); 770 $scope.proposal.tag_list = data.tag.split(',');
  771 + $scope.data.tag = '';
769 popup.then(function() { 772 popup.then(function() {
770 $scope.loading = false; 773 $scope.loading = false;
771 }); 774 });
772 }, function(err) { 775 }, function(err) {
773 $scope.closeTagModal(); 776 $scope.closeTagModal();
774 - var popup = $ionicPopup.alert({ title: 'Tag', template: 'Erro ao adicionar tag!' }); 777 + var popup = $ionicPopup.alert({ title: 'Tags', template: 'Erro ao adicionar tags!' });
775 popup.then(function() { 778 popup.then(function() {
776 $scope.loading = false; 779 $scope.loading = false;
777 $scope.openTagForm(); 780 $scope.openTagForm();