(function () { 'use strict'; BaseFormController.$inject = ['$scope', '$controller', '$q']; /** * @name BaseFormController * @param $scope * @param $controller * @param $q * @extends AbstractDirectiveController * @constructor */ function BaseFormController($scope, $controller, $q) { angular.extend(this, $controller('AbstractDirectiveController', {$scope: $scope})); this.formAction = function (action) { return this.bridgeAction.apply(this, arguments).then( angular.bind(this, this.onFormActionDone), angular.bind(this, this.onFormActionFail) ); }; /** * update .data * clear .formErrors * update .notifications * * @param {Object} response */ this.onFormActionDone = function (response) { $scope.formErrors = null; if (response.message) { this.notify(response.message); } $scope.data = response.data ? response.data : {}; return response; }; /** * clear .data * update .formErrors * update notifications * * @param {Object} response */ this.onFormActionFail = function (response) { $scope.formErrors = response.errors ? response.errors : null; if (response.message) { this.notify(response.message, 'warning'); } return $q.reject(response); }; $scope.formErrors = null; } angular.module('app.service').controller('BaseFormController', BaseFormController); })();