@Nic Brough [Adaptavist]
@Chris Fuller
Hi Team,
I am developing a plugin for JIRA admins. I m trying to load JS file in Velocity template but unable to do so. I want to add a dropdown which will provide the list of all the projects.
I have tried below post also, but it is not working for me:
https://answers.atlassian.com/questions/30540422/add-projects-to-project-picker-field
Below is the code snippet for atlassian-plugin.xml
<web-resource key="ForgeJiraMailHandler-resources" name="ForgeJiraMailHandler Web Resources"> <dependency>com.atlassian.auiplugin:ajs</dependency> <dependency>jira.webresources:jira-global</dependency> <dependency>jira.webresources:autocomplete</dependency> <resource type="download" name="ForgeJiraMailHandler.css" location="/css/ForgeJiraMailHandler.css"/> <resource type="download" name="ForgeJiraMailHandler.js" location="/js/ForgeJiraMailHandler.js"/> <resource type="download" name="images/" location="/images"/> <context>ForgeJiraMailHandler</context> </web-resource>
Below is the velocity template- ForgeJiraMailHandlerConfiguration.vm
<html> <head> <title>$i18n.getText("fjmh.name")</title> $webResourceManager.requireResource("com.atlassian.auiplugin:ajs") $webResourceManager.requireResource("com.soprasteria.di.mailhandler.ForgeJiraMailHandler:ForgeJiraMailHandler-resources") </head> ....
Below is the Javascript file ForgeJiraMailHandler.js
var ProjectPicker = AJS.SingleSelect.extend({ init: function (options) { function formatResponse(response) { var ret = []; var groupDescriptor = new AJS.GroupDescriptor({ weight: 1, label: "Projects" }); ret.push(groupDescriptor); AJS.$(response).each(function(i, project) { groupDescriptor.addItem(new AJS.ItemDescriptor({ value: project.key, label: project.name, html: "<div><span>" + project.name + "</span></div>", icon: project.avatarUrls[project.avatarUrls.length - 1] })); }); return ret; } AJS.$.extend(options, { errorMessage: "Missing Project", ajaxOptions: { url: contextPath + "/rest/api/2/project", query: true, formatResponse: formatResponse } }); this._super(options); } }); new ProjectPicker({ element: AJS.$("#projectdropdown"), itemAttrDisplayed: "label", width: 300 });
Could you please help?
@Yagnesh Bhat
Thanks For you kind reply. This thing works for me!!
There are some other few things which i need to mention here
You have defined the context "ForgeJiraMailHandler" in your xml, but you do not use it in your velocity template. I would change the context name in your xml to the full package name:
com.soprasteria.di.mailhandler.ForgeJiraMailHandler
and then use this code in your velocity template:
<head> #requireResourcesForContext("com.soprasteria.di.mailhandler.ForgeJiraMailHandler") </head>
If your JS and CSS is still not getting loaded, check if the location path to your file is correct and starts at the right level.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@TtheB
I tried with package name and #requireResourcesForContext as stated above, but no luck!!!
here is my package structure for your reference.
Eclipse_Structure.JPG
Please help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to remove the leading "/" from the location path in your web-resource, so
<resource type="download" name="ForgeJiraMailHandler.css" location="/css/ForgeJiraMailHandler.css"/> <resource type="download" name="ForgeJiraMailHandler.js" location="/js/ForgeJiraMailHandler.js"/>
becomes
<resource type="download" name="ForgeJiraMailHandler.css" location="css/ForgeJiraMailHandler.css"/> <resource type="download" name="ForgeJiraMailHandler.js" location="js/ForgeJiraMailHandler.js"/>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@TtheB
Thanks for your Help!!! I have incorporated your changes in my solution
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Petar Petrov [Botron]
I added below line in my velocity:
<script src="$req.contextPath/download/resources/com.soprasteria.di.mailhandler.ForgeJiraMailHandler:ForgeJiraMailHandler-resources/ForgeJiraMailHandler.js" type="text/javascript"></script>
So now when i m hitting below url, it is displaying js content to me
just that js is still not getting loaded in my browser/Velocity.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try wrapping the whole JS you have shown within this method
AJS.toInit(function() { //your JS here });
or within AJS.$() method instead.
Also make sure you are using the right contexts for your web resource, refer the section on contexts here:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I guess try adding the contexts as well:
<context>ForgeJiraMailHandler</context>
<context>atl.admin</context>
<context>atl.general</context>
And also be sure to clear the browser cache by hitting Ctrl-F5 on PC or Cmd-R on mac.
Also, can you check in if that web resource is actually enabled when you install the plugin? You can check that under "Manage Addons" and then expanding the link which shows your addon being installed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I m not able to load ForgeJiraMailHandler.js, I checked in Mozilla Firebug, js is not getting loaded. The dropdown is coming as empty. No errors in atlassian.log file and no error in Firebug console
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And by "not working" you mean?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.