Skip to content

Instantly share code, notes, and snippets.

@binford2k
Last active May 17, 2020 14:07
Show Gist options
  • Save binford2k/6de9f6f464b3a58f8a319bff27dd40ee to your computer and use it in GitHub Desktop.
Save binford2k/6de9f6f464b3a58f8a319bff27dd40ee to your computer and use it in GitHub Desktop.
/*
This is a jQuery function that runs after the document has been fully rendered.
It expects a variable set by Showoff that defines the URL for filing a ticket:
issueUrl = "http://tickets.puppet.com/secure/CreateIssueDetails!init.jspa?pid=10302&issuetype=1&components=10312&priority=6&summary=";
This approach is taken so the link can fail gracefully. If I broke something, the
link will still operate normally, it just won't be the fancy dialog, and it won't
allow external users to file tickets.
Note that this *must* run on an HTTPS site, or you'll get XREF errors and the issue
collector will not work.
It also checks for some other variables set by other code. Up to you whether you
want to implement that.
userEmail = 'the users email address';
userName = 'the users name';
*/
$(document).ready(function(){
// This will only load the js in the presenter window
if (typeof issueUrl !== 'undefined') {
var componentID = issueUrl.match(/components=(\d+)/)[1];
var priority = issueUrl.match(/priority=(\d+)/)[1];
var collectorEmail = (typeof userEmail === 'undefined') ? null : userEmail;
var collectorName = (typeof userName === 'undefined') ? null : userName;
// If partners can't use the inline collector, send them to the hosted one
// This is another fallback, and it's pretty horrible. It's a copy of the issue collector running on a
// page on puppet.com. It's terrible and it's fragile and you should ignore it.
if( collectorEmail !== null && ! collectorEmail.match(/puppet(?:labs)?\.com$/) ) {
var url = location.protocol + '//puppet.com/training/issues?';
issueUrl = url + 'components=' + componentID + '&fullname=' + collectorName + '&email=' + collectorEmail + '&summary=';
}
try {
// This loads the issue collector javascript from the jira so that when the button is clicked,
// the showCollectorDialog() function is available.
jQuery.ajax({
// The url field is the address of the issue collector that I created using the Jira UI
url: location.protocol + "//tickets.puppet.com/s/a1cd217e7d553453445bb14bd1008afe-T/en_US-y2pibk/6346/90/1.4.16/_/download/batch/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector-embededjs/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector-embededjs.js?locale=en-US&collectorId=01105c8a",
type: "get",
cache: true,
dataType: "script"
});
window.ATL_JQ_PAGE_PROPS = {
triggerFunction: function(showCollectorDialog) {
jQuery("#report").click(function(e) {
// This wiggy thing is because the "standard" function cannot access http
// protocol parent windows, so we have to pre-populate it. Any fields that
// that you want to retrieve data from the **top-level** DOM must be set this way.
var summary = 'Issue with slide: ' + $("span#slideFile").text(); // Use the standard showoff slide label text to generate a summary
window.ATL_JQ_PAGE_PROPS.fieldValues.summary = summary;
e.preventDefault();
showCollectorDialog(); // this will fail if cookies/session data is disabled
})
},
fieldValues: {
components : componentID,
priority : priority,
fullname : collectorName,
email : collectorEmail,
description : "This string will pre-populate the description field."
}
};
}
// This won't ever actually fire, because it appears that a security error is uncatchable.
catch(err) {
console.log(err);
window.open(issueUrl);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment