|
|
@@ -2263,11 +2263,16 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
|
|
|
});
|
|
|
};
|
|
|
getData();
|
|
|
- $scope.addRole = function(){
|
|
|
+ $scope.editRole = function(role){
|
|
|
var modalInstance = $modal.open({
|
|
|
animation: true,
|
|
|
- templateUrl: 'static/tpl/index/account/role_add.html',
|
|
|
- controller: 'RoleAddCtrl'
|
|
|
+ templateUrl: 'static/tpl/index/account/role_detail.html',
|
|
|
+ controller: 'RoleEditCtrl',
|
|
|
+ resolve: {
|
|
|
+ role: function() {
|
|
|
+ return role;
|
|
|
+ }
|
|
|
+ }
|
|
|
});
|
|
|
modalInstance.result.then(function(added){
|
|
|
added && (getData());
|
|
|
@@ -2275,16 +2280,44 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
|
|
|
};
|
|
|
});
|
|
|
|
|
|
- app.controller('RoleAddCtrl', function($scope, $modalInstance, AccountResource, AccountRole, toaster){
|
|
|
+ app.controller('RoleEditCtrl', function($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert){
|
|
|
+ $scope.role = role;
|
|
|
+ $scope.master = angular.copy($scope.role);
|
|
|
+ var isNew = role == null;
|
|
|
$scope.cancel = function() {
|
|
|
$modalInstance.close(false);
|
|
|
};
|
|
|
AccountResource.getAll({}, function(data){
|
|
|
if(data && data.length > 0) {
|
|
|
+ if(role && role.resourceItems) {
|
|
|
+ var rs = [];// 已分配的资源的id
|
|
|
+ angular.forEach(role.resourceItems, function(item){
|
|
|
+ rs.push(item.id);
|
|
|
+ });
|
|
|
+ angular.forEach(data, function(resource){
|
|
|
+ var c = 0;
|
|
|
+ angular.forEach(resource.items, function(item){
|
|
|
+ if(rs.indexOf(item.id) > -1) {
|
|
|
+ item.$checked = true;
|
|
|
+ c += 1;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ resource.$checked = c == resource.items.length;
|
|
|
+ });
|
|
|
+ }
|
|
|
$scope.resourceItems = data[0].items;
|
|
|
data[0].$active = true;
|
|
|
}
|
|
|
$scope.resources = data;
|
|
|
+ $timeout(function(){
|
|
|
+ angular.forEach($scope.resources, function(resource){
|
|
|
+ var c = 0;
|
|
|
+ angular.forEach(resource.items, function(item){
|
|
|
+ item.$checked && (c+=1);
|
|
|
+ });
|
|
|
+ angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
|
|
|
+ });
|
|
|
+ }, 100);
|
|
|
});
|
|
|
$scope.onItemClick = function(resource) {
|
|
|
$scope.resourceItems = resource.items;
|
|
|
@@ -2316,6 +2349,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
|
|
|
item.$checked && (c+=1);
|
|
|
});
|
|
|
resource.$checked = (c == resource.items.length);
|
|
|
+ angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
|
|
|
}
|
|
|
});
|
|
|
getChecked();
|
|
|
@@ -2328,12 +2362,25 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
|
|
|
$scope.save = function() {
|
|
|
$scope.master = angular.copy($scope.role);
|
|
|
AccountRole.save($scope.master, function(){
|
|
|
- toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 添加成功');
|
|
|
+ toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加': '修改') + '成功');
|
|
|
$modalInstance.close(true);
|
|
|
}, function(response){
|
|
|
toaster.pop('error', '错误', response.data);
|
|
|
});
|
|
|
};
|
|
|
+ $scope.del = function() {
|
|
|
+ new ngAlert({
|
|
|
+ title: '提示',
|
|
|
+ content: '确定删除角色(' + $scope.role.desc + ')吗?'
|
|
|
+ }, function(){
|
|
|
+ AccountRole.remove({id: role.id}, function(){
|
|
|
+ toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
|
|
|
+ $modalInstance.close(true);
|
|
|
+ }, function(response){
|
|
|
+ toaster.pop('error', '错误', response.data);
|
|
|
+ });
|
|
|
+ })
|
|
|
+ };
|
|
|
});
|
|
|
|
|
|
/**
|