(function () { "use strict"; var name = 'adAdminUserManageForm'; angular.module('app.directive') .directive('adAdminUserManageForm', ['$rootScope', '$state', 'cfg', 'adminUser', 'staticData', 'user', function ($rootScope, $state, cfg, adminUser, staticData, user) { return { templateUrl: 'directive/' + name + '/' + name + '.html', scope: {}, controller: 'BaseFormController', link: function (scope, element, attributes, controller) { cfg.debug && console.log(name); controller.bridge = adminUser; scope.userRoleId = user.roleId; scope.roleNames = angular.copy(adminUser.roleNames); if ('admin' !== user.roleId) { delete scope.roleNames.admin; } scope.save = function () { if (scope.adminUserManageForm.$invalid) return; var formData = scope.data; var promise = controller.formAction('save', scope.data); if ('' == attributes[name]) { promise.then(function (response) { if (response.data && response.data.id) { $state.go('menu.admin.user.edit', {id: response.data.id}); } }, function (response) { scope.data = formData; }); } }; if (attributes[name]) { controller.formAction('read', attributes[name]); } else { scope.data = {}; } } }; }]); })();