Ext.namespace("Zarafa.widgets.folderwidgets");
Zarafa.widgets.folderwidgets.AbstractFolderWidget=Ext.extend(Zarafa.core.ui.widget.Widget,{folder:undefined,store:undefined,folderType:undefined,constructor:function(a){a=a||{};Ext.applyIf(a,{hasConfig:true});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.onStoreLoad,this,{single:true});this.mon(this.store,"update",this.onStoreUpdate,this)},onHierarchyLoad:function(a){(this.folder=a.getDefaultFolder(this.folderType))&&this.reloadStore()},onStoreLoad:function(){var a=this.get("refreshinterval")||1E4;Ext.TaskMgr.start({run:this.updateFilter,interval:a,scope:this});a=this.get("reloadinterval")||3E5;Ext.TaskMgr.start({run:this.reloadStore,interval:a,scope:this})},onStoreUpdate:function(){this.updateFilter()},reloadStore:function(){this.folder&&
this.store.load({folder:this.folder})},updateFilter:Ext.emptyFn,config:function(){var a=new Ext.Window({title:_("Configure widget"),layout:"fit",width:320,height:200,items:[{xtype:"form",labelWidth:120,frame:true,items:[{xtype:"zarafa.spinnerfield",fieldLabel:_("Reload interval (ms)"),name:"reloadinterval",minValue:0,maxValue:18E5,incrementValue:1E3,defaultValue:this.get("reloadinterval")||3E5,listeners:{change:this.onFieldChange,scope:this},plugins:["zarafa.numberspinner"]},{xtype:"zarafa.spinnerfield",
fieldLabel:_("Refresh interval (ms)"),name:"refreshinterval",minValue:0,maxValue:18E5,incrementValue:1E3,defaultValue:this.get("refreshinterval")||1E4,listeners:{change:this.onFieldChange,scope:this},plugins:["zarafa.numberspinner"]}],buttons:[{text:_("Close"),scope:this,handler:function(){a.close()}}]}]});a.show(this)},onFieldChange:function(a,b){this.set(a.getName(),b)}});Ext.namespace("Zarafa.widgets.folderwidgets");
Zarafa.widgets.folderwidgets.AppointmentsWidget=Ext.extend(Zarafa.widgets.folderwidgets.AbstractFolderWidget,{constructor:function(a){a=a||{};var b=new Zarafa.calendar.AppointmentStore;Ext.applyIf(a,{height:300,autoScroll:true,layout:"fit",folderType:"calendar",store:b,items:[{xtype:"zarafa.gridpanel",store:b,border:true,hideHeaders:true,loadMask:{msg:_("Loading appointments")+"..."},sm:new Ext.grid.RowSelectionModel({singleSelect:true}),viewConfig:{deferEmptyText:false,emptyText:'<div class="emptytext">'+
_("No appointments for today.")+"</div>",forceFit:true,enableRowBody:true,getRowClass:this.applyRowClass},colModel:new Ext.grid.ColumnModel({columns:[{header:_("Subject"),dataIndex:"subject",editable:false,menuDisabled:true,renderer:this.subjectRenderer,width:300}]}),listeners:{rowcontextmenu:this.onRowContextMenu,rowdblclick:this.onRowDblClick,scope:this}}]});Zarafa.widgets.folderwidgets.AppointmentsWidget.superclass.constructor.call(this,a)},reloadStore:function(){if(this.folder){var a=new Date,
b=a.clearTime().add(Date.DAY,1);this.store.load({folder:this.folder,params:{restriction:{startdate:a.getTime()/1E3,duedate:b.getTime()/1E3}}})}},updateFilter:function(){this.store.filterBy(function(a){var b=new Date,c=a.get("startdate")||b;a=a.get("duedate")||b;return(c>=b||a>=b)&&c<b.clearTime().add(Date.DAY,1)},this)},subjectRenderer:function(a,b,c){var d=new Date,e=(c.get("startdate")||d).format(_("G:i")),f=(c.get("duedate")||d).format(_("G:i"));b.attr=(c.get("startdate")||d)<d?"style='color: #888; font-weight: bold;'":
"style='font-weight: bold;'";b="";d=function(g){return'<img src="'+g.src+'" /> '};if(c.get("private")===true)b+=d(Zarafa.calendar.ui.IconCache.getPrivateIcon());if(c.get("recurring")===true)b+=c.get("exception")===true?d(Zarafa.calendar.ui.IconCache.getExceptionIcon()):d(Zarafa.calendar.ui.IconCache.getRecurringIcon());return c.get("alldayevent")?String.format(_("Today: {1} {0}"),Ext.util.Format.htmlEncode(a),b):String.format(_("{1}&minus;{2}: {3} {0}"),Ext.util.Format.htmlEncode(a),e,f,b)},applyRowClass:function(a,
b,c){if(b=a.get("location")){c.body='<table style="width: 100%; padding: 0; border-spacing: 0;">';c.body+=String.format('<tr><td style="width: 100%; font-size: 80%;"><i>{0}</i></td></tr>',Ext.util.Format.htmlEncode(b));c.body+="</table>"}else c.body="";switch(a.get("busystatus")){case Zarafa.core.mapi.BusyStatus.FREE:return"today-item today-free";case Zarafa.core.mapi.BusyStatus.TENTATIVE:return"today-item today-tentative";case Zarafa.core.mapi.BusyStatus.BUSY:return"today-item today-busy";case Zarafa.core.mapi.BusyStatus.OUTOFOFFICE:return"today-item today-outofoffice";
default:return"today-item today-unknown"}},onRowContextMenu:function(a,b,c){a=a.getSelectionModel();a.isSelected(b)||a.selectRow(b);var d;if(this.folder)if(b=container.getContextByFolder(this.folder))d=b.getModel();Zarafa.core.data.UIFactory.openDefaultContextMenu(a.getSelections(),{position:c.getXY(),model:d})},onRowDblClick:function(a){a=a.getSelectionModel().getSelected();if(!Ext.isEmpty(a))if(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:_("Today's Appointments"),iconPath:"plugins/folderwidgets/resources/images/appointments.png",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)});Ext.applyIf(a,{height:200,autoScroll:true,layout:"fit",folderType:"inbox",store:b,items:[{xtype:"zarafa.gridpanel",
id:"unread-mail-widget",store:b,border:true,loadMask:{msg:_("Loading mail")+"..."},sm:new Ext.grid.RowSelectionModel({singleSelect:true}),viewConfig:{deferEmptyText:false,emptyText:'<div class="emptytext">'+_("No unread mail.")+"</div>",forceFit:true,enableRowBody:true,rowSelectorDepth:15,getRowClass:this.viewConfigGetRowClass},colModel:new Ext.grid.ColumnModel({columns:[{header:_("From"),dataIndex:"sent_representing_name",menuDisabled:true,renderer:Ext.util.Format.htmlEncode},{header:_("Received"),
dataIndex:"message_delivery_time",editable:false,menuDisabled:true,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){b=a.isRead()?"mail_read":"mail_unread";var d={},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;if(this.folder)if(b=container.getContextByFolder(this.folder))d=b.getModel();Zarafa.core.data.UIFactory.openDefaultContextMenu(a.getSelections(),{position:c.getXY(),model:d})},onRowDblClick:function(a){Zarafa.core.data.UIFactory.openViewRecord(a.getSelectionModel().getSelected())}});
Zarafa.onReady(function(){container.registerWidget(new Zarafa.core.ui.widget.WidgetMetaData({name:"mail",displayName:_("Unread Mail"),iconPath:"plugins/folderwidgets/resources/images/mail.png",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.setRestriction({search:Zarafa.core.data.RestrictionFactory.dataResProperty("status",Zarafa.core.mapi.Restrictions.RELOP_NE,Zarafa.core.mapi.TaskStatus.COMPLETE)});Ext.applyIf(a,{height:200,autoScroll:true,layout:"fit",folderType:"task",store:b,items:[{xtype:"zarafa.gridpanel",store:b,border:true,loadMask:{msg:_("Loading tasks")+"..."},
sm:new Ext.grid.RowSelectionModel({singleSelect:true}),viewConfig:{deferEmptyText:false,emptyText:'<div class="emptytext">'+_("No tasks.")+"</div>",forceFit:true},colModel:new Ext.grid.ColumnModel({columns:[{header:_("Owner"),dataIndex:"owner",menuDisabled:true,renderer:Ext.util.Format.htmlEncode},{header:_("Subject"),dataIndex:"subject",editable:false,menuDisabled:true,renderer:Ext.util.Format.htmlEncode}]}),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)},onRowContextMenu:function(a,b,c){a=a.getSelectionModel();a.isSelected(b)||a.selectRow(b);var d;if(this.folder)if(b=container.getContextByFolder(this.folder))d=b.getModel();Zarafa.core.data.UIFactory.openDefaultContextMenu(a.getSelections(),{position:c.getXY(),model:d})},onRowDblClick:function(a){Zarafa.core.data.UIFactory.openViewRecord(a.getSelectionModel().getSelected())}});
Zarafa.onReady(function(){container.registerWidget(new Zarafa.core.ui.widget.WidgetMetaData({name:"tasks",displayName:_("Tasks"),iconPath:"plugins/folderwidgets/resources/images/tasks.png",widgetConstructor:Zarafa.widgets.folderwidgets.TasksWidget}))});
