Ext.namespace('Zarafa.plugins.emailtracking'); /** * @class Zarafa.plugins.emailtracking.EmailTrackingPlugin * @extends Zarafa.core.Plugin */ Zarafa.plugins.emailtracking.EmailTrackingPlugin = Ext.extend(Zarafa.core.Plugin, { /* * Called after constructor. * Registers insertion points. * @protected */ initPlugin : function() { Zarafa.plugins.emailtracking.EmailTrackingPlugin.superclass.initPlugin.apply(this, arguments); // Tracking button in mailcreatecontentpanel this.registerInsertionPoint('context.mail.mailcreatecontentpanel.toolbar.options', this.showTrackButton, this); // Insertion point which shows the read status this.registerInsertionPoint('previewpanel.toolbar.detaillinks', this.showTrackingInfo, this); Zarafa.core.data.SharedComponentType.addProperty('plugin.emailtracking.ui.trackinginfopanel'); }, /** * Displays Tracking information in the previewpanel * * @return {Object} a box which on record update displays Tracking information */ showTrackingInfo : function() { return { xtype: 'button', style: 'margin-top: 4px; border: 2px solid red;', plugins : [ 'zarafa.recordcomponentupdaterplugin' ], autoEl: { tag: 'div', ref: 'trackingInfoBox' }, scope : this, update : this.onTrackingInfo, handler : this.onTrackingButton }; }, /** * Handler for the button which is displayed when a encrypted / signed message is openend * When an encrypted message is opened, we will send a request to unlock the certificate. * When an signed email is openend, we will show a popup with extra information about the signed message */ onTrackingButton: function(button, config) { var user = container.getUser(); container.getRequest().singleRequest( 'plugintrackingmodule', 'gettrackinglog', { 'trackingid' : button.record.get("trackingcode"), 'user' : user.getSMTPAddress() }, new Zarafa.plugins.emailtracking.data.ResponseHandler({ successCallback : this.onTrackingLogLoaded }) ); }, onTrackingLogLoaded: function(response) { if(response.status) { Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType['plugin.emailtracking.ui.trackinginfopanel'], response, { manager: Ext.WindowMgr }); } else { container.getNotifier().notify('info.saved', _('Error'), "No tracking log available!"); } }, /** * Function which displays information in the previewpanel. * In the case of a encrypted message, we either show a button to unlock the certificate * or shows the message that the message has been decrypted. * If the message is signed we display information depending on the state of the verification. * * @param {Zarafa.core.data.IPMRecord} record record which is displayed * @param {Boolean} contentReset force the component to perform a full update of the data. */ onTrackingInfo : function(record, resetContent) { // Set button.record for use in onSmimeButton this.record = record; var infoBox = this.getEl(); // Set smimeBox to empty value by default, to override previous S/MIME message text infoBox.update(""); if (this.record.opened) { // get the tracking code from the body var body = this.record.getBody(true); var trackingRegex = /(?:^|.*)track.php\?img=(.*?)(?:\"|\s|$)/g; var match = trackingRegex.exec(body); if(match) { infoBox.update("This message is getting tracked (" + match[1] + ")"); infoBox.show(); this.record.set("trackingcode", match[1]); } } else { infoBox.hide(); } }, /** * Create button which adds some tracking specials to the mail content. * * @return {Config} creates a button for tracking email */ showTrackButton : function() { return { xtype : 'button', text : _('Track'), tooltip: { title: _('Track message'), text: _('Track this message and get detailed information about the current status.') }, iconCls : 'icon_tracking_off', handler : this.onTrackButton, scope : this }; }, /** * Handler for the sign button, when clicked it checks if the private certificate exists. * If we have signing already set and click it again, we unset it. * If we already set have encryption set, we set a special message_class for both sign+ecnrypt. * * * @param {Ext.button} button * @param {Object} config */ onTrackButton : function(button, config) { var owner = button.ownerCt; var record = owner.record; var doTrack = button.iconCls === "icon_tracking_on" ? false : true; if(record && doTrack) { button.setIconClass('icon_tracking_on'); record.set('message_class', 'IPM.Note.Tracking'); record.set('entryid', record.entryid); } else { record.set('message_class', 'IPM.Note'); button.setIconClass('icon_tracking_off'); } owner.dialog.saveRecord(); }, /* * Bid for the type of shared component * and the given record. * This will bid on calendar.dialogs.importevents * @param {Zarafa.core.data.SharedComponentType} type Type of component a context can bid for. * @param {Zarafa.mail.dialogs.MailCreateContentPanel} owner Optionally passed panel * @return {Number} The bid for the shared component */ bidSharedComponent : function(type, record) { var bid = -1; switch(type) { case Zarafa.core.data.SharedComponentType['plugin.emailtracking.ui.trackinginfopanel']: bid = 1; break; } return bid; }, /** * Will return the reference to the shared component. * Based on the type of component requested a component is returned. * @param {Zarafa.core.data.SharedComponentType} type Type of component a context can bid for. * @param {Zarafa.mail.dialogs.MailCreateContentPanel} owner Optionally passed panel * @return {Ext.Component} Component */ getSharedComponent : function(type, record) { var component; switch(type) { case Zarafa.core.data.SharedComponentType['plugin.emailtracking.ui.trackinginfopanel']: component = Zarafa.plugins.emailtracking.ui.TrackingInfoPanel; break; } return component; } }); Zarafa.onReady(function() { container.registerPlugin(new Zarafa.core.PluginMetaData({ name : 'emailtracking', displayName : _('Tracking Plugin'), pluginConstructor : Zarafa.plugins.emailtracking.EmailTrackingPlugin })); });