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