Scriptrunner fragment displays modal as entire page

Jaden Zerbe December 20, 2019

Hello,

I am attempting to create a button that opens a modal within the confluence UI using scriptrunner. I have created a web fragment which seems correct from the documentation. I have attached a screenshot of my configuration. I have linked my fragment to a REST endpoint. The REST endpoint is directly copied from https://scriptrunner.adaptavist.com/latest/jira/fragments/WebItem.html under the Dialogs (Advanced) section. 

After doing all of this, my modal appears alone with no styling in its own tab/page when my link is clicked. I am confused as to why it is not appearing as a modal on the same screen as the clicked button. Any help is appreciated.

ThankWebItem.PNG

1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 9, 2020

That might be a bug/design flaw in scriptrunner. Try to put the same webitem on a page menu instead.

For this web fragment config to work, scriptrunner has to make sure they deploy some javascript in a given context that will listen to this link-click event and create a dialog instead of using the default behavior of the link (which is to navigate tot eh url).

If you can't get them to fix it or don't want to wait, then you have to deploy your own javascript in that specific context and change the "Do What" dropdown to "Do Nothing I will write my own javascript".

Something like this has worked for me in a different context:

(function ($) {
$(function () {

$('body').off('click', '#your-web-item-key').on('click', '#your-web-item-key', function(event){
event.preventDefault();
var ancestorAnchor = $(this).closest("[href]");
AJS.$.ajax({
type: "GET",
dataType: "html",
url: ancestorAnchor.attr("href")
}).done(function(data) {
AJS.dialog2($(data)).show();
}).fail(function(jqXHR, textStatus, errorThrown) {
console.warn("Failed to execute remote:", errorThrown);
});
});

});
})(AJS.$);

This will bind the click event of your web item so that when you click it, it will prevent the navigation (preventDefault)  then fetch the content of your rest API using ajax by reading the href attribute and then display an AJS.dialog2 with the data retrieved from the rest api.

This page may be helpful: https://docs.atlassian.com/aui/8.6.0/docs/dialog2.html

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events