diff --git a/js/settings/SettingsCalSyncWidget.js b/js/settings/SettingsCalSyncWidget.js new file mode 100644 index 0000000..b203800 --- /dev/null +++ b/js/settings/SettingsCalSyncWidget.js @@ -0,0 +1,110 @@ +Ext.namespace('Zarafa.plugins.calendarimporter.settings'); + +/** + * @class Zarafa.plugins.calendarimporter.settings.SettingsCalSyncWidget + * @extends Zarafa.settings.ui.SettingsWidget + * @xtype calendarimporter.settingscalsyncwidget + * + * The {@link Zarafa.settings.ui.SettingsWidget widget} for configuring + * delegation options in the {@link Zarafa.common.settings.SettingsSendAsCategory sendas category}. + */ +Zarafa.common.settings.SettingsSendAsWidget = Ext.extend(Zarafa.settings.ui.SettingsWidget, { + /** + * @cfg {Zarafa.settings.SettingsContext} settingsContext + */ + settingsContext : undefined, + + /** + * @constructor + * @param {Object} config Configuration object + */ + constructor : function(config) + { + config = config || {}; + + var store = new Ext.data.JsonStore({ + fields : [ + { name : 'id', type : 'int' }, + { name : 'icsurl' }, + { name : 'user' }, + { name : 'pass' }, + { name : 'intervall', type : 'int' }, + { name : 'lastsync' } + ], + sortInfo : { + field : 'id', + direction : 'ASC' + }, + autoDestroy : true + }); + + Ext.applyIf(config, { + height : 400, + title : _('Calendar Sync settings'), + xtype : 'calendarimporter.settingscalsyncwidget', + layout : { + // override from SettingsWidget + type : 'fit' + }, + items : [{ + xtype : 'calendarimporter.calsyncpanel', + store : store, + ref : 'calsyncPanel' + }] + }); + + Zarafa.plugins.calendarimporter.settings.SettingsCalSyncWidget.superclass.constructor.call(this, config); + }, + + /** + * Called by the {@link Zarafa.settings.ui.SettingsCategory Category} when + * it has been called with {@link zarafa.settings.ui.SettingsCategory#update}. + * This is used to load the latest version of the settings from the + * {@link Zarafa.settings.SettingsModel} into the UI of this category. + * @param {Zarafa.settings.SettingsModel} settingsModel The settings to load + */ + update : function(settingsModel) + { + this.model = settingsModel; + + // Convert the signatures into Store data + var icslinks = settingsModel.get('zarafa/v1/contexts/calendar/icssync', true); + var syncArray = []; + for (var key in icslinks) { + syncArray.push(Ext.apply({}, icslinks[key], { id : key })); + } + + // Load all icslinks into the GridPanel + var store = this.calsyncPanel.calsyncGrid.getStore(); + store.loadData(syncArray); + }, + + /** + * Called by the {@link Zarafa.settings.ui.SettingsCategory Category} when + * it has been called with {@link zarafa.settings.ui.SettingsCategory#updateSettings}. + * This is used to update the settings from the UI into the {@link Zarafa.settings.SettingsModel settings model}. + * @param {Zarafa.settings.SettingsModel} settingsModel The settings to update + */ + updateSettings : function(settingsModel) + { + settingsModel.beginEdit(); + + // Start reading the Grid store and convert the contents back into + // an object which can be pushed to the settings. + var icslinks = this.sendasPanel.sendasGrid.getStore().getRange(); + var icslinkData = {}; + for (var i = 0, len = icslinks.length; i < len; i++) { + var icslink = icslinks[i]; + + icslinkData[icslink.get('id')] = { + 'display_name' : icslink.get('display_name'), + 'email_address' : icslink.get('email_address') + }; + } + settingsModel.set('zarafa/v1/contexts/mail/sendas', icslinkData); + + settingsModel.endEdit(); + } +}); + +Ext.reg('calendarimporter.settingscalsyncwidget', Zarafa.plugins.calendarimporter.settings.SettingsCalSyncWidget); diff --git a/js/settings/dialogs/SendAsEditContentPanel.js b/js/settings/dialogs/SendAsEditContentPanel.js new file mode 100644 index 0000000..1258d83 --- /dev/null +++ b/js/settings/dialogs/SendAsEditContentPanel.js @@ -0,0 +1,40 @@ +Ext.namespace('Zarafa.common.sendas.dialogs'); + +/** + * @class Zarafa.common.sendas.dialogs.SendAsEditContentPanel + * @extends Zarafa.core.ui.ContentPanel + * @xtype zarafa.sendaseditcontentpanel + * + * {@link Zarafa.common.sendas.dialogs.SendAsEditContentPanel SendAsEditContentPanel} will be used to edit sendas addresses. + */ +Zarafa.common.sendas.dialogs.SendAsEditContentPanel = Ext.extend(Zarafa.core.ui.ContentPanel, { + /** + * @constructor + * @param config Configuration structure + */ + constructor : function(config) + { + config = config || {}; + + // Add in some standard configuration data. + Ext.applyIf(config, { + // Override from Ext.Component + xtype : 'zarafa.sendaseditcontentpanel', + // Override from Ext.Component + layout : 'fit', + model : true, + autoSave : false, + width : 400, + height : 100, + title : _('Send As'), + items : [{ + xtype : 'zarafa.sendaseditpanel', + item : config.item + }] + }); + + Zarafa.common.sendas.dialogs.SendAsEditContentPanel.superclass.constructor.call(this, config); + } +}); + +Ext.reg('zarafa.sendaseditcontentpanel', Zarafa.common.sendas.dialogs.SendAsEditContentPanel); diff --git a/js/settings/dialogs/SendAsEditPanel.js b/js/settings/dialogs/SendAsEditPanel.js new file mode 100644 index 0000000..36ad954 --- /dev/null +++ b/js/settings/dialogs/SendAsEditPanel.js @@ -0,0 +1,135 @@ +Ext.namespace('Zarafa.common.sendas.dialogs'); + +/** + * @class Zarafa.common.sendas.dialogs.SendAsEditPanel + * @extends Ext.form.FormPanel + * @xtype zarafa.sendaseditpanel + * + * Will generate UI for {@link Zarafa.common.sendas.dialogs.SendAsEditContentPanel SendAsEditContentPanel}. + */ +Zarafa.common.sendas.dialogs.SendAsEditPanel = Ext.extend(Ext.form.FormPanel, { + + /** + * the id of the currently edited item + */ + currentItem : undefined, + + /** + * @constructor + * @param config Configuration structure + */ + constructor : function(config) + { + config = config || {}; + + if(config.item) + this.currentItem = config.item; + + Ext.applyIf(config, { + // Override from Ext.Component + xtype : 'zarafa.sendaseditpanel', + labelAlign : 'left', + defaultType: 'textfield', + items : this.createPanelItems(config), + buttons: [{ + text: _('Save'), + handler: this.doSave, + scope: this + }, + { + text: _('Cancel'), + handler: this.doClose, + scope: this + }] + }); + + Zarafa.common.sendas.dialogs.SendAsEditPanel.superclass.constructor.call(this, config); + }, + + /** + * close the dialog + */ + doClose : function() { + this.dialog.close(); + }, + + /** + * save the data to the store + */ + doSave : function() { + var store = this.dialog.store; + var id = 0; + var record = undefined; + + if(!this.currentItem) { + record = new store.recordType({ + id: this.hashCode(this.email_address.getValue()), + display_name: this.display_name.getValue(), + email_address: this.email_address.getValue() + }); + } + + if(this.email_address.isValid()) { + if(record) { + store.add(record); + } else { + this.currentItem.set('display_name', this.display_name.getValue()); + this.currentItem.set('email_address', this.email_address.getValue()); + } + this.dialog.close(); + } + }, + + /** + * Function will create panel items for {@link Zarafa.common.sendas.dialogs.SendAsEditPanel SendAsEditPanel} + * @return {Array} array of items that should be added to panel. + * @private + */ + createPanelItems : function(config) + { + var displayName = ""; + var emailAddress = ""; + + if(config.item){ + displayName = config.item.get('display_name'); + emailAddress = config.item.get('email_address'); + } + + return [{ + fieldLabel: _('Display Name'), + name: 'display_name', + ref: 'display_name', + value: displayName, + anchor: '100%' + }, + { + fieldLabel: _('Email Address'), + name: 'email_address', + ref: 'email_address', + allowBlank: false, + value: emailAddress, + vtype:'email', + anchor: '100%' + }]; + }, + + /** + * Java String.hashCode() implementation + * @private + */ + hashCode : function(str){ + var hash = 0; + var chr = 0; + var i = 0; + + if (str.length == 0) return hash; + for (i = 0; i < str.length; i++) { + chr = str.charCodeAt(i); + hash = ((hash<<5)-hash)+chr; + hash = hash & hash; // Convert to 32bit integer + } + return Math.abs(hash); + } +}); + +Ext.reg('zarafa.sendaseditpanel', Zarafa.common.sendas.dialogs.SendAsEditPanel); diff --git a/js/settings/ui/SendAsGrid.js b/js/settings/ui/SendAsGrid.js new file mode 100644 index 0000000..64cb677 --- /dev/null +++ b/js/settings/ui/SendAsGrid.js @@ -0,0 +1,136 @@ +Ext.namespace('Zarafa.common.sendas.ui'); + +/** + * @class Zarafa.common.sendas.ui.SendAsGrid + * @extends Ext.grid.GridPanel + * @xtype zarafa.sendasgrid + * + * {@link Zarafa.common.sendas.ui.SendAsGrid SendAsGrid} will be used to display + * sendas of the current user. + */ +Zarafa.common.sendas.ui.SendAsGrid = Ext.extend(Ext.grid.GridPanel, { + /** + * @constructor + * @param {Object} config Configuration structure + */ + constructor : function(config) + { + config = config || {}; + + Ext.applyIf(config, { + xtype : 'zarafa.sendasgrid', + border : true, + store : config.store, + viewConfig : { + forceFit : true, + emptyText : '