The Adaptavist Group LogoDocumentation

Web Item

A web item is a button or link that appears at the location you choose.

Here are some things you can do with web items:

  • Redirect to another location
  • Invoke a script endpoint and run code, which can respond with:
    • A flag
    • A dialog
    • A redirection to another page

Examples

The following are web item examples.

Conditions

The Condition field is used to define whether the link should be shown or not, and it can use anything available in its context. What is available in the context depends on the particular web section and the page it is viewed on. Details of the current user can also be used.

Tip: In addition to using a script, you can use a concrete class that implements conditions, which extends the existing condition or one provided by the application.

Dialogs (advanced)

You can create and use some dialogs. In this case, JavaScript is needed for interactions.

To display a dialog when the user clicks on a web item see the following steps:

  1. Create a new Custom web item.
    1. From ScriptRunner, navigate to UI Fragments > Custom web item.
    2. Fill out the Custom web item form as below. Make sure to select Run Code and Display a Dialog value for the Do What field, and leave the Link field empty for now.
    3. Select Add to create the web item.
  2. Set up a new Custom REST Endpoint that will return a HTML for an AUI dialog 2 when it is accessed.
    1. Navigate to Scriptrunner → REST Endpoints → Add a New Item.
    2. Select Custom Endpoint and place the code below in the Inline Script field:
      import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
      import groovy.transform.BaseScript
      
      import jakarta.ws.rs.core.MediaType
      import jakarta.ws.rs.core.MultivaluedMap
      import jakarta.ws.rs.core.Response
      
      @BaseScript CustomEndpointDelegate delegate
      
      showDialog { MultivaluedMap queryParams ->
      
          def dialog =
       """<section
                  id="static-dialog"
       class="aui-dialog2 aui-dialog2-medium aui-layer"
                  role="dialog"
                  aria-modal="true"
                  tabindex="-1"
                  aria-labelledby="static-dialog--heading"
                  aria-describedby="static-dialog--description"
                  hidden
                  data-aui-remove-on-hide="true"
              >
                  <!-- Dialog header -->
                  <header class="aui-dialog2-header">
                      <!-- The dialog's title -->
                      <h1 class="aui-dialog2-header-main" id="static-dialog--heading">The modal dialog title</h1>
                  </header>
                  <!-- Main dialog content -->
                  <div class="aui-dialog2-content" id="static-dialog--description">
                      <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" id="dialog-close-button">Close</button>
                      </div>
                      <!-- Hint text is rendered on the left of the footer -->
                      <div class="aui-dialog2-footer-hint">This is a hint.</div>
                  </footer>
              </section>
       """
          Response.ok().type(MediaType.TEXT_HTML).entity(dialog.toString()).build()
      }
    3. Save your endpoint.
  3. Copy the url of your newly created endpoint to the Link field of the Web Item you created in step 1.

Results

Now, if you navigate to the Web Item and click on it:

The following dialog displays:

Additional details (Close functionality)

Note that in the current implementation the Close button will not actually close the dialog. To add this functionality, you need to use JavaScript.

  1. Add the following code after the </section> closing tag in your endpoint script:
    <script>
        AJS.toInit(() => { 
            document.getElementById("dialog-close-button").onclick = function(e) {
                e.preventDefault();
                AJS.dialog2("#static-dialog").hide();
            };
        });
    </script>

    The data-aui-remove-on-hide attribute controls the removing of the dialog from the DOM when the dialog is hidden (for example, when pressing the ESC key).

    Note: Removing this attribute hides the dialog rather than removing it when the dialog is hidden. In this case, you need to handle re-showing the dialog in your JavaScript code. Then, the web item trigger re-renders a new dialog for you.

    You can include your additional dialog with a web resource fragment.

  2. You can now save your REST endpoint.
    When you click on the web item you have selected, the dialog will appear, with the Close button functioning correctly.

Redirects

Return a redirect to run code and then redirect to another page, or load the same page after updating it.

Warning: Make sure to select Navigate to a link value for the Do What field.

Search documentation

Start typing to search the docs.