Commit c446582a9b78cf15939308e4b2ba8455da6c8510
1 parent
9acab0bf
Exists in
master
and in
8 other branches
Add 'create proposal'
Showing
8 changed files
with
137 additions
and
49 deletions
Show diff stats
src/app/components/article-service/article.service.js
| ... | ... | @@ -6,12 +6,13 @@ |
| 6 | 6 | .factory('ArticleService', ArticleService); |
| 7 | 7 | |
| 8 | 8 | /** @ngInject */ |
| 9 | - function ArticleService($http, $q, $rootScope, API, UtilService, Slug, $log) { | |
| 9 | + function ArticleService($http, $q, $rootScope, API, UtilService, Slug, GUID, $log) { | |
| 10 | 10 | $log.debug('ArticleService'); |
| 11 | 11 | |
| 12 | 12 | var service = { |
| 13 | 13 | apiArticles: $rootScope.basePath + '/api/v1/articles/', |
| 14 | 14 | apiCommunities: $rootScope.basePath + '/api/v1/communities/', |
| 15 | + apiProposals: $rootScope.basePath + '/api/v1/proposals_discussion_plugin/', | |
| 15 | 16 | getArticleById: getArticleById, |
| 16 | 17 | getArticleBySlug: getArticleBySlug, |
| 17 | 18 | getCategories: getCategories, |
| ... | ... | @@ -21,6 +22,7 @@ |
| 21 | 22 | getProposals: getProposals, |
| 22 | 23 | getProposalById: getProposalById, |
| 23 | 24 | getProposalsByTopicId: getProposalsByTopicId, |
| 25 | + createProposal: createProposal, | |
| 24 | 26 | getEvents: getEvents, |
| 25 | 27 | subscribeToEvent: subscribeToEvent, |
| 26 | 28 | searchTopics: searchTopics, |
| ... | ... | @@ -148,6 +150,28 @@ |
| 148 | 150 | getProposalById(topicId + '/children', params, cbSuccess, cbError); |
| 149 | 151 | } |
| 150 | 152 | |
| 153 | + function createProposal (proposal, targetId, cbSuccess, cbError){ | |
| 154 | + | |
| 155 | + if(!$rootScope.currentUser){ | |
| 156 | + cbError({message: 'Usuário não logado.'}); | |
| 157 | + }else{ | |
| 158 | + // /api/v1/proposals_discussion_plugin/' + targetId + '/propose | |
| 159 | + var url = service.apiProposals + targetId + '/propose'; | |
| 160 | + | |
| 161 | + var encodedParams = []; | |
| 162 | + encodedParams.push('private_token=' + $rootScope.currentUser.private_token); | |
| 163 | + encodedParams.push('fields=id'); | |
| 164 | + encodedParams.push('article[name]=article_' + GUID.generate()); | |
| 165 | + encodedParams = encodedParams.join('&'); | |
| 166 | + | |
| 167 | + UtilService.post(url, encodedParams).then(function(response){ | |
| 168 | + cbSuccess(response); | |
| 169 | + }).catch(function(error){ | |
| 170 | + cbError(error); | |
| 171 | + }); | |
| 172 | + } | |
| 173 | + } | |
| 174 | + | |
| 151 | 175 | function getEvents (community_id, params, cbSuccess, cbError) { |
| 152 | 176 | // Ex.: /api/v1/communities/19195/articles?categories_ids[]=' + cat_id + '&content_type=Event'; |
| 153 | 177 | // Ex.: /api/v1/communities/' + community_id + '/articles?categories_ids[]=' + cat_id + '&content_type=Event'; |
| ... | ... | @@ -183,16 +207,17 @@ |
| 183 | 207 | |
| 184 | 208 | if(!$rootScope.currentUser){ |
| 185 | 209 | cbError({message: 'Usuário não logado.'}); |
| 186 | - } | |
| 187 | 210 | |
| 188 | - var url = service.apiArticles + event_id + '/follow'; | |
| 189 | - var encodedParams = 'private_token=' + $rootScope.currentUser.private_token; | |
| 211 | + }else{ | |
| 212 | + var url = service.apiArticles + event_id + '/follow'; | |
| 213 | + var encodedParams = 'private_token=' + $rootScope.currentUser.private_token; | |
| 190 | 214 | |
| 191 | - UtilService.post(url, encodedParams).then(function(response){ | |
| 192 | - cbSuccess(response); | |
| 193 | - }).catch(function(error){ | |
| 194 | - cbError(error); | |
| 195 | - }); | |
| 215 | + UtilService.post(url, encodedParams).then(function(response){ | |
| 216 | + cbSuccess(response); | |
| 217 | + }).catch(function(error){ | |
| 218 | + cbError(error); | |
| 219 | + }); | |
| 220 | + } | |
| 196 | 221 | } |
| 197 | 222 | |
| 198 | 223 | function searchTopics (params, cbSuccess, cbError) { | ... | ... |
src/app/components/cadastro-proposta/cadastro-proposta.directive.js
| ... | ... | @@ -28,13 +28,20 @@ |
| 28 | 28 | // requeue to wait until DOM be created |
| 29 | 29 | vm.$timeout(function(){ |
| 30 | 30 | attachPopover.call(vm); |
| 31 | - }, 100); | |
| 31 | + }, 200); | |
| 32 | + }; | |
| 33 | + | |
| 34 | + CadastroPropostaController.prototype.sendProposal = function (proposal) { | |
| 35 | + var vm = this; | |
| 36 | + | |
| 37 | + // notify parents - handled by parents | |
| 38 | + vm.$scope.$emit('cadastro-proposa:startSendProposal', proposal); | |
| 32 | 39 | }; |
| 33 | 40 | |
| 34 | 41 | function attachPopover(){ |
| 35 | 42 | var vm = this; |
| 36 | 43 | |
| 37 | - vm.popover = angular.element(vm.$element.find('.link-popover')); | |
| 44 | + vm.popover = angular.element(vm.$element.find('.btn-question')); | |
| 38 | 45 | vm.popover.popover({ |
| 39 | 46 | html: true, |
| 40 | 47 | placement: 'bottom', |
| ... | ... | @@ -47,7 +54,9 @@ |
| 47 | 54 | var directive = { |
| 48 | 55 | restrict: 'E', |
| 49 | 56 | templateUrl: 'app/components/cadastro-proposta/cadastro-proposta.html', |
| 50 | - scope: {}, | |
| 57 | + scope: { | |
| 58 | + program: '=' | |
| 59 | + }, | |
| 51 | 60 | controller: CadastroPropostaController, |
| 52 | 61 | controllerAs: 'vm', |
| 53 | 62 | bindToController: true | ... | ... |
src/app/components/cadastro-proposta/cadastro-proposta.html
| ... | ... | @@ -11,23 +11,29 @@ |
| 11 | 11 | <div class="col-sm-8"> |
| 12 | 12 | <p>Você está fazendo uma proposta para o programa:</p> |
| 13 | 13 | <div class="bloco-programa"> |
| 14 | - <span class="texto-programa">Nome do progama</span> | |
| 14 | + <span class="texto-programa">{{::vm.program.title}}</span> | |
| 15 | 15 | </div> |
| 16 | 16 | </div> |
| 17 | 17 | </div> |
| 18 | - <form role="form" name="formPropostas" ng-submit="pageSignin.login(pageSignin.credentials)" novalidate> | |
| 18 | + <form role="form" name="formPropostas" ng-submit="vm.sendProposal(proposta)" novalidate> | |
| 19 | 19 | <div class="form-group"> |
| 20 | 20 | <div class="row linha-proposta"> |
| 21 | 21 | <div class="col-sm-8"> |
| 22 | - <span>Descrição da proposta*</span> | |
| 22 | + <label for="proposta-textarea">Descrição da proposta*</label> | |
| 23 | 23 | <a tabindex="0" class="btn btn-link btn-question" role="button" data-toggle="popover" data-trigger="focus">?</a> |
| 24 | - <textarea id="proposta" name="proposta" class="texto-proposta form-control" | |
| 24 | + <textarea id="proposta-textarea" name="proposta" class="texto-proposta form-control" | |
| 25 | 25 | ng-class="{ 'has-error' : formPropostas.proposta.$invalid && formPropostas.proposta.$touched }" |
| 26 | 26 | ng-model="proposta" |
| 27 | 27 | required ng-maxlength="200" ></textarea> |
| 28 | - <validation-messages field="formPropostas.proposta" maxlength="'Ops, esse campo não pode ser maior que 200 caracteres.'"/> | |
| 29 | - <span class="pull-left">*Dados obrigatórios</span> | |
| 30 | - <span class="pull-right">Máx. 200 caracteres</span> | |
| 28 | + <validation-messages field="formPropostas.proposta" maxlength="'Ops, esse campo não pode ser maior que 200 caracteres.'"></validation-messages> | |
| 29 | + <div class="row"> | |
| 30 | + <div class="col-xs-6"> | |
| 31 | + <span>*Dados obrigatórios</span> | |
| 32 | + </div> | |
| 33 | + <div class="col-xs-6 text-right"> | |
| 34 | + <span>Máx. 200 caracteres</span> | |
| 35 | + </div> | |
| 36 | + </div> | |
| 31 | 37 | </div> |
| 32 | 38 | </div> |
| 33 | 39 | </div> | ... | ... |
src/app/components/proposal-carousel/proposal-carousel.directive.js
| ... | ... | @@ -56,11 +56,11 @@ |
| 56 | 56 | } |
| 57 | 57 | }; |
| 58 | 58 | |
| 59 | - ProposalCarouselController.prototype.showProposals = function () { | |
| 59 | + ProposalCarouselController.prototype.showProposalsList = function () { | |
| 60 | 60 | var vm = this; |
| 61 | 61 | |
| 62 | 62 | // notify parents - handled by parents |
| 63 | - vm.$scope.$emit('proposal-carousel:showProposals'); | |
| 63 | + vm.$scope.$emit('proposal-carousel:showProposalsList'); | |
| 64 | 64 | }; |
| 65 | 65 | |
| 66 | 66 | var directive = { | ... | ... |
src/app/components/proposal-carousel/proposal-carousel.html
| ... | ... | @@ -23,7 +23,7 @@ |
| 23 | 23 | </div> |
| 24 | 24 | </div> |
| 25 | 25 | </div> |
| 26 | - <div class="proposal-carousel-bottom color-theme-common-bg" ng-click="vm.showProposals()"> | |
| 26 | + <div class="proposal-carousel-bottom color-theme-common-bg" ng-click="vm.showProposalsList()"> | |
| 27 | 27 | <div>Veja as propostas mais vortadas</div> |
| 28 | 28 | <div class="proposal-carousel-bottom-icon"> |
| 29 | 29 | <span class="glyphicon glyphicon-chevron-down pull-right color-theme-common-fg"></span> | ... | ... |
src/app/pages/programas/programa.controller.js
| ... | ... | @@ -118,29 +118,58 @@ |
| 118 | 118 | ProgramaPageController.prototype.attachListeners = function() { |
| 119 | 119 | var vm = this; |
| 120 | 120 | |
| 121 | - vm.$scope.$on('proposal-carousel:showProposals', function() { | |
| 122 | - if(!vm._proposal_list){ | |
| 123 | - vm._proposal_list = vm.$element.find('.proposal-ranking-section'); | |
| 124 | - } | |
| 121 | + vm.$scope.$on('proposal-carousel:showProposalsList', function() { | |
| 122 | + vm.showProposalsList(); | |
| 123 | + }); | |
| 125 | 124 | |
| 126 | - vm._proposal_list.slideDown(); | |
| 127 | - angular.element('body').animate({scrollTop: vm._proposal_list.offset().top}, 'fast'); | |
| 125 | + vm.$scope.$on('cadastro-proposa:startSendProposal', function(event, proposal) { | |
| 126 | + // vm.$log.debug('proposal', proposal); | |
| 127 | + vm.creatingProposal = true; | |
| 128 | + vm.DialogaService.createProposal(proposal, vm.article.id, function (response){ | |
| 129 | + vm.$log.debug('response', response); | |
| 130 | + vm.creatingProposal = false; | |
| 131 | + }, function (error) { | |
| 132 | + vm.$log.error(error); | |
| 133 | + vm.creatingProposal = false; | |
| 134 | + }); | |
| 128 | 135 | }); |
| 129 | 136 | }; |
| 130 | 137 | |
| 131 | - ProgramaPageController.prototype.hideProposals = function() { | |
| 138 | + ProgramaPageController.prototype.showProposalsList = function() { | |
| 132 | 139 | var vm = this; |
| 140 | + vm.findAndShow('#section-proposal-list'); | |
| 141 | + }; | |
| 133 | 142 | |
| 134 | - if(!vm._proposal_list){ | |
| 135 | - vm._proposal_list = vm.$element.find('.proposal-ranking-section'); | |
| 136 | - } | |
| 143 | + ProgramaPageController.prototype.hideProposalsList = function() { | |
| 144 | + var vm = this; | |
| 145 | + vm.findAndHide('#section-proposal-list'); | |
| 146 | + }; | |
| 137 | 147 | |
| 138 | - vm._proposal_list.slideUp(); | |
| 148 | + ProgramaPageController.prototype.showProposalForm = function() { | |
| 149 | + var vm = this; | |
| 150 | + vm.findAndShow('#section-proposal-form'); | |
| 139 | 151 | }; |
| 140 | 152 | |
| 141 | - ProgramaPageController.prototype.makeProposal = function() { | |
| 153 | + ProgramaPageController.prototype.hideProposalForm = function() { | |
| 154 | + var vm = this; | |
| 155 | + vm.findAndHide('#section-proposal-form'); | |
| 156 | + }; | |
| 157 | + | |
| 158 | + ProgramaPageController.prototype.findAndShow = function(rule) { | |
| 159 | + var vm = this; | |
| 160 | + var el = vm.$element.find(rule); | |
| 161 | + el.slideDown(); | |
| 162 | + angular.element('body').animate({scrollTop: el.offset().top}, 'fast'); | |
| 163 | + } | |
| 164 | + | |
| 165 | + ProgramaPageController.prototype.findAndHide = function(rule) { | |
| 166 | + var vm = this; | |
| 167 | + vm.$element.find(rule).slideUp(); | |
| 168 | + } | |
| 169 | + | |
| 170 | + ProgramaPageController.prototype.sendProposal = function() { | |
| 142 | 171 | var vm = this; |
| 143 | 172 | |
| 144 | - vm.$log.warn('Not implemented yet: "makeProposal"'); | |
| 173 | + vm.$log.warn('Not implemented yet: "sendProposal"'); | |
| 145 | 174 | }; |
| 146 | 175 | })(); | ... | ... |
src/app/pages/programas/programa.html
| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | </div> |
| 7 | 7 | </div> |
| 8 | 8 | |
| 9 | -<div class="page--conheca-o-programa"> | |
| 9 | +<div class="page--program"> | |
| 10 | 10 | <section> |
| 11 | 11 | <div class="container"> |
| 12 | 12 | <div class="row"> |
| ... | ... | @@ -47,7 +47,7 @@ |
| 47 | 47 | <div class="row"> |
| 48 | 48 | <div class="col-sm-6"> |
| 49 | 49 | <div class="button--themed"> |
| 50 | - <button type="button" class="btn btn-block" ng-click="pagePrograma.makeProposal()">Faça uma proposta</button> | |
| 50 | + <button type="button" class="btn btn-block" ng-click="pagePrograma.showProposalForm()">Faça uma proposta</button> | |
| 51 | 51 | </div> |
| 52 | 52 | </div> |
| 53 | 53 | </div> |
| ... | ... | @@ -70,7 +70,7 @@ |
| 70 | 70 | <p> |
| 71 | 71 | Este programa ainda não possui nenhuma proposta. |
| 72 | 72 | <div class="button--themed"> |
| 73 | - <button type="button" class="btn btn-block" ng-click="pagePrograma.makeProposal()">Faça uma proposta</button> | |
| 73 | + <button type="button" class="btn btn-block" ng-click="pagePrograma.showProposalForm()">Faça uma proposta</button> | |
| 74 | 74 | </div> |
| 75 | 75 | </p> |
| 76 | 76 | </div> |
| ... | ... | @@ -81,20 +81,33 @@ |
| 81 | 81 | </div> |
| 82 | 82 | </section> |
| 83 | 83 | |
| 84 | - <section class="proposal-ranking-section" style="display:none;" ng-if="pagePrograma.proposals && pagePrograma.proposals.length > 0"> | |
| 84 | + <section id="section-proposal-list" class="proposal-extended-section" style="display:none;" ng-if="pagePrograma.proposals && pagePrograma.proposals.length > 0"> | |
| 85 | 85 | <div class="container"> |
| 86 | - <div class="proposal-ranking-section-header"> | |
| 86 | + <div class="proposal-extended-section-header"> | |
| 87 | 87 | <h3 class="color-theme-fg">Resultados de propostas mais votadas</h3> |
| 88 | - <button class="btn btn-close" ng-click="pagePrograma.hideProposals()"> | |
| 88 | + <button type="button" aria-label="Close" class="btn btn-close" ng-click="pagePrograma.hideProposalsList()"> | |
| 89 | 89 | <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> |
| 90 | 90 | </button> |
| 91 | 91 | </div> |
| 92 | - <div class="proposal-ranking-section-table"> | |
| 92 | + <div class="proposal-extended-section-content"> | |
| 93 | 93 | <proposal-list proposals="pagePrograma.proposals"></proposal-list> |
| 94 | 94 | </div> |
| 95 | 95 | </div> |
| 96 | 96 | </section> |
| 97 | 97 | |
| 98 | + <section id="section-proposal-form" class="proposal-extended-section" style="display:none;"> | |
| 99 | + <div class="container"> | |
| 100 | + <div class="proposal-extended-section-header"> | |
| 101 | + <button type="button" aria-label="Close" class="btn btn-close" ng-click="pagePrograma.hideProposalForm()"> | |
| 102 | + <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> | |
| 103 | + </button> | |
| 104 | + </div> | |
| 105 | + <div class="proposal-extended-section-content"> | |
| 106 | + <cadastro-proposta program="pagePrograma.article"></cadastro-proposta> | |
| 107 | + </div> | |
| 108 | + </div> | |
| 109 | + </section> | |
| 110 | + | |
| 98 | 111 | <section class="section-content"> |
| 99 | 112 | <article class="program-content" ng-if="pagePrograma.article"> |
| 100 | 113 | <div ng-bind-html="pagePrograma.article.body"></div> | ... | ... |
src/app/pages/programas/programas.scss
| ... | ... | @@ -71,17 +71,23 @@ |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | -.proposal-ranking-section { | |
| 75 | - background-color: #f1f1f1; | |
| 76 | - margin: 30px 0; | |
| 77 | - | |
| 78 | - .proposal-ranking-section-header{ | |
| 79 | - position: relative; | |
| 80 | - } | |
| 74 | +.page--program { | |
| 81 | 75 | |
| 82 | 76 | .btn-close { |
| 83 | 77 | position: absolute; |
| 84 | 78 | right: 0; |
| 85 | 79 | top: 0; |
| 80 | + z-index: 99; | |
| 81 | + } | |
| 82 | + | |
| 83 | + .proposal-extended-section { | |
| 84 | + background-color: #f1f1f1; | |
| 85 | + margin: 20px 0; | |
| 86 | + padding: 20px 0; | |
| 87 | + } | |
| 88 | + | |
| 89 | + .proposal-extended-section-header { | |
| 90 | + position: relative; | |
| 86 | 91 | } |
| 87 | 92 | } |
| 93 | + | ... | ... |