1 function rcube_list_widget(_1,p){
12 this.multiselect=false;
13 this.multi_selecting=false;
16 this.toggleselect=false;
17 this.dont_select=false;
18 this.drag_active=false;
21 this.in_selection_before=false;
23 this.drag_mouse_start=null;
24 this.dblclick_time=600;
25 this.row_init=function(){
27 if(p&&typeof (p)=="object"){
33 rcube_list_widget.prototype={init:function(){
34 if(this.list&&this.list.tBodies[0]){
35 this.rows=new Array();
38 for(var r=0;r<this.list.tBodies[0].childNodes.length;r++){
39 _4=this.list.tBodies[0].childNodes[r];
40 while(_4&&(_4.nodeType!=1||_4.style.display=="none")){
47 this.frame=this.list.parentNode;
49 rcube_event.add_listener({element:document,event:bw.opera?"keypress":"keydown",object:this,method:"key_press"});
50 rcube_event.add_listener({element:document,event:"keydown",object:this,method:"key_down"});
53 },init_row:function(_6){
54 if(_6&&String(_6.id).match(/rcmrow([a-z0-9\-_=\+\/]+)/i)){
58 this.rows[_8]={uid:_8,id:_6.id,obj:_6,classname:_6.className};
59 _6.onmousedown=function(e){
60 return p.drag_row(e,this.uid);
62 _6.onmouseup=function(e){
63 return p.click_row(e,this.uid);
66 _6.onselectstart=function(){
70 this.row_init(this.rows[_8]);
73 var _c=document.createElement("tbody");
74 this.list.insertBefore(_c,this.list.tBodies[0]);
75 this.list.removeChild(this.list.tBodies[1]);
76 this.rows=new Array();
79 this.clear_selection();
81 },remove_row:function(_d,_e){
82 if(this.rows[_d].obj){
83 this.rows[_d].obj.style.display="none";
90 },insert_row:function(_f,_10){
92 var _11=this.background;
94 var _11=this.list.tBodies[0];
96 if(_10&&_11.rows.length){
97 _11.insertBefore(_f,_11.firstChild);
105 for(var n=0;n<this.selection.length;n++){
106 id=this.selection[n];
107 if(this.rows[id]&&this.rows[id].obj){
108 $(this.rows[id].obj).addClass("selected").removeClass("unfocused");
111 if(e||(e=window.event)){
112 rcube_event.cancel(e);
117 for(var n=0;n<this.selection.length;n++){
118 id=this.selection[n];
119 if(this.rows[id]&&this.rows[id].obj){
120 $(this.rows[id].obj).removeClass("selected").addClass("unfocused");
123 },drag_row:function(e,id){
124 var _18=rcube_event.get_target(e);
125 var _19=_18.tagName.toLowerCase();
126 if(this.dont_select||(_18&&(_19=="input"||_19=="img"))){
129 if(rcube_event.get_button(e)==2){
132 this.in_selection_before=this.in_selection(id)?id:false;
133 if(!this.in_selection_before){
134 var _1a=rcube_event.get_modifier(e);
135 this.select_row(id,_1a,false);
137 if(this.draggable&&this.selection.length){
138 this.drag_start=true;
139 this.drag_mouse_start=rcube_event.get_mouse_pos(e);
140 rcube_event.add_listener({element:document,event:"mousemove",object:this,method:"drag_mouse_move"});
141 rcube_event.add_listener({element:document,event:"mouseup",object:this,method:"drag_mouse_up"});
142 var _1b=document.getElementsByTagName("iframe");
143 this.iframe_events=Object();
146 if(_1b[n].contentDocument){
147 _1d=_1b[n].contentDocument;
149 if(_1b[n].contentWindow){
150 _1d=_1b[n].contentWindow.document;
159 var pos=$("#"+_1b[n].id).offset();
160 this.iframe_events[n]=function(e){
162 return _1e.drag_mouse_move(e);
164 if(_1d.addEventListener){
165 _1d.addEventListener("mousemove",this.iframe_events[n],false);
167 if(_1b[n].attachEvent){
168 _1d.attachEvent("onmousemove",this.iframe_events[n]);
170 _1d["onmousemove"]=this.iframe_events[n];
173 rcube_event.add_listener({element:_1d,event:"mouseup",object:this,method:"drag_mouse_up"});
178 },click_row:function(e,id){
179 var now=new Date().getTime();
180 var _24=rcube_event.get_modifier(e);
181 var _25=rcube_event.get_target(e);
182 var _26=_25.tagName.toLowerCase();
183 if((_25&&(_26=="input"||_26=="img"))){
186 if(this.dont_select){
187 this.dont_select=false;
190 var _27=now-this.rows[id].clicked<this.dblclick_time;
191 if(!this.drag_active&&this.in_selection_before==id&&!_27){
192 this.select_row(id,_24,false);
194 this.drag_start=false;
195 this.in_selection_before=false;
196 if(this.rows&&_27&&this.in_selection(id)){
197 this.triggerEvent("dblclick");
199 this.triggerEvent("click");
201 if(!this.drag_active){
202 rcube_event.cancel(e);
204 this.rows[id].clicked=now;
206 },get_next_row:function(){
210 var _28=this.rows[this.last_selected];
211 var _29=_28?_28.obj.nextSibling:null;
212 while(_29&&(_29.nodeType!=1||_29.style.display=="none")){
216 },get_prev_row:function(){
220 var _2a=this.rows[this.last_selected];
221 var _2b=_2a?_2a.obj.previousSibling:null;
222 while(_2b&&(_2b.nodeType!=1||_2b.style.display=="none")){
223 _2b=_2b.previousSibling;
226 },get_first_row:function(){
228 var _2c=this.list.tBodies[0].rows;
229 for(var i=0;i<_2c.length-1;i++){
230 if(_2c[i].id&&String(_2c[i].id).match(/rcmrow([a-z0-9\-_=\+\/]+)/i)&&this.rows[RegExp.$1]!=null){
236 },get_last_row:function(){
238 var _2e=this.list.tBodies[0].rows;
239 for(var i=_2e.length-1;i>=0;i--){
240 if(_2e[i].id&&String(_2e[i].id).match(/rcmrow([a-z0-9\-_=\+\/]+)/i)&&this.rows[RegExp.$1]!=null){
246 },select_row:function(id,_31,_32){
247 var _33=this.selection.join(",");
248 if(!this.multiselect){
251 if(!this.shift_start){
256 this.highlight_row(id,false);
257 this.multi_selecting=false;
261 this.shift_select(id,false);
265 this.highlight_row(id,true);
268 case CONTROL_SHIFT_KEY:
269 this.shift_select(id,true);
272 this.highlight_row(id,false);
275 this.multi_selecting=true;
277 if(this.selection.join(",")!=_33){
278 this.triggerEvent("select");
280 if(this.last_selected!=0&&this.rows[this.last_selected]){
281 $(this.rows[this.last_selected].obj).removeClass("focused");
283 if(this.toggleselect&&this.last_selected==id){
284 this.clear_selection();
287 $(this.rows[id].obj).addClass("focused");
289 if(!this.selection.length){
290 this.shift_start=null;
292 this.last_selected=id;
293 },select:function(id){
294 this.select_row(id,false);
296 },select_next:function(){
297 var _35=this.get_next_row();
298 var _36=this.get_prev_row();
299 var _37=(_35)?_35:_36;
301 this.select_row(_37.uid,false,false);
303 },select_first:function(){
304 var _38=this.get_first_row();
306 this.select_row(_38,false,false);
308 },shift_select:function(id,_3a){
309 if(!this.rows[this.shift_start]||!this.selection.length){
312 var _3b=this.rows[this.shift_start].obj.rowIndex;
313 var _3c=this.rows[id].obj.rowIndex;
314 var i=((_3b<_3c)?_3b:_3c);
315 var j=((_3b>_3c)?_3b:_3c);
316 for(var n in this.rows){
317 if((this.rows[n].obj.rowIndex>=i)&&(this.rows[n].obj.rowIndex<=j)){
318 if(!this.in_selection(n)){
319 this.highlight_row(n,true);
322 if(this.in_selection(n)&&!_3a){
323 this.highlight_row(n,true);
327 },in_selection:function(id){
328 for(var n in this.selection){
329 if(this.selection[n]==id){
334 },select_all:function(_42){
335 if(!this.rows||!this.rows.length){
338 var _43=this.selection.join(",");
339 this.selection=new Array();
340 for(var n in this.rows){
341 if(!_42||(this.rows[n]&&this.rows[n][_42]==true)){
342 this.last_selected=n;
343 this.highlight_row(n,true);
346 $(this.rows[n].obj).removeClass("selected").removeClass("unfocused");
350 if(this.selection.join(",")!=_43){
351 this.triggerEvent("select");
355 },invert_selection:function(){
356 if(!this.rows||!this.rows.length){
359 var _45=this.selection.join(",");
360 for(var n in this.rows){
361 this.highlight_row(n,true);
363 if(this.selection.join(",")!=_45){
364 this.triggerEvent("select");
368 },clear_selection:function(id){
369 var _48=this.selection.length;
371 for(var n=0;n<this.selection.length;n++){
372 if(this.selection[n]==id){
373 this.selection.splice(n,1);
378 for(var n=0;n<this.selection.length;n++){
379 if(this.rows[this.selection[n]]){
380 $(this.rows[this.selection[n]].obj).removeClass("selected").removeClass("unfocused");
383 this.selection=new Array();
385 if(_48&&!this.selection.length){
386 this.triggerEvent("select");
388 },get_selection:function(){
389 return this.selection;
390 },get_single_selection:function(){
391 if(this.selection.length==1){
392 return this.selection[0];
396 },highlight_row:function(id,_4b){
397 if(this.rows[id]&&!_4b){
398 if(this.selection.length>1||!this.in_selection(id)){
399 this.clear_selection();
400 this.selection[0]=id;
401 $(this.rows[id].obj).addClass("selected");
405 if(!this.in_selection(id)){
406 this.selection[this.selection.length]=id;
407 $(this.rows[id].obj).addClass("selected");
409 var p=find_in_array(id,this.selection);
410 var _4d=this.selection.slice(0,p);
411 var _4e=this.selection.slice(p+1,this.selection.length);
412 this.selection=_4d.concat(_4e);
413 $(this.rows[id].obj).removeClass("selected").removeClass("unfocused");
417 },key_press:function(e){
418 if(this.focused!=true){
421 var _50=rcube_event.get_keycode(e);
422 var _51=rcube_event.get_modifier(e);
428 rcube_event.cancel(e);
429 return this.use_arrow_key(_50,_51);
431 this.shiftkey=e.shiftKey;
432 this.key_pressed=_50;
433 this.triggerEvent("keypress");
434 if(this.key_pressed==this.BACKSPACE_KEY){
435 return rcube_event.cancel(e);
439 },key_down:function(e){
440 switch(rcube_event.get_keycode(e)){
442 if(this.drag_active){
443 return this.drag_mouse_up(e);
449 if(!rcube_event.get_modifier(e)&&this.focused){
450 return rcube_event.cancel(e);
455 },use_arrow_key:function(_53,_54){
457 if(_53==40||_53==63233){
458 _55=this.get_next_row();
460 if(_53==38||_53==63232){
461 _55=this.get_prev_row();
465 this.select_row(_55.uid,_54,true);
466 this.scrollto(_55.uid);
469 },scrollto:function(id){
470 var row=this.rows[id].obj;
472 var _58=Number(row.offsetTop);
473 if(_58<Number(this.frame.scrollTop)){
474 this.frame.scrollTop=_58;
476 if(_58+Number(row.offsetHeight)>Number(this.frame.scrollTop)+Number(this.frame.offsetHeight)){
477 this.frame.scrollTop=(_58+Number(row.offsetHeight))-Number(this.frame.offsetHeight);
481 },drag_mouse_move:function(e){
483 var m=rcube_event.get_mouse_pos(e);
484 if(!this.drag_mouse_start||(Math.abs(m.x-this.drag_mouse_start.x)<3&&Math.abs(m.y-this.drag_mouse_start.y)<3)){
488 this.draglayer=$("<div>").attr("id","rcmdraglayer").css({position:"absolute",display:"none","z-index":2000}).appendTo(document.body);
492 for(var n=0;n<this.selection.length;n++){
497 if(this.rows[this.selection[n]].obj){
498 obj=this.rows[this.selection[n]].obj;
500 for(c=0,i=0;i<obj.childNodes.length;i++){
501 if(obj.childNodes[i].nodeName=="TD"){
502 if(((_5e=obj.childNodes[i].firstChild)&&(_5e.nodeType==3||_5e.nodeName=="A"))&&(this.subject_col<0||(this.subject_col>=0&&this.subject_col==c))){
505 this.drag_start_pos=$(obj.childNodes[i]).offset();
507 this.drag_start_pos=$(_5e).offset();
510 _5f=_5e.nodeType==3?_5e.data:_5e.innerHTML;
511 _5f=_5f.replace(/^\s+/i,"");
512 _5b+=(_5f.length>50?_5f.substring(0,50)+"...":_5f)+"<br />";
520 this.draglayer.html(_5b);
521 this.draglayer.show();
522 this.drag_active=true;
523 this.triggerEvent("dragstart");
525 if(this.drag_active&&this.draglayer){
526 var pos=rcube_event.get_mouse_pos(e);
527 this.draglayer.css({left:(pos.x+20)+"px",top:(pos.y-5+(bw.ie?document.documentElement.scrollTop:0))+"px"});
528 this.triggerEvent("dragmove",e?e:window.event);
530 this.drag_start=false;
532 },drag_mouse_up:function(e){
533 document.onmousemove=null;
534 if(this.draglayer&&this.draglayer.is(":visible")){
535 if(this.drag_start_pos){
536 this.draglayer.animate(this.drag_start_pos,300,"swing").hide(20);
538 this.draglayer.hide();
541 this.drag_active=false;
542 this.triggerEvent("dragend");
543 rcube_event.remove_listener({element:document,event:"mousemove",object:this,method:"drag_mouse_move"});
544 rcube_event.remove_listener({element:document,event:"mouseup",object:this,method:"drag_mouse_up"});
545 var _64=document.getElementsByTagName("iframe");
548 if(_64[n].contentDocument){
549 _66=_64[n].contentDocument;
551 if(_64[n].contentWindow){
552 _66=_64[n].contentWindow.document;
560 if(this.iframe_events[n]){
561 if(_66.removeEventListener){
562 _66.removeEventListener("mousemove",this.iframe_events[n],false);
565 _66.detachEvent("onmousemove",this.iframe_events[n]);
567 _66["onmousemove"]=null;
571 rcube_event.remove_listener({element:_66,event:"mouseup",object:this,method:"drag_mouse_up"});
574 return rcube_event.cancel(e);
575 },set_background_mode:function(_67){
577 this.background=document.createElement("tbody");
580 this.list.replaceChild(this.background,this.list.tBodies[0]);
581 this.background=null;
585 rcube_list_widget.prototype.addEventListener=rcube_event_engine.prototype.addEventListener;
586 rcube_list_widget.prototype.removeEventListener=rcube_event_engine.prototype.removeEventListener;
587 rcube_list_widget.prototype.triggerEvent=rcube_event_engine.prototype.triggerEvent;