source: branches/2.2.0.1/calendar/js/dhtmlx/sample/codebase/dhtmlxscheduler.js @ 4001

Revision 4001, 105.3 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1615 - Componente novo para agenda......................................

Line 
1dhtmlx=function(obj){
2        for (var a in obj) dhtmlx[a]=obj[a];
3        return dhtmlx; //simple singleton
4};
5dhtmlx.extend_api=function(name,map,ext){
6        var t = window[name];
7        if (!t) return; //component not defined
8        window[name]=function(obj){
9                if (obj && typeof obj == "object" && !obj.tagName && !(obj instanceof Array)){
10                        var that = t.apply(this,(map._init?map._init(obj):arguments));
11                        //global settings
12                        for (var a in dhtmlx)
13                                if (map[a]) this[map[a]](dhtmlx[a]);                   
14                        //local settings
15                        for (var a in obj){
16                                if (map[a]) this[map[a]](obj[a]);
17                                else if (a.indexOf("on")==0){
18                                        this.attachEvent(a,obj[a]);
19                                }
20                        }
21                } else
22                        var that = t.apply(this,arguments);
23                if (map._patch) map._patch(this);
24                return that||this;
25        };
26        window[name].prototype=t.prototype;
27        if (ext)
28                dhtmlXHeir(window[name].prototype,ext);
29};
30
31dhtmlxAjax={
32        get:function(url,callback){
33                var t=new dtmlXMLLoaderObject(true);
34                t.async=(arguments.length<3);
35                t.waitCall=callback;
36                t.loadXML(url)
37                return t;
38        },
39        post:function(url,post,callback){
40                var t=new dtmlXMLLoaderObject(true);
41                t.async=(arguments.length<4);
42                t.waitCall=callback;
43                t.loadXML(url,true,post)
44                return t;
45        },
46        getSync:function(url){
47                return this.get(url,null,true)
48        },
49        postSync:function(url,post){
50                return this.post(url,post,null,true);           
51        }
52}
53
54/**
55  *     @desc: xmlLoader object
56  *     @type: private
57  *     @param: funcObject - xml parser function
58  *     @param: object - jsControl object
59  *     @param: async - sync/async mode (async by default)
60  *     @param: rSeed - enable/disable random seed ( prevent IE caching)
61  *     @topic: 0
62  */
63function dtmlXMLLoaderObject(funcObject, dhtmlObject, async, rSeed){
64        this.xmlDoc="";
65
66        if (typeof (async) != "undefined")
67                this.async=async;
68        else
69                this.async=true;
70
71        this.onloadAction=funcObject||null;
72        this.mainObject=dhtmlObject||null;
73        this.waitCall=null;
74        this.rSeed=rSeed||false;
75        return this;
76};
77/**
78  *     @desc: xml loading handler
79  *     @type: private
80  *     @param: dtmlObject - xmlLoader object
81  *     @topic: 0
82  */
83dtmlXMLLoaderObject.prototype.waitLoadFunction=function(dhtmlObject){
84        var once = true;
85        this.check=function (){
86                if ((dhtmlObject)&&(dhtmlObject.onloadAction != null)){
87                        if ((!dhtmlObject.xmlDoc.readyState)||(dhtmlObject.xmlDoc.readyState == 4)){
88                                if (!once)
89                                        return;
90
91                                once=false; //IE 5 fix
92                                if (typeof dhtmlObject.onloadAction == "function")
93                                        dhtmlObject.onloadAction(dhtmlObject.mainObject, null, null, null, dhtmlObject);
94
95                                if (dhtmlObject.waitCall){
96                                        dhtmlObject.waitCall.call(this,dhtmlObject);
97                                        dhtmlObject.waitCall=null;
98                                }
99                        }
100                }
101        };
102        return this.check;
103};
104
105/**
106  *     @desc: return XML top node
107  *     @param: tagName - top XML node tag name (not used in IE, required for Safari and Mozilla)
108  *     @type: private
109  *     @returns: top XML node
110  *     @topic: 0 
111  */
112dtmlXMLLoaderObject.prototype.getXMLTopNode=function(tagName, oldObj){
113        if (this.xmlDoc.responseXML){
114                var temp = this.xmlDoc.responseXML.getElementsByTagName(tagName);
115                if(temp.length==0 && tagName.indexOf(":")!=-1)
116                        var temp = this.xmlDoc.responseXML.getElementsByTagName((tagName.split(":"))[1]);
117                var z = temp[0];
118        } else
119                var z = this.xmlDoc.documentElement;
120
121        if (z){
122                this._retry=false;
123                return z;
124        }
125
126        if ((_isIE)&&(!this._retry)){
127                //fall back to MS.XMLDOM
128                var xmlString = this.xmlDoc.responseText;
129                var oldObj = this.xmlDoc;
130                this._retry=true;
131                this.xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
132                this.xmlDoc.async=false;
133                this.xmlDoc["loadXM"+"L"](xmlString);
134
135                return this.getXMLTopNode(tagName, oldObj);
136        }
137        dhtmlxError.throwError("LoadXML", "Incorrect XML", [
138                (oldObj||this.xmlDoc),
139                this.mainObject
140        ]);
141
142        return document.createElement("DIV");
143};
144
145/**
146  *     @desc: load XML from string
147  *     @type: private
148  *     @param: xmlString - xml string
149  *     @topic: 0 
150  */
151dtmlXMLLoaderObject.prototype.loadXMLString=function(xmlString){
152        {
153                try{
154                        var parser = new DOMParser();
155                        this.xmlDoc=parser.parseFromString(xmlString, "text/xml");
156                }
157                catch (e){
158                        this.xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
159                        this.xmlDoc.async=this.async;
160                        this.xmlDoc["loadXM"+"L"](xmlString);
161                }
162        }
163
164        this.onloadAction(this.mainObject, null, null, null, this);
165
166        if (this.waitCall){
167                this.waitCall();
168                this.waitCall=null;
169        }
170}
171/**
172  *     @desc: load XML
173  *     @type: private
174  *     @param: filePath - xml file path
175  *     @param: postMode - send POST request
176  *     @param: postVars - list of vars for post request
177  *     @topic: 0
178  */
179dtmlXMLLoaderObject.prototype.loadXML=function(filePath, postMode, postVars, rpc){
180        if (this.rSeed)
181                filePath+=((filePath.indexOf("?") != -1) ? "&" : "?")+"a_dhx_rSeed="+(new Date()).valueOf();
182        this.filePath=filePath;
183
184        if ((!_isIE)&&(window.XMLHttpRequest))
185                this.xmlDoc=new XMLHttpRequest();
186        else {
187                if (document.implementation&&document.implementation.createDocument){
188                        this.xmlDoc=document.implementation.createDocument("", "", null);
189                        this.xmlDoc.onload=new this.waitLoadFunction(this);
190                        this.xmlDoc.load(filePath);
191                        return;
192                } else
193                        this.xmlDoc=new ActiveXObject("Microsoft.XMLHTTP");
194        }
195
196        if (this.async)
197                this.xmlDoc.onreadystatechange=new this.waitLoadFunction(this);
198        this.xmlDoc.open(postMode ? "POST" : "GET", filePath, this.async);
199
200        if (rpc){
201                this.xmlDoc.setRequestHeader("User-Agent", "dhtmlxRPC v0.1 ("+navigator.userAgent+")");
202                this.xmlDoc.setRequestHeader("Content-type", "text/xml");
203        }
204
205        else if (postMode)
206                this.xmlDoc.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
207               
208        this.xmlDoc.setRequestHeader("X-Requested-With","XMLHttpRequest");
209        this.xmlDoc.send(null||postVars);
210
211        if (!this.async)
212                (new this.waitLoadFunction(this))();
213};
214/**
215  *     @desc: destructor, cleans used memory
216  *     @type: private
217  *     @topic: 0
218  */
219dtmlXMLLoaderObject.prototype.destructor=function(){
220        this.onloadAction=null;
221        this.mainObject=null;
222        this.xmlDoc=null;
223        return null;
224}
225
226dtmlXMLLoaderObject.prototype.xmlNodeToJSON = function(node){
227        var t={};
228        for (var i=0; i<node.attributes.length; i++)
229            t[node.attributes[i].name]=node.attributes[i].value;
230        t["_tagvalue"]=node.firstChild?node.firstChild.nodeValue:"";
231        for (var i=0; i<node.childNodes.length; i++){
232            var name=node.childNodes[i].tagName;
233            if (name){
234                if (!t[name]) t[name]=[];
235                t[name].push(this.xmlNodeToJSON(node.childNodes[i]));
236            }           
237        }       
238        return t;
239    }
240
241/** 
242  *     @desc: Call wrapper
243  *     @type: private
244  *     @param: funcObject - action handler
245  *     @param: dhtmlObject - user data
246  *     @returns: function handler
247  *     @topic: 0 
248  */
249function callerFunction(funcObject, dhtmlObject){
250        this.handler=function(e){
251                if (!e)
252                        e=window.event;
253                funcObject(e, dhtmlObject);
254                return true;
255        };
256        return this.handler;
257};
258
259/** 
260  *     @desc: Calculate absolute position of html object
261  *     @type: private
262  *     @param: htmlObject - html object
263  *     @topic: 0 
264  */
265function getAbsoluteLeft(htmlObject){
266        return getOffset(htmlObject).left;
267}
268/**
269  *     @desc: Calculate absolute position of html object
270  *     @type: private
271  *     @param: htmlObject - html object
272  *     @topic: 0 
273  */
274function getAbsoluteTop(htmlObject){
275        return getOffset(htmlObject).top;
276}
277
278function getOffsetSum(elem) {
279        var top=0, left=0;
280        while(elem) {
281                top = top + parseInt(elem.offsetTop);
282                left = left + parseInt(elem.offsetLeft);
283                elem = elem.offsetParent;
284        }
285        return {top: top, left: left};
286}
287function getOffsetRect(elem) {
288        var box = elem.getBoundingClientRect();
289        var body = document.body;
290        var docElem = document.documentElement;
291        var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop;
292        var scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft;
293        var clientTop = docElem.clientTop || body.clientTop || 0;
294        var clientLeft = docElem.clientLeft || body.clientLeft || 0;
295        var top  = box.top +  scrollTop - clientTop;
296        var left = box.left + scrollLeft - clientLeft;
297        return { top: Math.round(top), left: Math.round(left) };
298}
299function getOffset(elem) {
300        if (elem.getBoundingClientRect && !_isChrome) {
301                return getOffsetRect(elem);
302        } else {
303                return getOffsetSum(elem);
304        }
305}
306
307/** 
308*     @desc: Convert string to it boolean representation
309*     @type: private
310*     @param: inputString - string for covertion
311*     @topic: 0
312*/
313function convertStringToBoolean(inputString){
314        if (typeof (inputString) == "string")
315                inputString=inputString.toLowerCase();
316
317        switch (inputString){
318                case "1":
319                case "true":
320                case "yes":
321                case "y":
322                case 1:
323                case true:
324                        return true;
325                        break;
326
327                default: return false;
328        }
329}
330
331/** 
332*     @desc: find out what symbol to use as url param delimiters in further params
333*     @type: private
334*     @param: str - current url string
335*     @topic: 0 
336*/
337function getUrlSymbol(str){
338        if (str.indexOf("?") != -1)
339                return "&"
340        else
341                return "?"
342}
343
344function dhtmlDragAndDropObject(){
345        if (window.dhtmlDragAndDrop)
346                return window.dhtmlDragAndDrop;
347
348        this.lastLanding=0;
349        this.dragNode=0;
350        this.dragStartNode=0;
351        this.dragStartObject=0;
352        this.tempDOMU=null;
353        this.tempDOMM=null;
354        this.waitDrag=0;
355        window.dhtmlDragAndDrop=this;
356
357        return this;
358};
359
360dhtmlDragAndDropObject.prototype.removeDraggableItem=function(htmlNode){
361        htmlNode.onmousedown=null;
362        htmlNode.dragStarter=null;
363        htmlNode.dragLanding=null;
364}
365dhtmlDragAndDropObject.prototype.addDraggableItem=function(htmlNode, dhtmlObject){
366        htmlNode.onmousedown=this.preCreateDragCopy;
367        htmlNode.dragStarter=dhtmlObject;
368        this.addDragLanding(htmlNode, dhtmlObject);
369}
370dhtmlDragAndDropObject.prototype.addDragLanding=function(htmlNode, dhtmlObject){
371        htmlNode.dragLanding=dhtmlObject;
372}
373dhtmlDragAndDropObject.prototype.preCreateDragCopy=function(e){
374        if ((e||event) && (e||event).button == 2)
375                return;
376
377        if (window.dhtmlDragAndDrop.waitDrag){
378                window.dhtmlDragAndDrop.waitDrag=0;
379                document.body.onmouseup=window.dhtmlDragAndDrop.tempDOMU;
380                document.body.onmousemove=window.dhtmlDragAndDrop.tempDOMM;
381                return false;
382        }
383
384        window.dhtmlDragAndDrop.waitDrag=1;
385        window.dhtmlDragAndDrop.tempDOMU=document.body.onmouseup;
386        window.dhtmlDragAndDrop.tempDOMM=document.body.onmousemove;
387        window.dhtmlDragAndDrop.dragStartNode=this;
388        window.dhtmlDragAndDrop.dragStartObject=this.dragStarter;
389        document.body.onmouseup=window.dhtmlDragAndDrop.preCreateDragCopy;
390        document.body.onmousemove=window.dhtmlDragAndDrop.callDrag;
391        window.dhtmlDragAndDrop.downtime = new Date().valueOf();
392       
393
394        if ((e)&&(e.preventDefault)){
395                e.preventDefault();
396                return false;
397        }
398        return false;
399};
400dhtmlDragAndDropObject.prototype.callDrag=function(e){
401        if (!e)
402                e=window.event;
403        dragger=window.dhtmlDragAndDrop;
404        if ((new Date()).valueOf()-dragger.downtime<100) return;
405
406        if ((e.button == 0)&&(_isIE))
407                return dragger.stopDrag();
408
409        if (!dragger.dragNode&&dragger.waitDrag){
410                dragger.dragNode=dragger.dragStartObject._createDragNode(dragger.dragStartNode, e);
411
412                if (!dragger.dragNode)
413                        return dragger.stopDrag();
414
415                dragger.dragNode.onselectstart=function(){return false;}
416                dragger.gldragNode=dragger.dragNode;
417                document.body.appendChild(dragger.dragNode);
418                document.body.onmouseup=dragger.stopDrag;
419                dragger.waitDrag=0;
420                dragger.dragNode.pWindow=window;
421                dragger.initFrameRoute();
422        }
423
424        if (dragger.dragNode.parentNode != window.document.body){
425                var grd = dragger.gldragNode;
426
427                if (dragger.gldragNode.old)
428                        grd=dragger.gldragNode.old;
429
430                //if (!document.all) dragger.calculateFramePosition();
431                grd.parentNode.removeChild(grd);
432                var oldBody = dragger.dragNode.pWindow;
433
434                //              var oldp=dragger.dragNode.parentObject;
435                if (_isIE){
436                        var div = document.createElement("Div");
437                        div.innerHTML=dragger.dragNode.outerHTML;
438                        dragger.dragNode=div.childNodes[0];
439                } else
440                        dragger.dragNode=dragger.dragNode.cloneNode(true);
441
442                dragger.dragNode.pWindow=window;
443                //              dragger.dragNode.parentObject=oldp;
444
445                dragger.gldragNode.old=dragger.dragNode;
446                document.body.appendChild(dragger.dragNode);
447                oldBody.dhtmlDragAndDrop.dragNode=dragger.dragNode;
448        }
449
450        dragger.dragNode.style.left=e.clientX+15+(dragger.fx
451                ? dragger.fx*(-1)
452                : 0)
453                +(document.body.scrollLeft||document.documentElement.scrollLeft)+"px";
454        dragger.dragNode.style.top=e.clientY+3+(dragger.fy
455                ? dragger.fy*(-1)
456                : 0)
457                +(document.body.scrollTop||document.documentElement.scrollTop)+"px";
458
459        if (!e.srcElement)
460                var z = e.target;
461        else
462                z=e.srcElement;
463        dragger.checkLanding(z, e);
464}
465
466dhtmlDragAndDropObject.prototype.calculateFramePosition=function(n){
467        //this.fx = 0, this.fy = 0;
468        if (window.name){
469                var el = parent.frames[window.name].frameElement.offsetParent;
470                var fx = 0;
471                var fy = 0;
472
473                while (el){
474                        fx+=el.offsetLeft;
475                        fy+=el.offsetTop;
476                        el=el.offsetParent;
477                }
478
479                if ((parent.dhtmlDragAndDrop)){
480                        var ls = parent.dhtmlDragAndDrop.calculateFramePosition(1);
481                        fx+=ls.split('_')[0]*1;
482                        fy+=ls.split('_')[1]*1;
483                }
484
485                if (n)
486                        return fx+"_"+fy;
487                else
488                        this.fx=fx;
489                this.fy=fy;
490        }
491        return "0_0";
492}
493dhtmlDragAndDropObject.prototype.checkLanding=function(htmlObject, e){
494        if ((htmlObject)&&(htmlObject.dragLanding)){
495                if (this.lastLanding)
496                        this.lastLanding.dragLanding._dragOut(this.lastLanding);
497                this.lastLanding=htmlObject;
498                this.lastLanding=this.lastLanding.dragLanding._dragIn(this.lastLanding, this.dragStartNode, e.clientX,
499                        e.clientY, e);
500                this.lastLanding_scr=(_isIE ? e.srcElement : e.target);
501        } else {
502                if ((htmlObject)&&(htmlObject.tagName != "BODY"))
503                        this.checkLanding(htmlObject.parentNode, e);
504                else {
505                        if (this.lastLanding)
506                                this.lastLanding.dragLanding._dragOut(this.lastLanding, e.clientX, e.clientY, e);
507                        this.lastLanding=0;
508
509                        if (this._onNotFound)
510                                this._onNotFound();
511                }
512        }
513}
514dhtmlDragAndDropObject.prototype.stopDrag=function(e, mode){
515        dragger=window.dhtmlDragAndDrop;
516
517        if (!mode){
518                dragger.stopFrameRoute();
519                var temp = dragger.lastLanding;
520                dragger.lastLanding=null;
521
522                if (temp)
523                        temp.dragLanding._drag(dragger.dragStartNode, dragger.dragStartObject, temp, (_isIE
524                                ? event.srcElement
525                                : e.target));
526        }
527        dragger.lastLanding=null;
528
529        if ((dragger.dragNode)&&(dragger.dragNode.parentNode == document.body))
530                dragger.dragNode.parentNode.removeChild(dragger.dragNode);
531        dragger.dragNode=0;
532        dragger.gldragNode=0;
533        dragger.fx=0;
534        dragger.fy=0;
535        dragger.dragStartNode=0;
536        dragger.dragStartObject=0;
537        document.body.onmouseup=dragger.tempDOMU;
538        document.body.onmousemove=dragger.tempDOMM;
539        dragger.tempDOMU=null;
540        dragger.tempDOMM=null;
541        dragger.waitDrag=0;
542}
543
544dhtmlDragAndDropObject.prototype.stopFrameRoute=function(win){
545        if (win)
546                window.dhtmlDragAndDrop.stopDrag(1, 1);
547
548        for (var i = 0; i < window.frames.length; i++){
549                try{
550                if ((window.frames[i] != win)&&(window.frames[i].dhtmlDragAndDrop))
551                        window.frames[i].dhtmlDragAndDrop.stopFrameRoute(window);
552                } catch(e){}
553        }
554
555        try{
556        if ((parent.dhtmlDragAndDrop)&&(parent != window)&&(parent != win))
557                parent.dhtmlDragAndDrop.stopFrameRoute(window);
558        } catch(e){}
559}
560dhtmlDragAndDropObject.prototype.initFrameRoute=function(win, mode){
561        if (win){
562                window.dhtmlDragAndDrop.preCreateDragCopy({});
563                window.dhtmlDragAndDrop.dragStartNode=win.dhtmlDragAndDrop.dragStartNode;
564                window.dhtmlDragAndDrop.dragStartObject=win.dhtmlDragAndDrop.dragStartObject;
565                window.dhtmlDragAndDrop.dragNode=win.dhtmlDragAndDrop.dragNode;
566                window.dhtmlDragAndDrop.gldragNode=win.dhtmlDragAndDrop.dragNode;
567                window.document.body.onmouseup=window.dhtmlDragAndDrop.stopDrag;
568                window.waitDrag=0;
569
570                if (((!_isIE)&&(mode))&&((!_isFF)||(_FFrv < 1.8)))
571                        window.dhtmlDragAndDrop.calculateFramePosition();
572        }
573        try{
574        if ((parent.dhtmlDragAndDrop)&&(parent != window)&&(parent != win))
575                parent.dhtmlDragAndDrop.initFrameRoute(window);
576        }catch(e){}
577
578        for (var i = 0; i < window.frames.length; i++){
579                try{
580                if ((window.frames[i] != win)&&(window.frames[i].dhtmlDragAndDrop))
581                        window.frames[i].dhtmlDragAndDrop.initFrameRoute(window, ((!win||mode) ? 1 : 0));
582                } catch(e){}
583        }
584}
585
586var _isFF = false;
587var _isIE = false;
588var _isOpera = false;
589var _isKHTML = false;
590var _isMacOS = false;
591var _isChrome = false;
592
593if (navigator.userAgent.indexOf('Macintosh') != -1)
594        _isMacOS=true;
595
596
597if (navigator.userAgent.toLowerCase().indexOf('chrome')>-1)
598        _isChrome=true;
599
600if ((navigator.userAgent.indexOf('Safari') != -1)||(navigator.userAgent.indexOf('Konqueror') != -1)){
601        var _KHTMLrv = parseFloat(navigator.userAgent.substr(navigator.userAgent.indexOf('Safari')+7, 5));
602
603        if (_KHTMLrv > 525){ //mimic FF behavior for Safari 3.1+
604                _isFF=true;
605                var _FFrv = 1.9;
606        } else
607                _isKHTML=true;
608} else if (navigator.userAgent.indexOf('Opera') != -1){
609        _isOpera=true;
610        _OperaRv=parseFloat(navigator.userAgent.substr(navigator.userAgent.indexOf('Opera')+6, 3));
611}
612
613
614else if (navigator.appName.indexOf("Microsoft") != -1){
615        _isIE=true;
616        if (navigator.appVersion.indexOf("MSIE 8.0")!= -1 && document.compatMode != "BackCompat") _isIE=8;
617} else {
618        _isFF=true;
619        var _FFrv = parseFloat(navigator.userAgent.split("rv:")[1])
620}
621
622
623//multibrowser Xpath processor
624dtmlXMLLoaderObject.prototype.doXPath=function(xpathExp, docObj, namespace, result_type){
625        if (_isKHTML || (!_isIE && !window.XPathResult))
626                return this.doXPathOpera(xpathExp, docObj);
627
628        if (_isIE){ //IE
629                if (!docObj)
630                        if (!this.xmlDoc.nodeName)
631                                docObj=this.xmlDoc.responseXML
632                        else
633                                docObj=this.xmlDoc;
634
635                if (!docObj)
636                        dhtmlxError.throwError("LoadXML", "Incorrect XML", [
637                                (docObj||this.xmlDoc),
638                                this.mainObject
639                        ]);
640
641                if (namespace != null)
642                        docObj.setProperty("SelectionNamespaces", "xmlns:xsl='"+namespace+"'"); //
643
644                if (result_type == 'single'){
645                        return docObj.selectSingleNode(xpathExp);
646                }
647                else {
648                        return docObj.selectNodes(xpathExp)||new Array(0);
649                }
650        } else { //Mozilla
651                var nodeObj = docObj;
652
653                if (!docObj){
654                        if (!this.xmlDoc.nodeName){
655                                docObj=this.xmlDoc.responseXML
656                        }
657                        else {
658                                docObj=this.xmlDoc;
659                        }
660                }
661
662                if (!docObj)
663                        dhtmlxError.throwError("LoadXML", "Incorrect XML", [
664                                (docObj||this.xmlDoc),
665                                this.mainObject
666                        ]);
667
668                if (docObj.nodeName.indexOf("document") != -1){
669                        nodeObj=docObj;
670                }
671                else {
672                        nodeObj=docObj;
673                        docObj=docObj.ownerDocument;
674                }
675                var retType = XPathResult.ANY_TYPE;
676
677                if (result_type == 'single')
678                        retType=XPathResult.FIRST_ORDERED_NODE_TYPE
679                var rowsCol = new Array();
680                var col = docObj.evaluate(xpathExp, nodeObj, function(pref){
681                        return namespace
682                }, retType, null);
683
684                if (retType == XPathResult.FIRST_ORDERED_NODE_TYPE){
685                        return col.singleNodeValue;
686                }
687                var thisColMemb = col.iterateNext();
688
689                while (thisColMemb){
690                        rowsCol[rowsCol.length]=thisColMemb;
691                        thisColMemb=col.iterateNext();
692                }
693                return rowsCol;
694        }
695}
696
697function _dhtmlxError(type, name, params){
698        if (!this.catches)
699                this.catches=new Array();
700
701        return this;
702}
703
704_dhtmlxError.prototype.catchError=function(type, func_name){
705        this.catches[type]=func_name;
706}
707_dhtmlxError.prototype.throwError=function(type, name, params){
708        if (this.catches[type])
709                return this.catches[type](type, name, params);
710
711        if (this.catches["ALL"])
712                return this.catches["ALL"](type, name, params);
713
714        alert("Error type: "+arguments[0]+"\nDescription: "+arguments[1]);
715        return null;
716}
717
718window.dhtmlxError=new _dhtmlxError();
719
720
721//opera fake, while 9.0 not released
722//multibrowser Xpath processor
723dtmlXMLLoaderObject.prototype.doXPathOpera=function(xpathExp, docObj){
724        //this is fake for Opera
725        var z = xpathExp.replace(/[\/]+/gi, "/").split('/');
726        var obj = null;
727        var i = 1;
728
729        if (!z.length)
730                return [];
731
732        if (z[0] == ".")
733                obj=[docObj]; else if (z[0] == ""){
734                obj=(this.xmlDoc.responseXML||this.xmlDoc).getElementsByTagName(z[i].replace(/\[[^\]]*\]/g, ""));
735                i++;
736        } else
737                return [];
738
739        for (i; i < z.length; i++)obj=this._getAllNamedChilds(obj, z[i]);
740
741        if (z[i-1].indexOf("[") != -1)
742                obj=this._filterXPath(obj, z[i-1]);
743        return obj;
744}
745
746dtmlXMLLoaderObject.prototype._filterXPath=function(a, b){
747        var c = new Array();
748        var b = b.replace(/[^\[]*\[\@/g, "").replace(/[\[\]\@]*/g, "");
749
750        for (var i = 0; i < a.length; i++)
751                if (a[i].getAttribute(b))
752                        c[c.length]=a[i];
753
754        return c;
755}
756dtmlXMLLoaderObject.prototype._getAllNamedChilds=function(a, b){
757        var c = new Array();
758
759        if (_isKHTML)
760                b=b.toUpperCase();
761
762        for (var i = 0; i < a.length; i++)for (var j = 0; j < a[i].childNodes.length; j++){
763                if (_isKHTML){
764                        if (a[i].childNodes[j].tagName&&a[i].childNodes[j].tagName.toUpperCase() == b)
765                                c[c.length]=a[i].childNodes[j];
766                }
767
768                else if (a[i].childNodes[j].tagName == b)
769                        c[c.length]=a[i].childNodes[j];
770        }
771
772        return c;
773}
774
775function dhtmlXHeir(a, b){
776        for (var c in b)
777                if (typeof (b[c]) == "function")
778                        a[c]=b[c];
779        return a;
780}
781
782function dhtmlxEvent(el, event, handler){
783        if (el.addEventListener)
784                el.addEventListener(event, handler, false);
785
786        else if (el.attachEvent)
787                el.attachEvent("on"+event, handler);
788}
789
790//============= XSL Extension ===================================
791
792dtmlXMLLoaderObject.prototype.xslDoc=null;
793dtmlXMLLoaderObject.prototype.setXSLParamValue=function(paramName, paramValue, xslDoc){
794        if (!xslDoc)
795                xslDoc=this.xslDoc
796
797        if (xslDoc.responseXML)
798                xslDoc=xslDoc.responseXML;
799        var item =
800                this.doXPath("/xsl:stylesheet/xsl:variable[@name='"+paramName+"']", xslDoc,
801                        "http:/\/www.w3.org/1999/XSL/Transform", "single");
802
803        if (item != null)
804                item.firstChild.nodeValue=paramValue
805}
806dtmlXMLLoaderObject.prototype.doXSLTransToObject=function(xslDoc, xmlDoc){
807        if (!xslDoc)
808                xslDoc=this.xslDoc;
809
810        if (xslDoc.responseXML)
811                xslDoc=xslDoc.responseXML
812
813        if (!xmlDoc)
814                xmlDoc=this.xmlDoc;
815
816        if (xmlDoc.responseXML)
817                xmlDoc=xmlDoc.responseXML
818
819        //MOzilla
820        if (!_isIE){
821                if (!this.XSLProcessor){
822                        this.XSLProcessor=new XSLTProcessor();
823                        this.XSLProcessor.importStylesheet(xslDoc);
824                }
825                var result = this.XSLProcessor.transformToDocument(xmlDoc);
826        } else {
827                var result = new ActiveXObject("Msxml2.DOMDocument.3.0");
828                try{
829                        xmlDoc.transformNodeToObject(xslDoc, result);
830                }catch(e){
831                        result = xmlDoc.transformNode(xslDoc);
832                }
833        }
834        return result;
835}
836
837dtmlXMLLoaderObject.prototype.doXSLTransToString=function(xslDoc, xmlDoc){
838        var res = this.doXSLTransToObject(xslDoc, xmlDoc);
839        if(typeof(res)=="string")
840                return res;
841        return this.doSerialization(res);
842}
843
844dtmlXMLLoaderObject.prototype.doSerialization=function(xmlDoc){
845        if (!xmlDoc)
846                        xmlDoc=this.xmlDoc;
847        if (xmlDoc.responseXML)
848                        xmlDoc=xmlDoc.responseXML
849        if (!_isIE){
850                var xmlSerializer = new XMLSerializer();
851                return xmlSerializer.serializeToString(xmlDoc);
852        } else
853                return xmlDoc.xml;
854}
855
856/**
857*   @desc:
858*   @type: private
859*/
860dhtmlxEventable=function(obj){
861                obj.dhx_SeverCatcherPath="";
862                obj.attachEvent=function(name, catcher, callObj){
863                        name='ev_'+name.toLowerCase();
864                        if (!this[name])
865                                this[name]=new this.eventCatcher(callObj||this);
866                               
867                        return(name+':'+this[name].addEvent(catcher)); //return ID (event name & event ID)
868                }
869                obj.callEvent=function(name, arg0){
870                        name='ev_'+name.toLowerCase();
871                        if (this[name])
872                                return this[name].apply(this, arg0);
873                        return true;
874                }
875                obj.checkEvent=function(name){
876                        return (!!this['ev_'+name.toLowerCase()])
877                }
878                obj.eventCatcher=function(obj){
879                        var dhx_catch = [];
880                        var z = function(){
881                                var res = true;
882                                for (var i = 0; i < dhx_catch.length; i++){
883                                        if (dhx_catch[i] != null){
884                                                var zr = dhx_catch[i].apply(obj, arguments);
885                                                res=res&&zr;
886                                        }
887                                }
888                                return res;
889                        }
890                        z.addEvent=function(ev){
891                                if (typeof (ev) != "function")
892                                        ev=eval(ev);
893                                if (ev)
894                                        return dhx_catch.push(ev)-1;
895                                return false;
896                        }
897                        z.removeEvent=function(id){
898                                dhx_catch[id]=null;
899                        }
900                        return z;
901                }
902                obj.detachEvent=function(id){
903                        if (id != false){
904                                var list = id.split(':');           //get EventName and ID
905                                this[list[0]].removeEvent(list[1]); //remove event
906                        }
907                }
908}
909
910
911/**
912        *       @desc: constructor, data processor object
913        *       @param: serverProcessorURL - url used for update
914        *       @type: public
915        */
916function dataProcessor(serverProcessorURL){
917    this.serverProcessor = serverProcessorURL;
918    this.action_param="!nativeeditor_status";
919   
920        this.obj = null;
921        this.updatedRows = []; //ids of updated rows
922       
923        this.autoUpdate = true;
924        this.updateMode = "cell";
925        this._tMode="GET";
926       
927    this._waitMode=0;
928    this._in_progress={};//?
929    this._invalid={};
930    this.mandatoryFields=[];
931    this.messages=[];
932   
933    this.styles={
934        updated:"font-weight:bold;",
935        inserted:"font-weight:bold;",
936        deleted:"text-decoration : line-through;",
937        invalid:"background-color:FFE0E0;",
938        invalid_cell:"border-bottom:2px solid red;",
939        error:"color:red;",
940        clear:"font-weight:normal;text-decoration:none;"
941    }
942   
943    this.enableUTFencoding(true);
944    dhtmlxEventable(this);
945
946    return this;
947    }
948
949dataProcessor.prototype={
950        /**
951        *       @desc: select GET or POST transaction model
952        *       @param: mode - GET/POST
953        *       @param: total - true/false - send records row by row or all at once (for grid only)
954        *       @type: public
955        */
956        setTransactionMode:function(mode,total){
957        this._tMode=mode;
958                this._tSend=total;
959    },
960    escape:function(data){
961        if (this._utf)
962                return encodeURIComponent(data);
963        else
964                return escape(data);
965        },
966    /**
967        *       @desc: allows to set escaping mode
968        *       @param: true - utf based escaping, simple - use current page encoding
969        *       @type: public
970        */     
971        enableUTFencoding:function(mode){
972        this._utf=convertStringToBoolean(mode);
973    },
974    /**
975        *       @desc: allows to define, which column may trigger update
976        *       @param: val - array or list of true/false values
977        *       @type: public
978        */
979        setDataColumns:function(val){
980                this._columns=(typeof val == "string")?val.split(","):val;
981    },
982    /**
983        *       @desc: get state of updating
984        *       @returns:   true - all in sync with server, false - some items not updated yet.
985        *       @type: public
986        */
987        getSyncState:function(){
988                return !this.updatedRows.length;
989        },
990        /**
991        *       @desc: enable/disable named field for data syncing, will use column ids for grid
992        *       @param:   mode - true/false
993        *       @type: public
994        */
995        enableDataNames:function(mode){
996                this._endnm=convertStringToBoolean(mode);
997        },
998        /**
999        *       @desc: enable/disable mode , when only changed fields and row id send to the server side, instead of all fields in default mode
1000        *       @param:   mode - true/false
1001        *       @type: public
1002        */
1003        enablePartialDataSend:function(mode){
1004                this._changed=convertStringToBoolean(mode);
1005        },
1006        /**
1007        *       @desc: set if rows should be send to server automaticaly
1008        *       @param: mode - "row" - based on row selection changed, "cell" - based on cell editing finished, "off" - manual data sending
1009        *       @type: public
1010        */
1011        setUpdateMode:function(mode,dnd){
1012                this.autoUpdate = (mode=="cell");
1013                this.updateMode = mode;
1014                this.dnd=dnd;
1015        },
1016        /**
1017        *       @desc: mark row as updated/normal. check mandatory fields,initiate autoupdate (if turned on)
1018        *       @param: rowId - id of row to set update-status for
1019        *       @param: state - true for "updated", false for "not updated"
1020        *       @param: mode - update mode name
1021        *       @type: public
1022        */
1023        setUpdated:function(rowId,state,mode){
1024                var ind=this.findRow(rowId);
1025               
1026                mode=mode||"updated";
1027                var existing = this.obj.getUserData(rowId,this.action_param);
1028                if (existing && mode == "updated") mode=existing;
1029                       
1030                if (state){
1031                        this.set_invalid(rowId,false); //clear previous error flag
1032                        this.updatedRows[ind]=rowId;
1033                        this.obj.setUserData(rowId,this.action_param,mode);
1034                } else{
1035                        if (!this.is_invalid(rowId)){
1036                                this.updatedRows.splice(ind,1);
1037                                this.obj.setUserData(rowId,this.action_param,"");
1038                        }
1039                }
1040
1041                //clear changed flag
1042                if (!state)
1043                        this._clearUpdateFlag(rowId);
1044                       
1045                this.markRow(rowId,state,mode);
1046                if (state && this.autoUpdate) this.sendData(rowId);
1047        },
1048        _clearUpdateFlag:function(){
1049                if (this.obj.mytype!="tree"){
1050                var row=this.obj.getRowById(rowId);
1051            if (row)
1052                for (var j=0; j<this.obj._cCount; j++)
1053                        this.obj.cells(rowId,j).cell.wasChanged=false;  //using cells because of split
1054        }                       
1055        },
1056        markRow:function(id,state,mode){
1057                var str="";
1058                var invalid=this.is_invalid(id)
1059                if (invalid){
1060                str=this.styles[invalid]
1061                state=true;
1062        }
1063                if (this.callEvent("onRowMark",[id,state,mode,invalid])){
1064                        //default logic
1065                        if (state)
1066                                str+=this.styles[mode];
1067                        else
1068                        str+=this.styles.clear;
1069                this.obj[this._methods[0]](id,str);
1070
1071                        if (invalid && invalid.details){
1072                                str+=this.styles[invalid+"_cell"];
1073                                for (var i=0; i < invalid.details.length; i++)
1074                                        if (invalid.details[i])
1075                                        this.obj[this._methods[1]](id,i,str);
1076                        }
1077                }
1078        },
1079        getState:function(id){
1080                return this.obj.getUserData(id,this.action_param);
1081        },
1082        is_invalid:function(id){
1083                return this._invalid[id];
1084        },
1085        set_invalid:function(id,mode,details){
1086                if (details) mode={value:mode, details:details, toString:function(){ return this.value.toString(); }}
1087                this._invalid[id]=mode;
1088        },
1089        /**
1090        *       @desc: check mandatory fields and varify values of cells, initiate update (if specified)
1091        *       @param: rowId - id of row to set update-status for
1092        *       @type: public
1093        */
1094        checkBeforeUpdate:function(rowId){
1095                var valid=true; var c_invalid=[];
1096                for (var i=0; i<this.obj._cCount; i++)
1097                        if (this.mandatoryFields[i]){
1098                                var res=this.mandatoryFields[i](this.obj.cells(rowId,i).getValue(),rowId,i);
1099                                if (typeof res == "string")
1100                                        this.messages.push(res);
1101                                else {
1102                                        valid&=res;
1103                                        c_invalid[i]=!res;
1104                                }
1105                        }
1106                if (!valid){
1107                        this.set_invalid(rowId,"invalid",c_invalid);
1108                        this.setUpdated(rowId,false);
1109                }
1110                return valid;
1111        },
1112        /**
1113        *       @desc: send row(s) values to server
1114        *       @param: rowId - id of row which data to send. If not specified, then all "updated" rows will be send
1115        *       @type: public
1116        */
1117        sendData:function(rowId){
1118                if (this._waitMode && (this.obj.mytype=="tree" || this.obj._h2)) return;
1119                if (this.obj.editStop) this.obj.editStop();
1120                if (this.obj.linked_form) this.obj.linked_form.update();
1121               
1122               
1123                if(typeof rowId == "undefined" || this._tSend) return this.sendAllData();
1124                if (this._in_progress[rowId]) return false;
1125               
1126                this.messages=[];
1127                if (!this.checkBeforeUpdate(rowId) && this.callEvent("onValidatationError",[rowId,this.messages])) return false;
1128                this._beforeSendData(this._getRowData(rowId),rowId);
1129    },
1130    _beforeSendData:function(data,rowId){
1131        if (!this.callEvent("onBeforeUpdate",[rowId,this.getState(rowId)])) return false;       
1132                this._sendData(data,rowId);
1133    },
1134    _sendData:function(a1,rowId){
1135        if (!a1) return; //nothing to send
1136        if (rowId)
1137                        this._in_progress[rowId]=(new Date()).valueOf();
1138           
1139                if (!this.callEvent("onBeforeDataSending",rowId?[rowId,this.getState(rowId)]:[])) return false;                         
1140                var a2=new dtmlXMLLoaderObject(this.afterUpdate,this,true);
1141        var a3=this.serverProcessor;
1142
1143                if (this._tMode!="POST")
1144                a2.loadXML(a3+((a3.indexOf("?")!=-1)?"&":"?")+a1);
1145                else
1146                a2.loadXML(a3,true,a1);
1147
1148                this._waitMode++;
1149    },
1150        sendAllData:function(){
1151                if (!this.updatedRows.length) return;                   
1152
1153                this.messages=[]; var valid=true;
1154                for (var i=0; i<this.updatedRows.length; i++)
1155                        valid&=this.checkBeforeUpdate(this.updatedRows[i]);
1156                if (!valid && !this.callEvent("onValidatationError",["",this.messages])) return false;
1157       
1158                if (this._tSend)
1159                        this._sendData(this._getAllData());
1160                else
1161                        for (var i=0; i<this.updatedRows.length; i++)
1162                                if (!this._in_progress[this.updatedRows[i]]){
1163                                        if (this.is_invalid(this.updatedRows[i])) continue;
1164                                        this._beforeSendData(this._getRowData(this.updatedRows[i]),this.updatedRows[i]);
1165                                        if (this._waitMode && (this.obj.mytype=="tree" || this.obj._h2)) return; //block send all for tree
1166                                }
1167        },
1168   
1169       
1170       
1171       
1172       
1173       
1174       
1175       
1176        _getAllData:function(rowId){
1177                var out=new Array();
1178                var rs=new Array();
1179                for(var i=0;i<this.updatedRows.length;i++){
1180                        var id=this.updatedRows[i];
1181                        if (this._in_progress[id] || this.is_invalid(id)) continue;
1182                        if (!this.callEvent("onBeforeUpdate",[id,this.getState(id)])) continue;
1183                        out[out.length]=this._getRowData(id,id+"_");
1184                        rs[rs.length]=id;
1185                        this._in_progress[id]=(new Date()).valueOf();
1186                }
1187                if (out.length)
1188                        out[out.length]="ids="+rs.join(",");
1189                return out.join("&");
1190        },
1191        _getRowData:function(rowId,pref){
1192                pref=(pref||"");
1193        if (this.obj.mytype=="tree"){
1194                        var z=this.obj._globalIdStorageFind(rowId);
1195                        var z2=z.parentObject;
1196                       
1197                        var i=0;
1198                        for (i=0; i<z2.childsCount; i++)
1199                                if (z2.childNodes[i]==z) break;
1200                       
1201                        var str=pref+"tr_id="+this.escape(z.id);
1202                        str+="&"+pref+"tr_pid="+this.escape(z2.id);
1203                        str+="&"+pref+"tr_order="+i;
1204                        str+="&"+pref+"tr_text="+this.escape(z.span.innerHTML);
1205                       
1206                        z2=(z._userdatalist||"").split(",");
1207                        for (i=0; i<z2.length; i++)
1208                                str+="&"+pref+this.escape(z2[i])+"="+this.escape(z.userData["t_"+z2[i]]);
1209
1210        }
1211        else{
1212           var str=pref+"gr_id="+this.escape(rowId);
1213                   if (this.obj.isTreeGrid())
1214                   str+="&"+pref+"gr_pid="+this.escape(this.obj.getParentId(rowId));
1215
1216           var r=this.obj.getRowById(rowId);
1217
1218           for (var i=0; i<this.obj._cCount; i++)
1219               {
1220                           if (this.obj._c_order)
1221                                        var i_c=this.obj._c_order[i];
1222                           else
1223                                        var i_c=i;
1224
1225                           var c=this.obj.cells(r.idd,i);
1226                           if (this._changed && !c.wasChanged()) continue;
1227                           if (this._endnm)
1228                       str+="&"+pref+this.obj.getColumnId(i)+"="+this.escape(c.getValue());
1229                           else
1230                       str+="&"+pref+"c"+i_c+"="+this.escape(c.getValue());
1231               }
1232           var data=this.obj.UserData[rowId];
1233           if (data){
1234               for (var j=0; j<data.keys.length; j++)
1235                   str+="&"+pref+data.keys[j]+"="+this.escape(data.values[j]);
1236           }
1237           var data=this.obj.UserData["gridglobaluserdata"];
1238           if (data){
1239               for (var j=0; j<data.keys.length; j++)
1240                   str+="&"+pref+data.keys[j]+"="+this.escape(data.values[j]);
1241           }
1242           
1243        }
1244        if (this.obj.linked_form)
1245                str+=this.obj.linked_form.get_serialized(rowId,pref);
1246        return str;
1247        },
1248       
1249       
1250       
1251       
1252       
1253       
1254       
1255       
1256        /**
1257        *       @desc: specify column which value should be varified before sending to server
1258        *       @param: ind - column index (0 based)
1259        *       @param: verifFunction - function (object) which should verify cell value (if not specified, then value will be compared to empty string). Two arguments will be passed into it: value and column name
1260        *       @type: public
1261        */
1262        setVerificator:function(ind,verifFunction){
1263                this.mandatoryFields[ind] = verifFunction||(function(value){return (value!="");});
1264        },
1265        /**
1266        *       @desc: remove column from list of those which should be verified
1267        *       @param: ind - column Index (0 based)
1268        *       @type: public
1269        */
1270        clearVerificator:function(ind){
1271                this.mandatoryFields[ind] = false;
1272        },
1273       
1274       
1275       
1276       
1277       
1278        findRow:function(pattern){
1279                var i=0;
1280        for(i=0;i<this.updatedRows.length;i++)
1281                    if(pattern==this.updatedRows[i]) break;
1282            return i;
1283    },
1284
1285   
1286       
1287
1288
1289   
1290
1291
1292
1293
1294
1295        /**
1296        *       @desc: define custom actions
1297        *       @param: name - name of action, same as value of action attribute
1298        *       @param: handler - custom function, which receives a XMl response content for action
1299        *       @type: private
1300        */
1301        defineAction:function(name,handler){
1302        if (!this._uActions) this._uActions=[];
1303            this._uActions[name]=handler;
1304        },
1305
1306
1307
1308
1309        /**
1310*     @desc: used in combination with setOnBeforeUpdateHandler to create custom client-server transport system
1311*     @param: sid - id of item before update
1312*     @param: tid - id of item after up0ate
1313*     @param: action - action name
1314*     @type: public
1315*     @topic: 0
1316*/
1317        afterUpdateCallback:function(sid, tid, action, btag) {
1318                delete this._in_progress[sid];
1319                var correct=(action!="error" && action!="invalid");
1320                if (!correct) this.set_invalid(sid,action);
1321                if ((this._uActions)&&(this._uActions[action])&&(!this._uActions[action](btag))) return;
1322        this.setUpdated(sid, false);
1323           
1324            var soid = sid;
1325       
1326            switch (action) {
1327            case "inserted":
1328            case "insert":
1329                if (tid != sid) {
1330                    this.obj[this._methods[2]](sid, tid);
1331                    sid = tid;
1332                }
1333                break;
1334            case "delete":
1335            case "deleted":
1336                this.obj.setUserData(sid, this.action_param, "true_deleted");
1337                this.obj[this._methods[3]](sid);
1338                return this.callEvent("onAfterUpdate", [sid, action, tid, btag])
1339                break;
1340            }
1341            //???
1342            if (correct) this.obj.setUserData(sid, this.action_param,'');
1343            this.callEvent("onAfterUpdate", [sid, action, tid, btag])
1344        },
1345
1346        /**
1347        *       @desc: response from server
1348        *       @param: xml - XMLLoader object with response XML
1349        *       @type: private
1350        */
1351        afterUpdate:function(that,b,c,d,xml){
1352                xml.getXMLTopNode("data"); //fix incorrect content type in IE
1353                if (!xml.xmlDoc.responseXML) return;
1354                var atag=xml.doXPath("//data/action");
1355                for (var i=0; i<atag.length; i++){
1356                var btag=atag[i];
1357                        var action = btag.getAttribute("type");
1358                        var sid = btag.getAttribute("sid");
1359                        var tid = btag.getAttribute("tid");
1360                       
1361                   
1362                        that.afterUpdateCallback(sid,tid,action,btag);
1363                }
1364                if (that._waitMode) that._waitMode--;
1365               
1366                if ((that.obj.mytype=="tree" || that.obj._h2) && that.updatedRows.length)
1367                        that.sendData();
1368                that.callEvent("onAfterUpdateFinish",[]);
1369                if (!that.updatedRows.length)
1370                        that.callEvent("onFullSync",[]);
1371        },
1372
1373
1374
1375
1376       
1377        /**
1378        *       @desc: initializes data-processor
1379        *       @param: anObj - dhtmlxGrid object to attach this data-processor to
1380        *       @type: public
1381        */
1382        init:function(anObj){
1383                this.obj = anObj;
1384                if (this.obj._dp_init) return this.obj._dp_init(this);
1385                var self = this;
1386               
1387        if (this.obj.mytype=="tree"){
1388                this._methods=["setItemStyle","","changeItemId","deleteItem"];
1389            this.obj.attachEvent("onEdit",function(state,id){
1390                if (state==3)
1391                    self.setUpdated(id,true)
1392                return true;
1393            });
1394            this.obj.attachEvent("onDrop",function(id,id_2,id_3,tree_1,tree_2){
1395                if (tree_1==tree_2)
1396                        self.setUpdated(id,true);
1397            });
1398                this.obj._onrdlh=function(rowId){
1399                        if (self.getState(rowId)=="true_deleted")
1400                                return true;
1401                        self.setUpdated(rowId,true,"deleted")
1402                        return false;
1403                };
1404                this.obj._onradh=function(rowId){
1405                        self.setUpdated(rowId,true,"inserted")
1406                };
1407        }
1408        else{
1409                this._methods=["setRowTextStyle","setCellTextStyle","changeRowId",,"deleteRow"];
1410                this.obj.attachEvent("onEditCell",function(state,id,index){
1411                        if (self._columns && !self._columns[index]) return true;
1412                        var cell = self.obj.cells(id,index)
1413                        if(state==1){
1414                                        if(cell.isCheckbox()){
1415                                        self.setUpdated(id,true)
1416                                }
1417                        }else if(state==2){
1418                                if(cell.wasChanged()){
1419                                                self.setUpdated(id,true)
1420                                }
1421                        }
1422                return true;
1423                })
1424                this.obj.attachEvent("onRowPaste",function(id){
1425                        self.setUpdated(id,true)
1426                        })
1427                        this.obj.attachEvent("onRowIdChange",function(id,newid){
1428                                var ind=self.findRow(id);
1429                                if (ind<self.updatedRows.length)
1430                                self.updatedRows[ind]=newid;
1431                        })
1432                this.obj.attachEvent("onSelectStateChanged",function(rowId){
1433                        if(self.updateMode=="row")
1434                                self.sendData();
1435                    return true;
1436                });
1437                this.obj.attachEvent("onEnter",function(rowId,celInd){
1438                        if(self.updateMode=="row")
1439                                self.sendData();
1440                    return true;
1441                });
1442                this.obj.attachEvent("onBeforeRowDeleted",function(rowId){
1443                        if (this.dragContext && self.dnd) {
1444                                window.setTimeout(function(){
1445                                        self.setUpdated(rowId,true);
1446                                        },1)
1447                                return true;
1448                                }
1449                var z=self.getState(rowId);
1450                                if (this._h2){
1451                                this._h2.forEachChild(rowId,function(el){
1452                                        self.setUpdated(el.id,false);
1453                                        self.markRow(el.id,true,"deleted");
1454                                        },this);
1455                        }
1456                        if (z=="inserted") {  self.setUpdated(rowId,false);             return true; }
1457                        if (z=="deleted")  return false;
1458                        if (z=="true_deleted")  return true;
1459
1460                        self.setUpdated(rowId,true,"deleted");
1461                        return false;
1462                });
1463                this.obj.attachEvent("onRowAdded",function(rowId){
1464                        if (this.dragContext && self.dnd) return true;
1465                                self.setUpdated(rowId,true,"inserted")
1466                return true;
1467                });
1468                this.obj.on_form_update=function(id){
1469                                self.setUpdated(id,true);
1470                                return true;
1471                        }
1472        }
1473        },
1474       
1475       
1476        link_form:function(obj){
1477                obj.on_update=this.obj.on_form_update;
1478        },
1479        setOnAfterUpdate:function(ev){
1480                this.attachEvent("onAfterUpdate",ev);
1481        },
1482        enableDebug:function(mode){
1483        },
1484        setOnBeforeUpdateHandler:function(func){ 
1485                this.attachEvent("onBeforeDataSending",func);
1486        }
1487}
1488//(c)dhtmlx ltd. www.dhtmlx.com
1489
1490
1491if (window.dhtmlXGridObject){
1492        dhtmlXGridObject.prototype._init_point_connector=dhtmlXGridObject.prototype._init_point;
1493        dhtmlXGridObject.prototype._init_point=function(){
1494                var clear_url=function(url){
1495                        url=url.replace(/(\?|\&)connector[^\f]*/g,"");
1496                        return url+(url.indexOf("?")!=-1?"&":"?")+"connector=true";
1497                }
1498                var combine_urls=function(url){
1499                        return clear_url(url)+(this._connector_sorting||"")+(this._connector_filter||"");
1500                }
1501                var sorting_url=function(url,ind,dir){
1502                        this._connector_sorting="&sort_ind="+ind+"&sort_dir="+dir;
1503                        return combine_urls.call(this,url);
1504                }
1505                var filtering_url=function(url,inds,vals){
1506                        this._connector_filter="&filter="+this._cCount+"&";
1507                        for (var i=0; i<inds.length; i++)
1508                                inds[i]="col"+inds[i]+"="+encodeURIComponent(vals[i]);
1509                        this._connector_filter+=inds.join("&");
1510                        return combine_urls.call(this,url);
1511                }
1512                this.attachEvent("onCollectValues",function(ind){
1513                                if (this._server_lists && this._server_lists[ind])
1514                                        return this._server_lists[ind];
1515                                return true;
1516                });             
1517                this.attachEvent("onBeforeSorting",function(ind,type,dir){
1518                        if (type=="connector"){
1519                                var self=this;
1520                                this.clearAndLoad(sorting_url.call(this,this.xmlFileUrl,ind,dir),function(){
1521                                        self.setSortImgState(true,ind,dir);
1522                                });
1523                                return false;
1524                        }
1525                        return true;
1526                });
1527                this.attachEvent("onFilterStart",function(a,b){
1528                        if (this._connector_filter_used){
1529                                this.clearAndLoad(filtering_url.call(this,this.xmlFileUrl,a,b));
1530                                return false;
1531                        }
1532                        return true;
1533                });
1534                this.attachEvent("onXLE",function(a,b,c,xml){
1535                        if (!xml) return;
1536                       
1537                        var form=this.getUserData("","!linked_form");
1538                       
1539                        if (form && (form=document.forms[form]) && !form.dhtmlx){
1540                                this.linked_form=new dhtmlXForm(form.name,this.xmlFileUrl);
1541                                this.attachEvent("onRowSelect",function(id){
1542                                        this.linked_form.load(id);
1543                                        return;
1544                                });
1545                                if (this.on_form_update) this.linked_form.on_update=this.on_form_update;
1546                        }
1547                       
1548                        if (!this._server_lists){
1549                                var selects=this.xmlLoader.doXPath("//options",xml);
1550                                if (selects) this._server_lists=[];
1551                                for (var i=0; i < selects.length; i++) {
1552                                        var ind = selects[i].getAttribute("for");
1553                                        var opts = this.xmlLoader.doXPath("./option",selects[i]);
1554                                        var result = [];
1555                                        for (var k=0; k < opts.length; k++) {
1556                                                result[k]=opts[k].firstChild?opts[k].firstChild.data:"";
1557                                        };
1558                                        this._server_lists[ind]=result;
1559                                        this._loadSelectOptins(this.getFilterElement(ind),ind)
1560                                };
1561                        }
1562                        //we are using server side defined filters, so blocking filter updates
1563                        if (this.refreshFilters) this._loadSelectOptins=function(){};
1564                });
1565               
1566                if (this._init_point_connector) this._init_point_connector();
1567        }
1568        dhtmlXGridObject.prototype._in_header_connector_text_filter=function(t,i){
1569                this._connector_filter_used=true;
1570                return this._in_header_text_filter(t,i);
1571        }
1572        dhtmlXGridObject.prototype._in_header_connector_select_filter=function(t,i){
1573                this._connector_filter_used=true;
1574                return this._in_header_select_filter(t,i);
1575        }
1576}
1577
1578if (window.dataProcessor){
1579        dataProcessor.prototype.init_original=dataProcessor.prototype.init;
1580        dataProcessor.prototype.init=function(obj){
1581                this.init_original(obj);
1582                obj._dataprocessor=this;
1583               
1584                this.setTransactionMode("POST",true);
1585                this.serverProcessor+=(this.serverProcessor.indexOf("?")!=-1?"&":"?")+"editing=true";
1586        }
1587}
1588/*dhtmlxError.catchError("LoadXML",function(a,b,c){
1589        alert(c[0].responseText);
1590});*/
1591
1592
1593window.dhtmlXScheduler=window.scheduler={version:2.2};
1594dhtmlxEventable(scheduler);
1595scheduler.init=function(id,date,mode){
1596        date=date||(new Date());
1597        mode=mode||"week";
1598       
1599        this._obj=(typeof id == "string")?document.getElementById(id):id;
1600        this._els=[];
1601        this._scroll=true;
1602        this._quirks=(_isIE && document.compatMode == "BackCompat");
1603        this._quirks7=(_isIE && navigator.appVersion.indexOf("MSIE 8")==-1);
1604       
1605        this.init_templates();
1606        this.get_elements()             
1607        this.set_actions();
1608        dhtmlxEvent(window,"resize",function(){
1609                window.clearTimeout(scheduler._resize_timer);
1610                scheduler._resize_timer=window.setTimeout(function(){
1611                        if (scheduler.callEvent("onSchedulerResize",[]))
1612                                scheduler.update_view();
1613                }, 100);
1614        })
1615       
1616        this.set_sizes();
1617        this.setCurrentView(date,mode);
1618};
1619scheduler.xy={
1620        nav_height:22,
1621        scale_width:50,
1622        bar_height:20,
1623        scroll_width:18,
1624        scale_height:20,
1625        menu_width:25,
1626        margin_top:0,
1627        margin_left:0
1628};
1629scheduler.keys={
1630        edit_save:13,
1631        edit_cancel:27
1632};
1633scheduler.set_sizes=function(){
1634        var w = this._x = this._obj.clientWidth-this.xy.margin_left;
1635        var h = this._y = this._obj.clientHeight-this.xy.margin_top;
1636       
1637        //not-table mode always has scroll - need to be fixed in future
1638        var scale_x=this._table_view?0:(this.xy.scale_width+this.xy.scroll_width);
1639        var scale_s=this._table_view?-1:this.xy.scale_width;
1640        var data_y=this.xy.scale_height+this.xy.nav_height+(this._quirks?-2:0);
1641       
1642        this.set_xy(this._els["dhx_cal_navline"][0],w,this.xy.nav_height,0,0);
1643        this.set_xy(this._els["dhx_cal_header"][0],w-scale_x,this.xy.scale_height,scale_s,this.xy.nav_height+(this._quirks?-1:1));
1644        this.set_xy(this._els["dhx_cal_data"][0],w,h-(data_y+2),0,data_y+2);
1645}
1646scheduler.set_xy=function(node,w,h,x,y){
1647        node.style.width=Math.max(0,w)+"px";
1648        node.style.height=Math.max(0,h)+"px";
1649        if (arguments.length>3){
1650                node.style.left=x+"px";
1651                node.style.top=y+"px"; 
1652        }
1653}
1654scheduler.get_elements=function(){
1655        //get all child elements as named hash
1656        var els=this._obj.getElementsByTagName("DIV");
1657        for (var i=0; i < els.length; i++){
1658                var name=els[i].className;
1659                if (!this._els[name]) this._els[name]=[];
1660                this._els[name].push(els[i]);
1661               
1662                //check if name need to be changed
1663                var t=scheduler.locale.labels[els[i].getAttribute("name")||name];
1664                if (t) els[i].innerHTML=t;
1665        }
1666}
1667scheduler.set_actions=function(){
1668        for (var a in this._els)
1669                if (this._click[a])
1670                        for (var i=0; i < this._els[a].length; i++)
1671                                this._els[a][i].onclick=scheduler._click[a];
1672        this._obj.onselectstart=function(e){ return false; }
1673        this._obj.onmousemove=function(e){
1674                scheduler._on_mouse_move(e||event);
1675        }
1676        this._obj.onmousedown=function(e){
1677                scheduler._on_mouse_down(e||event);
1678        }
1679        this._obj.onmouseup=function(e){
1680                scheduler._on_mouse_up(e||event);
1681        }
1682        this._obj.ondblclick=function(e){
1683                scheduler._on_dbl_click(e||event);
1684        }
1685}
1686scheduler.select=function(id){
1687        if (this._table_view || !this.getEvent(id)._timed) return; //temporary block
1688        if (this._select_id==id) return;
1689        this.editStop(false);
1690        this.unselect();
1691        this._select_id = id;
1692        this.updateEvent(id);
1693}
1694scheduler.unselect=function(id){
1695        if (id && id!=this._select_id) return;
1696        var t=this._select_id;
1697        this._select_id = null;
1698        if (t) this.updateEvent(t);
1699}
1700scheduler._click={
1701        dhx_cal_data:function(e){
1702                var trg = e?e.target:event.srcElement;
1703                var id = scheduler._locate_event(trg);
1704                if ((id && !scheduler.callEvent("onClick",[id,(e||event)])) ||scheduler.config.readonly) return;
1705                if (id) {               
1706                        scheduler.select(id);
1707                        var mask = trg.className;
1708                        if (mask.indexOf("_icon")!=-1)
1709                                scheduler._click.buttons[mask.split(" ")[1].replace("icon_","")](id);
1710                } else
1711                        scheduler._close_not_saved();
1712        },
1713        dhx_cal_prev_button:function(){
1714                scheduler._click.dhx_cal_next_button(0,-1);
1715        },
1716        dhx_cal_next_button:function(dummy,step){
1717                scheduler.setCurrentView(scheduler.date.add( //next line changes scheduler._date , but seems it has not side-effects
1718                        scheduler.date[scheduler._mode+"_start"](scheduler._date),(step||1),scheduler._mode));
1719        },
1720        dhx_cal_today_button:function(){
1721                scheduler.setCurrentView(new Date());
1722        },
1723        dhx_cal_tab:function(){
1724                var mode = this.getAttribute("name").split("_")[0];
1725                scheduler.setCurrentView(scheduler._date,mode);
1726        },
1727        buttons:{
1728                "delete":function(id){ var c=scheduler.locale.labels.confirm_deleting; if (!c||confirm(c)) scheduler.deleteEvent(id); },
1729                edit:function(id){ scheduler.edit(id); },
1730                save:function(id){ scheduler.editStop(true); },
1731                details:function(id){ scheduler.showLightbox(id); },
1732                cancel:function(id){ scheduler.editStop(false); }
1733        }
1734}
1735
1736scheduler.addEventNow=function(start,end,e){
1737        var d = this.config.time_step*60000;
1738        if (!start) start = Math.round((new Date()).valueOf()/d)*d;
1739        var start_date = new Date(start);
1740        if (!end){
1741                var start_hour = this.config.first_hour;
1742                if (start_hour > start_date.getHours()){
1743                        start_date.setHours(start_hour);
1744                        start = start_date.valueOf();
1745                }
1746                end = start+d;
1747        }
1748       
1749       
1750        this._drag_id=this.uid();
1751        this._drag_mode="new-size";
1752       
1753        this._loading=true;
1754        this.addEvent(start_date, new Date(end),this.locale.labels.new_event,this._drag_id);
1755        this.callEvent("onEventCreated",[this._drag_id,e]);
1756        this._loading=false;
1757       
1758        this._drag_event={}; //dummy , to trigger correct event updating logic
1759        this._on_mouse_up(e);   
1760}
1761scheduler._on_dbl_click=function(e,src){
1762        src = src||(e.target||e.srcElement);
1763        if (this.config.readonly) return;
1764        var name = src.className.split(" ")[0];
1765        switch(name){
1766                case "dhx_scale_holder":
1767                case "dhx_scale_holder_now":
1768                case "dhx_month_body":
1769                        if (!scheduler.config.dblclick_create) break;
1770                        var pos=this._mouse_coords(e);
1771                        var start=this._min_date.valueOf()+(pos.y*this.config.time_step+(this._table_view?0:pos.x)*24*60)*60000;
1772                        start = this._correct_shift(start);
1773                        this.addEventNow(start,null,e);
1774                        break;
1775                case "dhx_body":
1776                case "dhx_cal_event_line":
1777                case "dhx_cal_event_clear":
1778                        var id = this._locate_event(src);
1779                        if (!this.callEvent("onDblClick",[id,e])) return;
1780                        if (this.config.details_on_dblclick || this._table_view || !this.getEvent(id)._timed)
1781                                this.showLightbox(id);
1782                        else
1783                                this.edit(id);
1784                        break;
1785                case "":
1786                        if (src.parentNode)
1787                                return scheduler._on_dbl_click(e,src.parentNode);                       
1788                default:
1789                        var t = this["dblclick_"+name];
1790                        if (t) t.call(this,e);
1791                        break;
1792        }
1793}
1794
1795scheduler._mouse_coords=function(ev){
1796        var pos;
1797        var b=document.body;
1798        var d = document.documentElement;
1799        if(ev.pageX || ev.pageY)
1800            pos={x:ev.pageX, y:ev.pageY};
1801        else pos={
1802            x:ev.clientX + (b.scrollLeft||d.scrollLeft||0) - b.clientLeft,
1803            y:ev.clientY + (b.scrollTop||d.scrollTop||0) - b.clientTop
1804        }
1805
1806        //apply layout
1807        pos.x-=getAbsoluteLeft(this._obj)+(this._table_view?0:this.xy.scale_width);
1808        pos.y-=getAbsoluteTop(this._obj)+this.xy.nav_height+this._dy_shift+this.xy.scale_height-this._els["dhx_cal_data"][0].scrollTop;
1809        //transform to date
1810        if (!this._table_view){
1811                pos.x=Math.max(0,Math.ceil(pos.x/this._cols[0])-1);
1812                pos.y=Math.max(0,Math.ceil(pos.y*60/(this.config.time_step*this.config.hour_size_px))-1)+this.config.first_hour*(60/this.config.time_step);
1813        } else {
1814                var dy=0;
1815                for (dy=1; dy < this._colsS.heights.length; dy++)
1816                        if (this._colsS.heights[dy]>pos.y) break;
1817
1818                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;
1819                pos.x=0;
1820        }
1821        return pos;
1822}
1823scheduler._close_not_saved=function(){
1824        if (new Date().valueOf()-(scheduler._new_event||0) > 500 && scheduler._edit_id){
1825                var c=scheduler.locale.labels.confirm_closing;
1826                if (!c || confirm(c))
1827                        scheduler.editStop(scheduler.config.positive_closing);
1828        }
1829}
1830scheduler._correct_shift=function(start, back){
1831        return start-=((new Date(scheduler._min_date)).getTimezoneOffset()-(new Date(start)).getTimezoneOffset())*60000*(back?-1:1);   
1832}
1833scheduler._on_mouse_move=function(e){
1834        if (this._drag_mode){
1835                var pos=this._mouse_coords(e);
1836                if (!this._drag_pos || this._drag_pos.x!=pos.x || this._drag_pos.y!=pos.y){
1837                       
1838                        if (this._edit_id!=this._drag_id)
1839                                this._close_not_saved();
1840                               
1841                        this._drag_pos=pos;
1842                       
1843                        if (this._drag_mode=="create"){
1844                                this._close_not_saved();
1845                                this._loading=true; //will be ignored by dataprocessor
1846                               
1847                                var start=this._min_date.valueOf()+(pos.y*this.config.time_step+(this._table_view?0:pos.x)*24*60)*60000;
1848                                //if (this._mode != "week" && this._mode != "day")
1849                                start = this._correct_shift(start);
1850                               
1851                                if (!this._drag_start){
1852                                        this._drag_start=start; return;
1853                                }
1854                                var end = start;
1855                                if (end==this._drag_start) return;
1856                               
1857                                this._drag_id=this.uid();
1858                                this.addEvent(new Date(this._drag_start), new Date(end),this.locale.labels.new_event,this._drag_id);
1859                               
1860                                this.callEvent("onEventCreated",[this._drag_id,e]);
1861                                this._loading=false;
1862                                this._drag_mode="new-size";
1863                               
1864                        }
1865
1866                        var ev=this.getEvent(this._drag_id);
1867                        var start,end;
1868                        if (this._drag_mode=="move"){
1869                                start = this._min_date.valueOf()+(pos.y*this.config.time_step+pos.x*24*60)*60000+(this._table_view? this.date.time_part(ev.start_date)*1000:0);
1870                                start = this._correct_shift(start);
1871                                end = ev.end_date.valueOf()-(ev.start_date.valueOf()-start);
1872                        } else {
1873                                start = ev.start_date.valueOf();
1874                                if (this._table_view)
1875                                        end = this._min_date.valueOf()+pos.y*this.config.time_step*60000 + 24*60*60000;
1876                                else{
1877                                        end = this.date.date_part(ev.end_date).valueOf()+pos.y*this.config.time_step*60000;
1878                                        this._els["dhx_cal_data"][0].style.cursor="s-resize";
1879                                        if (this._mode == "week" || this._mode == "day")
1880                                                end = this._correct_shift(end);
1881                                }
1882                                if (this._drag_mode == "new-size"){
1883                                        if (end < this._drag_start){
1884                                                start = end;
1885                                                end = this._drag_start;
1886                                        }
1887                                } else if (end<=start)
1888                                        end=start+this.config.time_step*60000;
1889                        }
1890                        var new_end = new Date(end-1);                 
1891                        var new_start = new Date(start);
1892                        //prevent out-of-borders situation for day|week view
1893                        if (this._table_view || (new_end.getDate()==new_start.getDate() && new_end.getHours()<this.config.last_hour)){
1894                                ev.start_date=new_start;
1895                                ev.end_date=new Date(end);
1896                                if (this.config.update_render)
1897                                        this.update_view();
1898                                else
1899                                        this.updateEvent(this._drag_id);
1900                        }
1901                        if (this._table_view)
1902                                this.for_rendered(this._drag_id,function(r){
1903                                        r.className+=" dhx_in_move";
1904                                })
1905                }
1906        }
1907}
1908scheduler._on_mouse_context=function(e,src){
1909        return this.callEvent("onContextMenu",[this._locate_event(src),e]);
1910}
1911scheduler._on_mouse_down=function(e,src){
1912        if (this.config.readonly || this._drag_mode) return;
1913        src = src||(e.target||e.srcElement);
1914        if (e.button==2) return this._on_mouse_context(e,src);
1915                switch(src.className.split(" ")[0]){
1916                case "dhx_cal_event_line":
1917                case "dhx_cal_event_clear":
1918                        if (this._table_view)
1919                                this._drag_mode="move"; //item in table mode
1920                        break;
1921                case "dhx_header":
1922                case "dhx_title":
1923                        this._drag_mode="move"; //item in table mode
1924                        break;
1925                case "dhx_footer":
1926                        this._drag_mode="resize"; //item in table mode
1927                        break;
1928                case "dhx_scale_holder":
1929                case "dhx_scale_holder_now":
1930                case "dhx_month_body":
1931                        this._drag_mode="create";
1932                        break;
1933                case "":
1934                        if (src.parentNode)
1935                                return scheduler._on_mouse_down(e,src.parentNode);
1936                default:
1937                        this._drag_mode=null;
1938                        this._drag_id=null;
1939        }
1940        if (this._drag_mode){
1941                var id = this._locate_event(src);
1942                if (!this.config["drag_"+this._drag_mode] || !this.callEvent("onBeforeDrag",[id, this._drag_mode, e]))
1943                        this._drag_mode=this._drag_id=0;
1944                else {
1945                        this._drag_id= id;
1946                        this._drag_event=this._copy_event(this.getEvent(this._drag_id)||{});
1947                }
1948        }
1949        this._drag_start=null;
1950}
1951scheduler._on_mouse_up=function(e){
1952        if (this._drag_mode && this._drag_id){
1953                this._els["dhx_cal_data"][0].style.cursor="default";
1954                //drop
1955                var ev=this.getEvent(this._drag_id);
1956                if (!this._drag_event.start_date || ev.start_date.valueOf()!=this._drag_event.start_date.valueOf() || ev.end_date.valueOf()!=this._drag_event.end_date.valueOf()){
1957                        var is_new=(this._drag_mode=="new-size");
1958                        if (!this.callEvent("onBeforeEventChanged",[ev,e,is_new])){
1959                                if (is_new)
1960                                        this.deleteEvent(ev.id, true);
1961                                else {
1962                                        ev.start_date = this._drag_event.start_date;
1963                                        ev.end_date = this._drag_event.end_date;
1964                                        this.updateEvent(ev.id);
1965                                }
1966                        } else {
1967                                if (is_new && this.config.edit_on_create){
1968                                        this.unselect();
1969                                        this._new_event=new Date();//timestamp of creation
1970                                        if (this._table_view || this.config.details_on_create) {
1971                                                this._drag_mode=null;
1972                                                return this.showLightbox(this._drag_id);
1973                                        }
1974                                        this._drag_pos=true; //set flag to trigger full redraw
1975                                        this._select_id=this._edit_id=this._drag_id;
1976                                } else if (!this._new_event)
1977                                        this.callEvent(is_new?"onEventAdded":"onEventChanged",[this._drag_id,this.getEvent(this._drag_id)]);
1978                        }
1979                }
1980                if (this._drag_pos) this.render_view_data(); //redraw even if there is no real changes - necessary for correct positioning item after drag
1981        }
1982        this._drag_mode=null;
1983        this._drag_pos=null;
1984}       
1985scheduler.update_view=function(){
1986        //this.set_sizes();
1987        this._reset_scale();
1988        if (this._load_mode && this._load()) return;
1989        this.render_view_data();
1990}
1991scheduler.setCurrentView=function(date,mode){
1992       
1993        if (!this.callEvent("onBeforeViewChange",[this._mode,this._date,mode,date])) return;
1994        //hide old custom view
1995        if (this[this._mode+"_view"] && mode && this._mode!=mode)
1996                this[this._mode+"_view"](false);
1997               
1998        this._close_not_saved();
1999       
2000        this._mode=mode||this._mode;
2001        this._date=date;
2002        this._table_view=(this._mode=="month");
2003       
2004        var tabs=this._els["dhx_cal_tab"];
2005        for (var i=0; i < tabs.length; i++) {
2006                tabs[i].className="dhx_cal_tab"+((tabs[i].getAttribute("name")==this._mode+"_tab")?" active":"");
2007        };
2008       
2009        //show new view
2010        var view=this[this._mode+"_view"];
2011        view?view(true):this.update_view();
2012       
2013        this.callEvent("onViewChange",[this._mode,this._date]);
2014}
2015scheduler._render_x_header = function(i,left,d,h){
2016        //header scale 
2017        var head=document.createElement("DIV"); head.className="dhx_scale_bar";
2018        this.set_xy(head,this._cols[i]-1,this.xy.scale_height-2,left,0);//-1 for border
2019        head.innerHTML=this.templates[this._mode+"_scale_date"](d,this._mode); //TODO - move in separate method
2020        h.appendChild(head);
2021}
2022scheduler._reset_scale=function(){
2023        var h=this._els["dhx_cal_header"][0];
2024        var b=this._els["dhx_cal_data"][0];
2025        var c = this.config;
2026       
2027        h.innerHTML="";
2028        b.innerHTML="";
2029       
2030       
2031        var str=((c.readonly||(!c.drag_resize))?" dhx_resize_denied":"")+((c.readonly||(!c.drag_move))?" dhx_move_denied":"");
2032        if (str) b.className = "dhx_cal_data"+str;
2033               
2034               
2035        this._cols=[];  //store for data section
2036        this._colsS={height:0};
2037        this._dy_shift=0;
2038       
2039        this.set_sizes();
2040        var summ=parseInt(h.style.width); //border delta
2041        var left=0;
2042       
2043        var d,dd,sd,today;
2044        dd=this.date[this._mode+"_start"](new Date(this._date.valueOf()));
2045        d=sd=this._table_view?scheduler.date.week_start(dd):dd;
2046        today=this.date.date_part(new Date());
2047       
2048        //reset date in header
2049        var ed=scheduler.date.add(dd,1,this._mode);
2050        var count = 7;
2051       
2052        if (!this._table_view){
2053                var count_n = this.date["get_"+this._mode+"_end"];
2054                if (count_n) ed = count_n(dd);
2055                count = Math.round((ed.valueOf()-dd.valueOf())/(1000*60*60*24));
2056        }
2057       
2058        this._min_date=d;
2059        this._els["dhx_cal_date"][0].innerHTML=this.templates[this._mode+"_date"](dd,ed,this._mode);
2060       
2061       
2062        for (var i=0; i<count; i++){
2063                this._cols[i]=Math.floor(summ/(count-i));
2064       
2065                this._render_x_header(i,left,d,h);
2066                if (!this._table_view){
2067                        var scales=document.createElement("DIV");
2068                        var cls = "dhx_scale_holder"
2069                        if (d.valueOf()==today.valueOf()) cls = "dhx_scale_holder_now";
2070                        scales.className=cls+" "+this.templates.week_date_class(d,today);
2071                        this.set_xy(scales,this._cols[i]-1,c.hour_size_px*(c.last_hour-c.first_hour),left+this.xy.scale_width+1,0);//-1 for border
2072                        b.appendChild(scales);
2073                }
2074               
2075                d=this.date.add(d,1,"day")
2076                summ-=this._cols[i];
2077                left+=this._cols[i];
2078                this._colsS[i]=(this._cols[i-1]||0)+(this._colsS[i-1]||(this._table_view?0:52));
2079        }
2080        this._max_date=d;
2081        this._colsS[count]=this._cols[count-1]+this._colsS[count-1];
2082       
2083        if (this._table_view)
2084                this._reset_month_scale(b,dd,sd);
2085        else{
2086                this._reset_hours_scale(b,dd,sd);
2087                if (c.multi_day){
2088                        var c1 = document.createElement("DIV");
2089                        c1.className="dhx_multi_day";
2090                        c1.style.visibility="hidden";
2091                        this.set_xy(c1,parseInt(h.style.width),0,this.xy.scale_width,0);
2092                        b.appendChild(c1);
2093                        var c2 = c1.cloneNode(true);
2094                        c2.className="dhx_multi_day_icon";
2095                        c2.style.visibility="hidden";
2096                        this.set_xy(c2,this.xy.scale_width-1,0,0,0);
2097                        b.appendChild(c2);
2098                       
2099                        this._els["dhx_multi_day"]=[c1,c2];
2100                }
2101        }
2102}
2103scheduler._reset_hours_scale=function(b,dd,sd){
2104        var c=document.createElement("DIV");
2105        c.className="dhx_scale_holder";
2106       
2107        var date = new Date(1980,1,1,this.config.first_hour,0,0);
2108        for (var i=this.config.first_hour*1; i < this.config.last_hour; i++) {
2109                var cc=document.createElement("DIV");
2110                cc.className="dhx_scale_hour";
2111                cc.style.height=this.config.hour_size_px-(this._quirks?0:1)+"px";
2112                cc.style.width=this.xy.scale_width+"px";
2113                cc.innerHTML=scheduler.templates.hour_scale(date);
2114               
2115                c.appendChild(cc);
2116                date=this.date.add(date,1,"hour");
2117        };
2118        b.appendChild(c);
2119        if (this.config.scroll_hour)
2120                b.scrollTop = this.config.hour_size_px*(this.config.scroll_hour-this.config.first_hour);
2121}
2122scheduler._reset_month_scale=function(b,dd,sd){
2123        var ed=scheduler.date.add(dd,1,"month");
2124       
2125        //trim time part for comparation reasons
2126        var cd=new Date();
2127        this.date.date_part(cd);
2128        this.date.date_part(sd);
2129       
2130        var rows=Math.ceil((ed.valueOf()-sd.valueOf())/(60*60*24*1000*7));
2131        var tdcss=[];
2132        var height=(Math.floor(b.clientHeight/rows)-22);
2133       
2134        this._colsS.height=height+22;
2135        var h = this._colsS.heights = [];
2136        for (var i=0; i<=7; i++)
2137                tdcss[i]=" style='height:"+height+"px; width:"+((this._cols[i]||0)-1)+"px;' "
2138
2139       
2140       
2141        var cellheight = 0;
2142        this._min_date=sd;
2143        var html="<table cellpadding='0' cellspacing='0'>";
2144        for (var i=0; i<rows; i++){
2145                html+="<tr>";
2146                        for (var j=0; j<7; j++){
2147                                html+="<td";
2148                                var cls = "";
2149                                if (sd<dd)
2150                                        cls='dhx_before';
2151                                else if (sd>=ed)
2152                                        cls='dhx_after';
2153                                else if (sd.valueOf()==cd.valueOf())
2154                                        cls='dhx_now';
2155                                html+=" class='"+cls+" "+this.templates.month_date_class(sd,cd)+"' ";
2156                                html+="><div class='dhx_month_head'>"+this.templates.month_day(sd)+"</div><div class='dhx_month_body' "+tdcss[j]+"></div></td>"
2157                                sd=this.date.add(sd,1,"day");
2158                        }
2159                html+="</tr>";
2160                h[i] = cellheight;
2161                cellheight+=this._colsS.height;
2162        }
2163        html+="</table>";
2164        this._max_date=sd;
2165       
2166        b.innerHTML=html;       
2167}
2168
2169scheduler.date={
2170        date_part:function(date){
2171                date.setHours(0);
2172                date.setMinutes(0);
2173                date.setSeconds(0);
2174                date.setMilliseconds(0);       
2175                return date;
2176        },
2177        time_part:function(date){
2178                return (date.valueOf()/1000 - date.getTimezoneOffset()*60)%86400;
2179        },
2180        week_start:function(date){
2181                        var shift=date.getDay();
2182                        if (scheduler.config.start_on_monday){
2183                                if (shift==0) shift=6
2184                                else shift--;
2185                        }
2186                        return this.date_part(this.add(date,-1*shift,"day"));
2187        },
2188        month_start:function(date){
2189                date.setDate(1);
2190                return this.date_part(date);
2191        },
2192        year_start:function(date){
2193                date.setMonth(0);
2194                return this.month_start(date);
2195        },
2196        day_start:function(date){
2197                        return this.date_part(date);
2198        },
2199        add:function(date,inc,mode){
2200                var ndate=new Date(date.valueOf());
2201                switch(mode){
2202                        case "day": ndate.setDate(ndate.getDate()+inc); break;
2203                        case "week": ndate.setDate(ndate.getDate()+7*inc); break;
2204                        case "month": ndate.setMonth(ndate.getMonth()+inc); break;
2205                        case "year": ndate.setYear(ndate.getFullYear()+inc); break;
2206                        case "hour": ndate.setHours(ndate.getHours()+inc); break;
2207                        case "minute": ndate.setMinutes(ndate.getMinutes()+inc); break;
2208                        default:
2209                                return scheduler.date["add_"+mode](date,inc,mode);
2210                }
2211                return ndate;
2212        },
2213        to_fixed:function(num){
2214                if (num<10)     return "0"+num;
2215                return num;
2216        },
2217        copy:function(date){
2218                return new Date(date.valueOf());
2219        },
2220        date_to_str:function(format,utc){
2221                format=format.replace(/%[a-zA-Z]/g,function(a){
2222                        switch(a){
2223                               
2224                                case "%d": return "\"+scheduler.date.to_fixed(date.getDate())+\"";
2225                                case "%m": return "\"+scheduler.date.to_fixed((date.getMonth()+1))+\"";
2226                                case "%j": return "\"+date.getDate()+\"";
2227                                case "%n": return "\"+(date.getMonth()+1)+\"";
2228                                case "%y": return "\"+date.getYear()+\"";
2229                                case "%Y": return "\"+date.getFullYear()+\"";
2230                                case "%D": return "\"+scheduler.locale.date.day_short[date.getDay()]+\"";
2231                                case "%l": return "\"+scheduler.locale.date.day_full[date.getDay()]+\"";
2232                                case "%M": return "\"+scheduler.locale.date.month_short[date.getMonth()]+\"";
2233                                case "%F": return "\"+scheduler.locale.date.month_full[date.getMonth()]+\"";
2234                                case "%h": return "\"+scheduler.date.to_fixed((date.getHours()+11)%12+1)+\"";
2235                                case "%H": return "\"+scheduler.date.to_fixed(date.getHours())+\"";
2236                                case "%i": return "\"+scheduler.date.to_fixed(date.getMinutes())+\"";
2237                                case "%a": return "\"+(date.getHours()>11?\"pm\":\"am\")+\"";
2238                                case "%A": return "\"+(date.getHours()>11?\"PM\":\"AM\")+\"";
2239                                case "%s": return "\"+scheduler.date.to_fixed(date.getSeconds())+\"";
2240                                default: return a;
2241                        }
2242                })
2243                if (utc) format=format.replace(/date\.get/g,"date.getUTC");
2244                return new Function("date","return \""+format+"\";");
2245        },
2246        str_to_date:function(format,utc){
2247                var splt="var temp=date.split(/[^0-9a-zA-Z]+/g);";
2248                var mask=format.match(/%[a-zA-Z]/g);
2249                for (var i=0; i<mask.length; i++){
2250                        switch(mask[i]){
2251                                case "%j":
2252                                case "%d": splt+="set[2]=temp["+i+"]||0;";
2253                                        break;
2254                                case "%n":
2255                                case "%m": splt+="set[1]=(temp["+i+"]||1)-1;";
2256                                        break;
2257                                case "%y": splt+="set[0]=temp["+i+"]*1+(temp["+i+"]>50?1900:2000);";
2258                                        break;
2259                                case "%h":
2260                                case "%H":
2261                                                        splt+="set[3]=temp["+i+"]||0;";
2262                                        break;
2263                                case "%i":
2264                                                        splt+="set[4]=temp["+i+"]||0;";
2265                                        break;
2266                                case "%Y":  splt+="set[0]=temp["+i+"]||0;";
2267                                        break;
2268                                case "%a":                                     
2269                                case "%A":  splt+="set[3]=set[3]%12+((temp["+i+"]||'').toLowerCase()=='am'?0:12);";
2270                                        break;                                 
2271                                case "%s":  splt+="set[5]=temp["+i+"]||0;";
2272                                        break;
2273                        }
2274                }
2275                var code ="set[0],set[1],set[2],set[3],set[4],set[5]";
2276                if (utc) code =" Date.UTC("+code+")";
2277                return new Function("date","var set=[0,0,0,0,0,0]; "+splt+" return new Date("+code+");");
2278        }
2279}
2280
2281
2282scheduler.locale={
2283        date:{
2284                month_full:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
2285                month_short:["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
2286                day_full:["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
2287        day_short:["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
2288    },
2289    labels:{
2290        dhx_cal_today_button:"Today",
2291        day_tab:"Day",
2292        week_tab:"Week",
2293        month_tab:"Month",
2294        new_event:"New event",
2295                icon_save:"Save",
2296                icon_cancel:"Cancel",
2297                icon_details:"Details",
2298                icon_edit:"Edit",
2299                icon_delete:"Delete",
2300                confirm_closing:"",//Your changes will be lost, are your sure ?
2301                confirm_deleting:"Event will be deleted permanently, are you sure?",
2302                section_description:"Description",
2303                section_time:"Time period",
2304               
2305                /*recurring events*/
2306                confirm_recurring:"Do you want to edit the whole set of repeated events?",
2307                section_recurring:"Repeat event",
2308                button_recurring:"Disabled",
2309                button_recurring_open:"Enabled",
2310               
2311                /*agenda view extension*/
2312                agenda_tab:"Agenda",
2313                date:"Date",
2314                description:"Description",
2315               
2316                /*year view extension*/
2317                year_tab:"Year"
2318    }
2319}
2320
2321
2322
2323/*
2324%e      Day of the month without leading zeros (01..31)
2325%d      Day of the month, 2 digits with leading zeros (01..31)
2326%j      Day of the year, 3 digits with leading zeros (001..366)
2327%a      A textual representation of a day, two letters
2328%W      A full textual representation of the day of the week
2329
2330%c      Numeric representation of a month, without leading zeros (0..12)
2331%m      Numeric representation of a month, with leading zeros (00..12)
2332%b      A short textual representation of a month, three letters (Jan..Dec)
2333%M      A full textual representation of a month, such as January or March (January..December)
2334
2335%y      A two digit representation of a year (93..03)
2336%Y      A full numeric representation of a year, 4 digits (1993..03)
2337*/
2338
2339scheduler.config={
2340        default_date: "%j %M %Y",
2341        month_date: "%F %Y",
2342        load_date: "%Y-%m-%d",
2343        week_date: "%l",
2344        day_date: "%D, %F %j",
2345        hour_date: "%H:%i",
2346        month_day : "%d",
2347        xml_date:"%m/%d/%Y %H:%i",
2348        api_date:"%d-%m-%Y %H:%i",
2349
2350        hour_size_px:42,
2351        time_step:5,
2352
2353        start_on_monday:1,
2354        first_hour:0,
2355        last_hour:24,
2356        readonly:false,
2357        drag_resize:1,
2358        drag_move:1,
2359        drag_create:1,
2360        dblclick_create:1,
2361        edit_on_create:1,
2362        details_on_create:0,
2363        click_form_details:0,
2364       
2365        server_utc:false,
2366
2367        positive_closing:false,
2368
2369        icons_edit:["icon_save","icon_cancel"],
2370        icons_select:["icon_details","icon_edit","icon_delete"],
2371       
2372        lightbox:{
2373                sections:[      {name:"description", height:200, map_to:"text", type:"textarea" , focus:true},
2374                                        {name:"time", height:72, type:"time", map_to:"auto"}    ]
2375        }
2376};
2377scheduler.templates={}
2378scheduler.init_templates=function(){
2379        var d=scheduler.date.date_to_str;
2380        var c=scheduler.config;
2381        var f = function(a,b){
2382                for (var c in b)
2383                        if (!a[c]) a[c]=b[c];
2384        }
2385        f(scheduler.templates,{
2386                day_date:d(c.default_date),
2387                month_date:d(c.month_date),
2388                week_date:function(d1,d2){
2389                        return scheduler.templates.day_date(d1)+" &ndash; "+scheduler.templates.day_date(scheduler.date.add(d2,-1,"day"));
2390                },
2391                day_scale_date:d(c.default_date),
2392                month_scale_date:d(c.week_date),
2393                week_scale_date:d(c.day_date),
2394                hour_scale:d(c.hour_date),
2395                time_picker:d(c.hour_date),
2396                event_date:d(c.hour_date),
2397                month_day:d(c.month_day),
2398                xml_date:scheduler.date.str_to_date(c.xml_date,c.server_utc),
2399                load_format:d(c.load_date,c.server_utc),
2400                xml_format:d(c.xml_date,c.server_utc),
2401                api_date:scheduler.date.str_to_date(c.api_date),
2402                event_header:function(start,end,ev){
2403                        return scheduler.templates.event_date(start)+" - "+scheduler.templates.event_date(end);
2404                },
2405                event_text:function(start,end,ev){
2406                        return ev.text;
2407                },
2408                event_class:function(start,end,ev){
2409                        return "";
2410                },
2411                month_date_class:function(d){
2412                        return "";
2413                },
2414                week_date_class:function(d){
2415                        return "";
2416                },
2417                event_bar_date:function(start,end,ev){
2418                        return scheduler.templates.event_date(start)+" ";
2419                },
2420                event_bar_text:function(start,end,ev){
2421                        return ev.text;
2422                }
2423        });
2424        this.callEvent("onTemplatesReady",[])
2425}
2426
2427
2428
2429
2430scheduler.uid=function(){
2431        if (!this._seed) this._seed=(new Date).valueOf();
2432        return this._seed++;
2433}
2434scheduler._events={};
2435scheduler.clearAll=function(){
2436        this._events={};
2437        this._loaded={};
2438        this.clear_view();
2439}
2440scheduler.addEvent=function(start_date,end_date,text,id,extra_data){
2441        var ev=start_date;
2442        if (arguments.length!=1){
2443                ev=extra_data||{};
2444                ev.start_date=start_date;
2445                ev.end_date=end_date;
2446                ev.text=text;
2447                ev.id=id
2448        }
2449        ev.id = ev.id||scheduler.uid();
2450        ev.text = ev.text||"";
2451       
2452        if (typeof ev.start_date == "string")  ev.start_date=this.templates.api_date(ev.start_date);
2453        if (typeof ev.end_date == "string")  ev.end_date=this.templates.api_date(ev.end_date);
2454        ev._timed=this.is_one_day_event(ev);
2455
2456        var is_new=!this._events[ev.id];
2457        this._events[ev.id]=ev;
2458        this.event_updated(ev);
2459        if (!this._loading)
2460                this.callEvent(is_new?"onEventAdded":"onEventChanged",[ev.id,ev]);
2461}
2462scheduler.deleteEvent=function(id,silent){
2463        var ev=this._events[id];
2464        if (!silent && !this.callEvent("onBeforeEventDelete",[id,ev])) return;
2465       
2466        if (ev){
2467                delete this._events[id];
2468                this.unselect(id);
2469                this.event_updated(ev);
2470        }
2471}
2472scheduler.getEvent=function(id){
2473        return this._events[id];
2474}
2475scheduler.setEvent=function(id,hash){
2476        this._events[id]=hash;
2477}
2478scheduler.for_rendered=function(id,method){
2479        for (var i=this._rendered.length-1; i>=0; i--)
2480                if (this._rendered[i].getAttribute("event_id")==id)
2481                        method(this._rendered[i],i);
2482}
2483scheduler.changeEventId=function(id,new_id){
2484        if (id == new_id) return;
2485        var ev=this._events[id];
2486        if (ev){
2487                ev.id=new_id;
2488                this._events[new_id]=ev;
2489                delete this._events[id];
2490        }
2491        this.for_rendered(id,function(r){
2492                r.setAttribute("event_id",new_id);
2493        })
2494        if (this._select_id==id) this._select_id=new_id;
2495        if (this._edit_id==id) this._edit_id=new_id;
2496        this.callEvent("onEventIdChange",[id,new_id]);
2497};
2498
2499(function(){
2500        var attrs=["text","Text","start_date","StartDate","end_date","EndDate"];
2501        var create_getter=function(name){
2502                return function(id){ return (scheduler.getEvent(id))[name]; }
2503        }
2504        var create_setter=function(name){
2505                return function(id,value){
2506                        var ev=scheduler.getEvent(id); ev[name]=value;
2507                        ev._changed=true;
2508                        ev._timed=this.is_one_day_event(ev);
2509                        scheduler.event_updated(ev,true);
2510                }
2511        }
2512        for (var i=0; i<attrs.length; i+=2){
2513                scheduler["getEvent"+attrs[i+1]]=create_getter(attrs[i]);
2514                scheduler["setEvent"+attrs[i+1]]=create_setter(attrs[i]);
2515        }
2516})();
2517
2518scheduler.event_updated=function(ev,force){
2519        if (this.is_visible_events(ev))
2520                this.render_view_data();
2521        else this.clear_event(ev.id);
2522}
2523scheduler.is_visible_events=function(ev){
2524        if (ev.start_date<this._max_date && this._min_date<ev.end_date) return true;
2525        return false;
2526}
2527scheduler.is_one_day_event=function(ev){
2528        var delta = ev.end_date.getDate()-ev.start_date.getDate();
2529       
2530        return ( (!delta || (delta == 1 && !ev.end_date.getHours() && !ev.end_date.getMinutes() && (ev.start_date.getHours() || ev.start_date.getMinutes() ))) && ev.start_date.getMonth()==ev.end_date.getMonth() && ev.start_date.getFullYear()==ev.end_date.getFullYear()) ;
2531}
2532scheduler.get_visible_events=function(){
2533        //not the best strategy for sure
2534        var stack=[];
2535        var filter = this["filter_"+this._mode];
2536       
2537        for( var id in this._events)
2538                if (this.is_visible_events(this._events[id]))
2539                        if (this._table_view || this.config.multi_day || this._events[id]._timed)
2540                                if (!filter || filter(id,this._events[id]))
2541                                        stack.push(this._events[id]);
2542                               
2543        return stack;
2544}
2545scheduler.render_view_data=function(){
2546        if (this._not_render) {
2547                this._render_wait=true;
2548                return;
2549        }
2550        this._render_wait=false;
2551       
2552        this.clear_view();
2553        var evs=this.get_visible_events();
2554       
2555        if (this.config.multi_day && !this._table_view){
2556                var tvs = [];
2557                var tvd = [];
2558                for (var i=0; i < evs.length; i++){
2559                        if (evs[i]._timed)
2560                                tvs.push(evs[i]);
2561                        else
2562                                tvd.push(evs[i]);
2563                };
2564                this._table_view=true;
2565                this.render_data(tvd);
2566                this._table_view=false;         
2567                this.render_data(tvs);
2568        } else
2569                this.render_data(evs); 
2570}
2571scheduler.render_data=function(evs,hold){
2572        evs=this._pre_render_events(evs,hold);
2573        for (var i=0; i<evs.length; i++)
2574                if (this._table_view)
2575                        this.render_event_bar(evs[i]);
2576                else
2577                        this.render_event(evs[i]);
2578}
2579scheduler._pre_render_events=function(evs,hold){
2580        var hb = this.xy.bar_height;
2581        var h_old = this._colsS.heights;       
2582        var h=this._colsS.heights=[0,0,0,0,0,0,0];
2583       
2584        if (!this._table_view) evs=this._pre_render_events_line(evs,hold); //ignore long events for now
2585        else evs=this._pre_render_events_table(evs,hold);
2586       
2587        if (this._table_view){
2588                if (hold)
2589                        this._colsS.heights = h_old;
2590                else {
2591                        var evl = this._els["dhx_cal_data"][0].firstChild;
2592                        if (evl.rows){
2593                                for (var i=0; i<evl.rows.length; i++){
2594                                        h[i]++;
2595                                        if ((h[i])*hb > this._colsS.height-hb-2){
2596                                                //we have overflow, update heights
2597                                                var cells = evl.rows[i].cells;
2598                                                for (var j=0; j < cells.length; j++) {
2599                                                        cells[j].childNodes[1].style.height = h[i]*hb+"px";
2600                                                }
2601                                                h[i]=(h[i-1]||0)+cells[0].offsetHeight;
2602                                        }
2603                                        h[i]=(h[i-1]||0)+evl.rows[i].cells[0].offsetHeight;
2604                                }       
2605                                h.unshift(0);
2606                                if (evl.parentNode.offsetHeight<evl.parentNode.scrollHeight && !evl._h_fix){
2607                                        //we have v-scroll, decrease last day cell
2608                                        for (var i=0; i<evl.rows.length; i++){
2609                                                var cell = evl.rows[i].cells[6].childNodes[0];
2610                                                var w = cell.offsetWidth-scheduler.xy.scroll_width+"px";
2611                                                cell.style.width = w;
2612                                                cell.nextSibling.style.width = w;
2613                                        }               
2614                                        evl._h_fix=true;
2615                                }
2616                        } else{
2617                               
2618                                if (!evs.length && this._els["dhx_multi_day"][0].style.visibility == "visible")
2619                                        h[0]=-1;
2620                                if (evs.length || h[0]==-1){
2621                                        //shift days to have space for multiday events
2622                                        var childs = evl.parentNode.childNodes;
2623                                        var dh = (h[0]+1)*hb+"px";
2624                                        for (var i=0; i<childs.length; i++)
2625                                                if (this._colsS[i])
2626                                                        childs[i].style.top=dh;
2627                                        var last = this._els["dhx_multi_day"][0];
2628                                        last.style.top = "0px";
2629                                        last.style.height=dh;
2630                                        last.style.visibility=(h[0]==-1?"hidden":"visible");
2631                                        last=this._els["dhx_multi_day"][1];
2632                                        last.style.height=dh;
2633                                        last.style.visibility=(h[0]==-1?"hidden":"visible");
2634                                        last.className=h[0]?"dhx_multi_day_icon":"dhx_multi_day_icon_small";
2635                                       
2636                                        this._dy_shift=(h[0]+1)*hb;
2637                                        h[0] = 0;
2638                                }                               
2639                               
2640                        }
2641                }
2642        }
2643       
2644        return evs;
2645}
2646scheduler._get_event_sday=function(ev){
2647        return Math.floor((ev.start_date.valueOf()-this._min_date.valueOf())/(24*60*60*1000));
2648}
2649scheduler._pre_render_events_line=function(evs,hold){
2650        evs.sort(function(a,b){ return a.start_date>b.start_date?1:-1; })
2651        var days=[]; //events by weeks
2652        var evs_originals = [];
2653        for (var i=0; i < evs.length; i++) {
2654                var ev=evs[i];
2655
2656                //check scale overflow
2657                var sh = ev.start_date.getHours();
2658                var eh = ev.end_date.getHours();
2659               
2660                ev._sday=this._get_event_sday(ev);
2661                if (!days[ev._sday]) days[ev._sday]=[];
2662               
2663                if (!hold){
2664                        ev._inner=false;
2665                        var stack=days[ev._sday];
2666                        while (stack.length && stack[stack.length-1].end_date<=ev.start_date)
2667                                stack.splice(stack.length-1,1);
2668                        if (stack.length) stack[stack.length-1]._inner=true;
2669                        ev._sorder=stack.length; stack.push(ev);
2670                        if (stack.length>(stack.max_count||0)) stack.max_count=stack.length;
2671                }
2672               
2673                if (sh < this.config.first_hour || eh >= this.config.last_hour){
2674                        evs_originals.push(ev);
2675                        evs[i]=ev=this._copy_event(ev);
2676                        if (sh < this.config.first_hour){
2677                                ev.start_date.setHours(this.config.first_hour);
2678                                ev.start_date.setMinutes(0);
2679                        }
2680                        if (eh >= this.config.last_hour){
2681                                ev.end_date.setMinutes(0);
2682                                ev.end_date.setHours(this.config.last_hour);
2683                        }
2684                        if (ev.start_date>ev.end_date) {
2685                                evs.splice(i,1); i--; continue;
2686                        }
2687                }
2688                               
2689        }
2690        if (!hold){
2691                for (var i=0; i < evs.length; i++)
2692                        evs[i]._count=days[evs[i]._sday].max_count;
2693                for (var i=0; i < evs_originals.length; i++)
2694                        evs_originals[i]._count=days[evs_originals[i]._sday].max_count;
2695        }
2696       
2697        return evs;
2698}       
2699scheduler._time_order=function(evs){
2700                evs.sort(function(a,b){
2701                if (a.start_date.valueOf()==b.start_date.valueOf()){
2702                        if (a._timed && !b._timed) return 1;
2703                        if (!a._timed && b._timed) return -1;
2704                        return 0;
2705                }
2706                return a.start_date>b.start_date?1:-1;
2707         })
2708}
2709scheduler._pre_render_events_table=function(evs,hold){ // max - max height of week slot
2710        this._time_order(evs);
2711       
2712        var out=[];
2713        var weeks=[[],[],[],[],[],[],[]]; //events by weeks
2714        var max = this._colsS.heights;
2715        var start_date;
2716        var cols = this._cols.length;
2717       
2718        for (var i=0; i < evs.length; i++) {
2719                var ev=evs[i];
2720                var sd = (start_date||ev.start_date);
2721                var ed = ev.end_date;
2722                //trim events which are crossing through current view
2723                if (sd<this._min_date) sd=this._min_date;
2724                if (ed>this._max_date) ed=this._max_date;
2725               
2726                var locate_s = this.locate_holder_day(sd,false,ev);
2727                ev._sday=locate_s%cols;
2728                var locate_e = this.locate_holder_day(ed,true,ev)||cols;
2729                ev._eday=(locate_e%cols)||cols; //cols used to fill full week, when event end on monday
2730                ev._length=locate_e-locate_s;
2731               
2732                //3600000 - compensate 1 hour during winter|summer time shift
2733                ev._sweek=Math.floor((this._correct_shift(sd.valueOf(),1)-this._min_date.valueOf())/(60*60*1000*24*cols));     
2734               
2735                //current slot
2736                var stack=weeks[ev._sweek];
2737                //check order position
2738                while (stack.length && stack[stack.length-1]._eday<=ev._sday)
2739                //while (stack.length && stack[stack.length-1].end_date<=this.date.date_part(this.date.copy(ev.start_date)) )
2740                                stack.splice(stack.length-1,1);
2741                //get max height of slot
2742                if (stack.length>max[ev._sweek]) max[ev._sweek]=stack.length;
2743                               
2744                ev._sorder=stack.length;
2745               
2746                if (ev._sday+ev._length<=cols){
2747                        start_date=null;
2748                        out.push(ev);
2749                        stack.push(ev);
2750                } else{ // split long event in chunks
2751                        copy=this._copy_event(ev);
2752                        copy._length=cols-ev._sday;
2753                        copy._eday=cols; copy._sday=ev._sday;
2754                        copy._sweek=ev._sweek; copy._sorder=ev._sorder;
2755                        copy.end_date=this.date.add(sd,copy._length,"day");
2756                       
2757                        out.push(copy);
2758                        stack.push(copy);
2759                        start_date=copy.end_date;
2760                        i--; continue;  //repeat same step
2761                }
2762        };
2763       
2764        return out;
2765}
2766scheduler._copy_dummy=function(){
2767        this.start_date=new Date(this.start_date);
2768        this.end_date=new Date(this.end_date);
2769}
2770scheduler._copy_event=function(ev){
2771        this._copy_dummy.prototype = ev;
2772        return new this._copy_dummy();
2773        //return {start_date:ev.start_date, end_date:ev.end_date, text:ev.text, id:ev.id}
2774}
2775scheduler._rendered=[];
2776scheduler.clear_view=function(){
2777        for (var i=0; i<this._rendered.length; i++){
2778                var obj=this._rendered[i];
2779                if (obj.parentNode) obj.parentNode.removeChild(obj);           
2780        }
2781        this._rendered=[];
2782}
2783scheduler.updateEvent=function(id){
2784        var ev=this.getEvent(id);
2785        this.clear_event(id);
2786        if (ev && this.is_visible_events(ev))
2787                this.render_data([ev],true);
2788}
2789scheduler.clear_event=function(id){
2790        this.for_rendered(id,function(node,i){
2791                if (node.parentNode)
2792                        node.parentNode.removeChild(node);
2793                scheduler._rendered.splice(i,1);
2794        })
2795}
2796scheduler.render_event=function(ev){
2797        var menu = scheduler.xy.menu_width;
2798        if (ev._sday<0) return; //can occur in case of recurring event during time shift
2799        var parent=scheduler.locate_holder(ev._sday);   
2800        if (!parent) return; //attempt to render non-visible event
2801        var sm = ev.start_date.getHours()*60+ev.start_date.getMinutes();
2802        var em = ev.end_date.getHours()*60+ev.end_date.getMinutes();
2803       
2804        var top = (Math.round((sm*60*1000-this.config.first_hour*60*60*1000)*this.config.hour_size_px/(60*60*1000)))%(this.config.hour_size_px*24)+1; //42px/hour
2805        var height = Math.max(36,(em-sm)*this.config.hour_size_px/60)+1; //42px/hour
2806        //var height = Math.max(25,Math.round((ev.end_date.valueOf()-ev.start_date.valueOf())*(this.config.hour_size_px+(this._quirks?1:0))/(60*60*1000))); //42px/hour
2807        var width=Math.ceil((parent.clientWidth-menu)/ev._count);
2808        var left=ev._sorder*width+1;
2809        if (!ev._inner) width=width*(ev._count-ev._sorder);
2810       
2811       
2812       
2813        var d=this._render_v_bar(ev.id,menu+left,top,width,height,ev._text_style,scheduler.templates.event_header(ev.start_date,ev.end_date,ev),scheduler.templates.event_text(ev.start_date,ev.end_date,ev));
2814               
2815        this._rendered.push(d);
2816        parent.appendChild(d);
2817       
2818        left=left+parseInt(parent.style.left)+menu;
2819       
2820        top+=this._dy_shift; //corrupt top, to include possible multi-day shift
2821        if (this._edit_id==ev.id){
2822                width=Math.max(width-4,140);
2823                var d=document.createElement("DIV");
2824                d.setAttribute("event_id",ev.id);
2825                this.set_xy(d,width,height-6,left,top+14);
2826                d.className="dhx_cal_editor";
2827                       
2828                var d2=document.createElement("DIV");
2829                this.set_xy(d2,width-6,height-12);
2830                d2.style.cssText+=";margin:2px 2px 2px 2px;overflow:hidden;";
2831               
2832                d.appendChild(d2);
2833                this._els["dhx_cal_data"][0].appendChild(d);
2834                this._rendered.push(d);
2835       
2836                d2.innerHTML="<textarea class='dhx_cal_editor'>"+ev.text+"</textarea>";
2837                if (this._quirks7) d2.firstChild.style.height=height-12+"px"; //IEFIX
2838                this._editor=d2.firstChild;
2839                this._editor.onkeypress=function(e){
2840                        if ((e||event).shiftKey) return true;
2841                        var code=(e||event).keyCode;
2842                        if (code==scheduler.keys.edit_save) scheduler.editStop(true);
2843                        if (code==scheduler.keys.edit_cancel) scheduler.editStop(false);
2844                }
2845                this._editor.onselectstart=function(e){ return (e||event).cancelBubble=true; }
2846                d2.firstChild.focus();
2847                //IE and opera can add x-scroll during focusing
2848                this._els["dhx_cal_data"][0].scrollLeft=0;
2849                d2.firstChild.select();
2850        }
2851       
2852        if (this._select_id==ev.id){
2853                var icons=this.config["icons_"+((this._edit_id==ev.id)?"edit":"select")];
2854                var icons_str="";
2855                for (var i=0; i<icons.length; i++)
2856                        icons_str+="<div class='dhx_menu_icon "+icons[i]+"' title='"+this.locale.labels[icons[i]]+"'></div>";
2857                var obj = this._render_v_bar(ev.id,left-menu+1,top,menu,icons.length*20+26,"","<div class='dhx_menu_head'></div>",icons_str,true);
2858                obj.style.left=left-menu+1;
2859                this._els["dhx_cal_data"][0].appendChild(obj);
2860                this._rendered.push(obj);
2861        }
2862}
2863scheduler._render_v_bar=function(id,x,y,w,h,style,contentA,contentB,bottom){
2864        var d=document.createElement("DIV");
2865       
2866        var ev = this.getEvent(id);
2867        var cs = "dhx_cal_event";
2868        var cse = scheduler.templates.event_class(ev.start_date,ev.end_date,ev);
2869        if (cse) cs=cs+" "+cse;
2870       
2871        var html='<div event_id="'+id+'" class="'+cs+'" style="position:absolute; top:'+y+'px; left:'+x+'px; width:'+(w-4)+'px; height:'+h+'px;'+(style||"")+'">';
2872        html+='<div class="dhx_header" style=" width:'+(w-6)+'px;" >&nbsp;</div>';
2873        html+='<div class="dhx_title">'+contentA+'</div>';
2874        html+='<div class="dhx_body" style=" width:'+(w-(this._quirks?4:14))+'px; height:'+(h-(this._quirks?20:30))+'px;">'+contentB+'</div>';
2875        html+='<div class="dhx_footer" style=" width:'+(w-8)+'px;'+(bottom?' margin-top:-1px;':'')+'" ></div></div>';
2876       
2877        d.innerHTML=html;
2878        return d.firstChild;
2879}
2880scheduler.locate_holder=function(day){
2881        if (this._mode=="day") return this._els["dhx_cal_data"][0].firstChild; //dirty
2882        return this._els["dhx_cal_data"][0].childNodes[day];
2883}
2884scheduler.locate_holder_day=function(date,past){
2885        var day = Math.floor((this._correct_shift(date,1)-this._min_date)/(60*60*24*1000));
2886        //when locating end data of event , we need to use next day if time part was defined
2887        if (past && this.date.time_part(date)) day++;
2888        return day;
2889}
2890scheduler.render_event_bar=function(ev){
2891        var parent=this._els["dhx_cal_data"][0];
2892
2893        var x=this._colsS[ev._sday];
2894        var x2=this._colsS[ev._eday];
2895        if (x2==x) x2=this._colsS[ev._eday+1];
2896        var hb = this.xy.bar_height;
2897       
2898        var y=this._colsS.heights[ev._sweek]+(this._colsS.height?(this.xy.scale_height+2):2)+ev._sorder*hb;
2899                       
2900        var d=document.createElement("DIV");
2901        var cs = ev._timed?"dhx_cal_event_clear":"dhx_cal_event_line";
2902        var cse = scheduler.templates.event_class(ev.start_date,ev.end_date,ev);
2903        if (cse) cs=cs+" "+cse;
2904       
2905        var html='<div event_id="'+ev.id+'" class="'+cs+'" style="position:absolute; top:'+y+'px; left:'+x+'px; width:'+(x2-x-15)+'px;'+(ev._text_style||"")+'">';
2906               
2907        if (ev._timed)
2908                html+=scheduler.templates.event_bar_date(ev.start_date,ev.end_date,ev);
2909        html+=scheduler.templates.event_bar_text(ev.start_date,ev.end_date,ev)+'</div>';
2910        html+='</div>';
2911       
2912        d.innerHTML=html;
2913       
2914        this._rendered.push(d.firstChild);
2915        parent.appendChild(d.firstChild);
2916}
2917
2918scheduler._locate_event=function(node){
2919        var id=null;
2920        while (node && !id && node.getAttribute){
2921                id=node.getAttribute("event_id");
2922                node=node.parentNode
2923        }
2924        return id;
2925}
2926
2927
2928scheduler.edit=function(id){
2929        if (this._edit_id==id) return;
2930        this.editStop(false,id);
2931        this._edit_id=id;
2932        this.updateEvent(id);
2933}
2934scheduler.editStop=function(mode,id){
2935        if (id && this._edit_id==id) return;
2936        var ev=this.getEvent(this._edit_id);
2937        if (ev){
2938                if (mode) ev.text=this._editor.value;
2939                this._edit_id=null;
2940                this._editor=null;     
2941                this.updateEvent(ev.id);
2942                this._edit_stop_event(ev,mode);
2943        }
2944}
2945scheduler._edit_stop_event=function(ev,mode){
2946        if (this._new_event){
2947                if (!mode) this.deleteEvent(ev.id,true);               
2948                else this.callEvent("onEventAdded",[ev.id,ev]);
2949                this._new_event=null;
2950        } else
2951                if (mode) this.callEvent("onEventChanged",[ev.id,ev]);
2952}
2953
2954scheduler.getEvents = function(from,to){
2955        var result = [];
2956        for (var a in this._events){
2957                var ev = this._events[a];
2958                if (ev && ev.start_date<to && ev.end_date>from)
2959                        result.push(ev);
2960        }
2961        return result;
2962}
2963
2964scheduler._loaded={};
2965scheduler._load=function(url,from){
2966        url=url||this._load_url;
2967        url+=(url.indexOf("?")==-1?"?":"&")+"timeshift="+(new Date()).getTimezoneOffset();
2968        if (this.config.prevent_cache)  url+="&uid="+this.uid();
2969        var to;
2970        from=from||this._date;
2971       
2972        if (this._load_mode){
2973                var lf = this.templates.load_format;
2974               
2975                from = this.date[this._load_mode+"_start"](new Date(from.valueOf()));
2976                while (from>this._min_date) from=this.date.add(from,-1,this._load_mode);
2977                to = from;
2978               
2979                var cache_line = true;
2980                while (to<this._max_date){
2981                        to=this.date.add(to,1,this._load_mode);
2982                        if (this._loaded[lf(from)] && cache_line)
2983                                from=this.date.add(from,1,this._load_mode);     
2984                        else cache_line = false;
2985                }
2986               
2987                var temp_to=to;
2988                do {
2989                        to = temp_to;
2990                        temp_to=this.date.add(to,-1,this._load_mode);
2991                } while (temp_to>from && this._loaded[lf(temp_to)]);
2992                       
2993                if (to<=from)
2994                        return false; //already loaded
2995                dhtmlxAjax.get(url+"&from="+lf(from)+"&to="+lf(to),function(l){scheduler.on_load(l);});
2996                while(from<to){
2997                        this._loaded[lf(from)]=true;
2998                        from=this.date.add(from,1,this._load_mode);     
2999                }
3000        } else
3001                dhtmlxAjax.get(url,function(l){scheduler.on_load(l);});
3002        this.callEvent("onXLS",[]);
3003        return true;
3004}
3005scheduler.on_load=function(loader){
3006        this._loading=true;
3007        if (this._process)
3008                var evs=this[this._process].parse(loader.xmlDoc.responseText);
3009        else
3010                var evs=this._magic_parser(loader);
3011       
3012        this._not_render=true;
3013        for (var i=0; i<evs.length; i++){
3014                if (!this.callEvent("onEventLoading",[evs[i]])) continue;
3015                this.addEvent(evs[i]);
3016        }
3017        this._not_render=false;
3018        if (this._render_wait) this.render_view_data();
3019       
3020        if (this._after_call) this._after_call();
3021        this._after_call=null;
3022        this._loading=false;
3023        this.callEvent("onXLE",[]);
3024}
3025scheduler.load=function(url,call){
3026        if (typeof call == "string"){
3027                this._process=call;
3028                call = arguments[2];
3029        }
3030       
3031        this._load_url=url;
3032        this._after_call=call;
3033        this._load(url,this._date);
3034};
3035//possible values - day,week,month,year,all
3036scheduler.setLoadMode=function(mode){
3037        if (mode=="all") mode="";
3038        this._load_mode=mode;
3039};
3040
3041//current view by default, or all data if "true" as parameter provided
3042scheduler.refresh=function(refresh_all){
3043        alert("not implemented");
3044        /*
3045        this._loaded={};
3046        this._load();
3047        */
3048}
3049scheduler.serverList=function(name){
3050        return this.serverList[name] = (this.serverList[name]||[]);
3051}
3052scheduler._magic_parser=function(loader){
3053        //xml only for now
3054        var xml=loader.getXMLTopNode("data");
3055        if (xml.tagName!="data") return [];//not an xml
3056       
3057        var opts = loader.doXPath("//coll_options");
3058        for (var i=0; i < opts.length; i++) {
3059                var bind = opts[i].getAttribute("for");
3060                var arr = this.serverList[bind];
3061                if (!arr) continue;
3062                arr.splice(0,arr.length);       //clear old options
3063                var itms = loader.doXPath("//item",opts[i]);
3064                for (var j=0; j < itms.length; j++)
3065                        arr.push({ key:itms[j].getAttribute("value"), label:itms[j].getAttribute("label")});
3066        }
3067        if (opts.length)
3068                scheduler.callEvent("onOptionsLoad",[]);
3069               
3070        var evs=[];
3071        var xml=loader.doXPath("//event");
3072       
3073        for (var i=0; i < xml.length; i++) {
3074                evs[i]=this.xmlNodeToJSON(xml[i])
3075               
3076                evs[i].text=evs[i].text||evs[i]._tagvalue;
3077                evs[i].start_date=this.templates.xml_date(evs[i].start_date);
3078                evs[i].end_date=this.templates.xml_date(evs[i].end_date);
3079        }
3080        return evs;
3081}
3082scheduler.xmlNodeToJSON = function(node){
3083        var t={};
3084        for (var i=0; i<node.attributes.length; i++)
3085            t[node.attributes[i].name]=node.attributes[i].value;
3086       
3087        for (var i=0; i<node.childNodes.length; i++){
3088                var child=node.childNodes[i];
3089            if (child.nodeType==1)
3090                t[child.tagName]=child.firstChild?child.firstChild.nodeValue:"";
3091        }
3092                 
3093        if (!t.text) t.text=node.firstChild?node.firstChild.nodeValue:"";
3094       
3095        return t;
3096}
3097
3098scheduler.attachEvent("onXLS",function(){
3099        if (this.config.show_loading===true){
3100                var t;
3101                t=this.config.show_loading=document.createElement("DIV");
3102                t.className='dhx_loading';
3103                t.style.left = Math.round((this._x-128)/2)+"px";
3104                t.style.top = Math.round((this._y-15)/2)+"px";
3105                this._obj.appendChild(t);
3106        }
3107});
3108scheduler.attachEvent("onXLE",function(){
3109        var t;
3110        if (t=this.config.show_loading)
3111                if (typeof t == "object"){
3112                this._obj.removeChild(t);
3113                this.config.show_loading=true;
3114        }
3115});
3116
3117
3118scheduler.ical={
3119        parse:function(str){
3120                var data = str.match(RegExp(this.c_start+"[^\f]*"+this.c_end,""));
3121                if (!data.length) return;
3122               
3123                //unfolding
3124                data[0]=data[0].replace(/[\r\n]+(?=[a-z \t])/g," ");
3125                //drop property
3126                data[0]=data[0].replace(/\;[^:]*/g,"");
3127               
3128               
3129                var incoming=[];
3130                var match;
3131                var event_r = RegExp("(?:"+this.e_start+")([^\f]*?)(?:"+this.e_end+")","g");
3132                while (match=event_r.exec(data)){
3133                        var e={};
3134                        var param;
3135                        var param_r = /[^\r\n]+\r\n/g;
3136                        while (param=param_r.exec(match[1]))
3137                                this.parse_param(param.toString(),e);
3138                        incoming.push(e);       
3139                }
3140                return incoming;
3141        },
3142        parse_param:function(str,obj){
3143                var d = str.indexOf(":");
3144                        if (d==-1) return;
3145               
3146                var name = str.substr(0,d).toLowerCase();
3147                var value = str.substr(d+1).replace(/\\\,/g,",").replace(/[\r\n]+$/,"");
3148                if (name=="summary")
3149                        name="text";
3150                else if (name=="dtstart"){
3151                        name = "start_date";
3152                        value = this.parse_date(value,0,0);
3153                }
3154                else if (name=="dtend"){
3155                        name = "end_date";
3156                        if (obj.start_date && obj.start_date.getHours()==0)
3157                                value = this.parse_date(value,24,00);
3158                        else
3159                                value = this.parse_date(value,23,59);
3160                }
3161                obj[name]=value;
3162        },
3163        parse_date:function(value,dh,dm){
3164                var t = value.split("T");
3165                if (t[1]){
3166                        dh=t[1].substr(0,2);
3167                        dm=t[1].substr(2,2);
3168                }
3169                var dy = t[0].substr(0,4);
3170                var dn = parseInt(t[0].substr(4,2),10)-1;
3171                var dd = t[0].substr(6,2);
3172               
3173                return new Date(dy,dn,dd,dh,dm);
3174        },
3175        c_start:"BEGIN:VCALENDAR",
3176        e_start:"BEGIN:VEVENT",
3177        e_end:"END:VEVENT",
3178        c_end:"END:VCALENDAR"   
3179}
3180
3181scheduler.form_blocks={
3182        textarea:{
3183                render:function(sns){
3184                        var height=(sns.height||"130")+"px";
3185                        return "<div class='dhx_cal_ltext' style='height:"+height+";'><textarea></textarea></div>";
3186                },
3187                set_value:function(node,value,ev){
3188                        node.firstChild.value=value||"";
3189                },
3190                get_value:function(node,ev){
3191                        return node.firstChild.value;
3192                },
3193                focus:function(node){
3194                        var a=node.firstChild; a.select(); a.focus();
3195                }
3196        },
3197        select:{
3198                render:function(sns){
3199                        var height=(sns.height||"23")+"px";
3200                        var html="<div class='dhx_cal_ltext' style='height:"+height+";'><select style='width:552px;'>";
3201                        for (var i=0; i < sns.options.length; i++)
3202                                html+="<option value='"+sns.options[i].key+"'>"+sns.options[i].label+"</option>";
3203                        html+="</select></div>";
3204                        return html;
3205                },
3206                set_value:function(node,value,ev){
3207                        node.firstChild.value=value||"";
3208                },
3209                get_value:function(node,ev){
3210                        return node.firstChild.value;
3211                },
3212                focus:function(node){
3213                        var a=node.firstChild; a.select(); a.focus();
3214                }
3215        },     
3216        time:{
3217                render:function(){
3218                        //hours
3219                        var cfg = scheduler.config;
3220                        var dt = this.date.date_part(new Date());
3221                        if (cfg.first_hour)
3222                                dt.setHours(cfg.first_hour);
3223                               
3224                        var html="<select>";
3225                        for (var i=60*cfg.first_hour; i<60*cfg.last_hour; i+=this.config.time_step*1){
3226                                var time=this.templates.time_picker(dt);
3227                                html+="<option value='"+i+"'>"+time+"</option>";
3228                                dt=this.date.add(dt,this.config.time_step,"minute");
3229                        }
3230                       
3231                        //days
3232                        html+="</select> <select>";
3233                        for (var i=1; i < 32; i++)
3234                                html+="<option value='"+i+"'>"+i+"</option>";
3235                       
3236                        //month
3237                        html+="</select> <select>";
3238                        for (var i=0; i < 12; i++)
3239                                html+="<option value='"+i+"'>"+this.locale.date.month_full[i]+"</option>";
3240                       
3241                        //year
3242                        html+="</select> <select>";
3243                        dt = dt.getFullYear()-5; //maybe take from config?
3244                        for (var i=0; i < 10; i++)
3245                                html+="<option value='"+(dt+i)+"'>"+(dt+i)+"</option>";
3246                        html+="</select> ";
3247                       
3248                        return "<div style='height:30px; padding-top:0px; font-size:inherit;' class='dhx_cal_lsection'>"+html+"<span style='font-weight:normal; font-size:10pt;'> &nbsp;&ndash;&nbsp; </span>"+html+"</div>";
3249                },
3250                set_value:function(node,value,ev){
3251                        function _fill_lightbox_select(s,i,d){
3252                                s[i+0].value=Math.round((d.getHours()*60+d.getMinutes())/scheduler.config.time_step)*scheduler.config.time_step;       
3253                                s[i+1].value=d.getDate();
3254                                s[i+2].value=d.getMonth();
3255                                s[i+3].value=d.getFullYear();
3256                        }
3257                        var s=node.getElementsByTagName("select");
3258                        _fill_lightbox_select(s,0,ev.start_date);
3259                        _fill_lightbox_select(s,4,ev.end_date);
3260                },
3261                get_value:function(node,ev){
3262                        s=node.getElementsByTagName("select");
3263                        ev.start_date=new Date(s[3].value,s[2].value,s[1].value,0,s[0].value);
3264                        ev.end_date=new Date(s[7].value,s[6].value,s[5].value,0,s[4].value);
3265                        if (ev.end_date<=ev.start_date)
3266                                ev.end_date=scheduler.date.add(ev.start_date,scheduler.config.time_step,"minute");
3267                },
3268                focus:function(node){
3269                        node.getElementsByTagName("select")[0].focus();
3270                }
3271        }
3272}
3273scheduler.showCover=function(box){
3274        this.show_cover();
3275        if (box){
3276                box.style.display="block";
3277                var pos = getOffset(this._obj);
3278                box.style.top=Math.round(pos.top+(this._obj.offsetHeight-box.offsetHeight)/2)+"px";
3279                box.style.left=Math.round(pos.left+(this._obj.offsetWidth-box.offsetWidth)/2)+"px";     
3280        }
3281}
3282scheduler.showLightbox=function(id){
3283        if (!id) return;
3284        if (!this.callEvent("onBeforeLightbox",[id])) return;
3285        var box = this._get_lightbox();
3286        this.showCover(box);
3287        this._fill_lightbox(id,box);
3288}
3289scheduler._fill_lightbox=function(id,box){
3290        var ev=this.getEvent(id);
3291        var s=box.getElementsByTagName("span");
3292        s[1].innerHTML=this.templates.event_header(ev.start_date,ev.end_date,ev);
3293        s[2].innerHTML=this.templates.event_bar_text(ev.start_date,ev.end_date,ev);
3294       
3295        var sns = this.config.lightbox.sections;       
3296        for (var i=0; i < sns.length; i++) {
3297                var node=document.getElementById(sns[i].id).nextSibling;
3298                var block=this.form_blocks[sns[i].type];
3299                block.set_value.call(this,node,ev[sns[i].map_to],ev)
3300                if (sns[i].focus)
3301                        block.focus.call(this,node);
3302        };
3303       
3304        scheduler._lightbox_id=id;
3305}
3306scheduler._lightbox_out=function(ev){
3307        var sns = this.config.lightbox.sections;       
3308        for (var i=0; i < sns.length; i++) {
3309                var node=document.getElementById(sns[i].id).nextSibling;
3310                var block=this.form_blocks[sns[i].type];
3311                var res=block.get_value.call(this,node,ev);
3312                if (sns[i].map_to!="auto")
3313                        ev[sns[i].map_to]=res;
3314        }
3315        return ev;
3316}
3317scheduler._empty_lightbox=function(){
3318        var id=scheduler._lightbox_id;
3319        var ev=this.getEvent(id);
3320        var box=this._get_lightbox();
3321       
3322        this._lightbox_out(ev);
3323       
3324        ev._timed=this.is_one_day_event(ev);
3325        this.setEvent(ev.id,ev);
3326        this._edit_stop_event(ev,true)
3327        this.render_view_data();
3328}
3329scheduler.hide_lightbox=function(id){
3330        this.hideCover(this._get_lightbox());
3331        this._lightbox_id=null;
3332        this.callEvent("onAfterLightbox",[]);
3333}
3334scheduler.hideCover=function(box){
3335        if (box) box.style.display="none";
3336        this.hide_cover();
3337}
3338scheduler.hide_cover=function(){
3339        if (this._cover)
3340                this._cover.parentNode.removeChild(this._cover);
3341        this._cover=null;
3342}
3343scheduler.show_cover=function(){
3344        this._cover=document.createElement("DIV");
3345        this._cover.className="dhx_cal_cover";
3346        document.body.appendChild(this._cover);
3347}
3348scheduler._init_lightbox_events=function(){
3349        this._get_lightbox().onclick=function(e){
3350                var src=e?e.target:event.srcElement;
3351                if (!src.className) src=src.previousSibling;
3352                if (src && src.className)
3353                        switch(src.className){
3354                                case "dhx_save_btn":
3355                                        if (scheduler.checkEvent("onEventSave") &&                                              !scheduler.callEvent("onEventSave",[scheduler._lightbox_id,scheduler._lightbox_out({})]))
3356                                                        return;
3357                                        scheduler._empty_lightbox()
3358                                        scheduler.hide_lightbox();
3359                                        break;
3360                                case "dhx_delete_btn":
3361                                        var c=scheduler.locale.labels.confirm_deleting;
3362                                        if (!c||confirm(c)) {
3363                                                scheduler.deleteEvent(scheduler._lightbox_id);
3364                                                scheduler._new_event = null; //clear flag, if it was unsaved event
3365                                                scheduler.hide_lightbox();
3366                                        }
3367                                        break;
3368                                case "dhx_cancel_btn":
3369                                        scheduler.callEvent("onEventCancel",[scheduler._lightbox_id]);
3370                                        scheduler._edit_stop_event(scheduler.getEvent(scheduler._lightbox_id),false);
3371                                        scheduler.hide_lightbox();
3372                                        break;
3373                                       
3374                                default:
3375                                        if (src.className.indexOf("dhx_custom_button_")!=-1){
3376                                                var index = src.parentNode.getAttribute("index");
3377                                                var block=scheduler.form_blocks[scheduler.config.lightbox.sections[index].type];
3378                                                var sec = src.parentNode.parentNode;
3379                                                block.button_click(index,src,sec,sec.nextSibling);     
3380                                        }
3381                        }
3382        };
3383        this._get_lightbox().onkeypress=function(e){
3384                switch((e||event).keyCode){
3385                        case scheduler.keys.edit_save:
3386                                if ((e||event).shiftKey) return;
3387                                scheduler._empty_lightbox()
3388                                scheduler.hide_lightbox();
3389                                break;
3390                        case scheduler.keys.edit_cancel:
3391                                scheduler._edit_stop_event(scheduler.getEvent(scheduler._lightbox_id),false)
3392                                scheduler.hide_lightbox();
3393                                break;
3394                }
3395        }
3396}
3397scheduler.setLightboxSize=function(){
3398        var d = this._lightbox;
3399        if (!d) return;
3400       
3401        var con = d.childNodes[1];
3402        con.style.height="0px";
3403        con.style.height=con.scrollHeight+"px";         
3404        d.style.height=con.scrollHeight+50+"px";               
3405        con.style.height=con.scrollHeight+"px";          //it is incredible , how ugly IE can be       
3406}
3407
3408scheduler._get_lightbox=function(){
3409        if (!this._lightbox){
3410                var d=document.createElement("DIV");
3411                d.className="dhx_cal_light";
3412                if (/msie|MSIE 6/.test(navigator.userAgent))
3413                        d.className+=" dhx_ie6";
3414                d.style.visibility="hidden";
3415                d.innerHTML=this._lightbox_template;
3416                document.body.insertBefore(d,document.body.firstChild);
3417                this._lightbox=d;
3418               
3419                var sns=this.config.lightbox.sections;
3420                var html="";
3421                for (var i=0; i < sns.length; i++) {
3422                        var block=this.form_blocks[sns[i].type];
3423                        if (!block) continue; //ignore incorrect blocks
3424                        sns[i].id="area_"+this.uid();
3425                        var button = "";
3426                        if (sns[i].button) button = "<div style='float:right;' class='dhx_custom_button' index='"+i+"'><div class='dhx_custom_button_"+sns[i].name+"'></div><div>"+this.locale.labels["button_"+sns[i].button]+"</div></div>";
3427                        html+="<div id='"+sns[i].id+"' class='dhx_cal_lsection'>"+button+this.locale.labels["section_"+sns[i].name]+"</div>"+block.render.call(this,sns[i]);
3428                };
3429               
3430       
3431                //localization
3432                var ds=d.getElementsByTagName("div");
3433                ds[4].innerHTML=scheduler.locale.labels.icon_save;
3434                ds[7].innerHTML=scheduler.locale.labels.icon_cancel;
3435                ds[10].innerHTML=scheduler.locale.labels.icon_delete;
3436                //sections
3437                ds[1].innerHTML=html;
3438                //sizes
3439                this.setLightboxSize();
3440       
3441                this._init_lightbox_events(this);
3442                d.style.display="none";
3443                d.style.visibility="visible";
3444        }
3445        return this._lightbox;
3446}
3447scheduler._lightbox_template="<div class='dhx_cal_ltitle'><span class='dhx_mark'>&nbsp;</span><span class='dhx_time'></span><span class='dhx_title'></span></div><div class='dhx_cal_larea'></div><div class='dhx_btn_set'><div class='dhx_save_btn'></div><div>&nbsp;</div></div><div class='dhx_btn_set'><div class='dhx_cancel_btn'></div><div>&nbsp;</div></div><div class='dhx_btn_set' style='float:right;'><div class='dhx_delete_btn'></div><div>&nbsp;</div></div>";
3448
3449scheduler._dp_init=function(dp){
3450        dp._methods=["setEventTextStyle","","changeEventId","deleteEvent"];
3451       
3452        this.attachEvent("onEventAdded",function(id){
3453                if (!this._loading && this.validId(id))
3454                        dp.setUpdated(id,true,"inserted");
3455        });
3456        this.attachEvent("onBeforeEventDelete",function(id){
3457                if (!this.validId(id)) return;
3458        var z=dp.getState(id);
3459       
3460                if (z=="inserted" || this._new_event) {  dp.setUpdated(id,false);               return true; }
3461                if (z=="deleted")  return false;
3462        if (z=="true_deleted")  return true;
3463       
3464                dp.setUpdated(id,true,"deleted");
3465        return false;
3466        });
3467        this.attachEvent("onEventChanged",function(id){
3468                if (!this._loading && this.validId(id))
3469                        dp.setUpdated(id,true,"updated");
3470        });
3471       
3472        dp._getRowData=function(id,pref){
3473                pref=pref||"";
3474                var ev=this.obj.getEvent(id);
3475               
3476                var str=[];
3477                for (var a in ev){
3478                        if (a.indexOf("_")==0) continue;
3479                        if (ev[a] && ev[a].getUTCFullYear) //not very good, but will work
3480                                str.push(a+"="+this.obj.templates.xml_format(ev[a]));
3481                        else
3482                                str.push(a+"="+this.escape(ev[a]));
3483                }
3484               
3485                return pref+str.join("&"+pref);
3486        }
3487        dp._clearUpdateFlag=function(){}
3488}
3489
3490
3491scheduler.setUserData=function(id,name,value){
3492        this.getEvent(id)[name]=value;
3493}
3494scheduler.getUserData=function(id,name){
3495        return this.getEvent(id)[name];
3496}
3497scheduler.setEventTextStyle=function(id,style){
3498        this.for_rendered(id,function(r){
3499                r.style.cssText+=";"+style;
3500        })
3501        var ev = this.getEvent(id);
3502        ev["_text_style"]=style;
3503        this.event_updated(ev);
3504}
3505scheduler.validId=function(id){
3506        return true;
3507}
3508
3509
3510
Note: See TracBrowser for help on using the repository browser.