Ext.namespace("Zarafa.widgets");
Zarafa.widgets.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.AbstractFolderWidget.superclass.constructor.call(this,a);a=container.getHierarchyStore();this.mon(a,"load",this.onHierarchyLoad,this);this.onHierarchyLoad(a);this.mon(this.store,"load",this.onStoreLoad,this,{single:true})},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})},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.onReloadSpinnerChange,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.onRefreshSpinnerChange,scope:this},plugins:["zarafa.numberspinner"]}],
buttons:[{text:_("Close"),scope:this,handler:function(){a.close()}}]}]});a.show(this)},onReloadSpinnerChange:function(a,b){this.set("reloadinterval",b)},onRefreshSpinnerChange:function(a,b){this.set("refreshinterval",b)}});Ext.namespace("Zarafa.widgets");
Zarafa.widgets.TasksWidget=Ext.extend(Zarafa.widgets.AbstractFolderWidget,{constructor:function(a){a=a||{};var b=new Zarafa.task.TaskStore;Ext.applyIf(a,{title:_("Tasks"),name:"tasks",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:{rowdblclick:this.onRowDblClick,scope:this}}]});Zarafa.widgets.TasksWidget.superclass.constructor.call(this,a)},updateFilter:function(){this.store.filterBy(function(a){return a.get("status")!=Zarafa.core.mapi.TaskStatus.COMPLETE},this)},onRowDblClick:function(a){Zarafa.common.Actions.openViewRecord(a.getSelectionModel().getSelected())}});
Zarafa.onReady(function(){container.registerWidget(Zarafa.widgets.TasksWidget,"tasks",_("Tasks"),"plugins/folderwidgets/resources/images/tasks.png")});Ext.namespace("Zarafa.widgets");
Zarafa.widgets.AppointmentsWidget=Ext.extend(Zarafa.widgets.AbstractFolderWidget,{constructor:function(a){a=a||{};var b=new Zarafa.calendar.AppointmentStore;Ext.applyIf(a,{title:_("Today's Appointments"),name:"appointments",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:{rowdblclick:this.onRowDblClick,scope:this}}]});Zarafa.widgets.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},this)},subjectRenderer:function(a,b,c){var d=new Date,e=(c.get("startdate")||d).format(_("H:i")),f=(c.get("duedate")||d).format(_("H: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"}},
onRowDblClick:function(a){Zarafa.common.Actions.openViewRecord(a.getSelectionModel().getSelected())}});Zarafa.onReady(function(){container.registerWidget(Zarafa.widgets.AppointmentsWidget,"appointments",_("Appointments"),"plugins/folderwidgets/resources/images/appointments.png")});
