diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 34e17e9c109b2db6e1be82ecb3aad945857b290f..57fbd8adbaa79a3ecf45d7355a5fb571feee22dc 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -152,6 +152,16 @@ public class Functions { public static String rfc822Date(Calendar cal) { return Util.RFC822_DATETIME_FORMATTER.format(cal.getTime()); } + + public static void initPageVariables(JellyContext context) { + String rootURL = Stapler.getCurrentRequest().getContextPath(); + Functions h = new Functions(); + + context.setVariable("rootURL", rootURL); + context.setVariable("h", h); + context.setVariable("resURL",rootURL+getResourcePath()); + context.setVariable("imagesURL",rootURL+getResourcePath()+"/images"); + } /** * Given {@code c=MyList (extends ArrayList), base=List}, compute the parameterization of 'base' diff --git a/core/src/main/java/hudson/model/Actionable.java b/core/src/main/java/hudson/model/Actionable.java index 24ae3c091b20cc7c446f20f069b8ae64cfc25504..039030ab899cad3218d32ee174cd7cafafa46aa6 100644 --- a/core/src/main/java/hudson/model/Actionable.java +++ b/core/src/main/java/hudson/model/Actionable.java @@ -23,8 +23,12 @@ */ package hudson.model; +import hudson.Functions; import hudson.model.queue.Tasks; import jenkins.model.ModelObjectWithContextMenu; +import org.apache.commons.jelly.JellyContext; +import org.apache.commons.jelly.JellyException; +import org.apache.commons.jelly.JellyTagException; import org.apache.commons.jelly.Script; import org.apache.commons.jelly.XMLOutput; import org.kohsuke.stapler.StaplerRequest; @@ -133,7 +137,7 @@ public abstract class Actionable extends AbstractModelObject implements ModelObj ContextMenu c = new ContextMenu(); WebApp webApp = WebApp.getCurrent(); - Script s = webApp.getMetaClass(this).getTearOff(JellyClassTearOff.class).findScript("sidepanel"); + final Script s = webApp.getMetaClass(this).getTearOff(JellyClassTearOff.class).findScript("sidepanel"); if (s==null) { // fallback c.addAll(getActions()); @@ -141,7 +145,16 @@ public abstract class Actionable extends AbstractModelObject implements ModelObj JellyFacet facet = webApp.getFacet(JellyFacet.class); request.setAttribute("taskTags",c); request.setAttribute("mode","side-panel"); - facet.scriptInvoker.invokeScript(request,response,s,this,new XMLOutput(new DefaultHandler())); + facet.scriptInvoker.invokeScript(request,response,new Script() { + public Script compile() throws JellyException { + return this; + } + + public void run(JellyContext context, XMLOutput output) throws JellyTagException { + Functions.initPageVariables(context); + s.run(context,output); + } + }, this,new XMLOutput(new DefaultHandler())); } return c; diff --git a/core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java b/core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java index bcc0dcbe1b1826876ff786340427cb5e01466b2e..a1b269a354f860e5091d5a48f2da82a018d6b64b 100644 --- a/core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java +++ b/core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java @@ -3,7 +3,6 @@ package jenkins.model; import hudson.Functions; import hudson.model.Action; import hudson.model.ModelObject; -import org.apache.commons.jelly.JellyException; import org.kohsuke.stapler.HttpResponse; import org.kohsuke.stapler.Stapler; import org.kohsuke.stapler.StaplerRequest; @@ -37,7 +36,7 @@ public interface ModelObjectWithContextMenu extends ModelObject { } public ContextMenu add(String url, String text) { - items.add(new MenuItem(url,text)); + items.add(new MenuItem(url,null,text)); return this; } @@ -50,7 +49,10 @@ public interface ModelObjectWithContextMenu extends ModelObject { public ContextMenu add(Action a) { StaplerRequest req = Stapler.getCurrentRequest(); String text = a.getDisplayName(); - String icon = Functions.getIconFilePath(a); + String base = Functions.getIconFilePath(a); + if (base==null) return this; + String icon = Stapler.getCurrentRequest().getContextPath()+(base.startsWith("images/")?Functions.getResourcePath():"")+'/'+base; + String url = Functions.getActionUrl(req.findAncestor(ModelObject.class).getUrl(),a); return add(url,icon,text); @@ -58,7 +60,7 @@ public interface ModelObjectWithContextMenu extends ModelObject { public ContextMenu add(String url, String icon, String text) { if (text != null && icon != null && url != null) - items.add(new MenuItem(url," "+text)); + items.add(new MenuItem(url,icon,text)); return this; } } @@ -68,11 +70,14 @@ public interface ModelObjectWithContextMenu extends ModelObject { @Exported public String url; @Exported - public String text; + public String displayName; + @Exported + public String icon; - public MenuItem(String url, String text) { + public MenuItem(String url, String icon, String displayName) { this.url = url; - this.text = text; + this.icon = icon; + this.displayName = displayName; } } } diff --git a/core/src/main/resources/lib/layout/ajax.jelly b/core/src/main/resources/lib/layout/ajax.jelly index c0c1e8d7bb227db167f4329980e7e436808fd69e..20f7b74a8e2aadf29bf17f10e2a8dd144edf4cf9 100644 --- a/core/src/main/resources/lib/layout/ajax.jelly +++ b/core/src/main/resources/lib/layout/ajax.jelly @@ -43,10 +43,8 @@ THE SOFTWARE. - - - + ${h.initPageVariables(context)} diff --git a/core/src/main/resources/lib/layout/layout.jelly b/core/src/main/resources/lib/layout/layout.jelly index 5767def193ab3a60526627c3e3d1c8939a293af8..3df8e0107fa4b634d6ff858dc75da533cb7b8784 100644 --- a/core/src/main/resources/lib/layout/layout.jelly +++ b/core/src/main/resources/lib/layout/layout.jelly @@ -233,29 +233,36 @@ THE SOFTWARE. /** @type {YAHOO.widget.Menu} */ var oMenu; + var xhr; + /** * @param {HTMLElement} e * The LI tag that the mouse has wondered into. */ function foo(e) { - window.setTimeout(function() { - oMenu.hide(); - oMenu.cfg.setProperty("context",[e,"tl","bl"]); - oMenu.clearContent(); - oMenu.addItems([ - { text: e.firstChild.innerHTML, url: "http://mail.yahoo.com" }, - { text: "Yahoo! Address Book", url: "http://addressbook.yahoo.com" }, - { text: " Yahoo! Calendar", url: "http://calendar.yahoo.com" }, - { text: "Yahoo! Notepad", url: "http://notepad.yahoo.com" } - ]); - oMenu.render("rendertarget"); - oMenu.show(); - },500); + if (xhr) + xhr.options.onComplete = function() {}; // ignore the currently pending call + + xhr = new Ajax.Request(e.firstChild.getAttribute("href")+"contextMenu", { + onComplete : function (x) { + var a = x.responseText.evalJSON().items; + a.each(function(e) { + e.text = " "+e.displayName; + }); + + oMenu.hide(); + oMenu.cfg.setProperty("context",[e,"tl","bl"]); + oMenu.clearContent(); + oMenu.addItems(a); + oMenu.render("rendertarget"); + oMenu.show(); + } + }); + return false; } window.addEventListener("load",function(){ oMenu = new YAHOO.widget.Menu("breadcrumb-menu", {position:"dynamic", hidedelay:1000}); - }) ]]>