(function(){u8.Crm.Widgets.CalendarItemList=function(e,t){this.Widget(e,$.extend({},u8.Crm.Widgets.CalendarItemList.defaults,t));if(!this.model){$error("Cannot create CalendarItemList without a model")}this.model.bind("Update",this._onModelUpdate.bind(this),this.id);this._isCreated=false;this._create()};u8.Crm.Widgets.CalendarItemList.makeClass({name:"CalendarItemList",deriveFrom:u8.Base.Widgets.Widget,events:["Create"]});u8.Crm.Widgets.CalendarItemList.defaults={items:[]};$.extend(u8.Crm.Widgets.CalendarItemList.prototype,{dispose:function(){if(this._isDisposed){return}this.model.unbind("Update",this.id);this.$(this.element).off("."+this.id);this.Widget_dispose()},close:function(){var e=u8.Base.Widgets.Tools.closest(this,"Popup");if(e){e.close()}},getSize:function(){var e=this.$;var t=e(this.element);var i=t.find(".u8-calendar-moreitems-container").get(0).scrollHeight+5;var s=0;t.find(".u8-calendar-item-general").each(function(){var t=e(this);var i=t.find(".u8-calendar-item-text").children().get(0);var n=i.scrollWidth-e(i).width();s=Math.max(t.width()+n,s)});return{height:i,width:s}},setFocus:function(){u8.Base.Dom.focus(this.element)},_create:function(){var e=this.$(this.element);this._itemViewIds={};this.$("<div class='u8-calendar-moreitems-loading' />").text(u8.session.commonTexts.loading).appendTo(e);var t=this.$("<div class='u8-calendar-moreitems-container' />").appendTo(e);var i=[];for(var s=0;s<this.items.length;s++){var n=u8.Base.Dom.uniqueId();var o=this.$("<div id='"+n+"' class='u8-calendar-moreitems-item' />").appendTo(t);var a=this.items[s];this._itemViewIds[a.id]=n;var d=u8.widget("CalendarItemView",o,{item:a,showTime:true,colorType:this.colorType,parent:this,model:this.model});i.push(d)}u8.tools.ready(i,function(){e.attr("tabIndex",0).on("keyup."+this.id,this._onKeyUp.bind(this)).find(".u8-calendar-moreitems-loading").remove();this.setFocus();u8.tools.created(this)}.bind(this))},_onKeyUp:function(e){if(e.keyCode==27){this.close()}else if(e.keyCode==46){this.model.deleteSelection()}},_onModelUpdate:function(e,t){if(this._isDisposed){return}var i=this["_onModel"+t.reason.toPascalCase()];if(i){i.apply(this,arguments)}},_onModelAddItem:function(){this.close()},_onModelUpdateItem:function(){this.close()},_onModelDeleteItems:function(e,t){t.itemIds.each(function(e){var t=this._itemViewIds[e];if(!t){return}this.$("#"+t).remove();var i=this.children.get(t);if(i){i.dispose()}}.bind(this))}});u8.Crm.Widgets.CalendarItemList.openInPopup=function(e,t){var i=267;var s=$.extend({position:"left-middle",allowMaximize:false,sizing:"fixed",minSize:{height:147},maxSize:{height:i},showArrow:true},e.popupOptions);var n=s.alignTo;delete s.alignTo;u8.Base.Widgets.Popup.openWidgetPopup({type:"CalendarItemList",popupOptions:s,widgetOptions:e.widgetOptions},function(e,s){var o=s.popup;var a=s.widget;var d=a.getSize();var r=450;var l=180;var h=i-25;o.alignTo=n;o.size={width:Math.min(r,Math.max(l,d.width)),height:Math.min(h,d.height)};o.autoSizeAndPosition();a.setFocus();if(typeof t=="function"){t(null,s)}})}})();