(function () { 'use strict'; AbstractDirectiveController.$inject = ['$scope', '$q', 'indicator', 'notification']; /** * @name AbstractDirectiveController * @param $scope * @param $q * @param indicator * @param notification * @constructor */ function AbstractDirectiveController($scope, $q, indicator, notification) { /** * @abstract * @type {AbstractBridge} */ this.bridge = null; this.bridgeAction = function (action) { if (!angular.isFunction(this.bridge[action])) { throw new Error('Unknown bridge method "' + action + '"'); } return this.bridge[action].apply(this.bridge, Array.prototype.slice.call(arguments, 1)); }; this.notify = function (msg, type, module) { if (msg) { if (undefined === module && this.bridge && this.bridge.controller) { module = this.bridge.controller; } notification.temporary(msg, type, module); } }; this.action = function (action) { return this.bridgeAction.apply(this, arguments).then( angular.bind(this, this.onActionDone), angular.bind(this, this.onActionFail) ); }; this.onActionDone = function (response) { if (response.message) { this.notify(response.message); } return response; }; this.onActionFail = function (response) { if (response.message) { this.notify(response.message, 'warning'); } return $q.reject(response); }; $scope.indicator = indicator; $scope.data = null; } angular.module('app.service').controller('AbstractDirectiveController', AbstractDirectiveController); })();