I've added resources folder in setenv.sh.
Then added web panel with condition
jiraHelper.project.key in ('someProjectKey')
And then I installed web resources for my web panel to hide collapse button
AJS.$(document).ready(function() {
console.log("Try to hide");
var el = document.querySelector("button.aui-button.toggle-title");
document.querySelector('button.aui-button.toggle-title[aria-label="Label Text:"]').style.visibility = "hidden";
});
with context
jira.view.issue
it works!
But question is will all users get this js from jira server? I mean if someone is viewing the page in project not equal 'someProjectKey' where even no web panel that I added, will he anyway get the js from web resources? May be there is some way not to send this js if issue not in someProjectKey?
Yes, in this case, your js specified with jira.view.issue will be included for anyone who accesses any issues from any projects.
But what I generally do for webpanels or dialog that require JS, is create a .js file that I then include as part of that panel's defintion.
This way, the JS is sent along with the panel's HTML.
For example, if you're building your panel with MarkupBuilder (and you should), you can just include your script like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.util.JiraHome
import groovy.xml.MarkupBuilder
def builder = new MarkupBuilder(writer)
/* ... al your code to build your panel html ... */
//now include your script at the end of the panel
builder.script(type: 'text/javascript') {
//if your panel script is stored in your <jira-home>/scripts directory, you can keep the .js file in the same folder and get it like this
String jiraHome = ComponentAccessor.getComponent(JiraHome).home.path
String currentPath = jiraHome + '/scripts/' + this.class.canonicalName.tokenize('.').dropRight(1).join('/')
def scriptFile = new File("$currentPath/panelJavaScriptSource.js")
builder.mkp.yieldUnescaped(scriptFile.getText('UTF-8'))
}
One other advantage of doing it this way, you can edit the .js file and the changes are seen immediately in the UI. With "Install Web Resources", the resources are cached in the browser and even if you change the file, browsers will not download the update file until you clear the cache or edit the fragment's key.
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.