diff --git a/src/app/components/article-service/article.service.js b/src/app/components/article-service/article.service.js index 9393b1d..59b4cde 100644 --- a/src/app/components/article-service/article.service.js +++ b/src/app/components/article-service/article.service.js @@ -6,12 +6,13 @@ .factory('ArticleService', ArticleService); /** @ngInject */ - function ArticleService($http, $q, $rootScope, API, UtilService, Slug, $log) { + function ArticleService($http, $q, $rootScope, API, UtilService, Slug, GUID, $log) { $log.debug('ArticleService'); var service = { apiArticles: $rootScope.basePath + '/api/v1/articles/', apiCommunities: $rootScope.basePath + '/api/v1/communities/', + apiProposals: $rootScope.basePath + '/api/v1/proposals_discussion_plugin/', getArticleById: getArticleById, getArticleBySlug: getArticleBySlug, getCategories: getCategories, @@ -21,6 +22,7 @@ getProposals: getProposals, getProposalById: getProposalById, getProposalsByTopicId: getProposalsByTopicId, + createProposal: createProposal, getEvents: getEvents, subscribeToEvent: subscribeToEvent, searchTopics: searchTopics, @@ -148,6 +150,28 @@ getProposalById(topicId + '/children', params, cbSuccess, cbError); } + function createProposal (proposal, targetId, cbSuccess, cbError){ + + if(!$rootScope.currentUser){ + cbError({message: 'Usuário não logado.'}); + }else{ + // /api/v1/proposals_discussion_plugin/' + targetId + '/propose + var url = service.apiProposals + targetId + '/propose'; + + var encodedParams = []; + encodedParams.push('private_token=' + $rootScope.currentUser.private_token); + encodedParams.push('fields=id'); + encodedParams.push('article[name]=article_' + GUID.generate()); + encodedParams = encodedParams.join('&'); + + UtilService.post(url, encodedParams).then(function(response){ + cbSuccess(response); + }).catch(function(error){ + cbError(error); + }); + } + } + function getEvents (community_id, params, cbSuccess, cbError) { // Ex.: /api/v1/communities/19195/articles?categories_ids[]=' + cat_id + '&content_type=Event'; // Ex.: /api/v1/communities/' + community_id + '/articles?categories_ids[]=' + cat_id + '&content_type=Event'; @@ -183,16 +207,17 @@ if(!$rootScope.currentUser){ cbError({message: 'Usuário não logado.'}); - } - var url = service.apiArticles + event_id + '/follow'; - var encodedParams = 'private_token=' + $rootScope.currentUser.private_token; + }else{ + var url = service.apiArticles + event_id + '/follow'; + var encodedParams = 'private_token=' + $rootScope.currentUser.private_token; - UtilService.post(url, encodedParams).then(function(response){ - cbSuccess(response); - }).catch(function(error){ - cbError(error); - }); + UtilService.post(url, encodedParams).then(function(response){ + cbSuccess(response); + }).catch(function(error){ + cbError(error); + }); + } } function searchTopics (params, cbSuccess, cbError) { diff --git a/src/app/components/cadastro-proposta/cadastro-proposta.directive.js b/src/app/components/cadastro-proposta/cadastro-proposta.directive.js index c19fb80..29c28b0 100644 --- a/src/app/components/cadastro-proposta/cadastro-proposta.directive.js +++ b/src/app/components/cadastro-proposta/cadastro-proposta.directive.js @@ -28,13 +28,20 @@ // requeue to wait until DOM be created vm.$timeout(function(){ attachPopover.call(vm); - }, 100); + }, 200); + }; + + CadastroPropostaController.prototype.sendProposal = function (proposal) { + var vm = this; + + // notify parents - handled by parents + vm.$scope.$emit('cadastro-proposa:startSendProposal', proposal); }; function attachPopover(){ var vm = this; - vm.popover = angular.element(vm.$element.find('.link-popover')); + vm.popover = angular.element(vm.$element.find('.btn-question')); vm.popover.popover({ html: true, placement: 'bottom', @@ -47,7 +54,9 @@ var directive = { restrict: 'E', templateUrl: 'app/components/cadastro-proposta/cadastro-proposta.html', - scope: {}, + scope: { + program: '=' + }, controller: CadastroPropostaController, controllerAs: 'vm', bindToController: true diff --git a/src/app/components/cadastro-proposta/cadastro-proposta.html b/src/app/components/cadastro-proposta/cadastro-proposta.html index 1bd003b..b58f752 100644 --- a/src/app/components/cadastro-proposta/cadastro-proposta.html +++ b/src/app/components/cadastro-proposta/cadastro-proposta.html @@ -11,23 +11,29 @@
Você está fazendo uma proposta para o programa: