Created
February 17, 2020 14:05
-
-
Save lbroshi/ee93bc9a685960285828d86882915476 to your computer and use it in GitHub Desktop.
Zendesk Filter Forms by Organization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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