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,constructor:function(a){a=a||{};Ext.applyIf(a,{hasConfig:!0});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:!0});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("reloadinterval")||300;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,renderCategories:function(a){var b=
"";Zarafa.common.categories.Util.getCategories(a).forEach(function(a,e){var c=a.substring(0,1);b='<span class="advanced-folderwidget-category-box" style="background-color: '+Zarafa.common.categories.Util.getCategoryColor(a)+'" title="'+Ext.util.Format.htmlEncode(a)+'">'+Ext.util.Format.htmlEncode(c)+"</span>"});return b+(b?" | ":"")},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=new Ext.Window({title:_("Configure widget"),layout:"fit",width:320,height:130,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()],buttons:[{text:_("Close"),scope:this,handler:function(){a.close()}}]}]});a.show(this)},onFieldChange:function(a,b,c){a=a.getName();this.set(a,b);"widgetheight"===a&&this.setHeight(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:this.get("widgetheight")||300,autoScroll:!0,layout:"fit",folderType:"calendar",store:b,items:[{xtype:"zarafa.gridpanel",store:b,hideHeaders:!0,loadMask:{msg:_("Loading appointments")+"..."},sm:new Ext.grid.RowSelectionModel({singleSelect:!0}),viewConfig:{deferEmptyText:!1,emptyText:'<div class="emptytext">'+
_("No appointments for today.")+"</div>",forceFit:!0,enableRowBody:!0,rowSelectorDepth:15,getRowClass:this.viewConfigGetRowClass,scope:this},colModel:new Ext.grid.ColumnModel({columns:[{header:_("Time"),dataIndex:"startdate",renderer:this.dummyColumnRenderer}]}),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,
10);this.store.load({folder:this.folder,params:{restriction:{startdate:a.getTime()/1E3,duedate:b.getTime()/1E3,limit:10}}})}},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)},dummyColumnRenderer:function(a,b,c){b.attr="style='padding:0; margin:0; height:0px; '";return""},viewConfigGetRowClass:function(a,b,c){var e=function(a){return'<img src="'+a.src+'" /> '},d='<table width="100%"><tbody>';
this.startdateArray||(this.startdateArray=[]);var f=a.get("startdate"),g=new Date;this.startdateArray[b]=f;if(!this.startdateArray[b-1]||this.startdateArray[b-1].add(Date.DAY,1).clearTime()<=f)d+='<tr><td><div class="folderwidget-groupedview">',d=f<=g.add(Date.DAY,1).clearTime()?d+_("Today"):f<g.add(Date.DAY,2).clearTime()?d+_("Tomorrow"):f<=g.add(Date.DAY,7).clearTime()?d+f.format("l"):d+f.format(_("d.m.Y")),d+="</div></td></tr>";d+="<tr><td>";d=a.get("alldayevent")?d+_("All Day"):d+(a.get("startdate").format(_("G:i"))+
" - "+a.get("duedate").format(_("G:i")));(b=a.get("recurring_pattern"))&&(d=!0===a.get("exception")?d+(' <span title="'+b+'">'+e(Zarafa.calendar.ui.IconCache.getExceptionIcon())+"</span>"):d+(' <span title="'+b+'">'+e(Zarafa.calendar.ui.IconCache.getRecurringIcon())+"</span>"));d=d+"</td></tr><tr><td>"+Zarafa.widgets.folderwidgets.AppointmentsWidget.superclass.renderCategories(a);d+=a.get("subject");!0===a.get("private")&&(d+=" "+e(Zarafa.calendar.ui.IconCache.getPrivateIcon()));c.body=d+"</td></tr></tbody></table>";
return"x-grid3-row-expanded "},subjectRenderer:function(a,b,c,e,d,f){f=new Date;e=(c.get("startdate")||f).format(_("G:i"));d=(c.get("duedate")||f).format(_("G:i"));(c.get("startdate")||f)<f?b.attr="style='color: #888; font-weight: bold;'":b.attr="style='font-weight: bold;'";b="";f=function(a){return'<img src="'+a.src+'" /> '};!0===c.get("private")&&(b+=f(Zarafa.calendar.ui.IconCache.getPrivateIcon()));!0===c.get("recurring")&&(b=!0===c.get("exception")?b+f(Zarafa.calendar.ui.IconCache.getExceptionIcon()):
b+f(Zarafa.calendar.ui.IconCache.getRecurringIcon()));return c.get("alldayevent")?String.format(_("Today: {1} {0}"),Ext.util.Format.htmlEncode(a),b):String.format("{1}-{2}: {3} {0}",Ext.util.Format.htmlEncode(a),e,d,b)},applyRowClass:function(a,b,c,e){(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>"):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);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:_("Today's Appointments"),widgetConstructor:Zarafa.widgets.folderwidgets.AppointmentsWidget}))});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.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,{height:200,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 Ext.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,e){b=a.isRead()?"mail_read":"mail_unread";var d;c.body='<table cellspacing="0" cellpadding="0" border="0" style="width: 100%;">';
c.body+="<tr>";e={};d=Zarafa.common.ui.grid.Renderers.subject(a.get("subject"),e,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>',e.css,d);e={};d=Zarafa.common.ui.grid.Renderers.attachment(a.get("hasattach"),e,a);c.body+=String.format('<td style="width: 24px"><div class="grid_compact {0}" style="height: 24px; width: 24px;">{1}</div></td>',e.css,d);e={};d=Zarafa.common.ui.grid.Renderers.importance(a.get("importance"),
e,a);c.body+=String.format('<td style="width: 24px"><div class="grid_compact {0}" style="height: 24px; width: 24px;">{1}</div></td>',e.css,d);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 e;this.folder&&(b=container.getContextByFolder(this.folder))&&(e=b.getModel());Zarafa.core.data.UIFactory.openDefaultContextMenu(a.getSelections(),{position:c.getXY(),model:e})},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.dataResProperty("status",Zarafa.core.mapi.Restrictions.RELOP_NE,Zarafa.core.mapi.TaskStatus.COMPLETE)});Ext.applyIf(a,{height:this.get("widgetheight")||300,autoScroll:!0,layout:"fit",folderType:"todolist",store:b,items:[{xtype:"zarafa.gridpanel",
store:b,loadMask:{msg:_("Loading tasks")+"..."},sm:new Ext.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 Date"),tooltip:_("Due Date"),dataIndex:"duedate",renderer:this.dueDateRenderer},{header:"<p class='icon_importance'>&nbsp;</p>",tooltip:_("Importance"),dataIndex:"importance",
align:"center",width:55,renderer:Zarafa.common.ui.grid.Renderers.importance},{header:"%",tooltip:_("% Completed"),dataIndex:"percent_complete",align:"center",width:80,renderer:Zarafa.common.ui.grid.Renderers.percentage},{header:_("Owner"),tooltip:_("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)},dueDateRenderer:function(a,b,c){a=new Date;c=c.get("duedate");b.attr="";c?c<a.clearTime().add(Date.DAY,1)?(a=_("Today"),b.attr="style='color: #F00;'"):a=c<a.clearTime().add(Date.DAY,2)?_("Tomorrow"):c.format(_("d/m/Y")):a=_("none");return String.format("{0}",a)},ownerRenderer:function(a,b,c){a=c.get("owner");if(!Ext.isString(a))return"";b=a.split(" ");c="";for(var e=0,d=
b.length;e<d;e++)c+=b[e].substring(0,1);return'<span title="'+Ext.util.Format.htmlEncode(a)+'">'+Ext.util.Format.htmlEncode(c)+"</span>"},viewConfigGetRowClass:function(a,b,c){b=a.get("subject");var e=Zarafa.widgets.folderwidgets.TasksWidget.superclass.renderCategories(a),d=new Date;a=a.get("duedate");var f="";a&&a<d.clearTime().add(Date.DAY,1)&&(f='style="color:#F00;"');c.body=String.format('<div class="folderwidget-task-row" {2}>{1}{0}</div>',b,e,f);return"x-grid3-row-expanded "},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"),widgetConstructor:Zarafa.widgets.folderwidgets.TasksWidget}))});//# sourceMappingURL=folderwidgets.js.map
