how to add javascript in jira 5.1.1

xuhai zhao September 11, 2012

I want to upgrade a plugin, but the Javascript in the plugin is not work. The javascript controls the "change" event of a "Select".

I have seen this:https://developer.atlassian.com/display/JIRADEV/Custom+Fields+that+use+CSS+or+JavaScript+Web+Resources+in+JIRA+5.0

The way to use JS has been changed since JIRA 5.0+, would someone give me some ideas.

Its source code is like this:

original JS:

AJS.toInit(function() {
    (function($) {
     $('#select-issue-type').change(function() {
          $('.cpji-loading').show();
          $('#fields').empty();
          var projectKey = $('#project-key').val();
          var issueType = $('#select-issue-type :selected').val();
          $.get('../GetFieldsHtmlAction.jspa?projectKey=' + projectKey + '&selectedIssueTypeId=' + issueType, function(data) {
            $('#fields').append($(data));
            $('.cpji-loading').hide();
          });
     });
     $('#select-issue-type').trigger('change');
    })(AJS.$);
});

Original .vm:

<div id="fields">	
</div>

Original atlassian.xml:

<web-resource key="cpjiadminrs">
    	<context>atl.general</context>
       <resource type="download" name="cpjiadmin.js" location="js/cpjiadmin.js"/>
       <resource type="download" name="cpjiadmin.css" location="css/cpjiadmin.css"/>
    </web-resource>

2 answers

0 votes
tousifs
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 11, 2012

No need to edit the java script.

make sure your additing this entry in the atlassian-plugin.xml file.

<web-resource key="scriptaculous" name="scriptaculous" >

<resource type="download" name="yourfile.js" location="temp/res/yourfile.js" />

</web-resource>

and then go to your velocity file and edit it to the .

#requireResource("your plugin key+ :cpjiadminrs")

make sure and check the syntax for the #requireResource on atlassian it will be help ful for you

if still not working then i cannot help you then you can really cry.

0 votes
tousifs
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 11, 2012

Have you tried setting the context to atl.general?

<web-resource name="AAC Connector Resources" i18n-name-key="aac-connector-resources.name" key="aac-connector-resources">
<context>atl.general</context>
<description key="aac-connector-resources.description">The AAC Connector Resources Plugin</description>
<dependency>com.atlassian.jira.plugins.support-resources:bindToEdit</dependency>
<resource name="aac-connector.css" type="download" location="assets/css/aac-connector.css"/>
<resource name="aac-connector.js" type="download" location="assets/js/aac-connector.js"/>
<resource type="download" name="assets/" location="assets/"/>
</web-resource>
tousifs
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 11, 2012

please try.

#requireResource("your plugin key+ :cpjiadminrs")

in your velocity template it should work.

xuhai zhao September 11, 2012

yes, there is <context>atl.general</context> in the <web-source>

and at the head of the related vm file has the following:

&lt;html&gt;
&lt;head&gt;
   &lt;meta name='decorator' content='atl.general'&gt;

xuhai zhao September 11, 2012

Thank you for your kindly answer, but it still not work. 555... I want to cry.

The css in the web-source can be added correctly, but the javascript could not be executed.

Does it need to modify the javascript file?

Suggest an answer

Log in or Sign up to answer