提交 5276c2f8 编写于 作者: K Kohsuke Kawaguchi

hooking up the whole thing for a demoable state

上级 30bb3fde
...@@ -152,6 +152,16 @@ public class Functions { ...@@ -152,6 +152,16 @@ public class Functions {
public static String rfc822Date(Calendar cal) { public static String rfc822Date(Calendar cal) {
return Util.RFC822_DATETIME_FORMATTER.format(cal.getTime()); 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<Foo>), base=List}, compute the parameterization of 'base' * Given {@code c=MyList (extends ArrayList<Foo>), base=List}, compute the parameterization of 'base'
......
...@@ -23,8 +23,12 @@ ...@@ -23,8 +23,12 @@
*/ */
package hudson.model; package hudson.model;
import hudson.Functions;
import hudson.model.queue.Tasks; import hudson.model.queue.Tasks;
import jenkins.model.ModelObjectWithContextMenu; 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.Script;
import org.apache.commons.jelly.XMLOutput; import org.apache.commons.jelly.XMLOutput;
import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerRequest;
...@@ -133,7 +137,7 @@ public abstract class Actionable extends AbstractModelObject implements ModelObj ...@@ -133,7 +137,7 @@ public abstract class Actionable extends AbstractModelObject implements ModelObj
ContextMenu c = new ContextMenu(); ContextMenu c = new ContextMenu();
WebApp webApp = WebApp.getCurrent(); 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) { if (s==null) {
// fallback // fallback
c.addAll(getActions()); c.addAll(getActions());
...@@ -141,7 +145,16 @@ public abstract class Actionable extends AbstractModelObject implements ModelObj ...@@ -141,7 +145,16 @@ public abstract class Actionable extends AbstractModelObject implements ModelObj
JellyFacet facet = webApp.getFacet(JellyFacet.class); JellyFacet facet = webApp.getFacet(JellyFacet.class);
request.setAttribute("taskTags",c); request.setAttribute("taskTags",c);
request.setAttribute("mode","side-panel"); 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; return c;
......
...@@ -3,7 +3,6 @@ package jenkins.model; ...@@ -3,7 +3,6 @@ package jenkins.model;
import hudson.Functions; import hudson.Functions;
import hudson.model.Action; import hudson.model.Action;
import hudson.model.ModelObject; import hudson.model.ModelObject;
import org.apache.commons.jelly.JellyException;
import org.kohsuke.stapler.HttpResponse; import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.Stapler; import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerRequest;
...@@ -37,7 +36,7 @@ public interface ModelObjectWithContextMenu extends ModelObject { ...@@ -37,7 +36,7 @@ public interface ModelObjectWithContextMenu extends ModelObject {
} }
public ContextMenu add(String url, String text) { public ContextMenu add(String url, String text) {
items.add(new MenuItem(url,text)); items.add(new MenuItem(url,null,text));
return this; return this;
} }
...@@ -50,7 +49,10 @@ public interface ModelObjectWithContextMenu extends ModelObject { ...@@ -50,7 +49,10 @@ public interface ModelObjectWithContextMenu extends ModelObject {
public ContextMenu add(Action a) { public ContextMenu add(Action a) {
StaplerRequest req = Stapler.getCurrentRequest(); StaplerRequest req = Stapler.getCurrentRequest();
String text = a.getDisplayName(); 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); String url = Functions.getActionUrl(req.findAncestor(ModelObject.class).getUrl(),a);
return add(url,icon,text); return add(url,icon,text);
...@@ -58,7 +60,7 @@ public interface ModelObjectWithContextMenu extends ModelObject { ...@@ -58,7 +60,7 @@ public interface ModelObjectWithContextMenu extends ModelObject {
public ContextMenu add(String url, String icon, String text) { public ContextMenu add(String url, String icon, String text) {
if (text != null && icon != null && url != null) if (text != null && icon != null && url != null)
items.add(new MenuItem(url,"<img src='"+url+"'> "+text)); items.add(new MenuItem(url,icon,text));
return this; return this;
} }
} }
...@@ -68,11 +70,14 @@ public interface ModelObjectWithContextMenu extends ModelObject { ...@@ -68,11 +70,14 @@ public interface ModelObjectWithContextMenu extends ModelObject {
@Exported @Exported
public String url; public String url;
@Exported @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.url = url;
this.text = text; this.icon = icon;
this.displayName = displayName;
} }
} }
} }
...@@ -43,10 +43,8 @@ THE SOFTWARE. ...@@ -43,10 +43,8 @@ THE SOFTWARE.
<!-- called to generate partial HTML. set up HTML headers and etc --> <!-- called to generate partial HTML. set up HTML headers and etc -->
<!-- copied from layout.jelly --> <!-- copied from layout.jelly -->
<st:contentType value="text/html;charset=UTF-8" /> <st:contentType value="text/html;charset=UTF-8" />
<j:set var="rootURL" value="${request.contextPath}" />
<j:new var="h" className="hudson.Functions" /><!-- instead of JSP functions --> <j:new var="h" className="hudson.Functions" /><!-- instead of JSP functions -->
<j:set var="resURL" value="${rootURL}${h.resourcePath}" /> ${h.initPageVariables(context)}
<j:set var="imagesURL" value="${rootURL}${h.resourcePath}/images" />
<j:set var="ajax" value="true"/> <j:set var="ajax" value="true"/>
<d:invokeBody/> <d:invokeBody/>
......
...@@ -233,29 +233,36 @@ THE SOFTWARE. ...@@ -233,29 +233,36 @@ THE SOFTWARE.
/** @type {YAHOO.widget.Menu} */ /** @type {YAHOO.widget.Menu} */
var oMenu; var oMenu;
var xhr;
/** /**
* @param {HTMLElement} e * @param {HTMLElement} e
* The LI tag that the mouse has wondered into. * The LI tag that the mouse has wondered into.
*/ */
function foo(e) { function foo(e) {
window.setTimeout(function() { if (xhr)
oMenu.hide(); xhr.options.onComplete = function() {}; // ignore the currently pending call
oMenu.cfg.setProperty("context",[e,"tl","bl"]);
oMenu.clearContent(); xhr = new Ajax.Request(e.firstChild.getAttribute("href")+"contextMenu", {
oMenu.addItems([ onComplete : function (x) {
{ text: e.firstChild.innerHTML, url: "http://mail.yahoo.com" }, var a = x.responseText.evalJSON().items;
{ text: "<b>Yahoo</b>! Address Book", url: "http://addressbook.yahoo.com" }, a.each(function(e) {
{ text: "<img src='http://localhost:8080/images/24x24/terminal.png'> Yahoo! Calendar", url: "http://calendar.yahoo.com" }, e.text = "<img src='"+e.icon+"' width=24 height=24 style='margin: 2px;' alt=''> "+e.displayName;
{ text: "Yahoo! Notepad", url: "http://notepad.yahoo.com" } });
]);
oMenu.render("rendertarget"); oMenu.hide();
oMenu.show(); oMenu.cfg.setProperty("context",[e,"tl","bl"]);
},500); oMenu.clearContent();
oMenu.addItems(a);
oMenu.render("rendertarget");
oMenu.show();
}
});
return false; return false;
} }
window.addEventListener("load",function(){ window.addEventListener("load",function(){
oMenu = new YAHOO.widget.Menu("breadcrumb-menu", {position:"dynamic", hidedelay:1000}); oMenu = new YAHOO.widget.Menu("breadcrumb-menu", {position:"dynamic", hidedelay:1000});
}) })
]]></script> ]]></script>
<div id="rendertarget"/> <div id="rendertarget"/>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册