提交 8a35f451 编写于 作者: K kohsuke

improved the <f:repeated> tag support for better UI experience.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@2669 71c3de6d-444a-0410-be80-ed276b4c234a
上级 eedcb9c1
......@@ -540,4 +540,17 @@ TABLE.fingerprint-in-build TD {
background-position: center left;
padding-left: 32px;
}
*/
\ No newline at end of file
*/
/* ========================= repeatable elements ========================= */
.repeated-chunk .show-if-last { display: none; }
.repeated-chunk.last .show-if-last { display: inline; }
.repeated-chunk .show-if-not-last { display: inline; }
.repeated-chunk.last .show-if-not-last { display: none; }
.repeated-chunk .show-if-not-only { display: inline; }
.repeated-chunk.only .show-if-not-only { display: none; }
// create a new object whose prototype is the given object
function object(o) {
function F() {}
F.prototype = o;
return new F();
}
// id generator
var iota = 0;
......@@ -163,7 +170,21 @@ var hudsonRules = {
}
}
);
}
},
// button to add a new repeatable block
"INPUT.repeatable-add" : function(e) {
e.onclick = function() {
repetableSupport.onAdd(this);
};
},
"INPUT.repeatable-delete" : function(e) {
e.onclick = function() {
repetableSupport.onDelete(this);
};
}
};
Behaviour.register(hudsonRules);
......@@ -399,4 +420,77 @@ function updateDropDownList(sel) {
td = td.nextSibling;
}
}
}
\ No newline at end of file
}
// code for supporting repeatable.jelly
var repetableSupport = {
// set by the inherited instance to the insertion point DIV
insertionPoint: null,
// HTML text of the repeated chunk
blockHTML: null,
// containing <div>.
container: null,
// do the initialization
init : function(container,master,insertionPoint) {
this.container = $(container);
this.container.tag = this;
master = $(master);
this.blockHTML = master.innerHTML;
master.parentNode.removeChild(master);
this.insertionPoint = $(insertionPoint);
this.update();
},
// insert one more block at the insertion position
expand : function() {
// importNode isn't supported in IE.
// nc = document.importNode(node,true);
var nc = document.createElement("div");
nc.className = "repeated-chunk";
nc.innerHTML = this.blockHTML;
this.insertionPoint.parentNode.insertBefore(nc, this.insertionPoint);
Behaviour.applySubtree(nc);
this.update();
},
// update CSS classes associated with repeated items.
update : function() {
var children = [];
for( var n=this.container.firstChild; n!=null; n=n.nextSibling )
if(Element.hasClassName(n,"repeated-chunk"))
children.push(n);
if(children.length==1) {
children[0].className = "repeated-chunk first last only";
} else {
children[0].className = "repeated-chunk first";
for(var i=1; i<children.length-1; i++)
children[i].className = "repeated-chunk middle";
children[children.length-1].className = "repeated-chunk last";
}
},
// these are static methods that don't rely on 'this'
// called when 'delete' button is clicked
onDelete : function(n) {
while (!Element.hasClassName(n,"repeated-chunk"))
n = n.parentNode;
var p = n.parentNode;
p.removeChild(n);
p.tag.update();
},
// called when 'add' button is clicked
onAdd : function(n) {
while(n.tag==null)
n = n.parentNode;
n.tag.expand();
}
};
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册