Skip to content

Instantly share code, notes, and snippets.

@jdlich
Created December 13, 2012 15:42
Show Gist options
  • Save jdlich/4277258 to your computer and use it in GitHub Desktop.
Save jdlich/4277258 to your computer and use it in GitHub Desktop.
(function () {
// Products as listed in Settings > Ticket Fields
products = {
cas: ["cas", "CAS"],
sakai: ["sak", "Sakai"],
shib: ["shib", "Shibboleth"],
uportal: ["up", "uPortal"],
zimbra: ["zimbra", "Zimbra"]
}
envs = ["dev", "qa", "prod"]
environments = {
hosted: envs,
manage_services: envs
}
// Zendesk's API is currently not available for users (i.e. client accounts)
// $j.getJSON('/ticket_fields.json', function(data) {
// });
$j(document).ready(function() {
var selectMenu = $j("select#ticket_fields_20945891"),
label = $j("#ticket_fields_20945891").parent().prev(),
userTags = currentUser.tags;
// Remove existing options and set empty default
selectMenu.html('<option value=""> - </option>');
// Add filtered options
$j.each(userTags, function(i, tag) {
// Hosted
if ( environments[tag] ) {
label.html('Environments <super>*</super>');
$j.each(envs, function(i, env) {
addSelectOptions(envs[i], envs[i].toUpperCase());
});
// Coop
} else if ( products[tag] ) {
addSelectOptions(products[tag][0], products[tag][1]);
}
});
function addSelectOptions(value, name) {
selectMenu.append('<option value="'+value+'">'+name+'</option');
}
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment