The jira Rest API example:Calling the REST API from an app: Quickview inline dialog app in jira version8+,9+cannot use

Calling the REST API from an app: Quickview inline dialog app

This example shows you how to create a Jira app that uses the REST API. We want to look through all the comments on the issue and add a little tooltip that will pop-up when you hover over a link to a Jira issue.

The pop-up should contain a “quick view” of information about the target issue (similar to the example shown in the following image) so that you do not have to click the issue’s link to see this information.

define(‘issue-hover’, [‘ajs’], function(AJS){
AJS.toInit(function() {
var i = new Date().getTime();
AJS.$(“#issue_actions_container”).find(‘.action-body a’).each(function() {
if (this.href.match(//browse/[A-Z]+-\d+$/)) {
var split = this.href.split(‘/browse/’);
var base = split[0];
var key = split[1];
var options = { cacheContent: true, onHover: true, showDelay: 400, hideDelay: 400, closeOthers: false, width: 500 }
var draw = function(contents, trigger, showPopup) {
AJS.$.getJSON(base + ‘/rest/api/latest/issue/’ + key, function(data) {
var fields = data[“fields”];
contents.empty();
contents.append(
“<ul class="item-details">”
+ “


  • + “
    Summary:
    ” + “
    ” + fields[“summary”] + “

    + “
    Type:
    ” + “
    ” + fields[“issuetype”][“name”] + “

    + “
    Priority:
    ” + “
    ” + fields[“priority”][“name”] + “

    + “
    Status:
    ” + “
    ” + fields[“status”][“name”] + “

    + “
    Assignee:
    ” + “
    ” + fields[“assignee”][“name”] + “

    + “
    Description:
    ” + “
    ” + fields[“description”] + “

    + “
  • ”);
    contents.append(“<form id="add-watch" name="watch" action="">”);
    AJS.$(“<input type="button" name="button" value="Watch"/>”).click(function() {
    // We don’t actually know our own username…and we need it to add a Watcher. So we get it from the
    // “current user” resource
    AJS.$.getJSON(base + ‘/rest/auth/latest/session’, function(data) {
    AJS.$.ajax({
    type: “POST”,
    url: base + “/rest/api/latest/issue/” + key + “/watchers”,
    data: “"”+ data[‘name’]+ “"”,
    dataType: “json”,
    contentType: “application/json”
    })
    })
    }).appendTo(contents);
    contents.append(“”);
    showPopup()
    })
    };
    AJS.InlineDialog(AJS.$(this), “issue-linking-” + (i++), draw, options)
    }
    })
    })
    });

    require(‘issue-hover’);