Ext.namespace("Zarafa.plugins.statslogging");
Zarafa.plugins.statslogging.StatsLogging=Ext.extend(Zarafa.core.Plugin,{actionQueue:[],sendIntervalID:null,initPlugin:function(){Zarafa.plugins.statslogging.StatsLogging.superclass.initPlugin.apply(this,arguments);Zarafa.core.data.ContentPanelMgr.on("createdialog",this.onCreateDialog,this);Zarafa.core.data.ContentPanelMgr.on("destroydialog",this.onDestroyDialog,this);container.on("contextswitch",this.onContextSwitch,this);Ext.ComponentMgr.register=Ext.ComponentMgr.register.createSequence(this.onRegisterComponent,this);
var a=container.getSettingsModel().get(this.getSettingsBase()+"/sendingInterval")||60;this.sendIntervalID=setInterval(this.sendActionQueueToServer.createDelegate(this),a*1E3)},queueAction:function(a){var b=new Date;this.actionQueue.push(b.format("H:i:s:")+b.getMilliseconds()+"> "+a)},sendActionQueueToServer:function(){if(this.actionQueue.length>0){var a=this.actionQueue;this.actionQueue=[];container.getRequest().singleRequest("pluginstatsloggingmodule","storeactions",{actions:a})}},onCreateDialog:function(a){try{this.queueAction("dialog - dialog: "+
a.items.get(0).constructor.xtype+" - create")}catch(b){}},onDestroyDialog:function(a){try{this.queueAction("dialog - dialog: "+a.items.get(0).constructor.xtype+" - destroy")}catch(b){}},onContextSwitch:function(a,b,c){try{this.queueAction("context - switch: "+b.getName()+"->"+c.getName())}catch(d){}},onRegisterComponent:function(a){try{if(a.isXType("button"))a.on("click",this.onButtonClick,this);else if(a.isXType("menuitem"))a.on("click",this.onMenuItemClick,this);else if(a.isXType("grid")){a.on("rowbodydblclick",
this.onRowDblClick,this);a.on("rowdblclick",this.onRowDblClick,this);a.on("rowcontextmenu",this.onRowContextmenu,this)}else if(a.isXType("treepanel")){a.on("click",this.onTreeClick,this);a.on("contextmenu",this.onTreeContextmenu,this)}else if(a.isXType("zarafa.navigationbuttonpanel"))a.on("afterrender",this.onButtonPanelAfterRender,this);else if(a.isXType("zarafa.calendarpanel")){a.on("appointmentcalendardrop",this.onCalendarDrop,this);a.on("appointmentmove",this.onAppointmentMove,this);a.on("appointmentresize",
this.onAppointmentResize,this);a.on("appointmentcreate",this.onAppointmentCreate,this);a.on("contextmenu",this.onCalendarContextMenu,this);a.on("dblclick",this.onCalendarDblClick,this);a.on("dayclick",this.onCalendarDayClick,this);a.on("calendarclose",this.onCalendarClose,this)}}catch(b){}},onButtonPanelAfterRender:function(a){try{for(var b=0,c=a.openButtons.length;b<c;b++)a.openButtons[b].on("click",this.onNavigationButtonClick,this);b=0;for(c=a.closedButtons.length;b<c;b++)a.closedButtons[b].on("click",
this.onNavigationButtonClick,this)}catch(d){}},onNavigationButtonClick:function(a,b){try{var c="navigation - ";c+="item: navbutton - ";c+="text: "+(b.textContent||b.classList[1]);this.queueAction(c)}catch(d){}},onButtonClick:function(a){try{var b=this.getComponentDialog(a),c=this.getComponentToolbar(a),d="button - ";if(b)d+="dialog: "+b.constructor.xtype+" - ";if(c)d+="toolbar: "+c.constructor.xtype+" - ";d+="item: "+a.constructor.xtype+" - ";d+="text: "+(a.text||a.overflowText||a.iconCls);this.queueAction(d)}catch(e){}},
onMenuItemClick:function(a){try{var b=this.getComponentDialog(a),c=this.getComponentToolbar(a),d=this.getComponentRootMenu(a),e="menu - ";if(b)e+="dialog: "+b.constructor.xtype+" - ";if(c)e+="toolbar: "+c.constructor.xtype+" - ";if(d)e+="menu: "+d.constructor.xtype+" - ";e+="item: "+a.constructor.xtype+" - ";e+="text: "+(a.text||a.overflowText);this.queueAction(e)}catch(f){}},onRowDblClick:function(a,b){try{var c=this.getComponentDialog(a),d="grid - ";if(c)d+="dialog: "+c.constructor.xtype+" - ";
d+="item: "+a.constructor.xtype+" - ";d+="index: "+b;this.queueAction(d)}catch(e){}},onRowContextmenu:function(a,b){try{var c=this.getComponentDialog(a),d="grid contextmenu - ";if(c)d+="dialog: "+c.constructor.xtype+" - ";d+="item: "+a.constructor.xtype+" - ";d+="index: "+b;this.queueAction(d)}catch(e){}},onTreeClick:function(a){try{var b=this.getComponentDialog(a),c=this.getComponentTree(a),d="tree - ";if(b)d+="dialog: "+b.constructor.xtype+" - ";if(c)d+="tree: "+c.constructor.xtype+" - ";d+="item: node - ";
d+="text: "+a.text;this.queueAction(d)}catch(e){}},onTreeContextmenu:function(a){try{var b=this.getComponentDialog(a),c=this.getComponentTree(a),d="tree contextmenu - ";if(b)d+="dialog: "+b.constructor.xtype+" - ";if(c)d+="tree: "+c.constructor.xtype+" - ";d+="item: node - ";d+="text: "+a.text;this.queueAction(d)}catch(e){}},onCalendarDrop:function(){try{var a="calendar - ";a+="action: calendardrop";this.queueAction(a)}catch(b){}},onAppointmentMove:function(){try{var a="calendar - ";a+="action: appointmentmove";
this.queueAction(a)}catch(b){}},onAppointmentResize:function(){try{var a="calendar - ";a+="action: appointmentresize";this.queueAction(a)}catch(b){}},onAppointmentCreate:function(){try{var a="calendar - ";a+="action: appointmentcreate";this.queueAction(a)}catch(b){}},onCalendarContextMenu:function(a,b){try{var c="calendar contextmenu - ";c+="text: "+(b.phantom?"daterange":"record");this.queueAction(c)}catch(d){}},onCalendarDblClick:function(a,b){try{var c="calendar - ";c+="action: dblclick - ";c+=
"text: "+(b.phantom?"daterange":"record");this.queueAction(c)}catch(d){}},onCalendarDayClick:function(a,b){try{var c="calendar - ";c+="action: dayclick - ";c+="text: "+b.toString();this.queueAction(c)}catch(d){}},onCalendarClose:function(){try{var a="calendar - ";a+="action: close ";this.queueAction(a)}catch(b){}},getComponentDialog:function(a){if(a instanceof Ext.tree.TreeNode)a=a.getOwnerTree();for(;a&&!a.dialog;)a=a.ownerCt;if(a)return a.dialog},getComponentToolbar:function(a){for(;a&&!a.isXType("toolbar");)a=
a.ownerCt;if(a&&a.isXType("toolbar"))return a},getComponentRootMenu:function(a){var b=a.parentMenu;if(!b&&a.ownerCt instanceof Ext.menu.Menu)b=a.ownerCt;for(;b&&(Ext.isDefined(b.parentMenu)||b.ownerCt instanceof Ext.menu.Menu);)b=b.parentMenu||b.ownerCt;return b},getComponentTree:function(a){return a.getOwnerTree()}});Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"statslogging",displayName:_("Statistics Logging"),pluginConstructor:Zarafa.plugins.statslogging.StatsLogging}))});
