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

hooking up the whole thing for a demoable state

上级 30bb3fde
......@@ -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<Foo>), base=List}, compute the parameterization of 'base'
......
......@@ -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;
......
......@@ -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,"<img src='"+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;
}
}
}
......@@ -43,10 +43,8 @@ THE SOFTWARE.
<!-- called to generate partial HTML. set up HTML headers and etc -->
<!-- copied from layout.jelly -->
<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:set var="resURL" value="${rootURL}${h.resourcePath}" />
<j:set var="imagesURL" value="${rootURL}${h.resourcePath}/images" />
${h.initPageVariables(context)}
<j:set var="ajax" value="true"/>
<d:invokeBody/>
......
......@@ -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: "<b>Yahoo</b>! Address Book", url: "http://addressbook.yahoo.com" },
{ text: "<img src='http://localhost:8080/images/24x24/terminal.png'> 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 = "<img src='"+e.icon+"' width=24 height=24 style='margin: 2px;' alt=''> "+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});
})
]]></script>
<div id="rendertarget"/>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册