mirror of https://github.com/jenkinsci/jenkins.git
[FIXED HUDSON-2781] This appears to be already fixed by brucechapman in rev.14235.
I tweaked the script a bit to avoid global scope corruption. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@14385 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
parent
0d98e72f40
commit
d46586fb87
|
|
@ -25,42 +25,17 @@
|
|||
name ="${h.defaulted(attrs.name,'_.'+attrs.field)}"
|
||||
value="${h.defaulted(attrs.value,instance[attrs.field])}"
|
||||
checkUrl="${checkUrl}" />
|
||||
<j:set target="${requestScope}" property="editableComboBoxCount" value="${editableComboBoxCount + 1}" defaultValue="1" />
|
||||
<j:set var="uniqid" value="${id + editableComboBoxCount}" />
|
||||
<j:set target="${requestScope}" property="editableComboBox" value="${uniqid}" />
|
||||
<script type="text/javascript">
|
||||
var ${uniqid}_values = new Array();
|
||||
|
||||
<!-- fill in values -->
|
||||
<j:if test="${items!=null}">
|
||||
<j:forEach var="v" items="${items}">
|
||||
<f:editableComboBoxValue value="${v}" />
|
||||
</j:forEach>
|
||||
</j:if>
|
||||
<d:invokeBody />
|
||||
|
||||
<![CDATA[
|
||||
function ${uniqid}_Callback(value /*, comboBox*/) {
|
||||
var items = new Array();
|
||||
var candidates = ${uniqid}_values;
|
||||
if (value.length > 0) { // if no value, we'll not provide anything
|
||||
value = value.toLowerCase();
|
||||
for (var i = 0; i < candidates.length; i++) {
|
||||
if (candidates[i].toLowerCase().indexOf(value) >= 0) {
|
||||
items.push(candidates[i]);
|
||||
if(items.length>20)
|
||||
break; // 20 items in the list should be enough
|
||||
}
|
||||
}
|
||||
}
|
||||
return items; // equiv to: comboBox.setItems(items);
|
||||
}
|
||||
]]>
|
||||
|
||||
<!-- IE doesn't like a combobox to be created before the page is fully loaded. -->
|
||||
var oldOnLoadFor${uniqid} = window.onload;
|
||||
window.onload = function() { if(oldOnLoadFor${uniqid}) oldOnLoadFor${uniqid}();
|
||||
new ComboBox("${id}", ${uniqid}_Callback);
|
||||
}
|
||||
createComboBox("${id}",function() {
|
||||
var values = [];
|
||||
<!-- fill in values -->
|
||||
<j:if test="${items!=null}">
|
||||
<j:forEach var="v" items="${items}">
|
||||
<f:editableComboBoxValue value="${v}" />
|
||||
</j:forEach>
|
||||
</j:if>
|
||||
<d:invokeBody />
|
||||
return values;
|
||||
});
|
||||
</script>
|
||||
</j:jelly>
|
||||
|
|
@ -1,6 +1,11 @@
|
|||
<!--
|
||||
<%@attribute name="value" required="true" %>
|
||||
-->
|
||||
<j:jelly xmlns:j="jelly:core">
|
||||
${editableComboBox}_values.push("${value}");
|
||||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
|
||||
<st:documentation>
|
||||
Used inside <f:editableComboBox/> to specify one value of a combobox.
|
||||
Normally one would use multiple values.
|
||||
<st:attribute name="value" use="required" />
|
||||
</st:documentation>
|
||||
values.push("${value}");
|
||||
</j:jelly>
|
||||
|
|
@ -1465,3 +1465,31 @@ function validateButton(checkUrl,paramList,button) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
// create a combobox.
|
||||
// @param id
|
||||
// ID of the <input type=text> element that becomes a combobox.
|
||||
// @param valueFunction
|
||||
// Function that returns all the candidates as an array
|
||||
function createComboBox(id,valueFunction) {
|
||||
var candidates = valueFunction();
|
||||
|
||||
Behaviour.addLoadEvent(function() {
|
||||
var callback = function(value /*, comboBox*/) {
|
||||
var items = new Array();
|
||||
if (value.length > 0) { // if no value, we'll not provide anything
|
||||
value = value.toLowerCase();
|
||||
for (var i = 0; i<candidates.length; i++) {
|
||||
if (candidates[i].toLowerCase().indexOf(value) >= 0) {
|
||||
items.push(candidates[i]);
|
||||
if(items.length>20)
|
||||
break; // 20 items in the list should be enough
|
||||
}
|
||||
}
|
||||
}
|
||||
return items; // equiv to: comboBox.setItems(items);
|
||||
};
|
||||
|
||||
new ComboBox(id,callback);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue