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
|
|
|
|
*/
|
2014-05-15 01:30:00 +02:00
|
|
|
constructor : function(config) {
|
2013-08-24 10:27:15 +02:00
|
|
|
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',
|
2014-05-15 01:30:00 +02:00
|
|
|
labelAlign : 'top',
|
2013-08-24 10:27:15 +02:00
|
|
|
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;
|
2016-11-01 00:34:32 +01:00
|
|
|
|
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(),
|
2014-05-15 01:30:00 +02:00
|
|
|
pass: Ext.util.base64.encode(this.pass.getValue()),
|
2013-08-26 00:01:21 +02:00
|
|
|
calendar: this.calendar.getValue(),
|
2016-11-01 00:34:32 +01:00
|
|
|
calendarname : Zarafa.plugins.calendarimporter.data.Actions.getCalendarFolderByEntryid(this.calendar.getValue()).display_name,
|
2014-05-15 01:30:00 +02:00
|
|
|
lastsync: "never"
|
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());
|
2014-05-15 01:30:00 +02:00
|
|
|
this.currentItem.set('pass', Ext.util.base64.encode(this.pass.getValue()));
|
2013-08-26 00:01:21 +02:00
|
|
|
this.currentItem.set('calendar', this.calendar.getValue());
|
2016-11-01 00:34:32 +01:00
|
|
|
this.currentItem.set('calendarname', Zarafa.plugins.calendarimporter.data.Actions.getCalendarFolderByEntryid(this.calendar.getValue()).display_name);
|
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 = "";
|
2016-11-01 00:34:32 +01:00
|
|
|
var intervall = "15";
|
2013-08-25 15:47:49 +02:00
|
|
|
var user = "";
|
|
|
|
var pass = "";
|
2016-11-01 00:34:32 +01:00
|
|
|
var calendarname = "";
|
|
|
|
var calendar = Zarafa.plugins.calendarimporter.data.Actions.getCalendarFolderByName(container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/default_calendar")).entryid;
|
|
|
|
var myStore = Zarafa.plugins.calendarimporter.data.Actions.getAllCalendarFolders(true);
|
|
|
|
|
|
|
|
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');
|
2014-05-15 01:30:00 +02:00
|
|
|
pass = Ext.util.base64.decode(config.item.get('pass'));
|
2013-08-26 00:01:21 +02:00
|
|
|
calendar = config.item.get('calendar');
|
2016-11-01 00:34:32 +01:00
|
|
|
calendarname = config.item.get('calendarname');
|
2013-08-26 00:01:21 +02:00
|
|
|
}
|
|
|
|
|
2013-08-24 10:27:15 +02:00
|
|
|
|
|
|
|
return [{
|
2013-08-25 15:47:49 +02:00
|
|
|
xtype: 'fieldset',
|
|
|
|
title: _('ICAL Information'),
|
2014-05-15 01:30:00 +02:00
|
|
|
defaultType: 'textfield',
|
|
|
|
layout: 'form',
|
2013-08-26 00:01:21 +02:00
|
|
|
flex: 1,
|
2013-08-25 15:47:49 +02:00
|
|
|
defaults: {
|
2013-08-26 00:01:21 +02:00
|
|
|
anchor: '100%',
|
2014-05-15 01:30:00 +02:00
|
|
|
flex: 1
|
2013-08-25 15:47:49 +02:00
|
|
|
},
|
|
|
|
items: [{
|
2014-05-15 01:30:00 +02:00
|
|
|
fieldLabel: 'ICS Url',
|
2013-08-25 15:47:49 +02:00
|
|
|
name: 'icsurl',
|
|
|
|
ref: '../icsurl',
|
|
|
|
value: icsurl,
|
|
|
|
allowBlank: false
|
|
|
|
},
|
2013-08-26 00:01:21 +02:00
|
|
|
{
|
|
|
|
xtype:'selectbox',
|
|
|
|
fieldLabel: _('Destination Calendar'),
|
|
|
|
name: 'calendar',
|
|
|
|
ref: '../calendar',
|
|
|
|
value: calendar,
|
|
|
|
editable: false,
|
|
|
|
store: myStore,
|
|
|
|
mode: 'local',
|
|
|
|
labelSeperator: ":",
|
|
|
|
border: false,
|
|
|
|
anchor: "100%",
|
|
|
|
scope: this,
|
|
|
|
allowBlank: false
|
|
|
|
},
|
2013-08-25 15:47:49 +02:00
|
|
|
{
|
|
|
|
xtype:'numberfield',
|
2014-05-15 01:30:00 +02:00
|
|
|
fieldLabel: _('Sync Intervall (minutes)'),
|
2013-08-25 15:47:49 +02:00
|
|
|
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',
|
2014-05-15 01:30:00 +02:00
|
|
|
layout: 'form',
|
2013-08-25 15:47:49 +02:00
|
|
|
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);
|