(function () { 'use strict'; // Define the common module // Contains services: // - common // - logger var commonModule = angular.module('common', []); // Must configure the common service and set its // events via the commonConfigProvider commonModule.provider('commonConfig', function () { this.config = { // These are the properties we need to set //controllerActivateSuccessEvent: '', }; this.$get = function () { return { config: this.config }; }; }); commonModule.factory('common', ['$q', '$rootScope', '$timeout', 'commonConfig', 'logger', common]); function common($q, $rootScope, $timeout, commonConfig, logger) { var service = { // common angular dependencies $broadcast: $broadcast, $q: $q, $timeout: $timeout, // generic activateController: activateController, logger: logger // for accessibility }; return service; function activateController(promises, controllerId) { $broadcast(commonConfig.config.controllerStartActivateEvent); return $q.all(promises).then(function (eventArgs) { var data = { controllerId: controllerId }; $broadcast(commonConfig.config.controllerActivateSuccessEvent, data); }); } function $broadcast() { return $rootScope.$broadcast.apply($rootScope, arguments); } } })();