From dd456159b4796b8d0b8db76ac988d56737e4bc2c Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Wed, 3 Aug 2011 16:09:14 +0200 Subject: [ADD] Updated dhtmlxSheduler to version 3.0. (Fixed dhtmlx core initialization) bzr revid: fme@openerp.com-20110803140914-5qjtozi94i4ruica --- .../codebase/dhtmlxscheduler_debug.js | 885 +++++++++++++++------ 1 file changed, 630 insertions(+), 255 deletions(-) (limited to 'addons/base_calendar/static/lib/dhtmlxScheduler/codebase/dhtmlxscheduler_debug.js') diff --git a/addons/base_calendar/static/lib/dhtmlxScheduler/codebase/dhtmlxscheduler_debug.js b/addons/base_calendar/static/lib/dhtmlxScheduler/codebase/dhtmlxscheduler_debug.js index a3c14bee033..6b2e961051c 100644 --- a/addons/base_calendar/static/lib/dhtmlxScheduler/codebase/dhtmlxscheduler_debug.js +++ b/addons/base_calendar/static/lib/dhtmlxScheduler/codebase/dhtmlxscheduler_debug.js @@ -1,11 +1,38 @@ -/* -dhtmlxScheduler v.2.3 - +/* This software is allowed to use under GPL or you need to obtain Commercial or Enterise License -to use it in not GPL project. Please contact sales@dhtmlx.com for details +to use it in not GPL project. Please contact sales@dhtmlx.com for details +*/ + +window.dhtmlx || (dhtmlx=function(obj){ + for (var a in obj) dhtmlx[a]=obj[a]; + return dhtmlx; //simple singleton +}) +dhtmlx.extend_api=function(name,map,ext){ + var t = window[name]; + if (!t) return; //component not defined + window[name]=function(obj){ + if (obj && typeof obj == "object" && !obj.tagName && !(obj instanceof Array)){ + var that = t.apply(this,(map._init?map._init(obj):arguments)); + //global settings + for (var a in dhtmlx) + if (map[a]) this[map[a]](dhtmlx[a]); + //local settings + for (var a in obj){ + if (map[a]) this[map[a]](obj[a]); + else if (a.indexOf("on")==0){ + this.attachEvent(a,obj[a]); + } + } + } else + var that = t.apply(this,arguments); + if (map._patch) map._patch(this); + return that||this; + }; + window[name].prototype=t.prototype; + if (ext) + dhtmlXHeir(window[name].prototype,ext); +}; -(c) DHTMLX Ltd. -*/ dhtmlxAjax={ get:function(url,callback){ var t=new dtmlXMLLoaderObject(true); @@ -554,12 +581,15 @@ dhtmlDragAndDropObject.prototype.initFrameRoute=function(win, mode){ } } -var _isFF = false; -var _isIE = false; -var _isOpera = false; -var _isKHTML = false; -var _isMacOS = false; -var _isChrome = false; +_isFF = false; +_isIE = false; +_isOpera = false; +_isKHTML = false; +_isMacOS = false; +_isChrome = false; +_KHTMLrv = false; +_OperaRv = false; +_FFrv = false; if (navigator.userAgent.indexOf('Macintosh') != -1) _isMacOS=true; @@ -876,8 +906,14 @@ dhtmlxEventable=function(obj){ this[list[0]].removeEvent(list[1]); //remove event } } + obj.detachAllEvents = function(){ + for (var name in this){ + if (name.indexOf("ev_")==0) + delete this[name]; + } + } } - + /** * @desc: constructor, data processor object * @param: serverProcessorURL - url used for update @@ -1242,6 +1278,8 @@ dataProcessor.prototype={ var soid = sid; switch (action) { + case "update": + case "updated": case "inserted": case "insert": if (tid != sid) { @@ -1458,7 +1496,7 @@ dataProcessor.prototype={ }; -//(c)dhtmlx ltd. www.dhtmlx.com +//(c)dhtmlx ltd. www.dhtmlx.com dataProcessor.prototype._o_init = dataProcessor.prototype.init; dataProcessor.prototype.init=function(obj){ this._console=this._console||this._createConsole(); @@ -1547,7 +1585,7 @@ dataProcessor.wrap("sendData",function(rowId){ if (!this.obj._idpull[rowId]) this._log(" Error! item with such ID not exists "+rowId+""); } else { - if (!this.obj.rowsAr[rowId]) + if (this.rowsAr && !this.obj.rowsAr[rowId]) this._log(" Error! row with such ID not exists "+rowId+""); } } @@ -1611,7 +1649,7 @@ dataProcessor.wrap("afterUpdateCallback",function(sid,tid,action){ if (this.obj.mytype=="tree"){ if (!this.obj._idpull[sid]) this._log("Incorrect SID, item with such ID not exists in grid"); } else { - if (!this.obj.rowsAr[sid]) this._log("Incorrect SID, row with such ID not exists in grid"); + if (this.obj.rowsAr && !this.obj.rowsAr[sid]) this._log("Incorrect SID, row with such ID not exists in grid"); } this._log(" Action: "+action+" SID:"+sid+" TID:"+tid); },function(){ @@ -1623,7 +1661,7 @@ dataProcessor.wrap("afterUpdateCallback",function(sid,tid,action){ - + /* dhx_sort[index]=direction dhx_filter[index]=mask @@ -1633,10 +1671,10 @@ if (window.dhtmlXGridObject){ dhtmlXGridObject.prototype._init_point=function(){ var clear_url=function(url){ url=url.replace(/(\?|\&)connector[^\f]*/g,""); - return url+(url.indexOf("?")!=-1?"&":"?")+"connector=true"+(mygrid.hdr.rows.length > 0 ? "&dhx_no_header=1":""); + return url+(url.indexOf("?")!=-1?"&":"?")+"connector=true"+(this.hdr.rows.length > 0 ? "&dhx_no_header=1":""); }; var combine_urls=function(url){ - return clear_url(url)+(this._connector_sorting||"")+(this._connector_filter||""); + return clear_url.call(this,url)+(this._connector_sorting||"")+(this._connector_filter||""); }; var sorting_url=function(url,ind,dir){ this._connector_sorting="&dhx_sort["+ind+"]="+dir; @@ -1738,14 +1776,10 @@ if (window.dhtmlXGridObject){ } if (this._con_f_used[f*1]) this._con_f_used[f*1]=v; - }; + } this._colls_loaded=true; } - }; - - - - + }; } if (window.dataProcessor){ @@ -1757,16 +1791,20 @@ if (window.dataProcessor){ this.setTransactionMode("POST",true); this.serverProcessor+=(this.serverProcessor.indexOf("?")!=-1?"&":"?")+"editing=true"; }; -}; +} dhtmlxError.catchError("LoadXML",function(a,b,c){ - alert(c[0].responseText); + if (c[0].status != 0) { + alert(c[0].responseText); + } }); - -window.dhtmlXScheduler=window.scheduler={version:2.2}; + +window.dhtmlXScheduler=window.scheduler={version:3.0}; dhtmlxEventable(scheduler); scheduler.init=function(id,date,mode){ date=date||(new Date()); mode=mode||"week"; + + scheduler.date.init(); this._obj=(typeof id == "string")?document.getElementById(id):id; this._els=[]; @@ -1783,9 +1821,9 @@ scheduler.init=function(id,date,mode){ if (scheduler.callEvent("onSchedulerResize",[])) scheduler.update_view(); }, 100); - }) - + }); this.set_sizes(); + scheduler.callEvent('onSchedulerReady', []); this.setCurrentView(date,mode); }; scheduler.xy={ @@ -1821,7 +1859,7 @@ scheduler.set_sizes=function(){ var data_y=this.xy.scale_height+this.xy.nav_height+(this._quirks?-2:0); this.set_xy(this._els["dhx_cal_data"][0],w,h-(data_y+2),0,data_y+2); -} +}; scheduler.set_xy=function(node,w,h,x,y){ node.style.width=Math.max(0,w)+"px"; node.style.height=Math.max(0,h)+"px"; @@ -1829,7 +1867,7 @@ scheduler.set_xy=function(node,w,h,x,y){ node.style.left=x+"px"; node.style.top=y+"px"; } -} +}; scheduler.get_elements=function(){ //get all child elements as named hash var els=this._obj.getElementsByTagName("DIV"); @@ -1842,26 +1880,26 @@ scheduler.get_elements=function(){ var t=scheduler.locale.labels[els[i].getAttribute("name")||name]; if (t) els[i].innerHTML=t; } -} +}; scheduler.set_actions=function(){ for (var a in this._els) if (this._click[a]) for (var i=0; i < this._els[a].length; i++) this._els[a][i].onclick=scheduler._click[a]; - this._obj.onselectstart=function(e){ return false; } + this._obj.onselectstart=function(e){ return false; }; this._obj.onmousemove=function(e){ scheduler._on_mouse_move(e||event); - } + }; this._obj.onmousedown=function(e){ scheduler._on_mouse_down(e||event); - } + }; this._obj.onmouseup=function(e){ scheduler._on_mouse_up(e||event); - } + }; this._obj.ondblclick=function(e){ scheduler._on_dbl_click(e||event); } -} +}; scheduler.select=function(id){ if (this._table_view || !this.getEvent(id)._timed) return; //temporary block if (this._select_id==id) return; @@ -1869,13 +1907,13 @@ scheduler.select=function(id){ this.unselect(); this._select_id = id; this.updateEvent(id); -} +}; scheduler.unselect=function(id){ if (id && id!=this._select_id) return; var t=this._select_id; this._select_id = null; if (t) this.updateEvent(t); -} +}; scheduler.getState=function(){ return { mode: this._mode, @@ -1883,11 +1921,13 @@ scheduler.getState=function(){ min_date: this._min_date, max_date: this._max_date, editor_id: this._edit_id, - lightbox_id: this._lightbox_id + lightbox_id: this._lightbox_id, + new_event: this._new_event }; -} +}; scheduler._click={ dhx_cal_data:function(e){ + //debugger; var trg = e?e.target:event.srcElement; var id = scheduler._locate_event(trg); @@ -1913,7 +1953,8 @@ scheduler._click={ scheduler.setCurrentView(new Date()); }, dhx_cal_tab:function(){ - var mode = this.getAttribute("name").split("_")[0]; + var name = this.getAttribute("name"); + var mode = name.substring(0, name.search("_tab")); scheduler.setCurrentView(scheduler._date,mode); }, buttons:{ @@ -1923,11 +1964,10 @@ scheduler._click={ details:function(id){ scheduler.showLightbox(id); }, cancel:function(id){ scheduler.editStop(false); } } -} - +}; scheduler.addEventNow=function(start,end,e){ var base = {}; - if (typeof start == "object"){ + if (start && start.constructor.toString().match(/object/i) !== null){ base = start; start = null; } @@ -1943,14 +1983,18 @@ scheduler.addEventNow=function(start,end,e){ } end = start+d; } - - + var end_date = new Date(end); + + // scheduler.addEventNow(new Date(), new Date()) + collision though get_visible events defect (such event was not retrieved) + if(start_date.valueOf() == end_date.valueOf()) + end_date.setTime(end_date.valueOf()+d); + base.start_date = base.start_date||start_date; - base.end_date = base.end_date||new Date(end); + base.end_date = base.end_date||end_date; base.text = base.text||this.locale.labels.new_event; base.id = this._drag_id = this.uid(); this._drag_mode="new-size"; - + this._loading=true; this.addEvent(base); this.callEvent("onEventCreated",[this._drag_id,e]); @@ -1958,7 +2002,7 @@ scheduler.addEventNow=function(start,end,e){ this._drag_event={}; //dummy , to trigger correct event updating logic this._on_mouse_up(e); -} +}; scheduler._on_dbl_click=function(e,src){ src = src||(e.target||e.srcElement); if (this.config.readonly) return; @@ -1967,6 +2011,7 @@ scheduler._on_dbl_click=function(e,src){ case "dhx_scale_holder": case "dhx_scale_holder_now": case "dhx_month_body": + case "dhx_wa_day_data": if (!scheduler.config.dblclick_create) break; var pos=this._mouse_coords(e); var start=this._min_date.valueOf()+(pos.y*this.config.time_step+(this._table_view?0:pos.x)*24*60)*60000; @@ -1974,6 +2019,7 @@ scheduler._on_dbl_click=function(e,src){ this.addEventNow(start,null,e); break; case "dhx_body": + case "dhx_wa_ev_body": case "dhx_cal_event_line": case "dhx_cal_event_clear": var id = this._locate_event(src); @@ -1991,7 +2037,7 @@ scheduler._on_dbl_click=function(e,src){ if (t) t.call(this,e); break; } -} +}; scheduler._mouse_coords=function(ev){ var pos; @@ -2002,17 +2048,17 @@ scheduler._mouse_coords=function(ev){ else pos={ x:ev.clientX + (b.scrollLeft||d.scrollLeft||0) - b.clientLeft, y:ev.clientY + (b.scrollTop||d.scrollTop||0) - b.clientTop - } + }; //apply layout pos.x-=getAbsoluteLeft(this._obj)+(this._table_view?0:this.xy.scale_width); pos.y-=getAbsoluteTop(this._obj)+this.xy.nav_height+(this._dy_shift||0)+this.xy.scale_height-this._els["dhx_cal_data"][0].scrollTop; pos.ev = ev; - + var handler = this["mouse_"+this._mode]; if (handler) return handler.call(this,pos); - + //transform to date if (!this._table_view){ pos.x=Math.max(0,Math.ceil(pos.x/this._cols[0])-1); @@ -2022,7 +2068,7 @@ scheduler._mouse_coords=function(ev){ for (dy=1; dy < this._colsS.heights.length; dy++) if (this._colsS.heights[dy]>pos.y) break; - pos.y=(Math.max(0,Math.ceil(pos.x/this._cols[0])-1)+Math.max(0,dy-1)*7)*24*60/this.config.time_step; + pos.y=(Math.max(0,Math.ceil(pos.x/this._cols[0])-1)+Math.max(0,dy-1)*7)*24*60/this.config.time_step; pos.x=0; } @@ -2034,14 +2080,14 @@ scheduler._close_not_saved=function(){ if (!c || confirm(c)) scheduler.editStop(scheduler.config.positive_closing); } -} +}; scheduler._correct_shift=function(start, back){ return start-=((new Date(scheduler._min_date)).getTimezoneOffset()-(new Date(start)).getTimezoneOffset())*60000*(back?-1:1); -} +}; scheduler._on_mouse_move=function(e){ if (this._drag_mode){ var pos=this._mouse_coords(e); - if (!this._drag_pos || this._drag_pos.x!=pos.x || this._drag_pos.y!=pos.y){ + if (!this._drag_pos || pos.custom || this._drag_pos.x!=pos.x || this._drag_pos.y!=pos.y){ if (this._edit_id!=this._drag_id) this._close_not_saved(); @@ -2080,8 +2126,11 @@ scheduler._on_mouse_move=function(e){ end = ev.end_date.valueOf()-(ev.start_date.valueOf()-start); } else { start = ev.start_date.valueOf(); - if (this._table_view) + if (this._table_view) { end = this._min_date.valueOf()+pos.y*this.config.time_step*60000 + (pos.custom?0:24*60*60000); + if (this._mode == "month") + end = this._correct_shift(end, false); + } else{ end = this.date.date_part(new Date(ev.end_date)).valueOf()+pos.y*this.config.time_step*60000; this._els["dhx_cal_data"][0].style.cursor="s-resize"; @@ -2091,7 +2140,7 @@ scheduler._on_mouse_move=function(e){ if (this._drag_mode == "new-size"){ if (end <= this._drag_start){ var shift = pos.shift||((this._table_view && !pos.custom)?24*60*60000:0); - start = end-shift; + start = end-(pos.shift?0:shift); end = this._drag_start+(shift||(this.config.time_step*60000)); } else { start = this._drag_start; @@ -2103,7 +2152,7 @@ scheduler._on_mouse_move=function(e){ var new_end = new Date(end-1); var new_start = new Date(start); //prevent out-of-borders situation for day|week view - if (this._table_view || (new_end.getDate()==new_start.getDate() && new_end.getHours() this._min_date && now.getHours() >= this.config.first_hour && now.getHours()
" + html+=">
"+this.templates.month_day(sd)+"
"; sd=this.date.add(sd,1,"day"); } html+=""; @@ -2389,7 +2479,7 @@ scheduler._reset_month_scale=function(b,dd,sd){ b.innerHTML=html; return sd; -} +}; scheduler.getLabel = function(property, key) { var sections = this.config.lightbox.sections; for (var i=0; ib.start_date?1:-1; }); + evs.sort(function(a,b){ + if(a.start_date.valueOf()==b.start_date.valueOf()) + return a.id>b.id?1:-1; + return a.start_date>b.start_date?1:-1; + }); var days=[]; //events by weeks var evs_originals = []; for (var i=0; i < evs.length; i++) { @@ -2926,12 +3090,70 @@ scheduler._pre_render_events_line=function(evs,hold){ if (!hold){ ev._inner=false; + var stack=days[ev._sday]; while (stack.length && stack[stack.length-1].end_date<=ev.start_date) stack.splice(stack.length-1,1); - if (stack.length) stack[stack.length-1]._inner=true; - ev._sorder=stack.length; stack.push(ev); - if (stack.length>(stack.max_count||0)) stack.max_count=stack.length; + + var sorderSet = false; + for(var j=0; j _max_sorder) + _max_sorder = stack[j]._sorder; + ev._sorder = _max_sorder + 1; + ev._inner = false; + } + + } + else + ev._sorder = 0; + } + + stack.push(ev); + + if (stack.length>(stack.max_count||0)) { + stack.max_count=stack.length; + ev._count=stack.length; + } + else { + ev._count=(ev._count)?ev._count:1; + } } if (sh < this.config.first_hour || eh >= this.config.last_hour){ @@ -2949,23 +3171,23 @@ scheduler._pre_render_events_line=function(evs,hold){ evs.splice(i,1); i--; continue; } } - } if (!hold){ - for (var i=0; i < evs.length; i++) - evs[i]._count=days[evs[i]._sday].max_count; - for (var i=0; i < evs_originals.length; i++) + for (var i=0; i < evs.length; i++) { + evs[i]._count = days[evs[i]._sday].max_count; + } + for (var i=0; i < evs_originals.length; i++) evs_originals[i]._count=days[evs_originals[i]._sday].max_count; } return evs; }; scheduler._time_order=function(evs){ - evs.sort(function(a,b){ + evs.sort(function(a,b){ if (a.start_date.valueOf()==b.start_date.valueOf()){ if (a._timed && !b._timed) return 1; if (!a._timed && b._timed) return -1; - return 0; + return a.id>b.id?1:-1; } return a.start_date>b.start_date?1:-1; }); @@ -3004,8 +3226,10 @@ scheduler._pre_render_events_table=function(evs,hold){ // max - max height of we for (stack_line=0; stack_line"; - var obj = this._render_v_bar(ev.id,left-menu+1,top,menu,icons.length*20+26,"","
",icons_str,true); + icons_str+="
"; + var obj = this._render_v_bar(ev.id,left-menu+1,top,menu,icons.length*20+26,"","
",icons_str,true); obj.style.left=left-menu+1; this._els["dhx_cal_data"][0].appendChild(obj); this._rendered.push(obj); @@ -3132,17 +3364,19 @@ scheduler.render_event=function(ev){ }; scheduler._render_v_bar=function(id,x,y,w,h,style,contentA,contentB,bottom){ var d=document.createElement("DIV"); - var ev = this.getEvent(id); var cs = "dhx_cal_event"; var cse = scheduler.templates.event_class(ev.start_date,ev.end_date,ev); if (cse) cs=cs+" "+cse; + + var bg_color = (ev.color?("background-color:"+ev.color+";"):""); + var color = (ev.textColor?("color:"+ev.textColor+";"):""); var html='
'; - html+='
 
'; - html+='
'+contentA+'
'; - html+='
'+contentB+'
'; - html+='
'; + html+='
 
'; + html+='
'+contentA+'
'; + html+='
'+contentB+'
'; + html+=''; d.innerHTML=html; return d.firstChild; @@ -3158,22 +3392,25 @@ scheduler.locate_holder_day=function(date,past){ return day; }; scheduler.render_event_bar=function(ev){ - var parent=this._els["dhx_cal_data"][0]; + var parent=this._rendered_location; var x=this._colsS[ev._sday]; var x2=this._colsS[ev._eday]; if (x2==x) x2=this._colsS[ev._eday+1]; var hb = this.xy.bar_height; - var y=this._colsS.heights[ev._sweek]+(this._colsS.height?(this.xy.month_scale_height+2):2)+ev._sorder*hb; + var y=this._colsS.heights[ev._sweek]+(this._colsS.height?(this.xy.month_scale_height+2):2)+(ev._sorder*hb); var d=document.createElement("DIV"); var cs = ev._timed?"dhx_cal_event_clear":"dhx_cal_event_line"; var cse = scheduler.templates.event_class(ev.start_date,ev.end_date,ev); - if (cse) cs=cs+" "+cse; + if (cse) cs=cs+" "+cse; + + var bg_color = (ev.color?("background-color:"+ev.color+";"):""); + var color = (ev.textColor?("color:"+ev.textColor+";"):""); + + var html='
'; - var html='
'; - if (ev._timed) html+=scheduler.templates.event_bar_date(ev.start_date,ev.end_date,ev); html+=scheduler.templates.event_bar_text(ev.start_date,ev.end_date,ev)+'
'; @@ -3230,6 +3467,7 @@ scheduler.getEvents = function(from,to){ } return result; }; + scheduler._loaded={}; scheduler._load=function(url,from){ url=url||this._load_url; @@ -3270,13 +3508,14 @@ scheduler._load=function(url,from){ dhtmlxAjax.get(url,function(l){scheduler.on_load(l);}); this.callEvent("onXLS",[]); return true; -} +}; scheduler.on_load=function(loader){ this._loading=true; + var evs; if (this._process) - var evs=this[this._process].parse(loader.xmlDoc.responseText); + evs=this[this._process].parse(loader.xmlDoc.responseText); else - var evs=this._magic_parser(loader); + evs=this._magic_parser(loader); this._not_render=true; for (var i=0; i
"; + }, + set_value:function(node,value,ev,config){ + node.innerHTML = value||""; + }, + get_value:function(node,ev,config){ + return node.innerHTML||""; + }, + focus: function(node){ + } + }, textarea:{ render:function(sns){ var height=(sns.height||"130")+"px"; @@ -3499,7 +3783,7 @@ scheduler.form_blocks={ select:{ render:function(sns){ var height=(sns.height||"23")+"px"; - var html="
"; for (var i=0; i < sns.options.length; i++) html+=""; html+="
"; @@ -3530,10 +3814,16 @@ scheduler.form_blocks={ } var html=" "; - return "
"+html+"  –  "+html+"
"; + return "
"+html+"  –  "+html+"
"; }, set_value:function(node,value,ev){ + var s=node.getElementsByTagName("select"); if(scheduler.config.full_day) { if (!node._full_day){ - node.previousSibling.innerHTML+="
"; + var html = ""; + if (!scheduler.config.wide_form) + html = node.previousSibling.innerHTML+html; + node.previousSibling.innerHTML=html; node._full_day=true; } var input=node.previousSibling.getElementsByTagName("input")[0]; - var isFulldayEvent = (scheduler.date.time_part(ev.start_date)==0 && scheduler.date.time_part(ev.end_date)==0 && ev.end_date.valueOf()-ev.start_date.valueOf() < 2*24*60*60*1000); + var isFulldayEvent = (scheduler.date.time_part(ev.start_date)===0 && scheduler.date.time_part(ev.end_date)===0 && ev.end_date.valueOf()-ev.start_date.valueOf() < 2*24*60*60*1000); input.checked = isFulldayEvent; for(var k in s) @@ -3578,14 +3872,14 @@ scheduler.form_blocks={ var end_date = new Date(ev.end_date); scheduler.date.date_part(start_date); - end_date = scheduler.date.add(start_date, 1, "day") + end_date = scheduler.date.add(start_date, 1, "day"); } for(var i in s) s[i].disabled=input.checked; _fill_lightbox_select(s,0,start_date||ev.start_date); _fill_lightbox_select(s,4,end_date||ev.end_date); - } + }; } if(scheduler.config.auto_end_date && scheduler.config.event_duration) { @@ -3620,16 +3914,29 @@ scheduler.form_blocks={ node.getElementsByTagName("select")[0].focus(); } } -} +}; scheduler.showCover=function(box){ - this.show_cover(); if (box){ box.style.display="block"; - var pos = getOffset(this._obj); - box.style.top=Math.round(pos.top+(this._obj.offsetHeight-box.offsetHeight)/2)+"px"; - box.style.left=Math.round(pos.left+(this._obj.offsetWidth-box.offsetWidth)/2)+"px"; + + var scroll_top = window.pageYOffset||document.body.scrollTop||document.documentElement.scrollTop; + var scroll_left = window.pageXOffset||document.body.scrollLeft||document.documentElement.scrollLeft; + + var view_height = window.innerHeight||document.documentElement.clientHeight; + + if(scroll_top) // if vertical scroll on window + box.style.top=Math.round(scroll_top+Math.max((view_height-box.offsetHeight)/2, 0))+"px"; + else // vertical scroll on body + box.style.top=Math.round(Math.max(((view_height-box.offsetHeight)/2), 0) + 9)+"px"; // +9 for compatibility with auto tests + + // not quite accurate but used for compatibility reasons + if(document.documentElement.scrollWidth > document.body.offsetWidth) // if horizontal scroll on the window + box.style.left=Math.round(scroll_left+(document.body.offsetWidth-box.offsetWidth)/2)+"px"; + else // horizontal scroll on the body + box.style.left=Math.round((document.body.offsetWidth-box.offsetWidth)/2)+"px"; } -} + this.show_cover(); +}; scheduler.showLightbox=function(id){ if (!id) return; if (!this.callEvent("onBeforeLightbox",[id])) return; @@ -3637,7 +3944,7 @@ scheduler.showLightbox=function(id){ this.showCover(box); this._fill_lightbox(id,box); this.callEvent("onLightbox",[id]); -} +}; scheduler._fill_lightbox=function(id,box){ var ev=this.getEvent(id); var s=box.getElementsByTagName("span"); @@ -3654,24 +3961,25 @@ scheduler._fill_lightbox=function(id,box){ for (var i=0; i < sns.length; i++) { var node=document.getElementById(sns[i].id).nextSibling; var block=this.form_blocks[sns[i].type]; - block.set_value.call(this,node,ev[sns[i].map_to],ev, sns[i]) + block.set_value.call(this,node,ev[sns[i].map_to],ev, sns[i]); if (sns[i].focus) block.focus.call(this,node); - }; + } scheduler._lightbox_id=id; -} +}; scheduler._lightbox_out=function(ev){ var sns = this.config.lightbox.sections; for (var i=0; i < sns.length; i++) { - var node=document.getElementById(sns[i].id).nextSibling; + var node = document.getElementById(sns[i].id); + node=(node?node.nextSibling:node); var block=this.form_blocks[sns[i].type]; var res=block.get_value.call(this,node,ev, sns[i]); if (sns[i].map_to!="auto") ev[sns[i].map_to]=res; } return ev; -} +}; scheduler._empty_lightbox=function(){ var id=scheduler._lightbox_id; var ev=this.getEvent(id); @@ -3681,38 +3989,41 @@ scheduler._empty_lightbox=function(){ ev._timed=this.is_one_day_event(ev); this.setEvent(ev.id,ev); - this._edit_stop_event(ev,true) + this._edit_stop_event(ev,true); this.render_view_data(); -} +}; scheduler.hide_lightbox=function(id){ this.hideCover(this._get_lightbox()); this._lightbox_id=null; this.callEvent("onAfterLightbox",[]); -} +}; scheduler.hideCover=function(box){ if (box) box.style.display="none"; this.hide_cover(); -} +}; scheduler.hide_cover=function(){ if (this._cover) this._cover.parentNode.removeChild(this._cover); this._cover=null; -} +}; scheduler.show_cover=function(){ this._cover=document.createElement("DIV"); this._cover.className="dhx_cal_cover"; + var _document_height = ((document.height !== undefined) ? document.height : document.body.offsetHeight); + var _scroll_height = ((document.documentElement) ? document.documentElement.scrollHeight : 0); + this._cover.style.height = Math.max(_document_height, _scroll_height) + 'px'; document.body.appendChild(this._cover); -} +}; scheduler.save_lightbox=function(){ - if (this.checkEvent("onEventSave") && !this.callEvent("onEventSave",[this._lightbox_id,this._lightbox_out({ id: this._lightbox_id}), this._new_event])) + if (this.checkEvent("onEventSave") && !this.callEvent("onEventSave",[this._lightbox_id,this._lightbox_out({ id: this._lightbox_id}), this._new_event])) return; - this._empty_lightbox() + this._empty_lightbox(); this.hide_lightbox(); }; scheduler.startLightbox = function(id, box){ this._lightbox_id=id; this.showCover(box); -} +}; scheduler.endLightbox = function(mode, box){ this._edit_stop_event(scheduler.getEvent(this._lightbox_id),mode); if (mode) @@ -3720,6 +4031,8 @@ scheduler.endLightbox = function(mode, box){ this.hideCover(box); }; scheduler.resetLightbox = function(){ + if (scheduler._lightbox) + scheduler._lightbox.parentNode.removeChild(scheduler._lightbox); scheduler._lightbox = null; }; scheduler.cancel_lightbox=function(){ @@ -3749,15 +4062,18 @@ scheduler._init_lightbox_events=function(){ break; default: - if (src.className.indexOf("dhx_custom_button_")!=-1){ + if (src.getAttribute("dhx_button")){ + scheduler.callEvent("onLightboxButton", [src.className, src, e]); + } else if (src.className.indexOf("dhx_custom_button_")!=-1){ var index = src.parentNode.getAttribute("index"); var block=scheduler.form_blocks[scheduler.config.lightbox.sections[index].type]; var sec = src.parentNode.parentNode; block.button_click(index,src,sec,sec.nextSibling); } + break; } }; - this._get_lightbox().onkeypress=function(e){ + this._get_lightbox().onkeydown=function(e){ switch((e||event).keyCode){ case scheduler.keys.edit_save: if ((e||event).shiftKey) return; @@ -3766,9 +4082,11 @@ scheduler._init_lightbox_events=function(){ case scheduler.keys.edit_cancel: scheduler.cancel_lightbox(); break; + default: + break; } - } -} + }; +}; scheduler.setLightboxSize=function(){ var d = this._lightbox; if (!d) return; @@ -3778,36 +4096,92 @@ scheduler.setLightboxSize=function(){ con.style.height=con.scrollHeight+"px"; d.style.height=con.scrollHeight+50+"px"; con.style.height=con.scrollHeight+"px"; //it is incredible , how ugly IE can be -} +}; -scheduler._get_lightbox=function(){ +scheduler._init_dnd_events = function(){ + dhtmlxEvent(document.body, "mousemove", scheduler._move_while_dnd); + dhtmlxEvent(document.body, "mouseup", scheduler._finish_dnd); + scheduler._init_dnd_events = function(){}; +}; +scheduler._move_while_dnd = function(e){ + if (scheduler._dnd_start_lb){ + if (!document.dhx_unselectable){ + document.body.className += " dhx_unselectable"; + document.dhx_unselectable = true; + } + var lb = scheduler._get_lightbox(); + var now = (e&&e.target)?[e.pageX, e.pageY]:[event.clientX, event.clientY]; + lb.style.top = scheduler._lb_start[1]+now[1]-scheduler._dnd_start_lb[1]+"px"; + lb.style.left = scheduler._lb_start[0]+now[0]-scheduler._dnd_start_lb[0]+"px"; + } +}; +scheduler._ready_to_dnd = function(e){ + var lb = scheduler._get_lightbox(); + scheduler._lb_start = [parseInt(lb.style.left,10), parseInt(lb.style.top,10)]; + scheduler._dnd_start_lb = (e&&e.target)?[e.pageX, e.pageY]:[event.clientX, event.clientY]; +}; +scheduler._finish_dnd = function(){ + if (scheduler._lb_start){ + scheduler._lb_start = scheduler._dnd_start_lb = false; + document.body.className = document.body.className.replace(" dhx_unselectable",""); + document.dhx_unselectable = false; + } +}; +scheduler._get_lightbox=function(){ //scheduler.config.wide_form=true; if (!this._lightbox){ var d=document.createElement("DIV"); d.className="dhx_cal_light"; + if (scheduler.config.wide_form) + d.className+=" dhx_cal_light_wide"; + if (scheduler.form_blocks.recurring) + d.className+=" dhx_cal_light_rec"; + if (/msie|MSIE 6/.test(navigator.userAgent)) d.className+=" dhx_ie6"; d.style.visibility="hidden"; - d.innerHTML=this._lightbox_template; + var html = this._lightbox_template + var buttons = this.config.buttons_left; + scheduler.locale.labels["dhx_save_btn"] = scheduler.locale.labels.icon_save; + scheduler.locale.labels["dhx_cancel_btn"] = scheduler.locale.labels.icon_cancel; + scheduler.locale.labels["dhx_delete_btn"] = scheduler.locale.labels.icon_delete; + for (var i = 0; i < buttons.length; i++) + html+="
"+scheduler.locale.labels[buttons[i]]+"
"; + buttons = this.config.buttons_right; + for (var i = 0; i < buttons.length; i++) + html+="
"+scheduler.locale.labels[buttons[i]]+"
"; + + html+=""; + d.innerHTML=html; + if (scheduler.config.drag_lightbox){ + d.firstChild.onmousedown = scheduler._ready_to_dnd; + d.firstChild.onselectstart = function(){ return false; }; + d.firstChild.style.cursor = "pointer"; + scheduler._init_dnd_events(); + + } document.body.insertBefore(d,document.body.firstChild); this._lightbox=d; var sns=this.config.lightbox.sections; - var html=""; + html=""; for (var i=0; i < sns.length; i++) { var block=this.form_blocks[sns[i].type]; if (!block) continue; //ignore incorrect blocks sns[i].id="area_"+this.uid(); var button = ""; - if (sns[i].button) button = "
"+this.locale.labels["button_"+sns[i].button]+"
"; + if (sns[i].button){ + button = "
"+this.locale.labels["button_"+sns[i].button]+"
"; + } + + if (this.config.wide_form){ + html+="
"; + } html+="
"+button+this.locale.labels["section_"+sns[i].name]+"
"+block.render.call(this,sns[i]); - }; + html+="
" + } - //localization var ds=d.getElementsByTagName("div"); - ds[4].innerHTML=scheduler.locale.labels.icon_save; - ds[7].innerHTML=scheduler.locale.labels.icon_cancel; - ds[10].innerHTML=scheduler.locale.labels.icon_delete; //sections ds[1].innerHTML=html; //sizes @@ -3818,8 +4192,9 @@ scheduler._get_lightbox=function(){ d.style.visibility="visible"; } return this._lightbox; -} -scheduler._lightbox_template="
 
 
 
 
"; +}; +scheduler._lightbox_template="
 
"; + scheduler._dp_init=function(dp){ dp._methods=["setEventTextStyle","","changeEventId","deleteEvent"]; @@ -3827,7 +4202,7 @@ scheduler._dp_init=function(dp){ if (!this._loading && this.validId(id)) dp.setUpdated(id,true,"inserted"); }); - this.attachEvent("onBeforeEventDelete",function(id){ + this.attachEvent("onConfirmedBeforeEventDelete", function(id){ if (!this.validId(id)) return; var z=dp.getState(id); @@ -3897,4 +4272,4 @@ scheduler._update_callback = function(upd,id){ data.end_date = scheduler.templates.xml_date(data.end_date); scheduler.addEvent(data); -}; +}; -- cgit v1.2.3