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;
|
|
|
|
|
2013-08-25 15:47:49 +02:00
|
|
|
console.log(this);
|
2013-08-24 10:27:15 +02:00
|
|
|
if(!this.currentItem) {
|
|
|
|
record = new store.recordType({
|
2013-08-25 12:44:25 +02:00
|
|
|
id: this.hashCode(this.icsurl.getValue()),
|
2013-08-25 15:47:49 +02:00
|
|
|
icsurl: this.icsurl.getValue(),
|
|
|
|
intervall: this.intervall.getValue(),
|
|
|
|
user: this.user.getValue(),
|
|
|
|
pass: this.pass.getValue(),
|
|
|
|
lastsync: 0
|
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 {
|
2013-08-25 12:44:25 +02:00
|
|
|
this.currentItem.set('icsurl', this.icsurl.getValue());
|
2013-08-25 15:47:49 +02:00
|
|
|
this.currentItem.set('intervall', this.intervall.getValue());
|
|
|
|
this.currentItem.set('user', this.user.getValue());
|
|
|
|
this.currentItem.set('pass', this.pass.getValue());
|
2013-08-24 10:27:15 +02:00
|
|
|
}
|
|
|
|
this.dialog.close();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-08-25 15:47:49 +02:00
|
|
|
* Function will create panel items for {@link Zarafa.plugins.calendarimporter.settings.dialogs.CalSyncEditPanel CalSyncEditPanel}
|
2013-08-24 10:27:15 +02:00
|
|
|
* @return {Array} array of items that should be added to panel.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
createPanelItems : function(config)
|
|
|
|
{
|
2013-08-25 15:47:49 +02:00
|
|
|
var icsurl = "";
|
|
|
|
var intervall = "";
|
|
|
|
var user = "";
|
|
|
|
var pass = "";
|
2013-08-24 10:27:15 +02:00
|
|
|
|
|
|
|
if(config.item){
|
2013-08-25 15:47:49 +02:00
|
|
|
icsurl = config.item.get('icsurl');
|
|
|
|
intervall = config.item.get('intervall');
|
|
|
|
user = config.item.get('user');
|
|
|
|
pass = config.item.get('pass');
|
2013-08-24 10:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return [{
|
2013-08-25 15:47:49 +02:00
|
|
|
xtype: 'fieldset',
|
|
|
|
title: _('ICAL Information'),
|
|
|
|
defaultType: 'textfield',
|
|
|
|
labelWidth: 120,
|
|
|
|
layout: 'anchor',
|
|
|
|
defaults: {
|
|
|
|
anchor: '100%'
|
|
|
|
},
|
|
|
|
items: [{
|
|
|
|
fieldLabel: _('ICS Url'),
|
|
|
|
name: 'icsurl',
|
|
|
|
ref: '../icsurl',
|
|
|
|
value: icsurl,
|
|
|
|
allowBlank: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype:'numberfield',
|
|
|
|
fieldLabel: _('Sync Intervall'),
|
|
|
|
name: 'intervall',
|
|
|
|
ref: '../intervall',
|
|
|
|
value: intervall,
|
|
|
|
allowBlank: false
|
|
|
|
}]
|
2013-08-24 10:27:15 +02:00
|
|
|
},
|
|
|
|
{
|
2013-08-25 15:47:49 +02:00
|
|
|
xtype: 'fieldset',
|
|
|
|
title: _('Authentication (optional)'),
|
|
|
|
defaultType: 'textfield',
|
|
|
|
labelWidth: 120,
|
|
|
|
layout: 'anchor',
|
|
|
|
defaults: {
|
|
|
|
anchor: '100%'
|
|
|
|
},
|
|
|
|
items: [{
|
|
|
|
fieldLabel: _('Username'),
|
|
|
|
name: 'user',
|
|
|
|
ref: '../user',
|
|
|
|
value: user,
|
|
|
|
allowBlank: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldLabel: _('Password'),
|
|
|
|
name: 'pass',
|
|
|
|
ref: '../pass',
|
|
|
|
value: pass,
|
|
|
|
inputType: 'password',
|
|
|
|
allowBlank: true
|
|
|
|
}]
|
2013-08-24 10:27:15 +02:00
|
|
|
}];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|