Commit 61267f5d911a45ad4d6e7f4d3b0fd8d912dcd14d

Authored by Caio Almeida
1 parent e0b7f461

Ticket #58: Fixing edit proposal

www/html/_edit_proposal.html
@@ -9,17 +9,8 @@ @@ -9,17 +9,8 @@
9 <label class="item item-input"><input type="text" placeholder="Título" ng-model="data.title" maxlength="40"></label> 9 <label class="item item-input"><input type="text" placeholder="Título" ng-model="data.title" maxlength="40"></label>
10 <label class="item item-input"><textarea placeholder="Descrição" ng-model="data.description"></textarea></label> 10 <label class="item item-input"><textarea placeholder="Descrição" ng-model="data.description"></textarea></label>
11 11
12 - <ng-include src="'html/_select_state.html'"></ng-include> 12 + <ng-include src="'html/_select_proposal_state.html'"></ng-include>
13 13
14 - <label id="proposal-topic">  
15 - <div class="input-label">  
16 - Eixo  
17 - </div>  
18 - <select ng-model="data.topic_id" id="select-topic" ng-value="topic.id" ng-options="topic.title for topic in topics track by topic.id">  
19 - <option value="">Escolha o eixo...</option>  
20 - </select>  
21 - </label>  
22 -  
23 <label class="checkbox free-conference-cbox"> 14 <label class="checkbox free-conference-cbox">
24 <input type="checkbox" ng-model="data.free_conference" > 15 <input type="checkbox" ng-model="data.free_conference" >
25 </label> 16 </label>
www/html/_left_sidebar.html
1 <div id="left-sidebar" class="sidebar" menu-toggle="left"> 1 <div id="left-sidebar" class="sidebar" menu-toggle="left">
2 <ion-content> 2 <ion-content>
3 <h2> 3 <h2>
4 - <span>{{user.name}}</span> 4 + <span>{{profile.login}}</span>
5 <button menu-toggle="left" class="button button-icon icon ion-close-circled"></button> 5 <button menu-toggle="left" class="button button-icon icon ion-close-circled"></button>
6 </h2> 6 </h2>
7 <ul class="list" ng-show="loggedIn"> 7 <ul class="list" ng-show="loggedIn">
www/html/_proposal.html
@@ -12,16 +12,16 @@ @@ -12,16 +12,16 @@
12 <span id="proposal-id" style="display: none;">{{proposal.id}}</span> 12 <span id="proposal-id" style="display: none;">{{proposal.id}}</span>
13 13
14 <p class="proposal-buttons"> 14 <p class="proposal-buttons">
15 - <button class="button tag" ng-click="openTagForm()" ng-show="proposal.author.id == user.id"> 15 + <button class="button tag" ng-click="openTagForm()" ng-show="proposal.author.id == profile.id">
16 <i class="icon ion-pricetags"></i> <span>Adicionar Tag</span> 16 <i class="icon ion-pricetags"></i> <span>Adicionar Tag</span>
17 </button> 17 </button>
18 - <button class="button edit" ng-click="openEditProposalForm()" ng-show="proposal.author.id == user.id"> 18 + <button class="button edit" ng-click="openEditProposalForm()" ng-show="proposal.author.id == profile.id">
19 <i class="icon ion-edit"></i> <span>Editar</span> 19 <i class="icon ion-edit"></i> <span>Editar</span>
20 </button> 20 </button>
21 <button class="button comment" ng-click="openCommentForm()"> 21 <button class="button comment" ng-click="openCommentForm()">
22 <i class="icon ion-chatbox-working"></i> <span>Comentar</span> 22 <i class="icon ion-chatbox-working"></i> <span>Comentar</span>
23 </button> 23 </button>
24 - <button class="button follow" ng-click="follow(proposal)" ng-hide="isFollowing(proposal) || proposal.author.id == user.id"> 24 + <button class="button follow" ng-click="follow(proposal)" ng-hide="isFollowing(proposal) || proposal.author.id == profile.id">
25 <i class="icon ion-eye"></i> <span>Seguir</span> 25 <i class="icon ion-eye"></i> <span>Seguir</span>
26 </button> 26 </button>
27 <br /> 27 <br />
www/html/_proposal_list.html
@@ -52,7 +52,7 @@ @@ -52,7 +52,7 @@
52 </div> 52 </div>
53 <div class="card-footer"> 53 <div class="card-footer">
54 <a ng-click="openProposal(proposal)" class="icon-left ion-android-open"> Leia Mais</a> 54 <a ng-click="openProposal(proposal)" class="icon-left ion-android-open"> Leia Mais</a>
55 - <a ng-click="follow(proposal)" class="icon-left ion-eye" ng-hide="isFollowing(proposal) || proposal.author.id == user.id"> Seguir</a> 55 + <a ng-click="follow(proposal)" class="icon-left ion-eye" ng-hide="isFollowing(proposal) || proposal.author.id == profile.id"> Seguir</a>
56 </div> 56 </div>
57 </div> 57 </div>
58 </td-card> 58 </td-card>
www/html/_select_city.html
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 <div class="input-label"> 2 <div class="input-label">
3 Cidade 3 Cidade
4 </div> 4 </div>
5 - <select ng-model="profile.city" ng-value="profile.city.id" ng-options="city.name for city in cities track by city.id" class="item"> 5 + <select ng-model="profile.city" ng-value="city.id" ng-options="city.name for city in cities track by city.id" class="item">
6 <option value="">Escolha a cidade...</option> 6 <option value="">Escolha a cidade...</option>
7 </select> 7 </select>
8 </label> 8 </label>
www/html/_select_proposal_city.html
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 <div class="input-label"> 2 <div class="input-label">
3 Cidade 3 Cidade
4 </div> 4 </div>
5 - <select ng-model="data.city" ng-value="data.city.id" ng-options="city.name for city in cities track by city.id" class="item"> 5 + <select ng-model="data.city" ng-value="city.id" ng-options="city.name for city in cities track by city.id" class="item">
6 <option value="">Escolha a cidade...</option> 6 <option value="">Escolha a cidade...</option>
7 </select> 7 </select>
8 </label> 8 </label>
www/html/_select_proposal_state.html
@@ -8,4 +8,3 @@ @@ -8,4 +8,3 @@
8 </label> 8 </label>
9 9
10 <ng-include src="'html/_select_proposal_city.html'"></ng-include> 10 <ng-include src="'html/_select_proposal_city.html'"></ng-include>
11 -  
www/index.html
@@ -35,14 +35,14 @@ @@ -35,14 +35,14 @@
35 35
36 <ion-side-menus id="body" ng-show="!introDisplayed"> 36 <ion-side-menus id="body" ng-show="!introDisplayed">
37 <ion-side-menu side="left"> 37 <ion-side-menu side="left">
38 - <ng-include src="'html/_left_sidebar.html'"></ng-include> 38 + <ng-include src="'html/_left_sidebar.html?1'"></ng-include>
39 </ion-side-menu> 39 </ion-side-menu>
40 40
41 <ion-side-menu-content> 41 <ion-side-menu-content>
42 <ng-include src="'html/_header.html?2'"></ng-include> 42 <ng-include src="'html/_header.html?2'"></ng-include>
43 <ion-pane> 43 <ion-pane>
44 <ion-content id="proposals-container" no-scroll=""> 44 <ion-content id="proposals-container" no-scroll="">
45 - <ng-include src="'html/_proposal_list.html?9'"></ng-include> 45 + <ng-include src="'html/_proposal_list.html?10'"></ng-include>
46 </ion-content> 46 </ion-content>
47 </ion-pane> 47 </ion-pane>
48 </ion-side-menu-content> 48 </ion-side-menu-content>
www/js/controllers.js
@@ -288,7 +288,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -288,7 +288,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
288 $scope.shouldDisplayCities = false; 288 $scope.shouldDisplayCities = false;
289 289
290 // Load States 290 // Load States
291 - $scope.loadStates = function() { 291 + $scope.loadStates = function(selected) {
292 $scope.loading = true; 292 $scope.loading = true;
293 $scope.shouldDisplayCities = false; 293 $scope.shouldDisplayCities = false;
294 294
@@ -297,8 +297,11 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -297,8 +297,11 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
297 $http.get(ConfJuvAppUtils.pathTo(path)) 297 $http.get(ConfJuvAppUtils.pathTo(path))
298 .then(function(resp) { 298 .then(function(resp) {
299 $scope.states = resp.data; 299 $scope.states = resp.data;
300 - if($scope.profile && $scope.profile.state){  
301 - $scope.loadCitiesByState($scope.profile.state.id) 300 + if (selected) {
  301 + $scope.loadCitiesByState(selected);
  302 + }
  303 + else if ($scope.profile && $scope.profile.state && !selected) {
  304 + $scope.loadCitiesByState($scope.profile.state.id);
302 } 305 }
303 $scope.loading = false; 306 $scope.loading = false;
304 }, function(err) { 307 }, function(err) {
@@ -450,7 +453,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -450,7 +453,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
450 perPage = 11; 453 perPage = 11;
451 } 454 }
452 455
453 - var params = '?private_token=' + token + '&fields=title,image,body,abstract,id,tag_list,categories,created_by&content_type=ProposalsDiscussionPlugin::Proposal&per_page=' + perPage + '&oldest=younger_than&reference_id=' + topic.lastProposalId + $scope.proposalsFilter; 456 + var params = '?t=' + (new Date().getTime()) + '&private_token=' + token + '&fields=title,image,body,abstract,id,tag_list,categories,created_by&content_type=ProposalsDiscussionPlugin::Proposal&per_page=' + perPage + '&oldest=younger_than&reference_id=' + topic.lastProposalId + $scope.proposalsFilter;
454 457
455 var path = 'articles/' + topic.id + '/children' + params; 458 var path = 'articles/' + topic.id + '/children' + params;
456 459
@@ -535,7 +538,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -535,7 +538,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
535 } 538 }
536 else { 539 else {
537 // Initiate the modal 540 // Initiate the modal
538 - $ionicModal.fromTemplateUrl('html/_proposal.html?16', { 541 + $ionicModal.fromTemplateUrl('html/_proposal.html?17', {
539 scope: $scope, 542 scope: $scope,
540 animation: 'slide-in-up' 543 animation: 'slide-in-up'
541 }).then(function(modal) { 544 }).then(function(modal) {
@@ -1028,8 +1031,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -1028,8 +1031,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
1028 $scope.loadCitiesByState($scope.data.state.id); 1031 $scope.loadCitiesByState($scope.data.state.id);
1029 } 1032 }
1030 else { 1033 else {
1031 - $scope.loadStates();  
1032 - $scope.loadCitiesByState($scope.data.state.id); 1034 + $scope.loadStates($scope.data.state.id);
1033 // Initiate the modal 1035 // Initiate the modal
1034 $ionicModal.fromTemplateUrl('html/_edit_proposal.html', { 1036 $ionicModal.fromTemplateUrl('html/_edit_proposal.html', {
1035 scope: $scope, 1037 scope: $scope,
@@ -1056,7 +1058,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -1056,7 +1058,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
1056 1058
1057 // Submit the updated proposal 1059 // Submit the updated proposal
1058 $scope.updateProposal = function(data) { 1060 $scope.updateProposal = function(data) {
1059 - if (!data || !data.title || !data.description || !data.topic_id) { 1061 + if (!data || !data.title || !data.description) {
1060 $scope.closeEditProposalModal(); 1062 $scope.closeEditProposalModal();
1061 var popup = $ionicPopup.alert({ title: 'Alterar proposta', template: 'Por favor preencha todos os campos!' }); 1063 var popup = $ionicPopup.alert({ title: 'Alterar proposta', template: 'Por favor preencha todos os campos!' });
1062 popup.then(function() { 1064 popup.then(function() {
@@ -1100,24 +1102,16 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -1100,24 +1102,16 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
1100 1102
1101 $http.post(ConfJuvAppUtils.pathTo('articles/' + $scope.proposal.id), jQuery.param(params), config) 1103 $http.post(ConfJuvAppUtils.pathTo('articles/' + $scope.proposal.id), jQuery.param(params), config)
1102 .then(function(resp) { 1104 .then(function(resp) {
1103 - $scope.closeEditProposalModal();  
1104 var popup = $ionicPopup.alert({ title: 'Alterar proposta', template: 'Proposta alterada com sucesso!' }); 1105 var popup = $ionicPopup.alert({ title: 'Alterar proposta', template: 'Proposta alterada com sucesso!' });
1105 popup.then(function() { 1106 popup.then(function() {
1106 - var topic = null;  
1107 - for (var i = 0; i < $scope.topics.length; i++) {  
1108 - if (data.topic_id.id == $scope.topics[i].id) {  
1109 - topic = $scope.topics[i];  
1110 - }  
1111 - }  
1112 -  
1113 $scope.proposal.categories[0] = data.city; 1107 $scope.proposal.categories[0] = data.city;
1114 $scope.proposal.categories[1] = data.state; 1108 $scope.proposal.categories[1] = data.state;
1115 $scope.proposal.title = data.title; 1109 $scope.proposal.title = data.title;
1116 $scope.proposal.body = data.description; 1110 $scope.proposal.body = data.description;
1117 - $scope.proposal.topic = data.topic_id;  
1118 1111
1119 $scope.loading = false; 1112 $scope.loading = false;
1120 document.getElementById('save-proposal').innerHTML = 'Salvar'; 1113 document.getElementById('save-proposal').innerHTML = 'Salvar';
  1114 + $scope.closeEditProposalModal();
1121 }); 1115 });
1122 }, function(err) { 1116 }, function(err) {
1123 $scope.closeEditProposalModal(); 1117 $scope.closeEditProposalModal();