j-PermissionsOP
The component edits OpenPlatform user, role and group permissions. Bind the selected permissions to a model path and configure find and read endpoints. The model contains permission strings:
['C@admin', 'U@admin', 'R@admin', 'D@admin', 'R123456', 'R#employees']- first letter means allowed type, defined in
types @adminmeans a roleadmin#employeesmeans a groupemployees123456means a specificuserid
Configuration:
placeholder{String} a placeholder forj-Directorycomponent (default:Search)types{String} types of permission (array delimited by char, default:CRUD)disabled{Boolean} optional, disables this componentdefault{String} default value oftype(default:R)dirkey{String} optional, a key for text inj-Directory(default:name)labelrole{String} optional a label for roles (default:Role)labelgroup{String} optional a label for groups (default:Group)limit{Number} a count of allowed permissions (default:0= unlimited)pk{String} a primary key which value will be binded into the model (default:id)- IMPORTANT
find{String} URL address for finding roles, groups and users, the component sendsurl?q=SEARCH_QUERY(it sends empty value) - IMPORTANT
read{String} URL address for reading roles, groups and users, the component sendsurl?id=@role,#group,userid,...
// The component expects data:
['C@admin', 'U@admin', 'R@admin', 'D@admin', 'R123456', 'R#employees'];
// The component tries to find data:
// The component tries to read data and it pairs them with the model automatically:
[{ id: '123456', name: 'Peter Širka' }, { id: '@admin', name: 'Administrators' }, { id: '#employees', name: 'Employees' }];Usage
<ui-component name="directory"></ui-component>
<ui-component name="permissionsop" path="form.permissions"
config="find:/api/permissions/search/;read:/api/permissions/read/;types:CRUD"></ui-component>
<script>
ON('request', function(request) {
if (request.method === 'GET' && request.data &&
request.url.indexOf('/api/permissions/') === 0) {
request.url = QUERIFY(request.url, request.data);
request.data = null;
}
});
SET('form.permissions', ['R@admin', 'U#employees']);
</script>Declare j-Directory for the selection menu. Both endpoints return an array of objects with id and name strings. The find endpoint receives the search text in q. The read endpoint receives comma-separated identifiers in id and resolves the permissions already in the model. Use pk to choose the identifier field; its default is id. Prefix role identifiers with @ and group identifiers with #.
Source: Total.js components. Copyright Peter Širka and contributors. MIT license.