Skip to content

Commit 13668d3

Browse files
committed
Merge branch 'radioBlock-inline'
2 parents 86ce56c + 3fd9889 commit 13668d3

File tree

2 files changed

+61
-51
lines changed

2 files changed

+61
-51
lines changed

core/src/main/resources/lib/form/radioBlock.jelly

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ THE SOFTWARE.
4343
<st:attribute name="checked" use="required" type="boolean">
4444
Should this control be initially checked or not?
4545
</st:attribute>
46+
<st:attribute name="inline">
47+
if present, the folded section will not be grouped into a separate JSON object upon submission.
48+
</st:attribute>
4649
<st:attribute name="help">
4750
If specified, the (?) help icon will be rendered on the right,
4851
for in place help text. See &lt;f:entry> for the details.
4952
</st:attribute>
5053
</st:documentation>
5154

52-
<tr class="radio-block-start" hasHelp="${attrs.help!=null}"><!-- this ID marks the beginning -->
55+
<tr class="radio-block-start ${attrs.inline?'':'row-set-start'}" hasHelp="${attrs.help!=null}"><!-- this ID marks the beginning -->
5356
<td colspan="3">
5457
<input type="radio" name="${name}" value="${value}"
5558
class="radio-block-control" checked="${checked?'true':null}" />
@@ -66,5 +69,5 @@ THE SOFTWARE.
6669
</j:if>
6770
<d:invokeBody />
6871
<!-- end marker -->
69-
<tr class="radio-block-end" style="display:none" />
72+
<tr class="${attrs.inline?'':'row-set-end'} radio-block-end" style="display:none" />
7073
</j:jelly>

war/src/main/webapp/scripts/hudson-behavior.js

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,54 @@ var hudsonRules = {
877877
e.setAttribute("ref", checkbox.id = "cb"+(iota++));
878878
},
879879

880+
// radioBlock.jelly
881+
"INPUT.radio-block-control" : function(r) {
882+
r.id = "radio-block-"+(iota++);
883+
884+
// when one radio button is clicked, we need to update foldable block for
885+
// other radio buttons with the same name. To do this, group all the
886+
// radio buttons with the same name together and hang it under the form object
887+
var f = r.form;
888+
var radios = f.radios;
889+
if (radios == null)
890+
f.radios = radios = {};
891+
892+
var g = radios[r.name];
893+
if (g == null) {
894+
radios[r.name] = g = object(radioBlockSupport);
895+
g.buttons = [];
896+
}
897+
898+
var s = findAncestorClass(r,"radio-block-start");
899+
s.setAttribute("ref", r.id);
900+
901+
// find the end node
902+
var e = (function() {
903+
var e = s;
904+
var cnt=1;
905+
while(cnt>0) {
906+
e = e.nextSibling;
907+
if (Element.hasClassName(e,"radio-block-start"))
908+
cnt++;
909+
if (Element.hasClassName(e,"radio-block-end"))
910+
cnt--;
911+
}
912+
return e;
913+
})();
914+
915+
var u = function() {
916+
g.updateSingleButton(r,s,e);
917+
};
918+
g.buttons.push(u);
919+
920+
// apply the initial visibility
921+
u();
922+
923+
// install event handlers to update visibility.
924+
// needs to use onclick and onchange for Safari compatibility
925+
r.onclick = r.onchange = function() { g.updateButtons(); };
926+
},
927+
880928
// see RowVisibilityGroupTest
881929
"TR.rowvg-start" : function(e) {
882930
// figure out the corresponding end marker
@@ -964,6 +1012,9 @@ var hudsonRules = {
9641012
}
9651013
var start = e;
9661014

1015+
// @ref on start refers to the ID of the element that controls the JSON object created from these rows
1016+
// if we don't find it, turn the start node into the governing node (thus the end result is that you
1017+
// created an intermediate JSON object that's always on.)
9671018
var ref = start.getAttribute("ref");
9681019
if(ref==null)
9691020
start.id = ref = "rowSetStart"+(iota++);
@@ -1028,54 +1079,6 @@ var hudsonRules = {
10281079
}
10291080
},
10301081

1031-
// radioBlock.jelly
1032-
"INPUT.radio-block-control" : function(r) {
1033-
r.id = "radio-block-"+(iota++);
1034-
1035-
// when one radio button is clicked, we need to update foldable block for
1036-
// other radio buttons with the same name. To do this, group all the
1037-
// radio buttons with the same name together and hang it under the form object
1038-
var f = r.form;
1039-
var radios = f.radios;
1040-
if (radios == null)
1041-
f.radios = radios = {};
1042-
1043-
var g = radios[r.name];
1044-
if (g == null) {
1045-
radios[r.name] = g = object(radioBlockSupport);
1046-
g.buttons = [];
1047-
}
1048-
1049-
var s = findAncestorClass(r,"radio-block-start");
1050-
1051-
// find the end node
1052-
var e = (function() {
1053-
var e = s;
1054-
var cnt=1;
1055-
while(cnt>0) {
1056-
e = e.nextSibling;
1057-
if (Element.hasClassName(e,"radio-block-start"))
1058-
cnt++;
1059-
if (Element.hasClassName(e,"radio-block-end"))
1060-
cnt--;
1061-
}
1062-
return e;
1063-
})();
1064-
1065-
var u = function() {
1066-
g.updateSingleButton(r,s,e);
1067-
};
1068-
applyNameRef(s,e,r.id);
1069-
g.buttons.push(u);
1070-
1071-
// apply the initial visibility
1072-
u();
1073-
1074-
// install event handlers to update visibility.
1075-
// needs to use onclick and onchange for Safari compatibility
1076-
r.onclick = r.onchange = function() { g.updateButtons(); };
1077-
},
1078-
10791082
// editableComboBox.jelly
10801083
"INPUT.combobox" : function(c) {
10811084
// Next element after <input class="combobox"/> should be <div class="combobox-values">
@@ -1348,6 +1351,10 @@ function replaceDescription() {
13481351
return false;
13491352
}
13501353

1354+
/**
1355+
* Indicates that form fields from rows [s,e) should be grouped into a JSON object,
1356+
* and attached under the element identified by the specified id.
1357+
*/
13511358
function applyNameRef(s,e,id) {
13521359
$(id).groupingNode = true;
13531360
// s contains the node itself
@@ -1684,7 +1691,7 @@ var repeatableSupport = {
16841691

16851692
// prototype object to be duplicated for each radio button group
16861693
var radioBlockSupport = {
1687-
buttons : null,
1694+
buttons : null, // set of functions, one for updating one radio block each
16881695

16891696
updateButtons : function() {
16901697
for( var i=0; i<this.buttons.length; i++ )

0 commit comments

Comments
 (0)