'),this.day_list=[],this.day_widgets=[],this.update_timer=null,this.resize_timer=null,this.setDOMNode(this.div[0])},destroy:function(){framework.getApplicationByName("calendar").tab&&$j(framework.getApplicationByName("calendar").tab.contentDiv).off("show."+this.id),this._super.apply(this,arguments),this._actionObject.clear(),this._actionObject.unregisterActions(),this._actionObject.remove(),this._actionObject=null,this.div.off(),this.div=null,this.gridHeader=null,this.dayHeader=null,this.days=null,this.scrolling=null,this._labelContainer=null,this.resize_timer&&window.clearTimeout(this.resize_timer)},doLoadingFinished:function(){this._super.apply(this,arguments),framework.getApplicationByName("calendar").tab&&$j(framework.getApplicationByName("calendar").tab.contentDiv).on("show."+this.id,jQuery.proxy(function(){this.scrolling&&this.scrolling.scrollTop(this._top_time)},this)),this.resize(),this._drawGrid(),this._link_actions(this.options.actions||this._parent.options.actions||[]);var timegrid=this;return this.div.on("mouseover",".calendar_calEvent:not(.ui-resizable):not(.rowNoEdit)",function(){if(0!==timegrid.options.granularity){timegrid._get_event_info(this);$j(this).resizable({distance:10,grid:[1e4,timegrid.rowHeight],autoHide:!1,handles:"s,se",containment:"parent",create:function(event,ui){var resizeHelper=event.target.getAttribute("data-resize");"WD"!=resizeHelper&&"WDS"!=resizeHelper||jQuery(this).resizable("destroy")},stop:function(event,ui){var e=new jQuery.Event("change");e.originalEvent=event,e.data={duration:0};var event_data=timegrid._get_event_info(this),event_widget=timegrid.getWidgetById(event_data.widget_id),sT=event_widget.options.value.start_m;if("undefined"!=typeof this.dropEnd&&1==this.dropEnd.length){var eT=parseInt(60*this.dropEnd.attr("data-hour"))+parseInt(this.dropEnd.attr("data-minute"));e.data.duration=(eT-sT)/60*3600,event_widget&&(event_widget.options.value.end_m=eT,event_widget.options.value.duration=e.data.duration),$j(this).trigger(e),event_widget._update(event_widget.options.value),$j(this).resizable("instance")&&$j(this).resizable("destroy")}event_widget&&event_widget._parent&&event_widget._parent.position_event(event_widget),timegrid.div.children(".drop-hover").removeClass(".drop-hover")},resize:function(event,ui){timegrid._get_time_from_position(ui.helper[0].getBoundingClientRect().left,ui.helper[0].getBoundingClientRect().bottom+5),timegrid.gridHover.hide();var drop=timegrid._drag_helper(this,ui.element[0]);drop&&!drop.is(":visible")&&drop.get(0).scrollIntoView(!1)}})}}),this.div.on("dragcreate",".calendar_calEvent",function(event,ui){$j(this).draggable("option","cancel",".rowNoEdit"),$j(this).draggable("option","cursorAt",{top:5,left:-5})}).on("dragstart",".calendar_calEvent",function(event,ui){$j(".calendar_calEvent",ui.helper).width($j(this).width()).height($j(this).outerHeight()).css("top","").css("left","").appendTo(ui.helper),ui.helper.width($j(this).width())}).on("mousemove",function(event){timegrid._get_time_from_position(event.clientX,event.clientY)}).on("mouseout",function(){timegrid.gridHover.hide()}),!0},_drag_helper:function(element,helper,height){if(element){if(element.dropEnd=this.gridHover,element.dropEnd.length&&(this._drop_data=element.dropEnd[0].dataset||{}),"undefined"!=typeof element.dropEnd&&element.dropEnd.length){this.gridHover.is(":visible")&&(this.scrolling.scrollTop()>0&&this.scrolling.scrollTop()>=this.gridHover.position().top-this.rowHeight?this.scrolling.scrollTop(this.gridHover.position().top-this.rowHeight):this.scrolling.scrollTop()+this.scrolling.height()<=this.gridHover.position().top+2*this.rowHeight&&this.scrolling.scrollTop(this.scrolling.scrollTop()+this.rowHeight));var time="";this._drop_data.whole_day?time=this.egw().lang("Whole day"):0===this.options.granularity?$j(helper).addClass("calendar_calTimeGridList"):time=jQuery.datepicker.formatTime("12"===egw.preference("timeformat")?"h:mmtt":"HH:mm",{hour:element.dropEnd.attr("data-hour"),minute:element.dropEnd.attr("data-minute"),seconds:0,timezone:0},{ampm:"12"==egw.preference("timeformat")}),element.innerHTML='
'+time+"
"}else element.innerHTML='
';return $j(element).width($j(helper).width()),element.dropEnd}},_event_drop:function(timegrid,event,ui,dropEnd){var e=new jQuery.Event("change");if(e.originalEvent=event,e.data={start:0},"undefined"!=typeof dropEnd&&dropEnd){var drop_date=dropEnd.date||!1,event_data=timegrid._get_event_info(ui.draggable),event_widget=timegrid.getWidgetById(event_data.widget_id);if(event_widget||(event_widget=timegrid.getParent().getWidgetById(event_data.widget_id)),event_widget){event_widget._parent.date_helper.set_year(drop_date.substring(0,4)),event_widget._parent.date_helper.set_month(drop_date.substring(4,6)),event_widget._parent.date_helper.set_date(drop_date.substring(6,8)),"calendar"==event_data.app&&event_widget.options.value.whole_day?(event_widget._parent.date_helper.set_hours(0),event_widget._parent.date_helper.set_minutes(0)):0===timegrid.options.granularity?(event_widget._parent.date_helper.set_hours(event_widget.options.value.start.getUTCHours()),event_widget._parent.date_helper.set_minutes(event_widget.options.value.start.getUTCMinutes())):(event_widget._parent.date_helper.set_hours(dropEnd.whole_day?0:dropEnd.hour||0),event_widget._parent.date_helper.set_minutes(dropEnd.whole_day?0:dropEnd.minute||0));var loading=ui.helper.clone(!0).appendTo($j("body"));0==$j(".calendar_timeDemo",loading).length?$j(".calendar_calEventHeader",loading).addClass("loading"):$j(".calendar_timeDemo",loading).after('
'),event_widget.recur_prompt(function(button_id){if("cancel"===button_id||!button_id){var app_id=event_widget.options.value.app_id?event_widget.options.value.app_id:event_widget.options.value.id+(event_widget.options.value.recur_type?":"+event_widget.options.value.recur_date:"");return egw().dataStoreUID("calendar::"+app_id,egw.dataGetUIDdata("calendar::"+app_id).data),void loading.remove()}if("infolog"===event_data.app){var duration=dropEnd.whole_day?86399:event_widget.options.value.whole_day?60*egw().preference("defaultlength","calendar"):!1;egw().json("stylite_infolog_calendar_integration::ajax_moveInfologEvent",[event_data.app_id,event_widget._parent.date_helper.getValue()||!1,duration],function(){loading.remove()}).sendRequest(!0)}else{var duration=event_widget.options.value.whole_day&&dropEnd.hour?86399:!1;dropEnd.whole_day&&(duration="whole_day");var _send=function(series_instance){var start=new Date(event_widget._parent.date_helper.getValue());egw().json("calendar.calendar_uiforms.ajax_moveEvent",["series"===button_id?event_data.id:event_data.app_id,event_data.owner,start,timegrid.options.owner||egw.user("account_id"),duration,series_instance],function(){loading.remove()}).sendRequest(!0)};event_widget.options.value.recur_type&&"series"===button_id?event_widget.series_split_prompt(function(_button_id){_button_id===et2_dialog.OK_BUTTON?_send(event_widget.options.value.recur_date):loading.remove()}):_send(event_widget.options.value.recur_date)}})}}},invalidate:function(trigger){this.day_list=[],this.update_timer&&window.clearTimeout(this.update_timer),this.update_timer=window.setTimeout(jQuery.proxy(function(){this.widget.update_timer=null,window.clearTimeout(this.resize_timer),this.widget.loader.hide().show(),this.widget._actionManager&&this.widget._link_actions(this.widget._actionManager.children),this.widget._drawDays(),this.widget._drawTimes(),this.trigger&&this.widget.change(),window.setTimeout(jQuery.proxy(function(){this.loader.hide()},this.widget),100)},{widget:this,trigger:trigger}),ET2_GRID_INVALIDATE_TIMEOUT)},detachFromDOM:function(){$j(this.div).off(".et2_calendar_timegrid"),this._super.apply(this,arguments)},attachToDOM:function(){this._super.apply(this,arguments),$j(this.div).on("change.et2_calendar_timegrid",".calendar_calEvent",this,function(e){var args=Array.prototype.slice.call(arguments);return-1==args.indexOf(this)&&args.push(this),e.data.event_change.apply(e.data,args)}),$j(this.div).on("change.et2_calendar_timegrid","*:not(.calendar_calEvent)",this,function(e){return e.data.change.call(e.data,e,this)}),this.div.on("resize",this,function(e){e.stopPropagation()})},getDOMNode:function(_sender){return _sender!==this&&_sender?_sender.instanceOf(et2_calendar_daycol)?this.days?this.days[0]:null:_sender?this.gridHeader?this.gridHeader[0]:null:void 0:this.div?this.div[0]:null},set_disabled:function(disabled){this._super.apply(this,arguments),disabled&&this.loader.show()},_drawGrid:function(){this.div.css("height",this.options.height).empty(),this.loader.prependTo(this.div).show(),this._drawTimes(),this.invalidate()},_drawTimes:function(){$j(".calendar_calTimeRow",this.div).remove(),this.div.toggleClass("calendar_calTimeGridList",0===this.options.granularity),this.gridHeader.attr("data-date",this.options.start_date).attr("data-owner",this.options.owner).append(this._labelContainer).append(this.owner.getDOMNode()).append(this.dayHeader).appendTo(this.div);Math.max(this.gridHeader.outerHeight(!0),18);if(this.scrolling.appendTo(this.div).off(),0===this.options.granularity)return this.scrolling.css("height","100%"),this.days.css("height","100%"),void this.iterateOver(function(day){day.resize()},this,et2_calendar_daycol);var wd_start=60*this.options.day_start,wd_end=60*this.options.day_end,granularity=this.options.granularity,totalDisplayMinutes=wd_end-wd_start,rowsToDisplay=Math.ceil((totalDisplayMinutes+60)/granularity),row_count=1440/this.options.granularity;this.scrolling.on("scroll",jQuery.proxy(this._scroll,this));(100/rowsToDisplay).toFixed(1);this.rowHeight=this.scrolling.height()/rowsToDisplay,this.rowHeight<5&&this.div.is(":visible")&&0===this.rowHeight&&(this.rowHeight=5);var show={5:[0,15,30,45],10:[0,30],15:[0,30],45:[0,15,30,45]},html="";parseInt(this.div.css("line-height"));this._top_time=0;for(var t=0,i=0;1440>t;t+=granularity,++i){html+='
';var time=jQuery.datepicker.formatTime("12"===egw.preference("timeformat")?"h:mmtt":"HH:mm",{hour:t/60,minute:t%60,seconds:0,timezone:0},{ampm:"12"===egw.preference("timeformat")});wd_start>=t&&t+granularity>wd_start&&(this._top_time=this.rowHeight*(i+1+(wd_start-(t+granularity))/granularity));var time_label=("undefined"==typeof show[granularity]?t%60===0:-1!==show[granularity].indexOf(t%60))?time:"";time_label&&"12"==egw.preference("timeformat")&&time_label.split(":")[0]<10&&(time_label=" "+time_label),html+='
'+time_label+"
\n"}$j(".calendar_calTimeLabels",this.scrolling).empty().height(this.rowHeight*i).append(html),this.days.css("height",this.rowHeight*i+"px"),this.gridHover.css("height",this.rowHeight),this.scrolling.scrollTop(this._top_time)},resizeTimes:function(){this.resize_timer&&window.clearTimeout(this.resize_timer),this.upate_timer||(this.resize_timer=window.setTimeout(jQuery.proxy(function(){this._resizeTimes&&(this.resize_timer=null,this._resizeTimes())},this),1))},_resizeTimes:function(){if(this.div.is(":visible")){var wd_start=60*this.options.day_start,wd_end=60*this.options.day_end,totalDisplayMinutes=wd_end-wd_start,rowsToDisplay=Math.ceil((totalDisplayMinutes+60)/this.options.granularity),row_count=1440/this.options.granularity,new_height=this.scrolling.height()/rowsToDisplay,old_height=this.rowHeight;this.rowHeight=new_height,$j(".calendar_calTimeLabels",this.scrolling).height(this.rowHeight*row_count),this.days.css("height",0===this.options.granularity?"100%":this.rowHeight*row_count+"px"),this._top_time=wd_start*this.rowHeight/this.options.granularity,this.scrolling.scrollTop(this._top_time),this.rowHeight!=old_height&&this.iterateOver(function(child){child!==this&&child.resize()},this,et2_IResizeable)}},_drawDays:function(){this.scrolling.append(this.days),0===this.day_list.length&&this.options.start_date&&this.options.end_date&&(this.day_list=this._calculate_day_list(this.options.start_date,this.options.end_date,this.options.show_weekend));var daily_owner=1===this.day_list.length&&this.options.owner.length>1&&this.options.owner.length<(parseInt(egw.preference("day_consolidate","calendar"))||6),daycols_needed=daily_owner?this.options.owner.length:this.day_list.length,day_width=Math.min($j(this.getInstanceManager().DOMContainer).width(),this.days.width())/daycols_needed;if(!day_width||!this.day_list){var dim=egw.getHiddenDimensions(this.days,!1);day_width=dim.w/Math.max(daycols_needed,1)}for(var add_index=0,before=!0;daycols_needed>this.day_widgets.length;){var existing_index=this.day_widgets[add_index]&&!daily_owner?this.day_list.indexOf(this.day_widgets[add_index].options.date):-1;before=existing_index>add_index;var day=et2_createWidget("calendar-daycol",{owner:this.options.owner,width:(before?0:day_width)+"px"},this);this.isInTree()&&day.doLoadingFinished(),-1!=existing_index&&parseInt(this.day_list[add_index])
daycols_needed;){for(;delete_index>1&&this.day_list.indexOf(this.day_widgets[delete_index].options.date)>-1;)delete_index--,before=!0;0>delete_index&&(delete_index=0),before&&this.day_widgets[delete_index].set_width("0px"),this.day_widgets[delete_index].div.hide(),this.day_widgets[delete_index].header.hide(),this.day_widgets[delete_index].destroy(),this.day_widgets.splice(delete_index--,1)}for(var i=0;i=this.date_helper.date.getTime()&&14>=i);return day_list},_link_actions:function(actions){var objectManager=egw_getObjectManager(this.getInstanceManager().app,!0,1);objectManager=objectManager.getObjectById(this.getInstanceManager().uniqueId,2)||objectManager;var parent=objectManager.getObjectById(this.id,1)||objectManager.getObjectById(this._parent.id,1)||objectManager;if(!parent)return void egw.debug("error","No parent objectManager found");for(var i=0;i0){parent=parent.children[i];break}}var widget_object=this._actionObject||parent.getObjectById(this.id),aoi=new et2_action_object_impl(this,this.getDOMNode());aoi.doTriggerEvent=function(_event,_data){var event=_data.event||!1;if(event&&!_data.ui.draggable.hasClass("rowNoEdit")){if("drop"===event.type){var dropEnd=!1,helper=$j(".calendar_d-n-d_timeCounter",_data.ui.helper)[0];helper&&helper.dropEnd&&helper.dropEnd.length>=1&&"undefined"!=typeof this.dropEnd&&this.dropEnd.length>=1&&(dropEnd=helper.dropEnd[0].dataset||!1),this.getWidget()._event_drop.call($j(".calendar_d-n-d_timeCounter",_data.ui.helper)[0],this.getWidget(),event,_data.ui,dropEnd)}var drag_listener=function(event,ui){aoi.getWidget()._drag_helper($j(".calendar_d-n-d_timeCounter",ui.helper)[0],ui.helper[0],0)},time=$j(".calendar_d-n-d_timeCounter",_data.ui.helper);switch(_event){case EGW_AI_DRAG_OVER:_data.ui.draggable.on("drag.et2_timegrid"+widget_object.id,drag_listener),_data.ui.draggable.on("dragend.et2_timegrid"+widget_object.id,function(){_data.ui.draggable.off("drag.et2_timegrid"+widget_object.id)}),$j(".calendar_calEventHeader",_data.ui.helper).css("top",""),$j(".calendar_calEventBody",_data.ui.helper).css("padding-top",""),time.length?time.data("count",time.data("count")+1):_data.ui.helper.prepend('
');break;case EGW_AI_DRAG_OUT:_data.ui.draggable.off("drag.et2_timegrid"+widget_object.id);var timegrid=aoi.getWidget();timegrid.gridHover.hide(),timegrid.scrolling.scrollTop(timegrid._top_time),time.data("count",time.data("count")-1),time.length&&time.data("count")<=0&&time.remove()}}},null==widget_object?widget_object=parent.insertObject(!1,new egwActionObject(this.id,parent,aoi,this._actionManager||parent.manager.getActionById(this.id)||parent.manager)):widget_object.setAOI(aoi),this._actionObject=widget_object,widget_object.clear(),widget_object.unregisterActions();var action_links=this._get_action_links(actions);this._init_links_dnd(widget_object.manager,action_links),widget_object.updateActionLinks(action_links)},_init_links_dnd:function(mgr,actionLinks){var self=this,drop_action=mgr.getActionById("egw_link_drop"),drag_action=mgr.getActionById("egw_link_drag");return!egw.link_get_registry(this.dataStorePrefix||"calendar","query")||egw.link_get_registry(this.dataStorePrefix||"calendar","title")?(drop_action&&(drop_action.remove(),actionLinks.indexOf(drop_action.id)>=0&&actionLinks.splice(actionLinks.indexOf(drop_action.id),1)),void(drag_action&&(drag_action.remove(),actionLinks.indexOf(drag_action.id)>=0&&actionLinks.splice(actionLinks.indexOf(drag_action.id),1)))):(null==drop_action&&(drop_action=mgr.addAction("drop","egw_link_drop",egw.lang("Create link"),egw.image("link"),function(action,source,target){for(var links=[],id="",i=0;i0&&label.trim().length<6||this.options.owner.length>1)},set_granularity:function(minutes){minutes=Math.max(0,minutes),this.options.granularity!==minutes?0===this.options.granularity||0===minutes?(this.options.granularity=minutes,this.invalidate()):(this.options.granularity=minutes,this._drawTimes()):this.update_timer||this.resizeTimes()},set_show_weekend:function(weekends){weekends=!!weekends,this.options.show_weekend!==weekends&&(this.options.show_weekend=weekends,this.isAttached()&&this.invalidate())},change:function(){if(this.onchange){if("function"==typeof this.onchange){var args=Array.prototype.slice.call(arguments);return-1==args.indexOf(this)&&args.push(this),this.onchange.apply(this,args)}return et2_compileLegacyJS(this.options.onchange,this,_node)()}},event_change:function(event,dom_node){if(this.onevent_change){var event_data=this._get_event_info(dom_node),event_widget=this.getWidgetById(event_data.widget_id);et2_calendar_event.recur_prompt(event_data,jQuery.proxy(function(button_id,event_data){if("cancel"===button_id)return!1;if("function"==typeof this.onevent_change){var args=Array.prototype.slice.call(arguments);return-1==args.indexOf(event_widget)&&args.push(event_widget),event.button_id=button_id,this.onevent_change.apply(this,[event,event_widget,button_id])}return et2_compileLegacyJS(this.options.onevent_change,event_widget,dom_node)()},this))}return!1},get_granularity:function(){return"undefined"==typeof this.options.granularity&&(this.options.granularity=egw.preference("interval","calendar")||30),parseInt(this.options.granularity)},click:function(_ev){var result=!0;if(_ev.target.dataset.id||$j(_ev.target).parents(".calendar_calEvent").length){var event=this._get_event_info(_ev.originalEvent.target);if("function"==typeof this.onclick){var args=Array.prototype.slice.call(arguments);-1==args.indexOf(this)&&args.splice(1,0,this),result=this.onclick.apply(this,args)}var event_node=$j(event.event_node);return event.id&&result&&!this.disabled&&!this.options.readonly&&event_node&&!event_node.hasClass("rowNoView")?(event.widget_id&&this.getWidgetById(event.widget_id)?this.getWidgetById(event.widget_id).recur_prompt():et2_calendar_event.recur_prompt(event),!1):result}if(this.gridHeader.is(_ev.target)&&_ev.target.dataset)app.calendar.update_state(jQuery.extend({view:"week"},_ev.target.dataset));else if(this.dayHeader.has(_ev.target).length)for(var i=1;ithis.options.height&&0!=this.options.granularity;if($j(this.getInstanceManager().DOMContainer).css({"overflow-y":too_small||_too_small?"auto":"hidden","overflow-x":"hidden",height:too_small||_too_small?height:"100%"}),too_small||_too_small){if(this.options.height=Math.max(this.options.height,needed),!_too_small&&rowCount>1&&this._parent)return void window.setTimeout(jQuery.proxy(function(){this._parent&&this._parent.iterateOver(function(widget){widget.disabled||widget.resize(!0)},this,et2_calendar_timegrid)},this),1);this.div.addClass("calendar_calTimeGridFixed")}else this.div.removeClass("calendar_calTimeGridFixed");this.div.css("height",this.options.height),this.update_timer||this.resizeTimes();for(var total_width=$j(this.getInstanceManager().DOMContainer).parent().innerWidth()-this.days.position().left,day_width=(total_width>0?total_width:$j(this.getInstanceManager().DOMContainer).width())/this.day_widgets.length,i=0;idays&&(width=85*days/31,this.rows.css("width",width+"%"))),"month"==this._parent.options.group_by&&this.rows.append(this._yearlyPlannerMarkDays(this.options.start_date,days)),"month"===this._parent.options.group_by&&31>days&&this.rows.after('')},set_label:function(label){this.options.label=label,this.title.text(label),"month"===this._parent.options.group_by?(this.title.attr("data-date",this.options.start_date.toJSON()),this.title.addClass("et2_clickable et2_link")):(this.title.attr("data-date",""),this.title.removeClass("et2_clickable"))},set_start_date:function(new_date){if(!new_date||null===new_date)throw exception("Invalid end date. "+new_date.toString());this.options.start_date=new Date("string"==typeof new_date?new_date:new_date.toJSON()),this.options.start_date.setUTCHours(0),this.options.start_date.setUTCMinutes(0),this.options.start_date.setUTCSeconds(0)},set_end_date:function(new_date){if(!new_date||null===new_date)throw exception("Invalid end date. "+new_date.toString());this.options.end_date=new Date("string"==typeof new_date?new_date:new_date.toJSON()),this.options.end_date.setUTCHours(23),this.options.end_date.setUTCMinutes(59),this.options.end_date.setUTCSeconds(59)},_yearlyPlannerMarkDays:function(start,days){for(var day_width=100/days,t=new Date(start),content="",i=0;days>i;i++){var holidays=[],day_class=this._parent.day_class_holiday(t,holidays);day_class&&(content+='"),t.setUTCDate(t.getUTCDate()+1)}return content},_update_events:function(events){for(;this._children.length;)this._children[this._children.length-1].free(),this.removeChild(this._children[this._children.length-1]);this._cached_rows=[];for(var c=0;c ').appendTo(this.rows),height=rows.length*(parseInt(window.getComputedStyle(row[0]).getPropertyValue("height"))||20);row.remove();for(var c=0;c