9 lines
14 KiB
JavaScript
9 lines
14 KiB
JavaScript
/*
|
|
* Kendo UI v2015.3.1111 (http://www.telerik.com/kendo-ui)
|
|
* Copyright 2015 Telerik AD. All rights reserved.
|
|
*
|
|
* Kendo UI commercial licenses may be obtained at
|
|
* http://www.telerik.com/purchase/license-agreement/kendo-ui-complete
|
|
* If you do not own a commercial license, this file shall be governed by the trial license terms.
|
|
*/
|
|
!function(e,define){define(["./kendo.scheduler.view.min"],e)}(function(){return function(e){function t(e,t){return e.slice(t).concat(e.slice(0,t))}function n(e,t){for(var n=t.firstDay,i=new Date(e.getFullYear(),e.getMonth(),0,e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds());i.getDay()!=n;)o.date.setTime(i,-1*u);return i}function i(e,t,n){var i,o=t,r=n;return i=e,i>=o&&r>=i}var o=window.kendo,r=o.ui,s=r.SchedulerView,a=".kendoMonthView",l=e.extend,c=o.date.getDate,u=o.date.MS_PER_DAY,d=6,h=7,f=o.template('<span class="k-link k-nav-day">#:kendo.toString(date, "dd")#</span>'),p='<div role="gridcell" aria-selected="false" data-#=ns#uid="#=uid#"#if (resources[0]) { #style="background-color:#=resources[0].color #; border-color: #=resources[0].color#"class="k-event#=inverseColor ? " k-event-inverse" : ""#"#} else {#class="k-event"#}#><span class="k-event-actions"># if(data.tail || data.middle) {#<span class="k-icon k-i-arrow-w"></span>#}## if(data.isException()) {#<span class="k-icon k-i-exception"></span># } else if(data.isRecurring()) {#<span class="k-icon k-i-refresh"></span>#}#</span>{0}<span class="k-event-actions">#if (showDelete) {#<a href="\\#" class="k-link k-event-delete"><span class="k-icon k-si-close"></span></a>#}## if(data.head || data.middle) {#<span class="k-icon k-i-arrow-e"></span>#}#</span># if(resizable && !data.tail && !data.middle) {#<span class="k-resize-handle k-resize-w"></span>#}## if(resizable && !data.head && !data.middle) {#<span class="k-resize-handle k-resize-e"></span>#}#</div>',g=o.template('<div title="#=title.replace(/"/g,"&\\#34;")#"><div class="k-event-template">#:title#</div></div>'),m=o.template('<div style="width:#=width#px;left:#=left#px;top:#=top#px" class="k-more-events k-button"><span>...</span></div>');r.MonthView=s.extend({init:function(e,t){var n=this;s.fn.init.call(n,e,t),n.title=n.options.title,n.name="month",n._templates(),n._editable(),n._renderLayout(n.options.date),n._groups()},_updateDirection:function(e,t,n,i,o){var r,s,a,l,c;n&&(r=t[0].start,s=t[t.length-1].end,a=r.index===s.index,l=r.collectionIndex===s.collectionIndex,c=o?a&&l||l:a&&l,c&&(e.backward=i))},_changeViewPeriod:function(e,t,n){var i=n?7:1;return t&&(i*=-1),e.start=o.date.addDays(e.start,i),e.end=o.date.addDays(e.end,i),(!n||n&&this._isVerticallyGrouped())&&(e.groupIndex=t?this.groups.length-1:0),e.events=[],!0},_continuousSlot:function(e,t,n){var i=e.backward?0:t.length-1,o=this.groups[e.groupIndex];return o.continuousSlot(t[i].start,n)},_changeGroupContinuously:function(e,t,n,i){var o,r,s,a;return n||(o=e.groupIndex,r=this.groups.length-1,s=this._isVerticallyGrouped(),a=this.groups[o],!t&&s?(t=a[i?"lastSlot":"firstSlot"](),o+=i?-1:1):t&&!s&&(o=i?r:0),(0>o||o>r)&&(o=i?r:0,t=null),e.groupIndex=o),t},_normalizeHorizontalSelection:function(e,t,n){var i;return i=n?t[0].start:t[t.length-1].end},_normalizeVerticalSelection:function(e,t){var n;return n=e.backward?t[0].start:t[t.length-1].end},_templates:function(){var e=this.options,t=l({},o.Template,e.templateSettings);this.eventTemplate=this._eventTmpl(e.eventTemplate,p),this.dayTemplate=o.template(e.dayTemplate,t),this.groupHeaderTemplate=o.template(e.groupHeaderTemplate,t)},dateForTitle:function(){return o.format(this.options.selectedDateFormat,this._firstDayOfMonth,this._lastDayOfMonth)},shortDateForTitle:function(){return o.format(this.options.selectedShortDateFormat,this._firstDayOfMonth,this._lastDayOfMonth)},nextDate:function(){return o.date.nextDay(this._lastDayOfMonth)},previousDate:function(){return o.date.previousDay(this._firstDayOfMonth)},startDate:function(){return this._startDate},endDate:function(){return this._endDate},_renderLayout:function(t){var i=this;this._firstDayOfMonth=o.date.firstDayOfMonth(t),this._lastDayOfMonth=o.date.lastDayOfMonth(t),this._startDate=n(t,this.calendarInfo()),this.createLayout(this._layout()),this._content(),this.refreshLayout(),this.content.on("click"+a,".k-nav-day,.k-more-events",function(t){var n=e(t.currentTarget).offset(),o=i._slotByPosition(n.left,n.top);t.preventDefault(),i.trigger("navigate",{view:"day",date:o.startDate()})})},_editable:function(){this.options.editable&&!this._isMobilePhoneView()&&(this._isMobile()?this._touchEditable():this._mouseEditable())},_mouseEditable:function(){var t=this;t.element.on("click"+a,".k-scheduler-monthview .k-event a:has(.k-si-close)",function(n){t.trigger("remove",{uid:e(this).closest(".k-event").attr(o.attr("uid"))}),n.preventDefault()}),t.options.editable.create!==!1&&t.element.on("dblclick"+a,".k-scheduler-monthview .k-scheduler-content td",function(n){var i,o=e(n.currentTarget).offset(),r=t._slotByPosition(o.left,o.top);r&&(i=t._resourceBySlot(r),t.trigger("add",{eventInfo:l({isAllDay:!0,start:r.startDate(),end:r.startDate()},i)})),n.preventDefault()}),t.options.editable.update!==!1&&t.element.on("dblclick"+a,".k-scheduler-monthview .k-event",function(n){t.trigger("edit",{uid:e(this).closest(".k-event").attr(o.attr("uid"))}),n.preventDefault()})},_touchEditable:function(){var t=this,n=0;o.support.mobileOS.android&&(n=5),t.options.editable.create!==!1&&(t._addUserEvents=new o.UserEvents(t.element,{threshold:n,filter:".k-scheduler-monthview .k-scheduler-content td",tap:function(n){var i,o=e(n.target).offset(),r=t._slotByPosition(o.left,o.top);r&&(i=t._resourceBySlot(r),t.trigger("add",{eventInfo:l({isAllDay:!0,start:r.startDate(),end:r.startDate()},i)})),n.preventDefault()}})),t.options.editable.update!==!1&&(t._editUserEvents=new o.UserEvents(t.element,{threshold:n,filter:".k-scheduler-monthview .k-event",tap:function(n){0===e(n.event.target).closest("a:has(.k-si-close)").length&&(t.trigger("edit",{uid:e(n.target).closest(".k-event").attr(o.attr("uid"))}),n.preventDefault())}}))},selectionByElement:function(t){var n=e(t).offset();return this._slotByPosition(n.left,n.top)},_columnCountForLevel:function(e){var t=this.columnLevels[e];return t?t.length:0},_rowCountForLevel:function(e){var t=this.rowLevels[e];return t?t.length:0},_content:function(){var e,t="<tbody>",n=1,i=this.groupedResources;for(i.length&&this._isVerticallyGrouped()&&(n=this._rowCountForLevel(i.length-1)),e=0;n>e;e++)t+=this._createCalendar(e);t+="</tbody>",this.content.find("table").html(t)},_createCalendar:function(e){var t,n,i,r,s=this.startDate(),a=h*d,l=h,c=[s],u="",f=1,p=this._isVerticallyGrouped(),g=this.groupedResources;for(g.length&&(p||(f=this._columnCountForLevel(g.length-1))),this._slotIndices={},t=0,n=a/l;n>t;t++){for(u+="<tr>",c.push(s),i=t*l,r=0;f>r;r++)u+=this._createRow(s,i,l,p?e:r);s=o.date.addDays(s,l),u+="</tr>"}return this._weekStartDates=c,this._endDate=o.date.previousDay(s),u},_createRow:function(e,t,n,i){var r,s=this,a=s._firstDayOfMonth,l=s._lastDayOfMonth,u=s.dayTemplate,d="",h="",f=function(){return s._resourceBySlot({groupIndex:i})};for(r=0;n>r;r++)d="",o.date.isToday(e)&&(d+="k-today"),o.date.isInDateRange(e,a,l)||(d+=" k-other-month"),h+="<td ",""!==d&&(h+='class="'+d+'"'),h+=">",h+=u({date:e,resources:f}),h+="</td>",s._slotIndices[c(e).getTime()]=t+r,e=o.date.nextDay(e);return h},_layout:function(){var n,i,o,r=this.calendarInfo(),s=this._isMobile()?r.days.namesShort:r.days.names,a=t(s,r.firstDay),l=e.map(a,function(e){return{text:e}}),c=this.groupedResources;if(c.length)if(this._isVerticallyGrouped()){for(i=[],o=0;6>o;o++)i.push({text:"<div> </div>",className:"k-hidden k-slot-cell"});n=this._createRowsLayout(c,i,this.groupHeaderTemplate)}else l=this._createColumnsLayout(c,l,this.groupHeaderTemplate);return{columns:l,rows:n}},_createEventElement:function(t){var n,i=this.options,r=i.editable,s=this._isMobile();return t.showDelete=r&&r.destroy!==!1&&!s,t.resizable=r&&r.resize!==!1&&!s,t.ns=o.ns,t.resources=this.eventResources(t),t.inverseColor=t.resources&&t.resources[0]?this._shouldInverseResourceColor(t.resources[0]):!1,n=e(this.eventTemplate(t)),this.angular("compile",function(){return{elements:n,data:[{dataItem:t}]}}),n},_isInDateSlot:function(e){var t=this.groups[0],n=t.firstSlot().start,r=t.lastSlot().end-1,s=o.date.toUtcTime(e.start),a=o.date.toUtcTime(e.end);return(i(s,n,r)||i(a,n,r)||i(n,s,a)||i(r,s,a))&&(!i(a,n,n)||i(a,s,s)||e.isAllDay)},_slotIndex:function(e){return this._slotIndices[c(e).getTime()]},_positionMobileEvent:function(t,n,i){var r,a,l,c,u,d,h,f=t.start;t.start.offsetLeft>t.end.offsetLeft&&(f=t.end),r=t.start.index,a=r,l=3,c=s.collidingEvents(t.events(),r,a),c.push({element:n,start:r,end:a}),u=s.createRows(c),d=t.collection.at(r),h=d.container,h||(h=e(o.format('<div class="k-events-container" style="top:{0};left:{1};width:{2}"/>',f.offsetTop+f.firstChildTop+f.firstChildHeight-3+"px",f.offsetLeft+"px",f.offsetWidth+"px")),d.container=h,this.content[0].appendChild(h[0])),l>=u.length&&(t.addEvent({element:n,start:r,end:a,groupIndex:f.groupIndex}),i._continuousEvents.push({element:n,uid:n.attr(o.attr("uid")),start:t.start,end:t.end}),h[0].appendChild(n[0]))},_positionEvent:function(t,n,i){var r,a,l,c,u,d,h,f,p,g,v,_,w,b,y,x=this.options.eventHeight,k=t.start;for(t.start.offsetLeft>t.end.offsetLeft&&(k=t.end),r=t.start.index,a=t.end.index,l=k.eventCount,c=s.collidingEvents(t.events(),r,a),u=r!==a?5:4,c.push({element:n,start:r,end:a}),d=s.createRows(c),h=0,f=Math.min(d.length,l);f>h;h++)for(p=d[h].events,g=k.offsetTop+k.firstChildHeight+h*x+3*h+"px",v=0,_=p.length;_>v;v++)p[v].element[0].style.top=g;if(d.length>l)for(w=r;a>=w;w++){if(b=t.collection,y=b.at(w),y.more)return;y.more=e(m({ns:o.ns,start:w,end:w,width:y.clientWidth-2,left:y.offsetLeft+2,top:y.offsetTop+y.firstChildHeight+l*x+3*l})),this.content[0].appendChild(y.more[0])}else t.addEvent({element:n,start:r,end:a,groupIndex:k.groupIndex}),n[0].style.width=t.innerWidth()-u+"px",n[0].style.left=k.offsetLeft+2+"px",n[0].style.height=x+"px",i._continuousEvents.push({element:n,uid:n.attr(o.attr("uid")),start:t.start,end:t.end}),n.appendTo(this.content)},_slotByPosition:function(e,t){var n,i,o=this.content.offset();for(e-=o.left,t-=o.top,t+=this.content[0].scrollTop,e+=this.content[0].scrollLeft,e=Math.ceil(e),t=Math.ceil(t),n=0;this.groups.length>n;n++)if(i=this.groups[n].daySlotByPosition(e,t))return i;return null},_createResizeHint:function(e){var t=e.startSlot().offsetLeft,n=e.start.offsetTop,i=e.innerWidth(),o=e.start.clientHeight-2,r=s.fn._createResizeHint.call(this,t,n,i,o);r.appendTo(this.content),this._resizeHint=this._resizeHint.add(r)},_updateResizeHint:function(e,t,n,i){var r,s,a;for(this._removeResizeHint(),r=this.groups[t],s=r.ranges(n,i,!0,e.isAllDay),a=0;s.length>a;a++)this._createResizeHint(s[a]);this._resizeHint.find(".k-label-top,.k-label-bottom").text(""),this._resizeHint.first().addClass("k-first").find(".k-label-top").text(o.toString(o.timezone.toLocalDate(n),"M/dd")),this._resizeHint.last().addClass("k-last").find(".k-label-bottom").text(o.toString(o.timezone.toLocalDate(i),"M/dd"))},_updateMoveHint:function(e,t,n){var i,r,s,a,l,c=o.date.toUtcTime(e.start)+n,u=c+e.duration(),d=this.groups[t],h=d.ranges(c,u,!0,e.isAllDay);for(this._removeMoveHint(),i=0;h.length>i;i++)r=h[i],s=r.startSlot(),a=r.endSlot(),l=this._createEventElement(e.clone({head:r.head,tail:r.tail})),l.css({left:s.offsetLeft+2,top:s.offsetTop+s.firstChildHeight,height:this.options.eventHeight,width:r.innerWidth()-(s.index!==a.index?5:4)}),l.addClass("k-event-drag-hint"),l.appendTo(this.content),this._moveHint=this._moveHint.add(l)},_groups:function(){var e,t,n,i,r,s,a,l,c,u,f,p,g,m,v,_,w,b,y,x=this._groupCount(),k=h,C=d;for(this.groups=[],e=0;x>e;e++)this._addResourceView(e);for(t=this.content[0].getElementsByTagName("tr"),n=this.startDate(),i=0;x>i;i++)for(r=0,s=0,this._isVerticallyGrouped()&&(s=i),a=s*C;(s+1)*C>a;a++)for(l=this.groups[i],c=l.addDaySlotCollection(o.date.addDays(n,r),o.date.addDays(this.startDate(),r+k)),u=t[a],f=u.children,p=0,u.setAttribute("role","row"),this._isVerticallyGrouped()||(p=i),g=p*k;(p+1)*k>g;g++)m=f[g],v=m.clientHeight,_=m.children.length?m.children[0].offsetHeight+3:0,w=o.date.addDays(n,r),b=o.date.MS_PER_DAY,n.getHours()!==w.getHours()&&(b+=(n.getHours()-w.getHours())*o.date.MS_PER_HOUR),w=o.date.toUtcTime(w),b+=w,r++,y=Math.floor((v-_-this.options.moreButtonHeight)/(this.options.eventHeight+3)),m.setAttribute("role","gridcell"),m.setAttribute("aria-selected",!1),c.addDaySlot(m,w,b,y)},render:function(e){this.content.children(".k-event,.k-more-events,.k-events-container").remove(),this._groups(),e=new o.data.Query(e).sort([{field:"start",dir:"asc"},{field:"end",dir:"desc"}]).toArray();var t=this.groupedResources;t.length?this._renderGroups(e,t,0,1):this._renderEvents(e,0),this.refreshLayout(),this.trigger("activate")},_renderEvents:function(e,t){var n,i,o,r,s,a,l,c,u,d,h,f=this._isMobilePhoneView();for(i=0,o=e.length;o>i;i++)if(n=e[i],this._isInDateSlot(n))for(r=this.groups[t],r._continuousEvents||(r._continuousEvents=[]),s=r.slotRanges(n,!0),a=s.length,l=0;a>l;l++)c=s[l],u=n.start,d=n.end,a>1&&(0===l?d=c.end.endDate():l==a-1?u=c.start.startDate():(u=c.start.startDate(),d=c.end.endDate())),h=n.clone({start:u,end:d,head:c.head,tail:c.tail}),f?this._positionMobileEvent(c,this._createEventElement(h),r):this._positionEvent(c,this._createEventElement(h),r)},_renderGroups:function(e,t,n,i){var r,a,l,c,u=t[0];if(u)for(r=u.dataSource.view(),a=0;r.length>a;a++)l=this._resourceValue(u,r[a]),c=new o.data.Query(e).filter({field:u.field,operator:s.groupEqFilter(l)}).toArray(),t.length>1?n=this._renderGroups(c,t.slice(1),n++,i+1):this._renderEvents(c,n++);return n},_groupCount:function(){var e=this.groupedResources;return e.length?this._isVerticallyGrouped()?this._rowCountForLevel(e.length-1):this._columnCountForLevel(e.length)/this._columnOffsetForResource(e.length):1},_columnOffsetForResource:function(e){return this._columnCountForLevel(e)/this._columnCountForLevel(e-1)},destroy:function(){this.table&&this.table.removeClass("k-scheduler-monthview"),this.content&&this.content.off(a),this.element&&this.element.off(a),s.fn.destroy.call(this),this._isMobile()&&!this._isMobilePhoneView()&&this.options.editable&&(this.options.editable.create!==!1&&this._addUserEvents.destroy(),this.options.editable.update!==!1&&this._editUserEvents.destroy())},events:["remove","add","edit","navigate"],options:{title:"Month",name:"month",eventHeight:25,moreButtonHeight:13,editable:!0,selectedDateFormat:"{0:y}",selectedShortDateFormat:"{0:y}",groupHeaderTemplate:"#=text#",dayTemplate:f,eventTemplate:g}})}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()}); |