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(),
|
2013-08-26 00:01:21 +02:00
|
|
|
calendar: this.calendar.getValue(),
|
2013-08-25 15:47:49 +02:00
|
|
|
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-26 00:01:21 +02:00
|
|
|
this.currentItem.set('calendar', this.calendar.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-26 00:01:21 +02:00
|
|
|
var calendar = "";
|
|
|
|
|
|
|
|
var defaultFolder = container.getHierarchyStore().getDefaultFolder('calendar'); // @type: Zarafa.hierarchy.data.MAPIFolderRecord
|
|
|
|
var subFolders = defaultFolder.getChildren();
|
|
|
|
var myStore = [];
|
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-26 00:01:21 +02:00
|
|
|
calendar = config.item.get('calendar');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add all local calendar folders */
|
|
|
|
var i = 0;
|
|
|
|
myStore.push(new Array(defaultFolder.getDefaultFolderKey(), defaultFolder.getDisplayName()));
|
|
|
|
for(i = 0; i < subFolders.length; i++) {
|
|
|
|
/* Store all subfolders */
|
|
|
|
myStore.push(new Array(subFolders[i].getDisplayName(), subFolders[i].getDisplayName(), false)); // 3rd field = isPublicfolder
|
2013-08-24 10:27:15 +02:00
|
|
|
}
|
2013-08-26 00:01:21 +02:00
|
|
|
|
|
|
|
/* add all shared calendar folders */
|
|
|
|
var pubStore = container.getHierarchyStore().getPublicStore();
|
|
|
|
|
|
|
|
if(typeof pubStore !== "undefined") {
|
|
|
|
try {
|
|
|
|
var pubFolder = pubStore.getDefaultFolder("publicfolders");
|
|
|
|
var pubSubFolders = pubFolder.getChildren();
|
|
|
|
|
|
|
|
for(i = 0; i < pubSubFolders.length; i++) {
|
|
|
|
if(pubSubFolders[i].isContainerClass("IPF.Appointment")){
|
|
|
|
myStore.push(new Array(pubSubFolders[i].getDisplayName(), pubSubFolders[i].getDisplayName() + " [Shared]", true)); // 3rd field = isPublicfolder
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.log("Error opening the shared folder...");
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-24 10:27:15 +02:00
|
|
|
|
|
|
|
return [{
|
2013-08-25 15:47:49 +02:00
|
|
|
xtype: 'fieldset',
|
|
|
|
title: _('ICAL Information'),
|
2013-08-26 00:01:21 +02:00
|
|
|
defaultType: 'textfield',
|
2013-08-25 15:47:49 +02:00
|
|
|
layout: 'anchor',
|
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%',
|
|
|
|
flex: 1,
|
|
|
|
labelWidth: 120
|
2013-08-25 15:47:49 +02:00
|
|
|
},
|
|
|
|
items: [{
|
|
|
|
fieldLabel: _('ICS Url'),
|
|
|
|
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',
|
|
|
|
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);
|