[4001] | 1 | window.dhtmlXScheduler=window.scheduler={version:2.2};
|
---|
| 2 | dhtmlxEventable(scheduler);
|
---|
| 3 | scheduler.init=function(id,date,mode){
|
---|
| 4 | date=date||(new Date());
|
---|
| 5 | mode=mode||"week";
|
---|
| 6 |
|
---|
| 7 | this._obj=(typeof id == "string")?document.getElementById(id):id;
|
---|
| 8 | this._els=[];
|
---|
| 9 | this._scroll=true;
|
---|
| 10 | this._quirks=(_isIE && document.compatMode == "BackCompat");
|
---|
| 11 | this._quirks7=(_isIE && navigator.appVersion.indexOf("MSIE 8")==-1);
|
---|
| 12 |
|
---|
| 13 | this.get_elements();
|
---|
| 14 | this.init_templates();
|
---|
| 15 | this.set_actions();
|
---|
| 16 | dhtmlxEvent(window,"resize",function(){
|
---|
| 17 | window.clearTimeout(scheduler._resize_timer);
|
---|
| 18 | scheduler._resize_timer=window.setTimeout(function(){
|
---|
| 19 | if (scheduler.callEvent("onSchedulerResize",[]))
|
---|
| 20 | scheduler.update_view();
|
---|
| 21 | }, 100);
|
---|
| 22 | })
|
---|
| 23 |
|
---|
| 24 | this.set_sizes();
|
---|
| 25 | this.setCurrentView(date,mode);
|
---|
| 26 | };
|
---|
| 27 | scheduler.xy={
|
---|
| 28 | nav_height:22,
|
---|
| 29 | min_event_height:40,
|
---|
| 30 | scale_width:50,
|
---|
| 31 | bar_height:20,
|
---|
| 32 | scroll_width:18,
|
---|
| 33 | scale_height:20,
|
---|
| 34 | month_scale_height:20,
|
---|
| 35 | menu_width:25,
|
---|
| 36 | margin_top:0,
|
---|
| 37 | margin_left:0,
|
---|
| 38 | editor_width:140
|
---|
| 39 | };
|
---|
| 40 | scheduler.keys={
|
---|
| 41 | edit_save:13,
|
---|
| 42 | edit_cancel:27
|
---|
| 43 | };
|
---|
| 44 | scheduler.set_sizes=function(){
|
---|
| 45 | var w = this._x = this._obj.clientWidth-this.xy.margin_left;
|
---|
| 46 | var h = this._y = this._obj.clientHeight-this.xy.margin_top;
|
---|
| 47 |
|
---|
| 48 | //not-table mode always has scroll - need to be fixed in future
|
---|
| 49 | var scale_x=this._table_view?0:(this.xy.scale_width+this.xy.scroll_width);
|
---|
| 50 | var scale_s=this._table_view?-1:this.xy.scale_width;
|
---|
| 51 |
|
---|
| 52 | this.set_xy(this._els["dhx_cal_navline"][0],w,this.xy.nav_height,0,0);
|
---|
| 53 | 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));
|
---|
| 54 | //to support alter-skin, we need a way to alter height directly from css
|
---|
| 55 | var actual_height = this._els["dhx_cal_navline"][0].offsetHeight;
|
---|
| 56 | if (actual_height > 0) this.xy.nav_height = actual_height;
|
---|
| 57 |
|
---|
| 58 | var data_y=this.xy.scale_height+this.xy.nav_height+(this._quirks?-2:0);
|
---|
| 59 | this.set_xy(this._els["dhx_cal_data"][0],w,h-(data_y+2),0,data_y+2);
|
---|
| 60 | }
|
---|
| 61 | scheduler.set_xy=function(node,w,h,x,y){
|
---|
| 62 | node.style.width=Math.max(0,w)+"px";
|
---|
| 63 | node.style.height=Math.max(0,h)+"px";
|
---|
| 64 | if (arguments.length>3){
|
---|
| 65 | node.style.left=x+"px";
|
---|
| 66 | node.style.top=y+"px";
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | scheduler.get_elements=function(){
|
---|
| 70 | //get all child elements as named hash
|
---|
| 71 | var els=this._obj.getElementsByTagName("DIV");
|
---|
| 72 | for (var i=0; i < els.length; i++){
|
---|
| 73 | var name=els[i].className;
|
---|
| 74 | if (!this._els[name]) this._els[name]=[];
|
---|
| 75 | this._els[name].push(els[i]);
|
---|
| 76 |
|
---|
| 77 | //check if name need to be changed
|
---|
| 78 | var t=scheduler.locale.labels[els[i].getAttribute("name")||name];
|
---|
| 79 | if (t) els[i].innerHTML=t;
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 | scheduler.set_actions=function(){
|
---|
| 83 | for (var a in this._els)
|
---|
| 84 | if (this._click[a])
|
---|
| 85 | for (var i=0; i < this._els[a].length; i++)
|
---|
| 86 | this._els[a][i].onclick=scheduler._click[a];
|
---|
| 87 | this._obj.onselectstart=function(e){ return false; }
|
---|
| 88 | this._obj.onmousemove=function(e){
|
---|
| 89 | scheduler._on_mouse_move(e||event);
|
---|
| 90 | }
|
---|
| 91 | this._obj.onmousedown=function(e){
|
---|
| 92 | scheduler._on_mouse_down(e||event);
|
---|
| 93 | }
|
---|
| 94 | this._obj.onmouseup=function(e){
|
---|
| 95 | scheduler._on_mouse_up(e||event);
|
---|
| 96 | }
|
---|
| 97 | this._obj.ondblclick=function(e){
|
---|
| 98 | scheduler._on_dbl_click(e||event);
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 | scheduler.select=function(id){
|
---|
| 102 | if (this._table_view || !this.getEvent(id)._timed) return; //temporary block
|
---|
| 103 | if (this._select_id==id) return;
|
---|
| 104 | this.editStop(false);
|
---|
| 105 | this.unselect();
|
---|
| 106 | this._select_id = id;
|
---|
| 107 | this.updateEvent(id);
|
---|
| 108 | }
|
---|
| 109 | scheduler.unselect=function(id){
|
---|
| 110 | if (id && id!=this._select_id) return;
|
---|
| 111 | var t=this._select_id;
|
---|
| 112 | this._select_id = null;
|
---|
| 113 | if (t) this.updateEvent(t);
|
---|
| 114 | }
|
---|
| 115 | scheduler.getState=function(){
|
---|
| 116 | return {
|
---|
| 117 | mode: this._mode,
|
---|
| 118 | date: this._date,
|
---|
| 119 | min_date: this._min_date,
|
---|
| 120 | max_date: this._max_date,
|
---|
| 121 | editor_id: this._edit_id,
|
---|
| 122 | lightbox_id: this._lightbox_id
|
---|
| 123 | };
|
---|
| 124 | }
|
---|
| 125 | scheduler._click={
|
---|
| 126 | dhx_cal_data:function(e){
|
---|
| 127 | var trg = e?e.target:event.srcElement;
|
---|
| 128 | var id = scheduler._locate_event(trg);
|
---|
| 129 |
|
---|
| 130 | e = e || event;
|
---|
| 131 | if ((id && !scheduler.callEvent("onClick",[id,e])) ||scheduler.config.readonly) return;
|
---|
| 132 |
|
---|
| 133 | if (id) {
|
---|
| 134 | scheduler.select(id);
|
---|
| 135 | var mask = trg.className;
|
---|
| 136 | if (mask.indexOf("_icon")!=-1)
|
---|
| 137 | scheduler._click.buttons[mask.split(" ")[1].replace("icon_","")](id);
|
---|
| 138 | } else
|
---|
| 139 | scheduler._close_not_saved();
|
---|
| 140 | },
|
---|
| 141 | dhx_cal_prev_button:function(){
|
---|
| 142 | scheduler._click.dhx_cal_next_button(0,-1);
|
---|
| 143 | },
|
---|
| 144 | dhx_cal_next_button:function(dummy,step){
|
---|
| 145 | scheduler.setCurrentView(scheduler.date.add( //next line changes scheduler._date , but seems it has not side-effects
|
---|
| 146 | scheduler.date[scheduler._mode+"_start"](scheduler._date),(step||1),scheduler._mode));
|
---|
| 147 | },
|
---|
| 148 | dhx_cal_today_button:function(){
|
---|
| 149 | scheduler.setCurrentView(new Date());
|
---|
| 150 | },
|
---|
| 151 | dhx_cal_tab:function(){
|
---|
| 152 | var mode = this.getAttribute("name").split("_")[0];
|
---|
| 153 | scheduler.setCurrentView(scheduler._date,mode);
|
---|
| 154 | },
|
---|
| 155 | buttons:{
|
---|
| 156 | "delete":function(id){ var c=scheduler.locale.labels.confirm_deleting; if (!c||confirm(c)) scheduler.deleteEvent(id); },
|
---|
| 157 | edit:function(id){ scheduler.edit(id); },
|
---|
| 158 | save:function(id){ scheduler.editStop(true); },
|
---|
| 159 | details:function(id){ scheduler.showLightbox(id); },
|
---|
| 160 | cancel:function(id){ scheduler.editStop(false); }
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | scheduler.addEventNow=function(start,end,e){
|
---|
| 165 | var base = {};
|
---|
| 166 | if (typeof start == "object"){
|
---|
| 167 | base = start;
|
---|
| 168 | start = null;
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | var d = (this.config.event_duration||this.config.time_step)*60000;
|
---|
| 172 | if (!start) start = Math.round((new Date()).valueOf()/d)*d;
|
---|
| 173 | var start_date = new Date(start);
|
---|
| 174 | if (!end){
|
---|
| 175 | var start_hour = this.config.first_hour;
|
---|
| 176 | if (start_hour > start_date.getHours()){
|
---|
| 177 | start_date.setHours(start_hour);
|
---|
| 178 | start = start_date.valueOf();
|
---|
| 179 | }
|
---|
| 180 | end = start+d;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 |
|
---|
| 184 | base.start_date = base.start_date||start_date;
|
---|
| 185 | base.end_date = base.end_date||new Date(end);
|
---|
| 186 | base.text = base.text||this.locale.labels.new_event;
|
---|
| 187 | base.id = this._drag_id = this.uid();
|
---|
| 188 | this._drag_mode="new-size";
|
---|
| 189 |
|
---|
| 190 | this._loading=true;
|
---|
| 191 | this.addEvent(base);
|
---|
| 192 | this.callEvent("onEventCreated",[this._drag_id,e]);
|
---|
| 193 | this._loading=false;
|
---|
| 194 |
|
---|
| 195 | this._drag_event={}; //dummy , to trigger correct event updating logic
|
---|
| 196 | this._on_mouse_up(e);
|
---|
| 197 | }
|
---|
| 198 | scheduler._on_dbl_click=function(e,src){
|
---|
| 199 | src = src||(e.target||e.srcElement);
|
---|
| 200 | if (this.config.readonly) return;
|
---|
| 201 | var name = src.className.split(" ")[0];
|
---|
| 202 | switch(name){
|
---|
| 203 | case "dhx_scale_holder":
|
---|
| 204 | case "dhx_scale_holder_now":
|
---|
| 205 | case "dhx_month_body":
|
---|
| 206 | if (!scheduler.config.dblclick_create) break;
|
---|
| 207 | var pos=this._mouse_coords(e);
|
---|
| 208 | var start=this._min_date.valueOf()+(pos.y*this.config.time_step+(this._table_view?0:pos.x)*24*60)*60000;
|
---|
| 209 | start = this._correct_shift(start);
|
---|
| 210 | this.addEventNow(start,null,e);
|
---|
| 211 | break;
|
---|
| 212 | case "dhx_body":
|
---|
| 213 | case "dhx_cal_event_line":
|
---|
| 214 | case "dhx_cal_event_clear":
|
---|
| 215 | var id = this._locate_event(src);
|
---|
| 216 | if (!this.callEvent("onDblClick",[id,e])) return;
|
---|
| 217 | if (this.config.details_on_dblclick || this._table_view || !this.getEvent(id)._timed)
|
---|
| 218 | this.showLightbox(id);
|
---|
| 219 | else
|
---|
| 220 | this.edit(id);
|
---|
| 221 | break;
|
---|
| 222 | case "":
|
---|
| 223 | if (src.parentNode)
|
---|
| 224 | return scheduler._on_dbl_click(e,src.parentNode);
|
---|
| 225 | default:
|
---|
| 226 | var t = this["dblclick_"+name];
|
---|
| 227 | if (t) t.call(this,e);
|
---|
| 228 | break;
|
---|
| 229 | }
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | scheduler._mouse_coords=function(ev){
|
---|
| 233 | var pos;
|
---|
| 234 | var b=document.body;
|
---|
| 235 | var d = document.documentElement;
|
---|
| 236 | if(ev.pageX || ev.pageY)
|
---|
| 237 | pos={x:ev.pageX, y:ev.pageY};
|
---|
| 238 | else pos={
|
---|
| 239 | x:ev.clientX + (b.scrollLeft||d.scrollLeft||0) - b.clientLeft,
|
---|
| 240 | y:ev.clientY + (b.scrollTop||d.scrollTop||0) - b.clientTop
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | //apply layout
|
---|
| 244 | pos.x-=getAbsoluteLeft(this._obj)+(this._table_view?0:this.xy.scale_width);
|
---|
| 245 | pos.y-=getAbsoluteTop(this._obj)+this.xy.nav_height+(this._dy_shift||0)+this.xy.scale_height-this._els["dhx_cal_data"][0].scrollTop;
|
---|
| 246 | pos.ev = ev;
|
---|
| 247 |
|
---|
| 248 | var handler = this["mouse_"+this._mode];
|
---|
| 249 | if (handler)
|
---|
| 250 | return handler.call(this,pos);
|
---|
| 251 |
|
---|
| 252 | //transform to date
|
---|
| 253 | if (!this._table_view){
|
---|
| 254 | pos.x=Math.max(0,Math.ceil(pos.x/this._cols[0])-1);
|
---|
| 255 | 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);
|
---|
| 256 | } else {
|
---|
| 257 | var dy=0;
|
---|
| 258 | for (dy=1; dy < this._colsS.heights.length; dy++)
|
---|
| 259 | if (this._colsS.heights[dy]>pos.y) break;
|
---|
| 260 |
|
---|
| 261 | 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;
|
---|
| 262 | pos.x=0;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | return pos;
|
---|
| 266 | }
|
---|
| 267 | scheduler._close_not_saved=function(){
|
---|
| 268 | if (new Date().valueOf()-(scheduler._new_event||0) > 500 && scheduler._edit_id){
|
---|
| 269 | var c=scheduler.locale.labels.confirm_closing;
|
---|
| 270 | if (!c || confirm(c))
|
---|
| 271 | scheduler.editStop(scheduler.config.positive_closing);
|
---|
| 272 | }
|
---|
| 273 | }
|
---|
| 274 | scheduler._correct_shift=function(start, back){
|
---|
| 275 | return start-=((new Date(scheduler._min_date)).getTimezoneOffset()-(new Date(start)).getTimezoneOffset())*60000*(back?-1:1);
|
---|
| 276 | }
|
---|
| 277 | scheduler._on_mouse_move=function(e){
|
---|
| 278 | if (this._drag_mode){
|
---|
| 279 | var pos=this._mouse_coords(e);
|
---|
| 280 | if (!this._drag_pos || this._drag_pos.x!=pos.x || this._drag_pos.y!=pos.y){
|
---|
| 281 |
|
---|
| 282 | if (this._edit_id!=this._drag_id)
|
---|
| 283 | this._close_not_saved();
|
---|
| 284 |
|
---|
| 285 | this._drag_pos=pos;
|
---|
| 286 |
|
---|
| 287 | if (this._drag_mode=="create"){
|
---|
| 288 | this._close_not_saved();
|
---|
| 289 | this._loading=true; //will be ignored by dataprocessor
|
---|
| 290 |
|
---|
| 291 | var start=this._min_date.valueOf()+(pos.y*this.config.time_step+(this._table_view?0:pos.x)*24*60)*60000;
|
---|
| 292 | //if (this._mode != "week" && this._mode != "day")
|
---|
| 293 | start = this._correct_shift(start);
|
---|
| 294 |
|
---|
| 295 | if (!this._drag_start){
|
---|
| 296 | this._drag_start=start; return;
|
---|
| 297 | }
|
---|
| 298 | var end = start;
|
---|
| 299 | if (end==this._drag_start) return;
|
---|
| 300 |
|
---|
| 301 | this._drag_id=this.uid();
|
---|
| 302 | this.addEvent(new Date(this._drag_start), new Date(end),this.locale.labels.new_event,this._drag_id, pos.fields);
|
---|
| 303 |
|
---|
| 304 | this.callEvent("onEventCreated",[this._drag_id,e]);
|
---|
| 305 | this._loading=false;
|
---|
| 306 | this._drag_mode="new-size";
|
---|
| 307 |
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | var ev=this.getEvent(this._drag_id);
|
---|
| 311 | var start,end;
|
---|
| 312 | if (this._drag_mode=="move"){
|
---|
| 313 | start = this._min_date.valueOf()+(pos.y*this.config.time_step+pos.x*24*60)*60000;
|
---|
| 314 | if (!pos.custom && this._table_view) start+=this.date.time_part(ev.start_date)*1000;
|
---|
| 315 | start = this._correct_shift(start);
|
---|
| 316 | end = ev.end_date.valueOf()-(ev.start_date.valueOf()-start);
|
---|
| 317 | } else {
|
---|
| 318 | start = ev.start_date.valueOf();
|
---|
| 319 | if (this._table_view)
|
---|
| 320 | end = this._min_date.valueOf()+pos.y*this.config.time_step*60000 + (pos.custom?0:24*60*60000);
|
---|
| 321 | else{
|
---|
| 322 | end = this.date.date_part(new Date(ev.end_date)).valueOf()+pos.y*this.config.time_step*60000;
|
---|
| 323 | this._els["dhx_cal_data"][0].style.cursor="s-resize";
|
---|
| 324 | if (this._mode == "week" || this._mode == "day")
|
---|
| 325 | end = this._correct_shift(end);
|
---|
| 326 | }
|
---|
| 327 | if (this._drag_mode == "new-size"){
|
---|
| 328 | if (end <= this._drag_start){
|
---|
| 329 | var shift = pos.shift||((this._table_view && !pos.custom)?24*60*60000:0);
|
---|
| 330 | start = end-shift;
|
---|
| 331 | end = this._drag_start+(shift||(this.config.time_step*60000));
|
---|
| 332 | } else {
|
---|
| 333 | start = this._drag_start;
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | } else if (end<=start)
|
---|
| 337 | end=start+this.config.time_step*60000;
|
---|
| 338 | }
|
---|
| 339 | var new_end = new Date(end-1);
|
---|
| 340 | var new_start = new Date(start);
|
---|
| 341 | //prevent out-of-borders situation for day|week view
|
---|
| 342 | if (this._table_view || (new_end.getDate()==new_start.getDate() && new_end.getHours()<this.config.last_hour)){
|
---|
| 343 | ev.start_date=new_start;
|
---|
| 344 | ev.end_date=new Date(end);
|
---|
| 345 | if (this.config.update_render)
|
---|
| 346 | this.update_view();
|
---|
| 347 | else
|
---|
| 348 | this.updateEvent(this._drag_id);
|
---|
| 349 | }
|
---|
| 350 | if (this._table_view)
|
---|
| 351 | this.for_rendered(this._drag_id,function(r){
|
---|
| 352 | r.className+=" dhx_in_move";
|
---|
| 353 | })
|
---|
| 354 | }
|
---|
| 355 | } else {
|
---|
| 356 | if (scheduler.checkEvent("onMouseMove")){
|
---|
| 357 | var id = this._locate_event(e.target||e.srcElement);
|
---|
| 358 | this.callEvent("onMouseMove",[id,e]);
|
---|
| 359 | }
|
---|
| 360 | }
|
---|
| 361 | }
|
---|
| 362 | scheduler._on_mouse_context=function(e,src){
|
---|
| 363 | return this.callEvent("onContextMenu",[this._locate_event(src),e]);
|
---|
| 364 | }
|
---|
| 365 | scheduler._on_mouse_down=function(e,src){
|
---|
| 366 | if (this.config.readonly || this._drag_mode) return;
|
---|
| 367 | src = src||(e.target||e.srcElement);
|
---|
| 368 | if (e.button==2||e.ctrlKey) return this._on_mouse_context(e,src);
|
---|
| 369 | switch(src.className.split(" ")[0]){
|
---|
| 370 | case "dhx_cal_event_line":
|
---|
| 371 | case "dhx_cal_event_clear":
|
---|
| 372 | if (this._table_view)
|
---|
| 373 | this._drag_mode="move"; //item in table mode
|
---|
| 374 | break;
|
---|
| 375 | case "dhx_header":
|
---|
| 376 | case "dhx_title":
|
---|
| 377 | this._drag_mode="move"; //item in table mode
|
---|
| 378 | break;
|
---|
| 379 | case "dhx_footer":
|
---|
| 380 | this._drag_mode="resize"; //item in table mode
|
---|
| 381 | break;
|
---|
| 382 | case "dhx_scale_holder":
|
---|
| 383 | case "dhx_scale_holder_now":
|
---|
| 384 | case "dhx_month_body":
|
---|
| 385 | case "dhx_matrix_cell":
|
---|
| 386 | this._drag_mode="create";
|
---|
| 387 | break;
|
---|
| 388 | case "":
|
---|
| 389 | if (src.parentNode)
|
---|
| 390 | return scheduler._on_mouse_down(e,src.parentNode);
|
---|
| 391 | default:
|
---|
| 392 | this._drag_mode=null;
|
---|
| 393 | this._drag_id=null;
|
---|
| 394 | }
|
---|
| 395 | if (this._drag_mode){
|
---|
| 396 | var id = this._locate_event(src);
|
---|
| 397 | if (!this.config["drag_"+this._drag_mode] || !this.callEvent("onBeforeDrag",[id, this._drag_mode, e]))
|
---|
| 398 | this._drag_mode=this._drag_id=0;
|
---|
| 399 | else {
|
---|
| 400 | this._drag_id= id;
|
---|
| 401 | this._drag_event=this._copy_event(this.getEvent(this._drag_id)||{});
|
---|
| 402 | }
|
---|
| 403 | }
|
---|
| 404 | this._drag_start=null;
|
---|
| 405 | }
|
---|
| 406 | scheduler._on_mouse_up=function(e){
|
---|
| 407 | if (this._drag_mode && this._drag_id){
|
---|
| 408 | this._els["dhx_cal_data"][0].style.cursor="default";
|
---|
| 409 | //drop
|
---|
| 410 | var ev=this.getEvent(this._drag_id);
|
---|
| 411 | 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()){
|
---|
| 412 | var is_new=(this._drag_mode=="new-size");
|
---|
| 413 | if (!this.callEvent("onBeforeEventChanged",[ev,e,is_new])){
|
---|
| 414 | if (is_new)
|
---|
| 415 | this.deleteEvent(ev.id, true);
|
---|
| 416 | else {
|
---|
| 417 | ev.start_date = this._drag_event.start_date;
|
---|
| 418 | ev.end_date = this._drag_event.end_date;
|
---|
| 419 | this.updateEvent(ev.id);
|
---|
| 420 | }
|
---|
| 421 | } else {
|
---|
| 422 | if (is_new && this.config.edit_on_create){
|
---|
| 423 | this.unselect();
|
---|
| 424 | this._new_event=new Date();//timestamp of creation
|
---|
| 425 | if (this._table_view || this.config.details_on_create) {
|
---|
| 426 | this._drag_mode=null;
|
---|
| 427 | return this.showLightbox(this._drag_id);
|
---|
| 428 | }
|
---|
| 429 | this._drag_pos=true; //set flag to trigger full redraw
|
---|
| 430 | this._select_id=this._edit_id=this._drag_id;
|
---|
| 431 | } else if (!this._new_event)
|
---|
| 432 | this.callEvent(is_new?"onEventAdded":"onEventChanged",[this._drag_id,this.getEvent(this._drag_id)]);
|
---|
| 433 | }
|
---|
| 434 | }
|
---|
| 435 | if (this._drag_pos) this.render_view_data(); //redraw even if there is no real changes - necessary for correct positioning item after drag
|
---|
| 436 | }
|
---|
| 437 | this._drag_mode=null;
|
---|
| 438 | this._drag_pos=null;
|
---|
| 439 | }
|
---|
| 440 | scheduler.update_view=function(){
|
---|
| 441 | //this.set_sizes();
|
---|
| 442 | this._reset_scale();
|
---|
| 443 | if (this._load_mode && this._load()) return this._render_wait = true;
|
---|
| 444 | this.render_view_data();
|
---|
| 445 | }
|
---|
| 446 | scheduler.setCurrentView=function(date,mode){
|
---|
| 447 |
|
---|
| 448 | if (!this.callEvent("onBeforeViewChange",[this._mode,this._date,mode,date])) return;
|
---|
| 449 | //hide old custom view
|
---|
| 450 | if (this[this._mode+"_view"] && mode && this._mode!=mode)
|
---|
| 451 | this[this._mode+"_view"](false);
|
---|
| 452 |
|
---|
| 453 | this._close_not_saved();
|
---|
| 454 |
|
---|
| 455 | this._mode=mode||this._mode;
|
---|
| 456 | this._date=date;
|
---|
| 457 | this._table_view=(this._mode=="month");
|
---|
| 458 |
|
---|
| 459 | var tabs=this._els["dhx_cal_tab"];
|
---|
| 460 | for (var i=0; i < tabs.length; i++) {
|
---|
| 461 | tabs[i].className="dhx_cal_tab"+((tabs[i].getAttribute("name")==this._mode+"_tab")?" active":"");
|
---|
| 462 | };
|
---|
| 463 |
|
---|
| 464 | //show new view
|
---|
| 465 | var view=this[this._mode+"_view"];
|
---|
| 466 | view?view(true):this.update_view();
|
---|
| 467 |
|
---|
| 468 | this.callEvent("onViewChange",[this._mode,this._date]);
|
---|
| 469 | }
|
---|
| 470 | scheduler._render_x_header = function(i,left,d,h){
|
---|
| 471 | //header scale
|
---|
| 472 | var head=document.createElement("DIV"); head.className="dhx_scale_bar";
|
---|
| 473 | this.set_xy(head,this._cols[i]-1,this.xy.scale_height-2,left,0);//-1 for border
|
---|
| 474 | head.innerHTML=this.templates[this._mode+"_scale_date"](d,this._mode); //TODO - move in separate method
|
---|
| 475 | h.appendChild(head);
|
---|
| 476 | }
|
---|
| 477 | scheduler._reset_scale=function(){
|
---|
| 478 | //current mode doesn't support scales
|
---|
| 479 | //we mustn't call reset_scale for such modes, so it just to be sure
|
---|
| 480 | if (!this.templates[this._mode+"_date"]) return;
|
---|
| 481 |
|
---|
| 482 | var h=this._els["dhx_cal_header"][0];
|
---|
| 483 | var b=this._els["dhx_cal_data"][0];
|
---|
| 484 | var c = this.config;
|
---|
| 485 |
|
---|
| 486 | h.innerHTML="";
|
---|
| 487 | b.scrollTop=0; //fix flickering in FF
|
---|
| 488 | b.innerHTML="";
|
---|
| 489 |
|
---|
| 490 |
|
---|
| 491 | var str=((c.readonly||(!c.drag_resize))?" dhx_resize_denied":"")+((c.readonly||(!c.drag_move))?" dhx_move_denied":"");
|
---|
| 492 | if (str) b.className = "dhx_cal_data"+str;
|
---|
| 493 |
|
---|
| 494 |
|
---|
| 495 | this._cols=[]; //store for data section
|
---|
| 496 | this._colsS={height:0};
|
---|
| 497 | this._dy_shift=0;
|
---|
| 498 |
|
---|
| 499 | this.set_sizes();
|
---|
| 500 | var summ=parseInt(h.style.width); //border delta
|
---|
| 501 | var left=0;
|
---|
| 502 |
|
---|
| 503 | var d,dd,sd,today;
|
---|
| 504 | dd=this.date[this._mode+"_start"](new Date(this._date.valueOf()));
|
---|
| 505 | d=sd=this._table_view?scheduler.date.week_start(dd):dd;
|
---|
| 506 | today=this.date.date_part(new Date());
|
---|
| 507 |
|
---|
| 508 | //reset date in header
|
---|
| 509 | var ed=scheduler.date.add(dd,1,this._mode);
|
---|
| 510 | var count = 7;
|
---|
| 511 |
|
---|
| 512 | if (!this._table_view){
|
---|
| 513 | var count_n = this.date["get_"+this._mode+"_end"];
|
---|
| 514 | if (count_n) ed = count_n(dd);
|
---|
| 515 | count = Math.round((ed.valueOf()-dd.valueOf())/(1000*60*60*24));
|
---|
| 516 | }
|
---|
| 517 |
|
---|
| 518 | this._min_date=d;
|
---|
| 519 | this._els["dhx_cal_date"][0].innerHTML=this.templates[this._mode+"_date"](dd,ed,this._mode);
|
---|
| 520 |
|
---|
| 521 |
|
---|
| 522 | for (var i=0; i<count; i++){
|
---|
| 523 | this._cols[i]=Math.floor(summ/(count-i));
|
---|
| 524 |
|
---|
| 525 | this._render_x_header(i,left,d,h);
|
---|
| 526 | if (!this._table_view){
|
---|
| 527 | var scales=document.createElement("DIV");
|
---|
| 528 | var cls = "dhx_scale_holder"
|
---|
| 529 | if (d.valueOf()==today.valueOf()) cls = "dhx_scale_holder_now";
|
---|
| 530 | scales.className=cls+" "+this.templates.week_date_class(d,today);
|
---|
| 531 | 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
|
---|
| 532 | b.appendChild(scales);
|
---|
| 533 | }
|
---|
| 534 |
|
---|
| 535 | d=this.date.add(d,1,"day")
|
---|
| 536 | summ-=this._cols[i];
|
---|
| 537 | left+=this._cols[i];
|
---|
| 538 | this._colsS[i]=(this._cols[i-1]||0)+(this._colsS[i-1]||(this._table_view?0:this.xy.scale_width+2));
|
---|
| 539 | }
|
---|
| 540 | this._max_date=d;
|
---|
| 541 | this._colsS[count]=this._cols[count-1]+this._colsS[count-1];
|
---|
| 542 |
|
---|
| 543 | if (this._table_view)
|
---|
| 544 | this._reset_month_scale(b,dd,sd);
|
---|
| 545 | else{
|
---|
| 546 | this._reset_hours_scale(b,dd,sd);
|
---|
| 547 | if (c.multi_day){
|
---|
| 548 | var c1 = document.createElement("DIV");
|
---|
| 549 | c1.className="dhx_multi_day";
|
---|
| 550 | c1.style.visibility="hidden";
|
---|
| 551 | this.set_xy(c1,parseInt(h.style.width),0,this.xy.scale_width,0);
|
---|
| 552 | b.appendChild(c1);
|
---|
| 553 | var c2 = c1.cloneNode(true);
|
---|
| 554 | c2.className="dhx_multi_day_icon";
|
---|
| 555 | c2.style.visibility="hidden";
|
---|
| 556 | this.set_xy(c2,this.xy.scale_width-1,0,0,0);
|
---|
| 557 | b.appendChild(c2);
|
---|
| 558 |
|
---|
| 559 | this._els["dhx_multi_day"]=[c1,c2];
|
---|
| 560 | }
|
---|
| 561 | }
|
---|
| 562 | }
|
---|
| 563 | scheduler._reset_hours_scale=function(b,dd,sd){
|
---|
| 564 | var c=document.createElement("DIV");
|
---|
| 565 | c.className="dhx_scale_holder";
|
---|
| 566 |
|
---|
| 567 | var date = new Date(1980,1,1,this.config.first_hour,0,0);
|
---|
| 568 | for (var i=this.config.first_hour*1; i < this.config.last_hour; i++) {
|
---|
| 569 | var cc=document.createElement("DIV");
|
---|
| 570 | cc.className="dhx_scale_hour";
|
---|
| 571 | cc.style.height=this.config.hour_size_px-(this._quirks?0:1)+"px";
|
---|
| 572 | cc.style.width=this.xy.scale_width+"px";
|
---|
| 573 | cc.innerHTML=scheduler.templates.hour_scale(date);
|
---|
| 574 |
|
---|
| 575 | c.appendChild(cc);
|
---|
| 576 | date=this.date.add(date,1,"hour");
|
---|
| 577 | };
|
---|
| 578 | b.appendChild(c);
|
---|
| 579 | if (this.config.scroll_hour)
|
---|
| 580 | b.scrollTop = this.config.hour_size_px*(this.config.scroll_hour-this.config.first_hour);
|
---|
| 581 | }
|
---|
| 582 | scheduler._reset_month_scale=function(b,dd,sd){
|
---|
| 583 | var ed=scheduler.date.add(dd,1,"month");
|
---|
| 584 |
|
---|
| 585 | //trim time part for comparation reasons
|
---|
| 586 | var cd=new Date();
|
---|
| 587 | this.date.date_part(cd);
|
---|
| 588 | this.date.date_part(sd);
|
---|
| 589 |
|
---|
| 590 | var rows=Math.ceil((ed.valueOf()-sd.valueOf())/(60*60*24*1000*7));
|
---|
| 591 | var tdcss=[];
|
---|
| 592 | var height=(Math.floor(b.clientHeight/rows)-22);
|
---|
| 593 |
|
---|
| 594 | this._colsS.height=height+22;
|
---|
| 595 | var h = this._colsS.heights = [];
|
---|
| 596 | for (var i=0; i<=7; i++)
|
---|
| 597 | tdcss[i]=" style='height:"+height+"px; width:"+((this._cols[i]||0)-1)+"px;' "
|
---|
| 598 |
|
---|
| 599 |
|
---|
| 600 |
|
---|
| 601 | var cellheight = 0;
|
---|
| 602 | this._min_date=sd;
|
---|
| 603 | var html="<table cellpadding='0' cellspacing='0'>";
|
---|
| 604 | for (var i=0; i<rows; i++){
|
---|
| 605 | html+="<tr>";
|
---|
| 606 | for (var j=0; j<7; j++){
|
---|
| 607 | html+="<td";
|
---|
| 608 | var cls = "";
|
---|
| 609 | if (sd<dd)
|
---|
| 610 | cls='dhx_before';
|
---|
| 611 | else if (sd>=ed)
|
---|
| 612 | cls='dhx_after';
|
---|
| 613 | else if (sd.valueOf()==cd.valueOf())
|
---|
| 614 | cls='dhx_now';
|
---|
| 615 | html+=" class='"+cls+" "+this.templates.month_date_class(sd,cd)+"' ";
|
---|
| 616 | html+="><div class='dhx_month_head'>"+this.templates.month_day(sd)+"</div><div class='dhx_month_body' "+tdcss[j]+"></div></td>"
|
---|
| 617 | sd=this.date.add(sd,1,"day");
|
---|
| 618 | }
|
---|
| 619 | html+="</tr>";
|
---|
| 620 | h[i] = cellheight;
|
---|
| 621 | cellheight+=this._colsS.height;
|
---|
| 622 | }
|
---|
| 623 | html+="</table>";
|
---|
| 624 | this._max_date=sd;
|
---|
| 625 |
|
---|
| 626 | b.innerHTML=html;
|
---|
| 627 | return sd;
|
---|
| 628 | }
|
---|
| 629 | scheduler.getLabel = function(property, key) {
|
---|
| 630 | var sections = this.config.lightbox.sections;
|
---|
| 631 | for (var i=0; i<sections.length; i++) {
|
---|
| 632 | if(sections[i].map_to == property) {
|
---|
| 633 | var options = sections[i].options;
|
---|
| 634 | for (var j=0; j<options.length; j++) {
|
---|
| 635 | if(options[j].key == key) {
|
---|
| 636 | return options[j].label;
|
---|
| 637 | }
|
---|
| 638 | }
|
---|
| 639 | }
|
---|
| 640 | }
|
---|
| 641 | return "";
|
---|
| 642 | }; |
---|