From 81a4a75ec4a41b1ece98a5a7454194e7e4441854 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 13 Aug 2014 09:26:07 +0200 Subject: [PATCH] Reloading left projects when necesary --- app/coffee/modules/admin/project-profile.coffee | 12 ++++++------ app/coffee/modules/admin/roles.coffee | 5 +++-- app/coffee/modules/nav.coffee | 5 +++++ app/coffee/modules/projects/lightboxes.coffee | 4 +++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/coffee/modules/admin/project-profile.coffee b/app/coffee/modules/admin/project-profile.coffee index 9da47015..c8adfe0c 100644 --- a/app/coffee/modules/admin/project-profile.coffee +++ b/app/coffee/modules/admin/project-profile.coffee @@ -85,7 +85,7 @@ module.controller("ProjectProfileController", ProjectProfileController) ## Project Profile Directive ############################################################################# -ProjectProfileDirective = ($log, $repo, $rootscope, $confirm, $location) -> +ProjectProfileDirective = ($rootscope, $log, $repo, $confirm, $location) -> link = ($scope, $el, $attrs) -> form = $el.find("form").checksley({"onlyOneErrorElement": true}) submit = => @@ -95,7 +95,7 @@ ProjectProfileDirective = ($log, $repo, $rootscope, $confirm, $location) -> promise.then -> $confirm.notify("success") $location.path("/project/#{$scope.project.slug}/admin/project-profile/details") - $rootscope.$broadcast("projects:reload") + $rootscope.$broadcast("project:loaded", $scope.project) promise.then null, (data) -> form.setErrors(data) @@ -116,7 +116,7 @@ ProjectProfileDirective = ($log, $repo, $rootscope, $confirm, $location) -> ## Project Features Directive ############################################################################# -ProjectFeaturesDirective = ($log, $repo, $confirm) -> +ProjectFeaturesDirective = ($rootscope, $log, $repo, $confirm) -> link = ($scope, $el, $attrs) -> form = $el.find("form").checksley() submit = => @@ -125,7 +125,7 @@ ProjectFeaturesDirective = ($log, $repo, $confirm) -> promise = $repo.save($scope.project) promise.then -> $confirm.notify("success") - $scope.$emit("project:loaded", $scope.project) + $rootscope.$broadcast("project:loaded", $scope.project) promise.then null, (data) -> $confirm.notify("error", data._error_message) @@ -154,5 +154,5 @@ ProjectFeaturesDirective = ($log, $repo, $confirm) -> return {link:link} -module.directive("tgProjectProfile", ["$log", "$tgRepo", "$rootScope", "$tgConfirm", "$location", ProjectProfileDirective]) -module.directive("tgProjectFeatures", ["$log", "$tgRepo", "$tgConfirm", ProjectFeaturesDirective]) +module.directive("tgProjectProfile", ["$rootScope", "$log", "$tgRepo", "$tgConfirm", "$location", ProjectProfileDirective]) +module.directive("tgProjectFeatures", ["$rootScope", "$log", "$tgRepo", "$tgConfirm", ProjectFeaturesDirective]) diff --git a/app/coffee/modules/admin/roles.coffee b/app/coffee/modules/admin/roles.coffee index 07e33d69..534a8668 100644 --- a/app/coffee/modules/admin/roles.coffee +++ b/app/coffee/modules/admin/roles.coffee @@ -180,7 +180,7 @@ module.directive("tgNewRole", ["$tgRepo", "$tgConfirm", NewRoleDirective]) # Use category-config.scss styles -RolePermissionsDirective = ($repo, $confirm) -> +RolePermissionsDirective = ($rootscope, $repo, $confirm) -> resumeTemplate = _.template("""
<%- category.name %>
<%- category.activePermissions %>/<%- category.permissions.length %>
@@ -313,6 +313,7 @@ RolePermissionsDirective = ($repo, $confirm) -> categories = generateCategoriesFromRole(role) categoryId = target.parents(".category-config").data("id") renderResume(target.parents(".category-config"), categories[categoryId]) + $rootscope.$broadcast("projects:reload") onError = -> $confirm.notify("error") @@ -332,4 +333,4 @@ RolePermissionsDirective = ($repo, $confirm) -> return {link:link} -module.directive("tgRolePermissions", ['$tgRepo', '$tgConfirm', RolePermissionsDirective]) +module.directive("tgRolePermissions", ["$rootScope", "$tgRepo", "$tgConfirm", RolePermissionsDirective]) diff --git a/app/coffee/modules/nav.coffee b/app/coffee/modules/nav.coffee index 55f80d04..bd9200a9 100644 --- a/app/coffee/modules/nav.coffee +++ b/app/coffee/modules/nav.coffee @@ -37,9 +37,14 @@ class ProjectsNavigationController extends taiga.Controller console.log "FAIL" # TODO + # Listen when someone wants to reload all the projects @scope.$on "projects:reload", => @.loadInitialData() + # Listen when someone has reloaded a project + @scope.$on "project:loaded", (ctx, project) => + @.loadInitialData() + loadInitialData: -> return @rs.projects.list().then (projects) => for project in projects diff --git a/app/coffee/modules/projects/lightboxes.coffee b/app/coffee/modules/projects/lightboxes.coffee index 734e6e71..2041774c 100644 --- a/app/coffee/modules/projects/lightboxes.coffee +++ b/app/coffee/modules/projects/lightboxes.coffee @@ -3,7 +3,7 @@ bindOnce = @.taiga.bindOnce module = angular.module("taigaProject") -CreateProject = ($repo, $confirm, $location, $navurls, $rs, lightboxService) -> +CreateProject = ($rootscope, $repo, $confirm, $location, $navurls, $rs, lightboxService) -> link = ($scope, $el, attrs) -> $scope.data = {} $scope.templates = [] @@ -18,6 +18,7 @@ CreateProject = ($repo, $confirm, $location, $navurls, $rs, lightboxService) -> fullUrl = $navurls.formatUrl(url, {'project': response.slug}) $location.url(fullUrl) + $rootscope.$broadcast("projects:reload") onErrorSubmit = (response) -> $confirm.notify("light-error", "According to our Oompa Loompas, project name is @@ -47,6 +48,7 @@ CreateProject = ($repo, $confirm, $location, $navurls, $rs, lightboxService) -> return {link:link} module.directive("tgLbCreateProject", [ + "$rootScope", "$tgRepo", "$tgConfirm", "$location",