If you need to hide a field in a dialog based on User role i.e. user group, you can do it through an Ajax call-
$.ajax({
type: "GET",
url: "/libs/granite/security/currentuser.json.rw.userprops.json?props=declaredMemberOf",
cache: false
}).done(function(data, textStatus, jqXHR) {
var isMember = false;
/* The Group ID for which the widget has to be disabled */
var groupId = "site-editor";
var membershipInfo = data.declaredMemberOf;
if (membershipInfo) {
for (var membershipIdx = 0; membershipIdx < membershipInfo.length; membershipIdx++) {
if (membershipInfo[membershipIdx].authorizableId == groupId) {
isMember = true;
break;
}
}
}
/*This example disables the Hide in Navigation checkbox on Page Properties dialog of the page*/
if (isMember) {
$('[name="./hideInNav"]').prop('disabled', 'true');
}
});
Ajax call should be invoked at "dialog-ready" event of document. You need to put the above code in a clientlibs JS file with category "cq.authoring.dialog".
$.ajax({
type: "GET",
url: "/libs/granite/security/currentuser.json.rw.userprops.json?props=declaredMemberOf",
cache: false
}).done(function(data, textStatus, jqXHR) {
var isMember = false;
/* The Group ID for which the widget has to be disabled */
var groupId = "site-editor";
var membershipInfo = data.declaredMemberOf;
if (membershipInfo) {
for (var membershipIdx = 0; membershipIdx < membershipInfo.length; membershipIdx++) {
if (membershipInfo[membershipIdx].authorizableId == groupId) {
isMember = true;
break;
}
}
}
/*This example disables the Hide in Navigation checkbox on Page Properties dialog of the page*/
if (isMember) {
$('[name="./hideInNav"]').prop('disabled', 'true');
}
});
Ajax call should be invoked at "dialog-ready" event of document. You need to put the above code in a clientlibs JS file with category "cq.authoring.dialog".
No comments:
Post a Comment