calendarimporter/js/settings/dialogs/CalSyncEditPanel.js

136 lines
3.1 KiB
JavaScript
Raw Normal View History

2013-08-25 12:44:25 +02:00
Ext.namespace('Zarafa.plugins.calendarimporter.settings.dialogs');
2013-08-24 10:27:15 +02:00
/**
2013-08-25 12:44:25 +02:00
* @class Zarafa.plugins.calendarimporter.settings.dialogs.CalSyncEditPanel
2013-08-24 10:27:15 +02:00
* @extends Ext.form.FormPanel
2013-08-25 12:44:25 +02:00
* @xtype calendarimporter.calsynceditpanel
2013-08-24 10:27:15 +02:00
*
2013-08-25 12:44:25 +02:00
* Will generate UI for {@link Zarafa.plugins.calendarimporter.settings.dialogs.CalSyncEditPanel CalSyncEditPanel}.
2013-08-24 10:27:15 +02:00
*/
2013-08-25 12:44:25 +02:00
Zarafa.plugins.calendarimporter.settings.dialogs.CalSyncEditPanel = Ext.extend(Ext.form.FormPanel, {
2013-08-24 10:27:15 +02:00
/**
* 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
2013-08-25 12:44:25 +02:00
xtype : 'calendarimporter.calsynceditpanel',
2013-08-24 10:27:15 +02:00
labelAlign : 'left',
defaultType: 'textfield',
items : this.createPanelItems(config),
buttons: [{
text: _('Save'),
handler: this.doSave,
scope: this
},
{
text: _('Cancel'),
handler: this.doClose,
scope: this
}]
});
2013-08-25 12:44:25 +02:00
Zarafa.plugins.calendarimporter.settings.dialogs.CalSyncEditPanel.superclass.constructor.call(this, config);
2013-08-24 10:27:15 +02:00
},
/**
* 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({
2013-08-25 12:44:25 +02:00
id: this.hashCode(this.icsurl.getValue()),
2013-08-24 10:27:15 +02:00
display_name: this.display_name.getValue(),
2013-08-25 12:44:25 +02:00
icsurl: this.icsurl.getValue()
2013-08-24 10:27:15 +02:00
});
}
2013-08-25 12:44:25 +02:00
if(this.icsurl.isValid()) {
2013-08-24 10:27:15 +02:00
if(record) {
store.add(record);
} else {
this.currentItem.set('display_name', this.display_name.getValue());
2013-08-25 12:44:25 +02:00
this.currentItem.set('icsurl', this.icsurl.getValue());
2013-08-24 10:27:15 +02:00
}
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 = "";
2013-08-25 12:44:25 +02:00
var icsUrl = "";
2013-08-24 10:27:15 +02:00
if(config.item){
displayName = config.item.get('display_name');
2013-08-25 12:44:25 +02:00
icsUrl = config.item.get('icsurl');
2013-08-24 10:27:15 +02:00
}
return [{
fieldLabel: _('Display Name'),
name: 'display_name',
ref: 'display_name',
value: displayName,
anchor: '100%'
},
{
2013-08-25 12:44:25 +02:00
fieldLabel: _('ICS Url'),
name: 'icsurl',
ref: 'icsurl',
2013-08-24 10:27:15 +02:00
allowBlank: false,
2013-08-25 12:44:25 +02:00
value: icsUrl,
2013-08-24 10:27:15 +02:00
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);
}
});
2013-08-25 12:44:25 +02:00
Ext.reg('calendarimporter.calsynceditpanel', Zarafa.plugins.calendarimporter.settings.dialogs.CalSyncEditPanel);