UNPKG

zettapi_client

Version:

Admin panel and client-side CRUD operations in angular to use with zettapi_server rest api to get started quickly in any CMS project.

41 lines (37 loc) 1.19 kB
app.controller('roleCtrl', function ($scope, $role, zapi) { $scope.useInputLarge = zapi.useInputLarge; $scope.permissions = {}; $role.getPermissions().then(function (response) { $scope.permissions = response.data; $scope.$watch('item._id', function (itemId) { if (itemId) return; if (!$scope.item) $scope.item = {}; if ($scope.item.permissions) return; var permissions = {}; for (var entity in $scope.permissions) { permissions[entity] = {}; for (var action in $scope.permissions[entity]) { if (action === 'label') continue; permissions[entity][action] = true; } } $scope.item.permissions = permissions; }); }); $scope.togglePermissions = function (value) { if (!$scope.item.permissions) { $scope.item.permissions = {}; } for (var entity in $scope.permissions) { if (!$scope.item.permissions[entity]) { $scope.item.permissions[entity] = {}; } for (var action in $scope.permissions[entity]) { if (action === 'label') { continue; } $scope.item.permissions[entity][action] = value; } } }; });