提交 b0f664df 编写于 作者: K kohsuke

improved construction of query string.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@30447 71c3de6d-444a-0410-be80-ed276b4c234a
上级 b03e53a1
......@@ -285,7 +285,7 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
if(method==null)
return NONE;
return singleQuote(getDescriptorUrl() +"/check"+capitalizedFieldName+"?") + buildParameterList(method, new StringBuilder());
return singleQuote(getDescriptorUrl() +"/check"+capitalizedFieldName) + buildParameterList(method, new StringBuilder()).append(".toString()");
}
/**
......@@ -300,13 +300,13 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
if (name==null || name.length()==0)
continue; // unknown parameter name. we'll report the error when the form is submitted.
if (query.length()>0) query.append('+').append(singleQuote("&"));
if (query.length()==0) query.append("+qs(this)");
if (name.equals("value")) {
// The special 'value' parameter binds to the the current field
query.append('+').append(singleQuote("value=")).append("+toValue(this)");
query.append(".addThis()");
} else {
query.append('+').append(singleQuote(name+'=')).append("+toValue(findNearBy(this,'"+name+"'))");
query.append(".nearBy('"+name+"')");
}
continue;
}
......
......@@ -160,6 +160,7 @@ function findNearBy(e,name) {
}
function controlValue(e) {
if (e==null) return null;
// compute the form validation value to be sent to the server
var type = e.getAttribute("type");
if(type!=null && type.toLowerCase()=="checkbox")
......@@ -171,6 +172,38 @@ function toValue(e) {
return encodeURIComponent(controlValue(e));
}
/**
* Builds a query string in a fluent API pattern.
* @param {HTMLElement} owner
* The 'this' control.
*/
function qs(owner) {
return {
params : "",
append : function(s) {
if (this.params.length==0) this.params+='?';
else this.params+='&';
this.params += s;
return this;
},
nearBy : function(name) {
var e = findNearBy(owner,name);
if (e==null) return this; // skip
return this.append(name+'='+toValue(e));
},
addThis : function() {
return this.append("value="+toValue(owner));
},
toString : function() {
return this.params;
}
};
}
// find the nearest ancestor node that has the given tag name
function findAncestor(e, tagName) {
do {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册