Skip to content

Instantly share code, notes, and snippets.

@lbroshi
Created February 17, 2020 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbroshi/ee93bc9a685960285828d86882915476 to your computer and use it in GitHub Desktop.
Save lbroshi/ee93bc9a685960285828d86882915476 to your computer and use it in GitHub Desktop.
Zendesk Filter Forms by Organization
// This will allow you to restrict forms by naming them with:
// Form-name-here [ONLY: Organization-name]
$(window).load(function() {
const formRegex = /\[ONLY: (\w+)]/;
function sanitizeForm(formName, orgs) {
result = {
formName: formName.replace(formRegex, ''),
allowed: false
}
if ((m = formRegex.exec(formName)) !== null) {
// form limitation
limitedOrg = m[1].toLowerCase();
orgs.forEach((orgEntry, index) => {
if ( orgEntry.name.toLowerCase() == limitedOrg ) {
result.allowed = true;
}
});
}
else {
// no limitation on that form
result.allowed = true;
}
return result;
}
var i = 0;
var checkExist = setInterval(function() {
i++;
if ($("a.nesty-input").length) {
clearInterval(checkExist);
$("a.nesty-input").each(function() {
$(this).bind("click", function() {
var forms = {}
var options = document.getElementById("request_issue_type_select").getElementsByTagName("option");
var formName;
for (i = 1; i < options.length; i++) {
formName = options[i].text;
formResult = sanitizeForm(formName, HelpCenter.user.organizations)
if ( formResult.allowed == false ) {
$('#' + options[i].value).remove();
}
else {
$('#' + options[i].value).html( formResult.formName );
}
};
});
});
}
if (i > 10) {
clearInterval(checkExist);
}
}, 100);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment