Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Scriptrunner - WebItem - Advanced Dialog example does not work when the open issues list is displayed.

Roberto Saltini September 21, 2016

I have followed the "Dialog (Advanced)" example described at https://scriptrunner.adaptavist.com/4.3.4/jira/fragments/WebItem.html and wired the dialog box to the javascript code listed at the same page.

If I display a single issue (e.g.  <jira_server>/jira/browse/OTMCOPY2-19), then everything works as expected and I am able to close the dialog box by means of the Close button.

On the contrary, if I display the list of open issues (e.g.  <jira_server>/jira/projects/OTMCOPY2/issues/OTMCOPY2-19?filter=allopenissues), then when I click on the Close button nothing happens and the dialog stays open.

Here is the rest end point code for your reference :

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript

import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

showDialog() { MultivaluedMap queryParams -&gt;

    // get a reference to the current page...
    // def page = getPage(queryParams)

    def dialog =
        """&lt;section role="dialog" id="my-own-dialog" class="aui-layer aui-dialog2 aui-dialog2-medium" aria-hidden="true"&gt;
            &lt;header class="aui-dialog2-header"&gt;
                &lt;h2 class="aui-dialog2-header-main"&gt;Some dialog&lt;/h2&gt;
                &lt;a class="aui-dialog2-header-close"&gt;
                    &lt;span class="aui-icon aui-icon-small aui-iconfont-close-dialog"&gt;Close&lt;/span&gt;
                &lt;/a&gt;
            &lt;/header&gt;
            &lt;div class="aui-dialog2-content"&gt;
                &lt;p&gt;This is a dialog...&lt;/p&gt;
            &lt;/div&gt;
            &lt;footer class="aui-dialog2-footer"&gt;
                &lt;div class="aui-dialog2-footer-actions"&gt;
                    &lt;button id="dialog-close-button" class="aui-button aui-button-link"&gt;Close&lt;/button&gt;
                &lt;/div&gt;
                &lt;div class="aui-dialog2-footer-hint"&gt;Some hint here if you like&lt;/div&gt;
            &lt;/footer&gt;
        &lt;/section&gt;
        """

    Response.ok().type(MediaType.TEXT_HTML).entity(dialog.toString()).build()
}

 

As suggested by Jonny, I have added several console.log() to the javascript function of the example. Here it is:

console.log("Register function");
(function ($) {
    console.log("Called function with Atlassian's jQuery object: ");
    console.log($);
    $(function ( ) {
        console.log("Setup show event handler");
        AJS.dialog2.on("show", function (e) {
            console.log("Show event fired");
            var targetId = e.target.id;
            if (targetId == "my-own-dialog") {
                console.log("Target ID matched");
                var someDialog = AJS.dialog2(e.target);
                $(e.target).find("#dialog-close-button").click(function (e) {
                    console.log("close button clicked; shut this stuff down");
                    e.preventDefault();
                    someDialog.hide();
                    someDialog.remove();
                });
                // etc
            }
        });
    });
})(AJS.$);
The context used is atl.general

Here is an excerpt of the console output after the page is loaded

Register function batch.js?agile_global_admin_condition=true&amp;is-server-instance=true&amp;is-system-admin=true&amp;jag=true&amp;ja…:15632

Called function with Atlassian's jQuery object:  batch.js?agile_global_admin_condition=true&amp;is-server-instance=true&amp;is-system-admin=true&amp;jag=true&amp;ja…:15634

function (a,b){return new j.fn.init(a,b,gb)} batch.js?agile_global_admin_condition=true&amp;is-server-instance=true&amp;is-system-admin=true&amp;jag=true&amp;ja…:15635


DEPRECATED - Inline dialog constructor has been deprecated and will be removed in a future release. Use inline dialog 2 instead.  
     at http://&lt;jira_server_address&gt;/jira/s/0f52c7b2f7bbe44352ed7b71e853e568-CDN/en_UKxud8…&amp;tempo_is_tempo_timesheets_license_valid=true&amp;user-logged-in=true:2728:421 batch.js?atlassian.aui.raphael.disabled=true&amp;locale=en-UK:213
XHR finished loading: "http://&lt;jira_server_address&gt;/jira/rest/webResources/1.0/resources". batch.js?atlassian.aui.raphael.disabled=true&amp;locale=en-UK:175


Downloading resources:
js!/jira/s/d41d8cd98f00b204e9800998ecf8427e-CDN/en_UKxud80d/71012/b6b48b2829824b869586ac216d119363/017bee1cfb84708a7ba1e4bae9f57901/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-atl.general/batch.js!order batch.js?atlassian.aui.raphael.disabled=true&amp;locale=en-UK:213
Deprecation warning: moment.langData is deprecated. Use moment.localeData instead.
Arguments: jira
Error
    at Function.&lt;anonymous&gt; (http://&lt;jira_server_address&gt;/jira/s/0f52c7b2f7bbe44352ed7b71e853e568-CDN/en_UKxud8…tempo_is_tempo_timesheets_license_valid=true&amp;user-logged-in=true:2949:3313)
    at http://&lt;jira_server_address&gt;/jira/s/d41d8cd98f00b204e9800998ecf8427e-CDN/en_UKxud8…ocalisation-moment/jira.webresources:calendar-localisation-moment.js:3:134
    at http://&lt;jira_server_address&gt;/jira/s/d41d8cd98f00b204e9800998ecf8427e-CDN/en_UKxud8…ocalisation-moment/jira.webresources:calendar-localisation-moment.js:3:431 batch.js?agile_global_admin_condition=true&amp;is-server-instance=true&amp;is-system-admin=true&amp;jag=true&amp;ja…:2949
DEPRECATED - Dropdown constructor has been deprecated and will be removed in a future release. Use Dropdown2 instead.  
     at Object.exports.bindConfigDashboardDds (http://&lt;jira_server_address&gt;/jira/s/4d5ae9bcb5c2695e2b15e1d59489d026-CDN/en_UKxud8…/_super/batch.js?atlassian.aui.raphael.disabled=true&amp;locale=en-UK:2986:545) batch.js?atlassian.aui.raphael.disabled=true&amp;locale=en-UK:213
DEPRECATED - Inline dialog constructor has been deprecated and will be removed in a future release. Use inline dialog 2 instead.  
     at _initShareDialog (http://&lt;jira_server_address&gt;/jira/s/0f52c7b2f7bbe44352ed7b71e853e568-CDN/en_UKxud8…tempo_is_tempo_timesheets_license_valid=true&amp;user-logged-in=true:2520:7075) batch.js?atlassian.aui.raphael.disabled=true&amp;locale=en-UK:213

Setup show event handler batch.js?agile_global_admin_condition=true&amp;is-server-instance=true&amp;is-system-admin=true&amp;jag=true&amp;ja…:15637

DEPRECATED

When I press the button for showing the dialog window the following output is printed to the console

XHR finished loading: "http://&lt;jira_server_address&gt;/jira/rest/scriptrunner/latest/custom/showDialog?_=1474546065767". batch.js?atlassian.aui.raphael.disabled=true&amp;locale=en-UK:175

Whereas the message "Show event fired" is supposed to be printed as well, but it does not.

 

 

 

3 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Jonny Carter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2016

Given that your code is trying to setup the event handler, but doesn't run when the event should be firing, you might try using some different contexts besides alt.general. You might also investigate the AJS object and make sure it has a dialog2 property when the script runs. If it doesn't exist when your script runs, but does exist when you check from the console (just run AJS.dialog2), then it's probably a timing issue. Try a different context, or maybe using a setInterval function to wait for dialog2 to be registered.

0 votes
Roberto Saltini September 22, 2016

I have updated my questions with your suggestions

0 votes
Jonny Carter September 21, 2016

I'd like a little more detail about the console.log calls you used. There are several layers of interest. Maybe try something like this to help narrow down what's happening:

console.log("Register function");
(function ($) {
    console.log("Called function with Atlassian's jQuery object: ");
    console.log($);
    $(function ( ) {
        console.log("Setup show event handler");
        AJS.dialog2.on("show", function (e) {
            console.log("Show event fired");
            var targetId = e.target.id;
            if (targetId == "my-own-dialog") {
                console.log("Target ID matched");
                var someDialog = AJS.dialog2(e.target);
                $(e.target).find("#dialog-close-button").click(function (e) {
                    console.log("close button clicked; shut this stuff down");
                    e.preventDefault();
                    someDialog.hide();
                    someDialog.remove();
                });
                // etc
            }
        });
    });
})(AJS.$);

Also, what contexts did you set your Javascript's web resource to display in? Are you certain that it includes the issue results screen?

TAGS
AUG Leaders

Atlassian Community Events