Skip to content

Instantly share code, notes, and snippets.

@skipjac
Created May 2, 2013 20:25
Show Gist options
  • Save skipjac/5505114 to your computer and use it in GitHub Desktop.
Save skipjac/5505114 to your computer and use it in GitHub Desktop.
This is a Zendesk Classic widget that will hide ticket fields and then only show them with the agent is part of a allowed group list
jQuery(document).ready(function() {
//list of fields to hide
var options = ['#ticket_fields_139051'];
//groups allowed to see the fields
var allowGroups = [88054];
//function to hide a array of arrays
var hide = function(){
$j.each(arguments, function(i, item){
for(y = 0; y < item.length; y++){
$j(item[y]).parent().hide();
}
}
);
}
//function to show a array of arrays
var show = function(){
$j.each(arguments, function(i, item){
for(y = 0; y < item.length; y++){
$j(item[y]).parent().show();
}
}
);
}
//hide the fields
hide(options)
//get the current users groups and show the fields if the user is in the allowed groups
$j.getJSON('/' + currentUser.version, function(data){
_.each(data.groups, function(x){
var inArr = _.contains(allowGroups, x.id);
if(inArr) {
show(options);
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment