📄 9.clist.js
字号:
var clist = {
create:function(lsinfo,obj,name,pager,_get){
delete(_get['_P']);
delete(_get['toStr']);
delete(_get['returnValue']);
delete(_get['cancelBubble']);
baseuri = $H(_get).toQueryString();
width = clist._width(lsinfo.cols,obj.offsetWidth,lsinfo.opts);
obj.setAttribute('callback',lsinfo.callback);
var header = Builder.node('li',{className:'header'});
if(lsinfo.opts){
header.appendChild(
Builder.node('input',{type:'checkbox',className:'sel',id:'selectAll',onclick:'clist.selectAll(this)'})
);
}
lsinfo.cols.each(
function(c,k){
if(typeof(c.action)=='object'){
act = X.url($H(c.action).toQueryString());
url = '__NULL__';
}else if(typeof(c.action)=='string'){
url = c.action;
act ='__NULL__';
}else{
url = '__NULL__';
act = '__NULL__';
}
header.appendChild(Builder.node('span',{style:'width:'+width[k]+'px;',key:c.key,type:(c.type?c.type:''),edit:(c.edit?c.edit:''),'url':(url?url:url),action:act,editable:(c.editable?1:0),'click':(c.click?c.click:''),'mouseover':(c.mouseover?c.mouseover:''),'mouseout':(c.mouseout?c.mouseout:'')},[c.label]));
}
);
var tbaseHeight = Element.getStyle(obj,'height');
tbody = Builder.node('div',{className:'tbody',style:''});
if(Element.getStyle(obj,'height')!='0px'){
tbody.style.height = Element.getHeight(obj)>40?(Element.getHeight(obj) -40):300 + 'px';
}
ul = Builder.node('ul',{className:'clist'},[header,tbody]);
if(lsinfo.opts){
ul.setAttribute('opts',1);
var optbar = Builder.node('div',{className:'operation'});
for(label in lsinfo.opts){
optbar.appendChild(
Builder.node('a',{className:'button',action:X.url($H(lsinfo.opts[label]).toQueryString()),onclick:'clist.submit(this)'},[
Builder.node('label',{},
[Builder.node('b',{className:'operationadd'},label)]
)
])
);
}
obj.appendChild(optbar);
}
obj.appendChild(ul);
if(pager){
ul.parentNode.appendChild(
Builder.node('div',{className:'pagerbar'},[
Builder.node('div',{className:'pager','baseuri':baseuri,pname:name},[
Builder.node('a',{},__('Total:')+pager.count+__('item(s)')),
' ',
Builder.node('a',{className:'pagerpre',onclick:(pager.now>1?'clist.jump(this,'+pager.prev+')':'')},__('Previou')),
Builder.node('a',{},pager.now+'/'+pager.last),
Builder.node('a',{className:'pagernext',onclick:(pager.now<pager.last?'clist.jump(this,'+pager.next+')':'')},__('Next')),
Builder.node('a',{},__('Go to page')),
Builder.node('input',{className:'validate-number',style:'width:20px;float:left;margin:0 5px;',value:pager.now},[]),
Builder.node('a',{className:'searchgo',onclick:'if(this.previousSibling.value>'+pager.last+'){page='+pager.last+'}else if(this.previousSibling.value<1){page=1}else{page=this.previousSibling.value}clist.jump(this, page)'},__('go')),
])]));
}
if(lsinfo.data){
clist.full(ul,lsinfo.data);
}
},
selectAll:function(o) {
var v = o.checked ? true : false;
for(o=o.parentNode; o.tagName!='FORM'; o=o.parentNode){;}
var tag = o.getElementsByTagName('input');
for(var i=0; i<tag.length; i++){
if (tag[i].id == 'selectAll') {
continue;
}
if (tag[i].type == 'checkbox') {
tag[i].checked = v;
}
}
},
select:function(obj){
if(obj.checked){
Element.addClassName(obj.parentNode,'selected');
}else{
Element.removeClassName(obj.parentNode,'selected');
}
},
jump:function(obj,p){
for(obj=obj.parentNode;obj&&obj.className!='pager';obj=obj.parentNode){;}
X.ajax(obj.getAttribute('baseuri')+'&_P['+obj.getAttribute('pname')+']='+p);
},
click:function(obj){
},
_width:function(cols,width,hasOpt){
var wt=1;
var wa=[];
var we=[];
width-=20+15*cols.length;
if(hasOpt)width-=40;
cols.each(
function(c,k){
if(c.width){
wt -= c.width;
wa[k]=(c.width * width).toFixed(0);
}else{
we.push(k);
}
}
);
var ws = wt/we.length;
we.each(
function(e){
wa[e]=(ws * width).toFixed(0);
}
);
return wa;
},
edit:{
runtime:{iptseq:0},
init:function(e){
iptId = '_clist_editor'+clist.edit.runtime.iptseq++;
obj = Event.element(e);
for(tbody=obj.parentNode;tbody.className!='tbody';tbody=tbody.parentNode){;};
pos1 = Position.cumulativeOffset(tbody);
pos2 = Position.cumulativeOffset(obj);
clist.edit.runtime.current = obj;
clist.edit.runtime.ipt = Builder.node('input',{id:iptId,style:'border:2px solid #36c;position: absolute;left:'+(pos2[0]-pos1[0])+'px;top:'+(pos2[1]-pos1[1]+2)+'px;width:'+obj.offsetWidth+'px;',value:obj.innerHTML});
tbody.appendChild(clist.edit.runtime.ipt);
if(obj.getAttribute('type')=='date'){
new Date().datePicker(iptId,{onComplete:function(e,o){
clist.edit.finish();
}})
}else{
Event.observe(clist.edit.runtime.ipt, 'blur', clist.edit.finish, false);
}
clist.edit.runtime.ipt.focus();
},
finish:function(e){
if(clist.edit.runtime.current.innerHTML !=clist.edit.runtime.ipt.value){
clist.edit.runtime.current.innerHTML = clist.edit.runtime.ipt.value;
clist.call(clist.edit.runtime.current,'save',[clist.rowid(clist.edit.runtime.current),clist.colkey(clist.edit.runtime.current),clist.edit.runtime.ipt.value]);
}
removeElement(clist.edit.runtime.ipt);
}
},
call:function(obj,method,argv){
for(n=obj.parentNode;n.tagName!='FORM';n=n.parentNode){}
callback = eval('('+n.getAttribute('callback')+')');
if(callback){
action = callback[method];
if(action){
action.p = argv;
X.go(action);
}
}
},
rowid:function(obj){
for(n=obj.parentNode;n.tagName!='LI';n=n.parentNode){;}
return n.getAttribute('rowid');
},
colkey:function(obj){
return obj.getAttribute('key');
},
s_entry:function(e){
obj = Event.element(e);
X.ajax(X.url(obj.getAttribute('action')+'&p[0]='+clist.rowid(obj)));
},
submit:function(obj){
for(f=obj.parentNode;f&&f.tagName!='FORM';f=f.parentNode){;}
f.action = '?'+obj.getAttribute('action');
X.form.submit(f);
}
,
full:function(list,data){
lis = list.getElementsByTagName('LI');
for(var i=0;i<lis.length;i++){
if(lis[i].className!='header'){
removeElement(lis[i]);
}
}
tbody = list.getElementsByTagName('div')[0];
tbody.innerHTML='';
data.each(
function(d,i){
row = Builder.node('li',{className:(i%2==0?'row_1':'row_2')});
if(d.id)row.setAttribute('rowid',d.id);
if(list.getAttribute('opts')){
row.appendChild(Builder.node('input',{type:'checkbox',className:'sel',onclick:'clist.select(this)',value:d.id,name:'id[]'}));
}
for(var n=list.firstChild.firstChild;n;n=n.nextSibling){
if (n.tagName != 'SPAN') {
continue;
}
openHTML = true;
ckey = n.getAttribute('key');
cdata = d[ckey];
cdata = cdata?cdata:' ';
type = n.getAttribute('type');
if(type){
Element.addClassName(cell,type);
}
if(type=='input'){
cell = Builder.node('span',{style:'width:'+n.style.width,key:ckey},[
Builder.node('input',{className:'editable', style:'width:'+n.style.width,key:ckey,name:ckey+'['+d.id+']',value:cdata})
]);
}else if(type=='progressBar'){
cell = Builder.node('span',{className:'progressBar',title:(cdata*100),style:'padding-top:5px;width:'+n.style.width,key:ckey},
[Builder.node('div',{className:'base',style:'width:95%;height:5px;'},[
Builder.node('div',{className:'body',style:'width:'+(cdata*100)+'%;height:5px;'})
])]
);
}else{
if(type=='date'){
cell = Builder.node('span',{title:cdata.describe?cdata.describe:'',style:'width:'+n.style.width,key:ckey},[cdata.friendly?cdata.friendly:'']);
}else{
cell = Builder.node('span',{style:'width:'+n.style.width,key:ckey},[cdata]);
}
if(n.getAttribute('action')!='__NULL__'){
Element.addClassName(cell,'handle');
Event.observe(cell,'click', clist.s_entry, false);
cell.setAttribute('entry_id',d.id);
cell.setAttribute('action',n.getAttribute('action'));
}else if(n.getAttribute('url')!='__NULL__'){
cell.innerHTML='';
cell.appendChild(Builder.node('a',{href:clist.parseUrl(d,n.getAttribute('url')),target:'_blank'},[cdata]));
openHTML = false;
}else if(n.getAttribute('editable')==1){
Element.addClassName(cell,'editable');
cell.setAttribute('type',n.getAttribute('type'));
Event.observe(cell,'click', clist.edit.init, false);
}else if(n.getAttribute('click')!='') {
eval('func = function(){'+clist.parseUrl(d,n.getAttribute('click'))+'}');
Event.observe(cell,'click', func, false);
}
if(n.getAttribute('mouseover')!='') {
eval('func = function(e){obj = Event.element(e);'+clist.parseUrl(d,n.getAttribute('mouseover'))+'}');
Event.observe(cell,'mouseover', func, false);
}
if(n.getAttribute('mouseout')!='') {
eval('func = function(){'+clist.parseUrl(d,n.getAttribute('mouseout'))+'}');
Event.observe(cell,'mouseout', func, false);
}
}
if (openHTML) {
//Alex comment in 2007.10.30
//cell.innerHTML = cdata;
}
row.appendChild(cell);
}
tbody.appendChild(row);
}
)
},
parseUrl:function(d,u){
for(a in d){
u = u.replace(new RegExp('%'+a+'%',"gm"),d[a]);
}
return u;
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -