From cbcf500ca020b5fb797db8179d00a4a14c5af30e Mon Sep 17 00:00:00 2001 From: kohsuke Date: Wed, 20 Jan 2010 18:29:02 +0000 Subject: [PATCH] Made radioBlock ID-less so that it can be inserted into the HTML dynamically and still function as expected git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@26127 71c3de6d-444a-0410-be80-ed276b4c234a --- .../main/resources/lib/form/radioBlock.jelly | 12 +- war/resources/scripts/hudson-behavior.js | 146 ++++++++++-------- 2 files changed, 87 insertions(+), 71 deletions(-) diff --git a/core/src/main/resources/lib/form/radioBlock.jelly b/core/src/main/resources/lib/form/radioBlock.jelly index 35f4b6a587..2d59dc32ec 100644 --- a/core/src/main/resources/lib/form/radioBlock.jelly +++ b/core/src/main/resources/lib/form/radioBlock.jelly @@ -48,14 +48,12 @@ THE SOFTWARE. - - - + + class="radio-block-control" checked="${checked?'true':null}" /> - + @@ -68,7 +66,5 @@ THE SOFTWARE. - - - + \ No newline at end of file diff --git a/war/resources/scripts/hudson-behavior.js b/war/resources/scripts/hudson-behavior.js index 149cc140d5..eb442339e5 100644 --- a/war/resources/scripts/hudson-behavior.js +++ b/war/resources/scripts/hudson-behavior.js @@ -140,6 +140,13 @@ function findAncestor(e, tagName) { return e; } +function findAncestorClass(e, cssClass) { + do { + e = e.parentNode; + } while (e != null && !Element.hasClassName(e,cssClass)); + return e; +} + function findFollowingTR(input, className) { // identify the parent TR var tr = input; @@ -643,6 +650,54 @@ var hudsonRules = { return false; }; e = null; // memory leak prevention + }, + + // radioBlock.jelly + "INPUT.radio-block-control" : function(r) { + r.id = "radio-block-"+(iota++); + + // when one radio button is clicked, we need to update foldable block for + // other radio buttons with the same name. To do this, group all the + // radio buttons with the same name together and hang it under the form object + var f = r.form; + var radios = f.radios; + if (radios == null) + f.radios = radios = {}; + + var g = radios[r.name]; + if (g == null) { + radios[r.name] = g = object(radioBlockSupport); + g.buttons = []; + } + + var s = findAncestorClass(r,"radio-block-start"); + + // find the end node + var e = (function() { + var e = s; + var cnt=1; + while(cnt>0) { + e = e.nextSibling; + if (Element.hasClassName(e,"radio-block-start")) + cnt++; + if (Element.hasClassName(e,"radio-block-end")) + cnt--; + } + return e; + })(); + + var u = function() { + g.updateSingleButton(r,s,e); + }; + applyNameRef(s,e,r.id); + g.buttons.push(u); + + // apply the initial visibility + u(); + + // install event handlers to update visibility. + // needs to use onclick and onchange for Safari compatibility + r.onclick = r.onchange = function() { g.updateButtons(); }; } }; @@ -1047,78 +1102,43 @@ var repeatableSupport = { } }; -// Used by radioBlock.jelly to wire up expandable radio block -function addRadioBlock(id) { - // prototype object to be duplicated for each radio button group - var radioBlockSupport = { - buttons : null, +// prototype object to be duplicated for each radio button group +var radioBlockSupport = { + buttons : null, - updateButtons : function() { - for( var i=0; i