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

JS and jQuery in JIRA

Karel Rozhon July 7, 2014

Hi everyone,

I am totaly newbie in JIRA, so please be indulgent:-). I am trying to write some relatively simple custom field. I think, I have all code which I need written in Java, but now I am tryting to work with the velocity template. There are some questions.

The first one:

This is the basic one, I would like to use some jQuery like this:

this is an extract from my edit.vm:

$webResourceManager.requireResource("cz.firma.rozy:zakaznik")

<input id="test" style="width:500px" type="text" placeholder="Sem zadejte ID" value="" /> <button id="buttonID" >Use ID</button>

and there is my simple zakaznik.js

EDIT:

AJS.$( "#buttonID" ).click(function() {
    AJS.$("#test").hide();
});

finally atlassian-plugin.xml

...

&lt;web-resource key="zakaznik-resources" name="zakaznik Web Resources"&gt;
    &lt;dependency&gt;com.atlassian.auiplugin:ajs&lt;/dependency&gt;
    &lt;dependency&gt;com.atlassian.auiplugin:jquery&lt;/dependency&gt;
    &lt;dependency&gt;com.atlassian.auiplugin:jquery-ui-other&lt;/dependency&gt;
    &lt;dependency&gt;com.atlassian.auiplugin:aui-select2&lt;/dependency&gt;
    &lt;context&gt;atl.general&lt;/context&gt;
    &lt;context&gt;atl.admin&lt;/context&gt;
    &lt;resource type="download" name="zakaznik.css" location="/css/zakaznik.css"/&gt;
    &lt;resource type="download" name="zakaznik.js" location="/js/zakaznik.js"/&gt;
    &lt;resource type="download" name="images/" location="/images"/&gt;
    &lt;context&gt;zakaznik&lt;/context&gt;
  &lt;/web-resource&gt;

...
  &lt;customfield-type name="Pridani zakaznika" i18n-name-key="customer-add.name" key="customer-add" class="cz.firma.rozy.jira.customfields.CustomerCustomField"&gt;
    &lt;description key="customer-add.description"&gt;Plugin, ktery prida zakaznika z abry&lt;/description&gt;
    &lt;resource name="view" type="velocity" location="templates/viewCustomer.vm"/&gt;
    &lt;resource name="edit" type="velocity" location="templates/edit.vm"/&gt;
  &lt;/customfield-type&gt;

Plugin is succesfully builded and installed in JIRA ( JIRA v6.2.3) and I can add this field to any screen. Now I am in edit mode and I would like to try if is this all right. Now when I click on this added button, I would like to see, that input is hidden (I know, this functionality is not usefull, I am only trying it). But my problem is that, when I click on my button, nothing is done and editing mode is closed. Please, could you tell me, what I am doing wrong?

The second question is:

I found this page: https://docs.atlassian.com/aui/latest/sandbox/#and in future I would like to use set an example Auiselect2.

https://docs.atlassian.com/aui/5.5.1/docs/auiselect2.html- here is written, that this is only experimental, so which step I should do to use it? In previous examples you can see, that I was trying to added this funcionality, but it simple did not work. attlassian-plugin.xml was the same in edit.vm and zakaznik.js I was used an example mentioned in docs -

edit.vm:

$webResourceManager.requireResource("cz.firma.rozy:zakaznik")

&lt;form class="aui"&gt;
    &lt;select id="select2-example" multiple&gt;
        &lt;option value="CONF"&gt;Confluence&lt;/option&gt;
        &lt;option value="JIRA"&gt;JIRA&lt;/option&gt;
        &lt;option value="BAM"&gt;Bamboo&lt;/option&gt;
        &lt;option value="JAG"&gt;JIRA Agile&lt;/option&gt;
        &lt;option value="CAP"&gt;JIRA Capture&lt;/option&gt;
        &lt;option value="AUI"&gt;AUI&lt;/option&gt;
    &lt;/select&gt;
&lt;/form&gt;

and zakaznik.js

AJS.$(function() {
    AJS.$("#select2-example").auiSelect2();
});

But when I visit the edit mode, no js is done.

Thank you very much for your advises and for your patience.

Karel Rozhon

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
John Bishop
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.
July 7, 2014

First Question:

I believe your javascript should be:

AJS.$( "#buttonID" ).click(function() {
    AJS.$("#test").hide();
});

Second Question:

Does your web browser show any javascript errors? Perhaps you need to have that javascript inside the jQuery ready function (http://learn.jquery.com/using-jquery-core/document-ready/)

Karel Rozhon July 7, 2014

Thank you for quick response.

Oh, sorry I was published one of my test javasripts - I was trying if there isn't some need to escape "#". But in fact, this one which you mentioned I was trying too. And result was the same.

Unfortunately, my browser is not showing any errors.


Now, I have tryied document ready function which you mentioned:

AJS.$( document ).ready(function() {
    AJS.$( "#buttonID" ).click(function() {
        AJS.$("#test").hide();
    });
});

But result is the same. Edit mode is closed after I clicked on my button.

TAGS
AUG Leaders

Atlassian Community Events