Ext.namespace("Zarafa.widgets.folderwidgets");
Zarafa.widgets.folderwidgets.AbstractFolderWidget=Ext.extend(Zarafa.core.ui.widget.Widget,{folder:void 0,store:void 0,folderType:void 0,reloadTask:void 0,configurationConfig:void 0,constructor:function(a){a=a||{};this.guid=a.guid;Ext.applyIf(a,{hasConfig:!0,height:this.get("widgetheight")||300});Zarafa.widgets.folderwidgets.AbstractFolderWidget.superclass.constructor.call(this,a)},initEvents:function(){Zarafa.widgets.folderwidgets.AbstractFolderWidget.superclass.initEvents.apply(this,arguments);var a=
container.getHierarchyStore();this.mon(a,"load",this.onHierarchyLoad,this);this.onHierarchyLoad(a);this.mon(this.store,"load",this.startReloadTask,this,{single:!0});this.mon(this.store,"load",this.updateFilter,this);this.mon(this.store,"update",this.onStoreUpdate,this)},onHierarchyLoad:function(a){(this.folder=a.getDefaultFolder(this.folderType))&&this.reloadStore()},startReloadTask:function(){this.reloadTask&&Ext.TaskMgr.stop(this.reloadTask);var a=this.get("reloadinterval")||300;this.reloadTask=
Ext.TaskMgr.start({run:this.reloadStore,interval:1E3*a,scope:this})},onStoreUpdate:function(){this.updateFilter()},reloadStore:function(){this.folder&&this.store.load({folder:this.folder})},updateFilter:Ext.emptyFn,viewConfigGetRowClass:function(a,b,c){c.body='<div class="zarafa-grid-body-container">';b=Zarafa.common.categories.Util.getCategories(a);b=Zarafa.common.categories.Util.getCategoriesHtml(b);c.body+='<div class="k-category-container">'+b+"</div>";b=Zarafa.common.ui.grid.Renderers.subject(a.get("subject"),
{});c.body+=String.format('<div class="grid_compact grid_compact_left grid_compact_subject_cell">{0}</div>',b);c.body+="</div>";return"x-grid3-row-expanded "+Zarafa.task.ui.TaskGridView.prototype.viewConfigGetRowClass(a)},createConfigHeight:function(a,b){return{xtype:"zarafa.spinnerfield",fieldLabel:_("Widget height"),name:"widgetheight",boxLabel:_("pixels"),width:60,minValue:a||100,maxValue:b||500,incrementValue:5,defaultValue:this.get("widgetheight")||300,listeners:{change:this.onFieldChange,scope:this},
plugins:["zarafa.numberspinner"]}},config:function(){var a=Ext.apply({},this.configurationConfig||{},{title:_("Configure widget"),layout:"fit",width:320,height:135,modal:!0,items:[{xtype:"form",frame:!0,cls:"k-configure-widget",labelWidth:120,items:[{xtype:"zarafa.spinnerfield",fieldLabel:_("Reload interval"),name:"reloadinterval",boxLabel:_("seconds"),width:60,minValue:30,maxValue:1800,incrementValue:30,defaultValue:this.get("reloadinterval")||300,listeners:{change:this.onFieldChange,scope:this},
plugins:["zarafa.numberspinner"]},this.createConfigHeight()].concat(this.getConfigurationItems()),buttons:[{text:_("Close"),scope:this,handler:function(){this.win.close()}}]}]});this.win=new Ext.Window(a);this.win.show(this)},getConfigurationItems:function(){return[]},onFieldChange:function(a,b,c){a=a.getName();this.set(a,b);"widgetheight"===a&&this.setHeight(b);"reloadinterval"===a&&this.startReloadTask()}});Ext.namespace("Zarafa.widgets.folderwidgets");
Zarafa.widgets.folderwidgets.AppointmentsWidget=Ext.extend(Zarafa.widgets.folderwidgets.AbstractFolderWidget,{folder:void 0,folderId:void 0,constructor:function(a){a=a||{};var b=new Zarafa.calendar.AppointmentStore;Ext.applyIf(a,{autoScroll:!0,layout:"fit",folderType:"calendar",store:b,items:[{xtype:"zarafa.gridpanel",cls:"k-appointmentwidget",store:b,hideHeaders:!0,ref:"appointmentsGrid",loadMask:{msg:_("Loading appointments...")},sm:new Zarafa.common.ui.grid.RowSelectionModel({singleSelect:!0}),
viewConfig:{deferEmptyText:!1,emptyText:'<div class="emptytext">'+_("Please select a calendar via widget settings")+"</div>",forceFit:!0,enableRowBody:!0,rowSelectorDepth:15,getRowClass:this.viewConfigGetRowClass,scope:this},colModel:new Ext.grid.ColumnModel({columns:[{header:_("Time"),dataIndex:"startdate",renderer:this.timeRenderer,scope:this}]}),listeners:{rowcontextmenu:this.onRowContextMenu,rowdblclick:this.onRowDblClick,scope:this}}]});this.configurationConfig={height:180};Zarafa.widgets.folderwidgets.AppointmentsWidget.superclass.constructor.call(this,
a);this.folderId=this.get("folderId")},getConfigurationItems:function(){return[{xtype:"zarafa.spinnerfield",fieldLabel:_("Number of days"),name:"numdays",boxLabel:_("day(s)"),width:60,minValue:1,maxValue:365,incrementValue:1,defaultValue:this.get("numdays")||5,listeners:{change:this.onNumDaysChange,scope:this},plugins:["zarafa.numberspinner"]},{xtype:"zarafa.calendarfolderselectionlink",folder:this.folder,fieldLabel:_("Calendar"),name:"Calendar",listeners:{folderupdate:this.onUpdateFolder,scope:this}}]},
initEvents:function(){Zarafa.widgets.folderwidgets.AppointmentsWidget.superclass.initEvents.apply(this,arguments);var a=container.getHierarchyStore();this.mon(a,{remove:this.onSharedStoreRemove,removeFolder:this.onSharedStoreRemove,scope:this});this.mon(this.store,"load",this.onStoreLoad,this,{single:!0});this.mon(this.store,"exception",this.onStoreException,this)},onStoreLoad:function(){this.startFilterTask();this.setEmptytext()},onStoreException:function(a,b,c,d,e,g){var f;e&&e.error&&(a=e.error,
a.info&&a.info.display_message&&(f=String.format(_("{0}"),a.info.display_message)));this.appointmentsGrid.getStore().removeAll();this.setEmptytext(f)},onHierarchyLoad:function(a){Ext.isEmpty(this.folderId)||(this.folder=a.getFolder(this.folderId),a=Zarafa.core.mapi.Rights.RIGHTS_READ_ANY,Ext.isEmpty(this.folder)||(this.folder.get("rights")&a)!==a?this.resetWidget():(this.setWidgetTitle(this.folder),this.reloadStore()))},resetWidget:function(){this.folderId=this.folder=void 0;this.set("folderId",void 0);
this.appointmentsGrid.getStore().removeAll()},setWidgetTitle:function(a){var b=_("Upcoming Appointments");if(a){var c=a.getMAPIStore(),d=c.isDefaultStore(),e=a.isDefaultFolder(),c=c.get("display_name");a=a.get("display_name");d&&e||(b=d?String.format(_("Appointments of {0}"),a):String.format(_("Appointments of {0} - {1}"),a,c))}this.setTitle(b)},setEmptytext:function(a){var b=this.appointmentsGrid.getView();Ext.isEmpty(a)&&(a=this.folder?_("No appointments"):_("Please select a calendar via widget settings"));
b.emptyText='<div class="emptytext">'+a+"</div>";b.refresh()},onSharedStoreRemove:function(a,b,c){b=this.get("folderId");Ext.isEmpty(b)||(a=a.getFolder(b),Ext.isEmpty(a)&&(this.resetWidget(),this.setEmptytext()))},onUpdateFolder:function(a){this.folder=a;this.folderId=a.get("entryid");this.set("folderId",this.folderId);this.setWidgetTitle(a);this.reloadStore();this.setEmptytext()},onNumDaysChange:function(a,b,c){this.set(a.getName(),b);this.reloadStore()},startFilterTask:function(){Ext.TaskMgr.start({run:this.updateFilter,
interval:3E4,scope:this})},reloadStore:function(){if(this.folder){var a=this.get("numdays")||5,b=(new Date).clearTime().getTime()/1E3,a=(new Date).clearTime().add(Date.DAY,a).getTime()/1E3;this.store.load({folder:this.folder,params:{ignoreException:!0,restriction:{startdate:b,duedate:a}}})}},updateFilter:function(){var a=(new Date).getTime()/1E3;this.store.filterBy(function(b){b=b.get("duedate").getTime()/1E3;return!b||b>=a},this)},timeRenderer:function(a,b,c){b="";var d=c.get("recurring_pattern");
d&&(b=!0===c.get("exception")?'&nbsp;<span ext:qwidth="300" ext:qtip="'+d+'"><img src="'+Zarafa.calendar.ui.IconCache.getExceptionIcon().src+'"/></span>':'&nbsp;<span ext:qwidth="300" ext:qtip="'+d+'"><img src="'+Zarafa.calendar.ui.IconCache.getRecurringIcon().src+'"/></span>');d="";!0===c.get("private")&&(d='&nbsp;<img src="'+Zarafa.calendar.ui.IconCache.getPrivateIcon().src+'"/>');var e=(new Date).clearTime(),g=(new Date).add(Date.DAY,1).clearTime(),f=c.get("duedate");c=c.get("alldayevent");return a>=
e&&f<=g?c?_("Today (all day)")+b+d:String.format(_("Today {0} - {1}"),a.format(_("G:i")),f.format(_("G:i")))+b+d:c?String.format(_("{0} - {1} (all day)"),a.format(_("d/m/y")),f.format(_("d/m/y")))+b+d:String.format(_("{0} - {1}"),a.format(_("d/m/y G:i")),f.format(_("d/m/y G:i")))+b+d},onRowContextMenu:function(a,b,c){a=a.getSelectionModel();a.isSelected(b)||a.selectRow(b);this.folder&&(b=container.getContextByFolder(this.folder))&&(b=b.getModel(),Zarafa.core.data.UIFactory.openDefaultContextMenu(a.getSelections(),
{position:c.getXY(),model:b}))},onRowDblClick:function(a,b,c){a=a.getSelectionModel().getSelected();Ext.isEmpty(a)||a.isRecurringOccurence()&&(a=a.convertToOccurenceRecord());Zarafa.core.data.UIFactory.openViewRecord(a)}});Zarafa.onReady(function(){container.registerWidget(new Zarafa.core.ui.widget.WidgetMetaData({name:"appointments",displayName:_("Upcoming Appointments"),widgetConstructor:Zarafa.widgets.folderwidgets.AppointmentsWidget}))});Ext.namespace("Zarafa.widgets.folderwidgets");
Zarafa.widgets.folderwidgets.MailWidget=Ext.extend(Zarafa.widgets.folderwidgets.AbstractFolderWidget,{constructor:function(a){a=a||{};var b=new Zarafa.mail.MailStore;b.setDefaultSort(b.defaultSortInfo.field,b.defaultSortInfo.direction);b.setRestriction({search:Zarafa.core.data.RestrictionFactory.dataResBitmask("0x00E070003",Zarafa.core.mapi.Restrictions.BMR_EQZ,Zarafa.core.mapi.MessageFlags.MSGFLAG_READ)});b.isAdvanceSearchStore=function(){return!0};Ext.applyIf(a,{autoScroll:!0,layout:"fit",folderType:"inbox",
store:b,items:[{xtype:"zarafa.gridpanel",id:"unread-mail-widget",store:b,border:!0,loadMask:{msg:_("Loading mail")+"..."},sm:new Zarafa.common.ui.grid.RowSelectionModel({singleSelect:!0}),viewConfig:{deferEmptyText:!1,emptyText:'<div class="emptytext">'+_("No unread mail.")+"</div>",forceFit:!0,enableRowBody:!0,rowSelectorDepth:15,getRowClass:this.viewConfigGetRowClass},colModel:new Ext.grid.ColumnModel({columns:[{header:_("From"),dataIndex:"sent_representing_name",menuDisabled:!0,renderer:Ext.util.Format.htmlEncode},
{header:_("Received"),dataIndex:"message_delivery_time",editable:!1,menuDisabled:!0,renderer:Zarafa.common.ui.grid.Renderers.datetime}]}),listeners:{rowcontextmenu:this.onRowContextMenu,rowdblclick:this.onRowDblClick,scope:this}}]});Zarafa.widgets.folderwidgets.MailWidget.superclass.constructor.call(this,a)},updateFilter:function(){this.store.filterBy(function(a){return!a.isRead()},this)},viewConfigGetRowClass:function(a,b,c,d){b=a.isRead()?"mail_read":"mail_unread";var e;c.body='<table cellspacing="0" cellpadding="0" border="0" style="width: 100%;">';
c.body+="<tr>";d={};e=Zarafa.common.ui.grid.Renderers.subject(a.get("subject"),d,a);c.body+=String.format('<td style="width: 100%"><div class="grid_compact grid_compact_left grid_compact_subject_cell {0}" style="height: 24px;">{1}</div></td>',d.css,e);d={};e=Zarafa.common.ui.grid.Renderers.attachment(a.get("hasattach"),d,a);c.body+=String.format('<td style="width: 24px"><div class="grid_compact {0}" style="height: 24px; width: 24px;">{1}</div></td>',d.css,e);d={};e=Zarafa.common.ui.grid.Renderers.importance(a.get("importance"),
d,a);c.body+=String.format('<td style="width: 24px"><div class="grid_compact {0}" style="height: 24px; width: 24px;">{1}</div></td>',d.css,e);c.body+="</tr></table>";return"x-grid3-row-expanded "+b},onRowContextMenu:function(a,b,c){a=a.getSelectionModel();a.isSelected(b)||a.selectRow(b);var d;this.folder&&(b=container.getContextByFolder(this.folder))&&(d=b.getModel());Zarafa.core.data.UIFactory.openDefaultContextMenu(a.getSelections(),{position:c.getXY(),model:d})},onRowDblClick:function(a,b,c){Zarafa.core.data.UIFactory.openViewRecord(a.getSelectionModel().getSelected())}});
Zarafa.onReady(function(){container.registerWidget(new Zarafa.core.ui.widget.WidgetMetaData({name:"mail",displayName:_("Unread Mail"),widgetConstructor:Zarafa.widgets.folderwidgets.MailWidget}))});Ext.namespace("Zarafa.widgets.folderwidgets");
Zarafa.widgets.folderwidgets.TasksWidget=Ext.extend(Zarafa.widgets.folderwidgets.AbstractFolderWidget,{constructor:function(a){a=a||{};var b=new Zarafa.task.TaskStore;b.setDefaultSort("duedate","asc");b.setRestriction({task:Zarafa.core.data.RestrictionFactory.createResAnd([Zarafa.core.data.RestrictionFactory.dataResProperty("status",Zarafa.core.mapi.Restrictions.RELOP_NE,Zarafa.core.mapi.TaskStatus.COMPLETE),Zarafa.core.data.RestrictionFactory.dataResProperty("flag_status",Zarafa.core.mapi.Restrictions.RELOP_NE,
Zarafa.core.mapi.FlagStatus.completed)])});Ext.applyIf(a,{autoScroll:!0,layout:"fit",folderType:"todolist",store:b,items:[{xtype:"zarafa.gridpanel",cls:"k-taskwidget",store:b,loadMask:{msg:_("Loading tasks")+"..."},sm:new Zarafa.common.ui.grid.RowSelectionModel({singleSelect:!0}),viewConfig:{deferEmptyText:!1,emptyText:'<div class="emptytext">'+_("No tasks.")+"</div>",forceFit:!0,enableRowBody:!0,rowSelectorDepth:15,getRowClass:this.viewConfigGetRowClass},colModel:new Ext.grid.ColumnModel({columns:[{header:_("Due"),
tooltip:_("Sort by: Due Date"),dataIndex:"duedate",renderer:Zarafa.common.ui.grid.Renderers.utcdate},{header:"<p class='icon_importance'>&nbsp;</p>",tooltip:_("Sort by: Priority"),dataIndex:"importance",width:24,fixed:!0,renderer:Zarafa.common.ui.grid.Renderers.importance},{header:"%",tooltip:_("Sort by: Percentage Completed"),dataIndex:"percent_complete",width:75,renderer:Zarafa.common.ui.grid.Renderers.percentage},{header:_("Owner"),tooltip:_("Sort by: Owner"),dataIndex:"owner",renderer:this.ownerRenderer}],
defaults:{sortable:!0,menuDisabled:!0}}),listeners:{rowcontextmenu:this.onRowContextMenu,rowdblclick:this.onRowDblClick,scope:this}}]});Zarafa.widgets.folderwidgets.TasksWidget.superclass.constructor.call(this,a)},updateFilter:function(){this.store.filterBy(function(a){return a.get("status")!=Zarafa.core.mapi.TaskStatus.COMPLETE},this)},ownerRenderer:function(a,b,c){a=c.get("owner");if(!Ext.isString(a))return"";b=a.split(" ");c="";for(var d=0,e=b.length;d<e;d++)c+=b[d].substring(0,1);return'<span ext:qtip="'+
Ext.util.Format.htmlEncode(a)+'" ext:qwidth="100%">'+Ext.util.Format.htmlEncode(c)+"</span>"},onRowContextMenu:function(a,b,c){a=a.getSelectionModel();a.isSelected(b)||a.selectRow(b);this.folder&&(b=container.getContextByFolder(this.folder))&&(b=b.getModel(),Zarafa.core.data.UIFactory.openDefaultContextMenu(a.getSelections(),{position:c.getXY(),model:b}))},onRowDblClick:function(a,b,c){Zarafa.core.data.UIFactory.openViewRecord(a.getSelectionModel().getSelected())}});
Zarafa.onReady(function(){container.registerWidget(new Zarafa.core.ui.widget.WidgetMetaData({name:"tasks",displayName:_("Tasks / To-Do"),widgetConstructor:Zarafa.widgets.folderwidgets.TasksWidget}))});Ext.namespace("Zarafa.widgets.folderwidgets");
Zarafa.widgets.folderwidgets.DatepickerWidget=Ext.extend(Zarafa.widgets.folderwidgets.AbstractFolderWidget,{constructor:function(a){a=a||{};var b=new Zarafa.calendar.AppointmentStore;Ext.applyIf(a,{autoScroll:!1,autoHeight:!0,layout:"hbox",folderType:"calendar",store:b,items:[{xtype:"zarafa.datepicker",ref:"datePicker",hideLabel:!0,showWeekNumber:!0,showToday:!0,width:"100%",listeners:{scope:this},handler:this.datePickerHandler}]});Zarafa.widgets.folderwidgets.DatepickerWidget.superclass.constructor.call(this,
a);Ext.TaskMgr.start({run:this.updateFilter,interval:2E3,scope:this})},datePickerHandler:Ext.emptyFn,updateFilter:function(){this.datePicker&&this.datePicker.show();return Zarafa.widgets.folderwidgets.DatepickerWidget.superclass.updateFilter.apply(this,arguments)}});Zarafa.onReady(function(){container.registerWidget(new Zarafa.core.ui.widget.WidgetMetaData({name:"datepicker",displayName:_("Datepicker"),widgetConstructor:Zarafa.widgets.folderwidgets.DatepickerWidget}))});Ext.namespace("Zarafa.widgets.folderwidgets");
Zarafa.widgets.folderwidgets.CalendarFolderSelectionLink=Ext.extend(Ext.BoxComponent,{emptyText:_("Select one..."),folder:void 0,constructor:function(a){a=a||{};Ext.applyIf(a,{xtype:"zarafa.calendarfolderselectionlink",border:!1,autoScroll:!0,anchor:"100%",tpl:new Ext.XTemplate('<div class="zarafa-folder-link"><tpl if="!Ext.isEmpty(values.display_name)">&quot;{display_name:htmlEncode}&quot;</tpl><tpl if="Ext.isEmpty(values.display_name)">&quot;'+_("Unnamed folder")+"&quot;</tpl></div>",{compiled:!0})});
Zarafa.widgets.folderwidgets.CalendarFolderSelectionLink.superclass.constructor.call(this,a)},afterRender:function(){Zarafa.widgets.folderwidgets.CalendarFolderSelectionLink.superclass.afterRender.apply(this,arguments);this.update();this.mon(this.getEl(),"click",this.onClick,this)},onClick:function(a,b,c,d){a=container.getHierarchyStore().getDefaultFolder("calendar");a=Ext.isEmpty(this.folder)?a:this.folder;Zarafa.hierarchy.Actions.openFolderSelectionContent({folder:a,hideTodoList:!0,IPMFilter:"IPF.Appointment",
callback:this.update,scope:this,modal:!0})},update:function(a){a?(this.folder=a,this.fireEvent("folderupdate",a)):a=this.folder;Zarafa.widgets.folderwidgets.CalendarFolderSelectionLink.superclass.update.call(this,this.tpl.apply(a?a.data:{display_name:this.emptyText}))}});Ext.reg("zarafa.calendarfolderselectionlink",Zarafa.widgets.folderwidgets.CalendarFolderSelectionLink);//# sourceMappingURL=folderwidgets.js.map
