Hi all,
my question is related to an issue concerning the current baheviours plugin. Maybe someone of you guys can help me out...
That's the problem:
If you set up a Behaviours action for "Project A" only, and you hit the "Create Issue" button and a "Project A" issue was on screen at the time, the behaviors will continue to fire even if you switch to "Project B" on the top of the create form. And the opposite is true. If you hit the "Create Issue" button while you are on a "Project B" issue, and then switch to "Project A" (where the Behaviour should now be triggered) nothing happens. If you are not at an issue page, it will work
It's not only the project the behaviour seems to be bound to the issue type that's been opened in the background. Looking at the source code the problem could be somewhere here:
AJS.$(document).ready(function() {
// todo other forms possibly
var selectors = ["form[id='issue-workflow-transition']", "#issue-create", "form[id='issue-edit']", "form[id='subtask-create-details']"];
var behaviourRequired = false;
AJS.$.each(selectors, function(i, v) {
var el = AJS.$(v);
el.unbind('submit', submitForm).bind('submit', {docRoot: AJS.$("body")}, submitForm);
if (el.length) {
behaviourRequired = true;
}
});
var issueId = AJS.$("#key-val").attr('rel');
console.log ("issueId: " + issueId);
var actionId = AJS.$("input[name='action']").val();
if (typeof actionId == "undefined") {
actionId = 0;
}
console.log ("actionId: " + actionId);
// if we have a pid and issue type use that
var issueTypeId = AJS.$("input[name=issuetype]").val();
console.log ("issueType: " + issueTypeId);
var pid = AJS.$("input[name=pid]").val();
console.log ("pid: " + pid);
// get list of validators
console.log(typeof(issueId));
console.log(issueId);
if (behaviourRequired && typeof(issueId) != "undefined") {
AJS.$.get(AJS.params.baseURL + "/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/validators.json",
{issueId: issueId, actionId: actionId},
function (data) {
addFieldListeners(AJS.$("body"), data, true);
}
);
}
else if (typeof(pid) != "undefined" && typeof(issueTypeId) != "undefined") {
AJS.$.get(AJS.params.baseURL + "/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/validatorsByPid.json",
{pid: pid, issueTypeId: issueTypeId, actionId: actionId},
function (data) {
addFieldListeners(AJS.$("body"), data, true);
}
);
}
AJS.$(document).bind('dialogContentReady', function(event, dialog) {
actionId = AJS.$(".aui-popup").find("input[name='action']").val();
// console.log(dialog.$popup);
// console.log(dialog.$popup.attr('id'));
pid = dialog.$popup.find("#project").val();
issueTypeId = dialog.$popup.find("#issuetype").val();
// console.log("pid: " + pid);
// console.log("issueId: " + issueId);
// not always true
// edit issue popup
var formIds = "#issue-workflow-transition,#assign-issue,input[type='hidden'][name='id'],div.issue-setup-fields";
if (dialog.$popup.find(formIds).length) {
// todo: duplicated above
if (typeof(issueId) != "undefined") {
AJS.$.get(AJS.params.baseURL + "/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/validators.json",
{issueId: issueId, actionId: actionId},
function (data) {
addFieldListeners(dialog.$popup, data, true);
}
);
}
else if (typeof(pid) != "undefined" && typeof(issueTypeId) != "undefined") {
AJS.$.get(AJS.params.baseURL + "/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/validatorsByPid.json",
{pid: pid, issueTypeId: issueTypeId, actionId: actionId},
function (data) {
addFieldListeners(dialog.$popup, data, true);
}
);
}
I guess you would have to check if you're editing an issue (which should get the behaviour assigned to that particular issue type) or want to create a new issue in which the current issue id should be ignored.
Hope that you know what I mean...