Created
January 10, 2011 18:21
-
-
Save leonardinius/773182 to your computer and use it in GitHub Desktop.
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 code is copied and modified from dialogs.js | |
(function(){ | |
var chainedonload = function(callback){ | |
var old = window.onload; | |
window.onload = function(){ | |
if(typeof old == 'function') old.apply(this, arguments); | |
if(typeof callback == 'function') callback.apply(this, arguments); | |
}; | |
}; | |
chainedonload(function() | |
{ | |
function getAjaxOptions () { | |
var $focusRow = jira.app.issuenavigator.get$focusedRow(); | |
var linkIssueURI = this.options.url || this.$activeTrigger.attr("href"); | |
if (/id=\{0\}/.test(linkIssueURI)) { | |
if (!$focusRow.length) { | |
return false; | |
} else { | |
linkIssueURI = linkIssueURI.replace(/(id=\{0\})/, "id=" + $focusRow.attr("rel")); | |
} | |
} | |
if (jira.app.issuenavigator.isNavigator()) { | |
var result = /[?&]id=([0-9]+)/.exec(linkIssueURI); | |
this.issueId = result && result.length == 2 ? result[1] : null; | |
if(this.issueId !== $focusRow.attr("rel")) { | |
//if the issue id doesn't match the focused row's issue id then reassign focus and get the | |
//issuekey from the newly focused row! This can happen when clicking the pencil for the | |
//labels picker. | |
jira.app.issuenavigator.shortcuts.focusRow(this.issueId); | |
$focusRow = jira.app.issuenavigator.get$focusedRow(); | |
} | |
this.issueKey = jira.app.issuenavigator.getSelectedIssueKey(); | |
} | |
return { | |
data: {decorator: "dialog", inline: "true"}, | |
url: linkIssueURI | |
}; | |
} | |
/** | |
* Stores the current issue id into session storage if the dialogs submits successfully | |
*/ | |
function storeCurrentIssueIdOnSucessfulSubmit() { | |
if (jira.app.issuenavigator.isNavigator()) { | |
var issueId = this.issueId; | |
var issueKey = this.issueKey; | |
if (! issueId) { | |
issueId = jira.app.issuenavigator.getSelectedIssueId(); | |
issueKey = jira.app.issuenavigator.getSelectedIssueKey(); | |
} | |
if (issueId) | |
{ | |
var sessionStorge = jira.app.session.storage; | |
sessionStorge.setItem('selectedIssueId', issueId); | |
sessionStorge.setItem('selectedIssueKey', issueKey); | |
sessionStorge.setItem('selectedIssueMsg', this.options.issueMsg); | |
} | |
} | |
this.issueId = null; | |
this.issueKey = null; | |
} | |
function applyCommentControls(context) { | |
new AJS.SecurityLevelMenu(AJS.$("#commentLevel", context)); | |
var wikiRenders = jQuery(".wiki-js-prefs", context); | |
wikiRenders.each(function() { | |
jira.app.wikiPreview(this, context).init(); | |
}); | |
} | |
var DIALOGS = { | |
xyz : new AJS.FormPopup({ | |
id: "xxx-yyy-zzz-dialog", | |
width : 1320, | |
trigger: "a#xxx.yyy.myId", // link id spefied previously as web-item link id | |
ajaxOptions: getAjaxOptions, | |
onSuccessfulSubmit : storeCurrentIssueIdOnSucessfulSubmit, | |
issueMsg : 'thanks_xyz', | |
onContentRefresh: function () { | |
jQuery(".overflow-ellipsis").textOverflow(); | |
var context = this.get$popupContent(); | |
applyCommentControls(context); | |
} | |
}) | |
}; | |
/** | |
* Dialogs should only show up if there's an issue to work on! | |
*/ | |
AJS.$.each(DIALOGS, function (name, dialog) { | |
if (dialog instanceof AJS.FlexiPopup) { | |
AJS.$(dialog).bind("beforeShow", function (e) { | |
//for all dialogs except for the keyboard shortcuts, check if we have a valid issue to work on! | |
return jira.app.issuenavigator.isRowSelected() || jira.app.issue.getIssueId() !== undefined; | |
}); | |
} | |
}); | |
AJS.$('<input type="hidden" id="thanks_xyz" value="Thanks, xyz"/>') | |
.appendTo(document.body); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment