diff --git a/src/app/cms/cms.controller.js b/src/app/cms/cms.controller.js index e6c5931..1153ccb 100644 --- a/src/app/cms/cms.controller.js +++ b/src/app/cms/cms.controller.js @@ -11,20 +11,17 @@ var vm = this; vm.article = {}; vm.profile = null; - activate(); - - function activate() { - vm.profile = noosfero.currentProfile; - } vm.save = function() { - noosfero.profiles.one(vm.profile.id).customPOST( - {article: vm.article}, - 'articles', - {}, - {'Content-Type':'application/json'} - ).then(function(response) { - $state.transitionTo('main.profile.page', {page: response.data.article.path, profile: vm.profile.identifier}); + noosfero.currentProfile.then(function(profile) { + return noosfero.profiles.one(profile.id).customPOST( + {article: vm.article}, + 'articles', + {}, + {'Content-Type':'application/json'} + ) + }).then(function(response) { + $state.transitionTo('main.profile.page', {page: response.data.article.path, profile: response.data.article.profile.identifier}); SweetAlert.swal({ title: "Good job!", text: "Article saved!", diff --git a/src/app/components/noosfero/noosfero.service.js b/src/app/components/noosfero/noosfero.service.js index 23aefd7..1a075cb 100644 --- a/src/app/components/noosfero/noosfero.service.js +++ b/src/app/components/noosfero/noosfero.service.js @@ -1,11 +1,12 @@ (function() { 'use strict'; - angular.module('angular').factory('noosfero', function(Restangular) { - var currentProfile; + angular.module('angular').factory('noosfero', function(Restangular, $q) { + var currentProfile = $q.defer(); return { - currentProfile: currentProfile, + currentProfile: currentProfile.promise, + setCurrentProfile: function(profile) { currentProfile.resolve(profile) }, profiles: Restangular.service('profiles'), articles: Restangular.service('articles'), profile: function(profileId) { diff --git a/src/app/content-viewer/content-viewer-actions.controller.js b/src/app/content-viewer/content-viewer-actions.controller.js index 639cd0c..f1908aa 100644 --- a/src/app/content-viewer/content-viewer-actions.controller.js +++ b/src/app/content-viewer/content-viewer-actions.controller.js @@ -14,11 +14,9 @@ activate(); function activate() { - $scope.$watch(function() { return noosfero.currentProfile }, - function() { - vm.profile = noosfero.currentProfile; - } - ); + noosfero.currentProfile.then(function(profile) { + vm.profile = profile; + }); } } })(); diff --git a/src/app/content-viewer/content-viewer.controller.js b/src/app/content-viewer/content-viewer.controller.js index 07046a3..4b5acf0 100644 --- a/src/app/content-viewer/content-viewer.controller.js +++ b/src/app/content-viewer/content-viewer.controller.js @@ -14,8 +14,10 @@ activate(); function activate() { - vm.profile = noosfero.currentProfile; - noosfero.profiles.one(vm.profile.id).one('articles').get({path: $stateParams.page}).then(function(response) { + noosfero.currentProfile.then(function(profile) { + vm.profile = profile; + return noosfero.profiles.one(vm.profile.id).one('articles').get({path: $stateParams.page}); + }).then(function(response) { vm.article = response.data.article; }); } diff --git a/src/app/profile-info/profile-info.controller.js b/src/app/profile-info/profile-info.controller.js index 96ee38e..cdf3e3f 100644 --- a/src/app/profile-info/profile-info.controller.js +++ b/src/app/profile-info/profile-info.controller.js @@ -14,8 +14,10 @@ activate(); function activate() { - vm.profile = noosfero.currentProfile; - noosfero.profiles.one(vm.profile.id).one('activities').get().then(function(response) { + noosfero.currentProfile.then(function(profile) { + vm.profile = profile; + return noosfero.profiles.one(vm.profile.id).one('activities').get(); + }).then(function(response) { vm.activities = response.data.activities; }); } diff --git a/src/app/profile/profile-home.controller.js b/src/app/profile/profile-home.controller.js index ea7fbda..36f4633 100644 --- a/src/app/profile/profile-home.controller.js +++ b/src/app/profile/profile-home.controller.js @@ -12,8 +12,10 @@ activate(); function activate() { - vm.profile = noosfero.currentProfile; - noosfero.profile(vm.profile.id).customGET('home_page', {fields: 'path'}).then(function(response) { + noosfero.currentProfile.then(function(profile) { + vm.profile = profile; + return noosfero.profile(vm.profile.id).customGET('home_page', {fields: 'path'}); + }).then(function(response) { if(response.data.article) { $state.transitionTo('main.profile.page', {page: response.data.article.path, profile: vm.profile.identifier}, {location: false}); } else { diff --git a/src/app/profile/profile.controller.js b/src/app/profile/profile.controller.js index 4087b72..dccb0d5 100644 --- a/src/app/profile/profile.controller.js +++ b/src/app/profile/profile.controller.js @@ -15,7 +15,7 @@ function activate() { noosfero.profiles.one().get({identifier: $stateParams.profile}).then(function(response) { vm.profile = response.data[0]; - noosfero.currentProfile = vm.profile; + noosfero.setCurrentProfile(vm.profile); return noosfero.boxes(vm.profile.id).one().get(); }).then(function(response) { vm.boxes = response.data.boxes; -- libgit2 0.21.2