From 8abb2516d651e953d7990a7c469a86c42b6e837a Mon Sep 17 00:00:00 2001 From: kohsuke Date: Wed, 31 Dec 2008 19:50:46 +0000 Subject: [PATCH] working on nested view inline expansion git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@14053 71c3de6d-444a-0410-be80-ed276b4c234a --- core/pom.xml | 2 +- core/src/main/java/hudson/model/TreeView.java | 12 ++++++++ .../hudson/model/TreeView/ajaxRows.jelly | 17 +++++++++++ .../resources/lib/hudson/projectView.jelly | 11 +------ .../lib/hudson/projectViewNested.jelly | 20 +++++++++++++ .../resources/lib/hudson/projectViewNested.js | 28 +++++++++++++++++ war/resources/scripts/hudson-behavior.js | 30 +++++++++++++++++++ 7 files changed, 109 insertions(+), 11 deletions(-) create mode 100644 core/src/main/resources/hudson/model/TreeView/ajaxRows.jelly create mode 100644 core/src/main/resources/lib/hudson/projectViewNested.jelly create mode 100644 core/src/main/resources/lib/hudson/projectViewNested.js diff --git a/core/pom.xml b/core/pom.xml index 68cbbca187..7e0f3d8c7c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -231,7 +231,7 @@ org.kohsuke.stapler stapler - 1.91 + 1.92 org.jvnet.localizer diff --git a/core/src/main/java/hudson/model/TreeView.java b/core/src/main/java/hudson/model/TreeView.java index 6d58dbe8e7..c21566cc76 100644 --- a/core/src/main/java/hudson/model/TreeView.java +++ b/core/src/main/java/hudson/model/TreeView.java @@ -2,6 +2,7 @@ package hudson.model; import hudson.model.Descriptor.FormException; import hudson.util.CaseInsensitiveComparator; +import hudson.Indenter; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @@ -45,6 +46,17 @@ public class TreeView extends View implements ViewGroup { super(name); } + /** + * Returns {@link Indenter} that has the fixed indentation width. + * Used for assisting view rendering. + */ + public Indenter createFixedIndenter(String d) { + final int depth = Integer.parseInt(d); + return new Indenter() { + protected int getNestLevel(Job job) { return depth; } + }; + } + /** * Returns a read-only view of all {@link Job}s in this view. * diff --git a/core/src/main/resources/hudson/model/TreeView/ajaxRows.jelly b/core/src/main/resources/hudson/model/TreeView/ajaxRows.jelly new file mode 100644 index 0000000000..6480369f20 --- /dev/null +++ b/core/src/main/resources/hudson/model/TreeView/ajaxRows.jelly @@ -0,0 +1,17 @@ + + + + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/core/src/main/resources/lib/hudson/projectView.jelly b/core/src/main/resources/lib/hudson/projectView.jelly index 0be22b0cfc..b073f9984a 100644 --- a/core/src/main/resources/lib/hudson/projectView.jelly +++ b/core/src/main/resources/lib/hudson/projectView.jelly @@ -37,16 +37,7 @@ - - - - - - - ${v.viewName} - - - + diff --git a/core/src/main/resources/lib/hudson/projectViewNested.jelly b/core/src/main/resources/lib/hudson/projectViewNested.jelly new file mode 100644 index 0000000000..696ec6ffb6 --- /dev/null +++ b/core/src/main/resources/lib/hudson/projectViewNested.jelly @@ -0,0 +1,20 @@ + + + + + + + + + + + + + ${v.viewName} + + + + diff --git a/core/src/main/resources/lib/hudson/projectViewNested.js b/core/src/main/resources/lib/hudson/projectViewNested.js new file mode 100644 index 0000000000..1501a2d7e1 --- /dev/null +++ b/core/src/main/resources/lib/hudson/projectViewNested.js @@ -0,0 +1,28 @@ +hudsonRules["IMG.treeview-fold-control"] = function(e) { + e.onexpanded = function() { + var img = this; + var tr = findAncestor(this, "TR"); + var tail = tr.nextSibling; + + img.oncollapsed = function() { + while(tr.nextSibling!=tail) + tr.nextSibling.remove(); + }; + + new Ajax.Request( + this.getAttribute("url"), + { + method : 'post', + onComplete : function(x) { + var cont = document.createElement("div"); + cont.innerHTML = x.responseText; + var rows = $A(cont.firstChild.rows); + rows.reverse().each(function(r) { + YAHOO.util.Dom.insertAfter(r, tr); + Behaviour.applySubtree(r); + }); + } + }); + }; + e = null; +}; diff --git a/war/resources/scripts/hudson-behavior.js b/war/resources/scripts/hudson-behavior.js index 3874f21cc4..a37b2a3e0e 100644 --- a/war/resources/scripts/hudson-behavior.js +++ b/war/resources/scripts/hudson-behavior.js @@ -437,6 +437,36 @@ var hudsonRules = { "INPUT.yui-button" : function(e) { makeButton(e); + }, + + // image that shows [+] or [-], with hover effect. + // oncollapsed and onexpanded will be called when the button is triggered. + "IMG.fold-control" : function(e) { + function changeTo(e,img) { + var src = e.src; + e.src = src.substring(0,src.lastIndexOf('/'))+"/"+e.getAttribute("state")+img; + } + e.onmouseover = function() { + changeTo(this,"-hover.png"); + }; + e.onmouseout = function() { + changeTo(this,".png"); + }; + e.parentNode.onclick = function(event) { + var e = this.firstChild; + var s = e.getAttribute("state"); + if(s=="plus") { + e.setAttribute("state","minus"); + if(e.onexpanded) e.onexpanded(); + } else { + e.setAttribute("state","plus"); + if(e.oncollapsed) e.oncollapsed(); + } + changeTo(e,"-hover.png"); + YAHOO.util.Event.stopEvent(event); + return false; + }; + e = null; // memory leak prevention } }; -- GitLab