Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Showing a popup when clicking a custom web item

Daniel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 22, 2019

What I need
What I want to achieve is when clicking on a button in the action pane of the release list of a project to gather some text of custom fields from tickets within this specific release and show it in a popup.

Problem
I tried multiple approaches from different tutorials but my problem is to show this html as an popup and not opening it within the same tab. 

What I did so far
So I created a custom web item in the section atl.jira.version.admin.operations.
I picket the "Run code and display a dialog" option with the link like "/rest/scriptrunner/latest/custom/showDialog"

Next on I created a rest endpoint:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
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 ->

def dialog ="""
<section id="static-dialog" class="aui-layer aui-dialog2 aui-dialog2-medium" role="dialog" aria-hidden="true">
<!-- Dialog header -->
<header class="aui-dialog2-header">
<!-- The dialog's title -->
<h2 class="aui-dialog2-header-main">The modal dialog title</h2>
</header>
<!-- Main dialog content -->
<div class="aui-dialog2-content">
<p>Content for the modal dialog.</p>
</div>
<!-- Dialog footer -->
<footer class="aui-dialog2-footer">
<!-- Actions to render on the right of the footer -->
<div class="aui-dialog2-footer-actions">
<button class="aui-button aui-button-link">Close</button>
</div>
</footer>
</section>
"""

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

But it always opens within the same tab. What did I miss here?

Bonus Question
Another question would be how can I access the id of the release to pass it to my rest endpoint? 
Something like this?


/rest/scriptrunner/latest/custom/showDialog?versionid={version.key}

 

1 answer

0 votes
PD Sheehan
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.
August 26, 2019

My experience is that the whatever javascript that scriptrunner deploys to support the “Run code and display a dialog” is not available in all contexts. 

Specifically, in project setting and other admin screens as well as in agile boards, that action doesn’t work. 

What I've done is selected the “run code and do nothing” and deployed my own javascript resource using a script fragment in the appropriate context. My javascript finds my custom item and binds the I click event to display the dialog. 

You’ll find some ideas on how to do that and the fields you can offer on your form here: https://docs.atlassian.com/aui/7.9.3/docs/dialog2.html

Examine the code of your release page in your browser developper tools to get ideas how to get the version I’d. You can use jquery  to find an element relative to the clicked element to extrapolate the version I’d and pass it to your dialog. 

This is pretty advanced territory. 

Suggest an answer

Log in or Sign up to answer