2013-03-30 14:55:18 +01:00
|
|
|
/**
|
|
|
|
* ImportPanel.js zarafa calender to ics im/exporter
|
|
|
|
*
|
|
|
|
* Author: Christoph Haas <christoph.h@sprinternet.at>
|
|
|
|
* Copyright (C) 2012-2013 Christoph Haas
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-12-29 19:49:24 +01:00
|
|
|
/**
|
|
|
|
* ImportPanel
|
|
|
|
*
|
|
|
|
* The main Panel of the calendarimporter plugin.
|
|
|
|
*/
|
2012-11-12 23:57:50 +01:00
|
|
|
Ext.namespace("Zarafa.plugins.calendarimporter.dialogs");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class Zarafa.plugins.calendarimporter.dialogs.ImportPanel
|
|
|
|
* @extends Ext.form.FormPanel
|
|
|
|
*/
|
2012-12-08 01:53:21 +01:00
|
|
|
Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
|
2012-11-12 23:57:50 +01:00
|
|
|
|
2012-11-13 21:25:52 +01:00
|
|
|
/* store the imported timezone here... */
|
|
|
|
timezone: null,
|
2012-12-28 21:10:45 +01:00
|
|
|
|
2013-03-30 14:55:18 +01:00
|
|
|
/* ignore daylight saving time... */
|
|
|
|
ignoredst: null,
|
|
|
|
|
|
|
|
/* path to ics file on server... */
|
|
|
|
icsfile: null,
|
|
|
|
|
|
|
|
/* loadmask for timezone/dst changes... */
|
|
|
|
loadMask: null,
|
2013-02-27 00:32:02 +01:00
|
|
|
|
2013-03-30 14:55:18 +01:00
|
|
|
/* export event buffer */
|
|
|
|
exportResponse: new Array(),
|
|
|
|
|
|
|
|
/* how many requests are still running? */
|
|
|
|
runningRequests: null,
|
|
|
|
|
|
|
|
/* The store for the selection grid */
|
|
|
|
store: null,
|
2013-01-03 18:48:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The internal 'iframe' which is hidden from the user, which is used for downloading
|
|
|
|
* attachments. See {@link #doOpen}.
|
|
|
|
* @property
|
|
|
|
* @type Ext.Element
|
|
|
|
*/
|
2013-03-30 14:55:18 +01:00
|
|
|
downloadFrame : undefined,
|
2012-11-17 12:42:48 +01:00
|
|
|
|
2012-11-12 23:57:50 +01:00
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @param {object} config
|
|
|
|
*/
|
2013-03-30 14:55:18 +01:00
|
|
|
constructor : function (config) {
|
2012-11-12 23:57:50 +01:00
|
|
|
config = config || {};
|
|
|
|
var self = this;
|
2013-03-30 14:55:18 +01:00
|
|
|
this.timezone = container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/default_timezone");
|
|
|
|
|
|
|
|
if(typeof config.filename !== "undefined") {
|
|
|
|
this.icsfile = config.filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create the data store
|
|
|
|
this.store = new Ext.data.ArrayStore({
|
|
|
|
fields: [
|
|
|
|
{name: 'title'},
|
|
|
|
{name: 'start'},
|
|
|
|
{name: 'end'},
|
|
|
|
{name: 'location'},
|
|
|
|
{name: 'description'},
|
|
|
|
{name: 'priority'},
|
|
|
|
{name: 'label'},
|
|
|
|
{name: 'busy'},
|
|
|
|
{name: 'privatestate'},
|
|
|
|
{name: 'organizer'},
|
|
|
|
{name: 'trigger'}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2012-11-12 23:57:50 +01:00
|
|
|
Ext.apply(config, {
|
|
|
|
xtype : 'calendarimporter.importpanel',
|
2013-03-30 14:55:18 +01:00
|
|
|
ref : "importpanel",
|
|
|
|
id : "importpanel",
|
2012-11-12 23:57:50 +01:00
|
|
|
layout : {
|
|
|
|
type : 'form',
|
|
|
|
align : 'stretch'
|
|
|
|
},
|
2013-03-30 14:55:18 +01:00
|
|
|
anchor : '100%',
|
2012-11-12 23:57:50 +01:00
|
|
|
bodyStyle : 'background-color: inherit;',
|
|
|
|
defaults : {
|
|
|
|
border : true,
|
|
|
|
bodyStyle : 'background-color: inherit; padding: 3px 0px 3px 0px; border-style: none none solid none;'
|
|
|
|
},
|
|
|
|
items : [
|
|
|
|
this.createSelectBox(),
|
2012-12-28 21:10:45 +01:00
|
|
|
this.createTimezoneBox(),
|
2013-02-27 00:32:02 +01:00
|
|
|
this.createDaylightSavingCheckBox(),
|
2013-03-30 14:55:18 +01:00
|
|
|
this.initForm(),
|
|
|
|
this.createGrid()
|
2012-11-12 23:57:50 +01:00
|
|
|
],
|
|
|
|
buttons: [
|
2012-12-05 22:31:10 +01:00
|
|
|
this.createExportAllButton(),
|
2012-11-17 12:42:48 +01:00
|
|
|
this.createSubmitAllButton(),
|
|
|
|
this.createSubmitButton(),
|
2012-11-12 23:57:50 +01:00
|
|
|
this.createCancelButton()
|
2013-03-30 14:55:18 +01:00
|
|
|
],
|
|
|
|
listeners: {
|
|
|
|
afterrender: function (cmp) {
|
|
|
|
Ext.getCmp('importbutton').disable();
|
|
|
|
this.loadMask = new Ext.LoadMask(Ext.getCmp("importpanel").getEl(), {msg:'Loading...'});
|
|
|
|
|
|
|
|
if(this.icsfile != null) { // if we have got the filename from an attachment
|
|
|
|
this.parseCalendar(this.icsfile, this.timezone, this.ignoredst);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
close: function (cmp) {
|
|
|
|
Ext.getCmp('importbutton').enable();
|
|
|
|
},
|
|
|
|
hide: function (cmp) {
|
|
|
|
Ext.getCmp('importbutton').enable();
|
|
|
|
},
|
|
|
|
destroy: function (cmp) {
|
|
|
|
Ext.getCmp('importbutton').enable();
|
|
|
|
}
|
|
|
|
}
|
2012-11-12 23:57:50 +01:00
|
|
|
});
|
2013-03-30 14:55:18 +01:00
|
|
|
|
2012-11-12 23:57:50 +01:00
|
|
|
Zarafa.plugins.calendarimporter.dialogs.ImportPanel.superclass.constructor.call(this, config);
|
|
|
|
},
|
2012-11-17 12:42:48 +01:00
|
|
|
|
2012-11-12 23:57:50 +01:00
|
|
|
/**
|
|
|
|
* Init embedded form, this is the form that is
|
|
|
|
* posted and contains the attachments
|
|
|
|
* @private
|
|
|
|
*/
|
2013-03-30 14:55:18 +01:00
|
|
|
initForm : function () {
|
2012-11-12 23:57:50 +01:00
|
|
|
return {
|
|
|
|
xtype: 'form',
|
|
|
|
ref: 'addFormPanel',
|
|
|
|
layout : 'column',
|
|
|
|
fileUpload: true,
|
|
|
|
autoWidth: true,
|
|
|
|
autoHeight: true,
|
|
|
|
border: false,
|
|
|
|
bodyStyle: 'padding: 5px;',
|
|
|
|
defaults: {
|
|
|
|
anchor: '95%',
|
|
|
|
border: false,
|
|
|
|
bodyStyle: 'padding: 5px;'
|
|
|
|
},
|
|
|
|
items: [this.createUploadField()]
|
|
|
|
};
|
|
|
|
},
|
2012-11-17 12:42:48 +01:00
|
|
|
|
2012-11-12 23:57:50 +01:00
|
|
|
/**
|
2013-03-30 14:55:18 +01:00
|
|
|
* Reloads the data of the grid
|
2012-11-12 23:57:50 +01:00
|
|
|
* @private
|
|
|
|
*/
|
2013-03-30 14:55:18 +01:00
|
|
|
reloadGridStore: function(eventdata) {
|
2012-12-05 22:31:10 +01:00
|
|
|
var parsedData = [];
|
2013-02-27 00:32:02 +01:00
|
|
|
|
2013-03-30 14:55:18 +01:00
|
|
|
// this is done to get rid of the local browser timezone....
|
|
|
|
// because all timezone specific stuff is done via php
|
|
|
|
var local_tz_offset = new Date().getTimezoneOffset() * 60000; // getTimezoneOffset returns minutes... we need milliseconds
|
2012-12-29 19:49:24 +01:00
|
|
|
|
|
|
|
|
2012-12-05 22:31:10 +01:00
|
|
|
if(eventdata !== null) {
|
2012-12-30 18:18:39 +01:00
|
|
|
parsedData = new Array(eventdata.events.length);
|
|
|
|
var i = 0;
|
|
|
|
for(i = 0; i < eventdata.events.length; i++) {
|
|
|
|
var trigger = null;
|
|
|
|
|
|
|
|
if(eventdata.events[i]["VALARM"]) {
|
|
|
|
trigger = eventdata.events[i]["VALARM"]["TRIGGER"];
|
2013-03-30 14:55:18 +01:00
|
|
|
trigger = new Date(parseInt(trigger) + local_tz_offset);
|
2013-02-27 00:32:02 +01:00
|
|
|
}
|
2013-03-30 14:55:18 +01:00
|
|
|
parsedData[i] = new Array(eventdata.events[i]["SUMMARY"], new Date(parseInt(eventdata.events[i]["DTSTART"]) + local_tz_offset), new Date(parseInt(eventdata.events[i]["DTEND"]) + local_tz_offset), eventdata.events[i]["LOCATION"], eventdata.events[i]["DESCRIPTION"],eventdata.events[i]["PRIORITY"],eventdata.events[i]["X-ZARAFA-LABEL"],eventdata.events[i]["X-MICROSOFT-CDO-BUSYSTATUS"],eventdata.events[i]["CLASS"],eventdata.events[i]["ORGANIZER"],trigger);
|
2012-11-12 23:57:50 +01:00
|
|
|
}
|
2012-12-29 19:49:24 +01:00
|
|
|
} else {
|
|
|
|
return null;
|
2012-11-12 23:57:50 +01:00
|
|
|
}
|
2012-11-17 12:42:48 +01:00
|
|
|
|
2013-03-30 14:55:18 +01:00
|
|
|
this.store.loadData(parsedData, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init embedded form, this is the form that is
|
|
|
|
* posted and contains the attachments
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
createGrid : function() {
|
2012-11-17 12:42:48 +01:00
|
|
|
return {
|
2012-11-12 23:57:50 +01:00
|
|
|
xtype: 'grid',
|
|
|
|
ref: 'eventgrid',
|
|
|
|
id: 'eventgrid',
|
|
|
|
columnWidth: 1.0,
|
2013-03-30 14:55:18 +01:00
|
|
|
store: this.store,
|
2012-11-12 23:57:50 +01:00
|
|
|
width: '100%',
|
|
|
|
height: 300,
|
|
|
|
title: 'Select events to import',
|
2013-03-30 14:55:18 +01:00
|
|
|
frame: false,
|
|
|
|
viewConfig:{
|
|
|
|
forceFit:true
|
|
|
|
},
|
2012-11-12 23:57:50 +01:00
|
|
|
colModel: new Ext.grid.ColumnModel({
|
|
|
|
defaults: {
|
|
|
|
width: 300,
|
|
|
|
sortable: true
|
|
|
|
},
|
|
|
|
columns: [
|
2013-03-30 14:55:18 +01:00
|
|
|
{id: 'Summary', header: 'Title', width: 200, sortable: true, dataIndex: 'title'},
|
|
|
|
{header: 'Start', width: 200, sortable: true, dataIndex: 'start', renderer : Zarafa.common.ui.grid.Renderers.datetime},
|
|
|
|
{header: 'End', width: 200, sortable: true, dataIndex: 'end', renderer : Zarafa.common.ui.grid.Renderers.datetime},
|
2012-11-13 21:25:52 +01:00
|
|
|
{header: 'Location', width: 150, sortable: true, dataIndex: 'location'},
|
2013-03-30 14:55:18 +01:00
|
|
|
{header: 'Description', sortable: true, dataIndex: 'description'},
|
2012-12-30 18:18:39 +01:00
|
|
|
{header: "Priority", dataIndex: 'priority', hidden: true},
|
|
|
|
{header: "Label", dataIndex: 'label', hidden: true},
|
|
|
|
{header: "Busystatus", dataIndex: 'busy', hidden: true},
|
|
|
|
{header: "Privacystatus", dataIndex: 'privatestate', hidden: true},
|
|
|
|
{header: "Organizer", dataIndex: 'organizer', hidden: true},
|
2013-03-30 14:55:18 +01:00
|
|
|
{header: "Alarm", dataIndex: 'trigger', hidden: true, renderer : Zarafa.common.ui.grid.Renderers.datetime}
|
2012-11-12 23:57:50 +01:00
|
|
|
]
|
|
|
|
}),
|
|
|
|
sm: new Ext.grid.RowSelectionModel({multiSelect:true})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
createSelectBox: function() {
|
2012-12-30 19:18:46 +01:00
|
|
|
var defaultFolder = container.getHierarchyStore().getDefaultFolder('calendar'); // @type: Zarafa.hierarchy.data.MAPIFolderRecord
|
2012-12-30 18:18:39 +01:00
|
|
|
var subFolders = defaultFolder.getChildren();
|
2013-03-30 14:55:18 +01:00
|
|
|
var myStore = [];
|
2012-12-30 19:18:46 +01:00
|
|
|
|
|
|
|
/* add all local calendar folders */
|
2012-12-30 18:18:39 +01:00
|
|
|
var i = 0;
|
2012-12-30 19:18:46 +01:00
|
|
|
myStore.push(new Array(defaultFolder.getDefaultFolderKey(), defaultFolder.getDisplayName()));
|
2012-12-30 18:18:39 +01:00
|
|
|
for(i = 0; i < subFolders.length; i++) {
|
2012-11-12 23:57:50 +01:00
|
|
|
/* Store all subfolders */
|
2012-12-30 19:18:46 +01:00
|
|
|
myStore.push(new Array(subFolders[i].getDisplayName(), subFolders[i].getDisplayName(), false)); // 3rd field = isPublicfolder
|
2012-11-17 12:42:48 +01:00
|
|
|
}
|
2012-12-30 19:18:46 +01:00
|
|
|
|
|
|
|
/* add all shared calendar folders */
|
|
|
|
var pubStore = container.getHierarchyStore().getPublicStore();
|
|
|
|
|
2013-03-30 14:55:18 +01:00
|
|
|
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);
|
2012-12-30 19:18:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-12 23:57:50 +01:00
|
|
|
return {
|
2012-11-17 12:42:48 +01:00
|
|
|
xtype: "selectbox",
|
|
|
|
ref: 'calendarselector',
|
|
|
|
id: 'calendarselector',
|
|
|
|
editable: false,
|
|
|
|
name: "choosen_calendar",
|
2012-12-30 18:18:39 +01:00
|
|
|
value: container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/default_calendar"),
|
2012-11-17 12:42:48 +01:00
|
|
|
width: 100,
|
|
|
|
fieldLabel: "Select a calender",
|
|
|
|
store: myStore,
|
2012-12-30 19:18:46 +01:00
|
|
|
mode: 'local',
|
2012-11-17 12:42:48 +01:00
|
|
|
labelSeperator: ":",
|
|
|
|
border: false,
|
|
|
|
anchor: "100%",
|
|
|
|
scope: this,
|
|
|
|
allowBlank: false
|
|
|
|
}
|
2012-11-12 23:57:50 +01:00
|
|
|
},
|
|
|
|
|
2012-12-28 21:10:45 +01:00
|
|
|
createTimezoneBox: function() {
|
|
|
|
return {
|
|
|
|
xtype: "selectbox",
|
|
|
|
ref: 'timezoneselector',
|
|
|
|
id: 'timezoneselector',
|
|
|
|
editable: false,
|
|
|
|
name: "choosen_timezone",
|
2013-03-30 14:55:18 +01:00
|
|
|
value: Zarafa.plugins.calendarimporter.data.Timezones.unMap(container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/default_timezone")),
|
2012-12-28 21:10:45 +01:00
|
|
|
width: 100,
|
|
|
|
fieldLabel: "Select a timezone (optional)",
|
|
|
|
store: Zarafa.plugins.calendarimporter.data.Timezones.store,
|
|
|
|
labelSeperator: ":",
|
|
|
|
mode: 'local',
|
|
|
|
border: false,
|
|
|
|
anchor: "100%",
|
|
|
|
scope: this,
|
|
|
|
allowBlank: true,
|
|
|
|
listeners: {
|
|
|
|
'select': this.onTimezoneSelected,
|
|
|
|
scope: this
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-02-27 00:32:02 +01:00
|
|
|
createDaylightSavingCheckBox: function() {
|
|
|
|
return {
|
|
|
|
xtype: "checkbox",
|
|
|
|
ref: 'dstcheck',
|
|
|
|
id: 'dstcheck',
|
|
|
|
name: "dst_check",
|
|
|
|
width: 100,
|
2013-03-30 14:55:18 +01:00
|
|
|
fieldLabel: "Ignore DST (optional)",
|
|
|
|
boxLabel: 'This will ignore "Daylight saving time" offsets.',
|
2013-02-27 00:32:02 +01:00
|
|
|
labelSeperator: ":",
|
|
|
|
border: false,
|
|
|
|
anchor: "100%",
|
|
|
|
scope: this,
|
|
|
|
allowBlank: true,
|
|
|
|
listeners: {
|
|
|
|
'check': this.onDstChecked,
|
|
|
|
scope: this
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-12 23:57:50 +01:00
|
|
|
createUploadField: function() {
|
|
|
|
return {
|
2012-11-17 12:42:48 +01:00
|
|
|
xtype: "fileuploadfield",
|
2012-11-12 23:57:50 +01:00
|
|
|
ref: 'fileuploadfield',
|
|
|
|
columnWidth: 1.0,
|
|
|
|
id: 'form-file',
|
|
|
|
name: 'icsdata',
|
2012-11-17 12:42:48 +01:00
|
|
|
emptyText: 'Select an .ics calendar',
|
|
|
|
border: false,
|
|
|
|
anchor: "100%",
|
|
|
|
scope: this,
|
|
|
|
allowBlank: false,
|
2012-11-12 23:57:50 +01:00
|
|
|
listeners: {
|
|
|
|
'fileselected': this.onFileSelected,
|
|
|
|
scope: this
|
|
|
|
}
|
2012-11-17 12:42:48 +01:00
|
|
|
}
|
2012-11-12 23:57:50 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
createSubmitButton: function() {
|
|
|
|
return {
|
2012-11-17 12:42:48 +01:00
|
|
|
xtype: "button",
|
2012-11-12 23:57:50 +01:00
|
|
|
ref: "submitButton",
|
|
|
|
id: "submitButton",
|
|
|
|
disabled: true,
|
2012-11-17 12:42:48 +01:00
|
|
|
width: 100,
|
|
|
|
border: false,
|
|
|
|
text: _("Import"),
|
|
|
|
anchor: "100%",
|
|
|
|
handler: this.importCheckedEvents,
|
|
|
|
scope: this,
|
|
|
|
allowBlank: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
createSubmitAllButton: function() {
|
|
|
|
return {
|
|
|
|
xtype: "button",
|
|
|
|
ref: "submitAllButton",
|
|
|
|
id: "submitAllButton",
|
|
|
|
disabled: true,
|
|
|
|
width: 100,
|
|
|
|
border: false,
|
|
|
|
text: _("Import All"),
|
|
|
|
anchor: "100%",
|
|
|
|
handler: this.importAllEvents,
|
|
|
|
scope: this,
|
|
|
|
allowBlank: false
|
|
|
|
}
|
2012-11-12 23:57:50 +01:00
|
|
|
},
|
|
|
|
|
2012-12-05 22:31:10 +01:00
|
|
|
createExportAllButton: function() {
|
|
|
|
return {
|
|
|
|
xtype: "button",
|
|
|
|
ref: "exportAllButton",
|
|
|
|
id: "exportAllButton",
|
|
|
|
hidden: !container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/enable_export"),
|
|
|
|
width: 100,
|
|
|
|
border: false,
|
|
|
|
text: _("Export All"),
|
|
|
|
anchor: "100%",
|
|
|
|
handler: this.exportAllEvents,
|
|
|
|
scope: this,
|
|
|
|
allowBlank: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-12 23:57:50 +01:00
|
|
|
createCancelButton: function() {
|
|
|
|
return {
|
2012-11-17 12:42:48 +01:00
|
|
|
xtype: "button",
|
|
|
|
width: 100,
|
|
|
|
border: false,
|
|
|
|
text: _("Cancel"),
|
|
|
|
anchor: "100%",
|
|
|
|
handler: this.close,
|
|
|
|
scope: this,
|
|
|
|
allowBlank: false
|
|
|
|
}
|
2012-11-12 23:57:50 +01:00
|
|
|
},
|
|
|
|
|
2012-12-28 21:10:45 +01:00
|
|
|
/**
|
|
|
|
* This is called when a timezone has been seleceted in the timezone dialog
|
|
|
|
* @param {Ext.form.ComboBox} combo
|
|
|
|
* @param {Ext.data.Record} record
|
|
|
|
* @param {Number} index
|
|
|
|
*/
|
|
|
|
onTimezoneSelected : function(combo, record, index) {
|
2012-12-29 19:49:24 +01:00
|
|
|
this.timezone = record.data.field1;
|
2013-03-30 14:55:18 +01:00
|
|
|
|
|
|
|
if(this.icsfile != null) {
|
|
|
|
this.parseCalendar(this.icsfile, this.timezone, this.ignoredst);
|
2012-12-29 19:49:24 +01:00
|
|
|
}
|
2012-12-28 21:10:45 +01:00
|
|
|
},
|
|
|
|
|
2013-02-27 00:32:02 +01:00
|
|
|
/**
|
|
|
|
* This is called when the dst checkbox has been selected
|
2013-03-30 14:55:18 +01:00
|
|
|
* @param {Ext.form.CheckBox} combo
|
|
|
|
* @param {boolean} checked
|
2013-02-27 00:32:02 +01:00
|
|
|
*/
|
|
|
|
onDstChecked : function(checkbox, checked) {
|
2013-03-30 14:55:18 +01:00
|
|
|
this.ignoredst = checked;
|
|
|
|
|
|
|
|
if(this.icsfile != null) {
|
|
|
|
this.parseCalendar(this.icsfile, this.timezone, this.ignoredst);
|
2013-02-27 00:32:02 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-12 23:57:50 +01:00
|
|
|
/**
|
|
|
|
* This is called when a file has been seleceted in the file dialog
|
|
|
|
* in the {@link Ext.ux.form.FileUploadField} and the dialog is closed
|
|
|
|
* @param {Ext.ux.form.FileUploadField} uploadField being added a file to
|
|
|
|
*/
|
2013-03-30 14:55:18 +01:00
|
|
|
onFileSelected : function(uploadField) {
|
2012-11-12 23:57:50 +01:00
|
|
|
var form = this.addFormPanel.getForm();
|
|
|
|
|
|
|
|
if (form.isValid()) {
|
|
|
|
form.submit({
|
|
|
|
waitMsg: 'Uploading and parsing calendar...',
|
|
|
|
url: 'plugins/calendarimporter/php/upload.php',
|
|
|
|
failure: function(file, action) {
|
2012-11-17 12:42:48 +01:00
|
|
|
Ext.getCmp('submitButton').disable();
|
|
|
|
Ext.getCmp('submitAllButton').disable();
|
2012-12-30 18:18:39 +01:00
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
2012-11-12 23:57:50 +01:00
|
|
|
title : _('Error'),
|
2013-03-30 14:55:18 +01:00
|
|
|
msg : _(action.result.error),
|
2012-12-30 18:18:39 +01:00
|
|
|
icon : Zarafa.common.dialogs.MessageBox.ERROR,
|
|
|
|
buttons : Zarafa.common.dialogs.MessageBox.OK
|
2012-11-12 23:57:50 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
success: function(file, action){
|
|
|
|
uploadField.reset();
|
2013-03-30 14:55:18 +01:00
|
|
|
this.icsfile = action.result.ics_file;
|
2012-12-28 21:10:45 +01:00
|
|
|
|
2013-03-30 14:55:18 +01:00
|
|
|
this.parseCalendar(this.icsfile, this.timezone, this.ignoredst);
|
2012-11-12 23:57:50 +01:00
|
|
|
},
|
|
|
|
scope : this
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2013-03-30 14:55:18 +01:00
|
|
|
|
|
|
|
parseCalendar: function (icsPath, timezone, ignoredst) {
|
|
|
|
this.loadMask.show();
|
|
|
|
// call export function here!
|
|
|
|
var responseHandler = new Zarafa.plugins.calendarimporter.data.ResponseHandler({
|
|
|
|
successCallback: this.handleParsingResult.createDelegate(this)
|
|
|
|
});
|
|
|
|
|
|
|
|
container.getRequest().singleRequest(
|
|
|
|
'calendarmodule',
|
|
|
|
'import',
|
|
|
|
{
|
|
|
|
ics_filepath: icsPath,
|
|
|
|
timezone: timezone,
|
|
|
|
ignore_dst: ignoredst
|
|
|
|
},
|
|
|
|
responseHandler
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleParsingResult: function(response) {
|
|
|
|
this.loadMask.hide();
|
|
|
|
|
|
|
|
if(response["status"] == true) {
|
|
|
|
Ext.getCmp('submitButton').enable();
|
|
|
|
Ext.getCmp('submitAllButton').enable();
|
|
|
|
|
|
|
|
if(typeof response.parsed.calendar["X-WR-TIMEZONE"] !== "undefined") {;
|
|
|
|
this.timezone = response.parsed.calendar["X-WR-TIMEZONE"];
|
|
|
|
this.timezoneselector.setValue(Zarafa.plugins.calendarimporter.data.Timezones.unMap(this.timezone));
|
2013-03-30 23:10:58 +01:00
|
|
|
}
|
2013-03-30 14:55:18 +01:00
|
|
|
this.reloadGridStore(response.parsed);
|
|
|
|
} else {
|
|
|
|
Ext.getCmp('submitButton').disable();
|
|
|
|
Ext.getCmp('submitAllButton').disable();
|
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
|
|
|
title : _('Parser Error'),
|
|
|
|
msg : _(response["message"]),
|
|
|
|
icon : Zarafa.common.dialogs.MessageBox.ERROR,
|
|
|
|
buttons : Zarafa.common.dialogs.MessageBox.OK
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2012-11-17 12:42:48 +01:00
|
|
|
|
2012-11-12 23:57:50 +01:00
|
|
|
close: function () {
|
|
|
|
this.addFormPanel.getForm().reset();
|
|
|
|
this.dialog.close()
|
|
|
|
},
|
2012-11-17 12:42:48 +01:00
|
|
|
|
2012-11-12 23:57:50 +01:00
|
|
|
convertToAppointmentRecord: function (calendarFolder,entry) {
|
|
|
|
var newRecord = Zarafa.core.data.RecordFactory.createRecordObjectByMessageClass('IPM.Appointment', {
|
|
|
|
startdate: new Date(entry.start),
|
2012-12-30 18:18:39 +01:00
|
|
|
duedate: (entry.end != null) ?
|
2012-11-12 23:57:50 +01:00
|
|
|
new Date(entry.end) :
|
|
|
|
new Date(entry.start).add(Date.HOUR, 1),
|
|
|
|
location: entry.location,
|
|
|
|
subject: entry.title,
|
|
|
|
body: entry.description,
|
|
|
|
commonstart: new Date(entry.start),
|
2012-12-30 18:18:39 +01:00
|
|
|
commonend: (entry.end != null) ?
|
2012-11-12 23:57:50 +01:00
|
|
|
new Date(entry.end) :
|
|
|
|
new Date(entry.start).add(Date.HOUR, 1),
|
2012-11-13 21:25:52 +01:00
|
|
|
timezone: this.timezone,
|
2012-11-12 23:57:50 +01:00
|
|
|
parent_entryid: calendarFolder.get('entryid'),
|
|
|
|
store_entryid: calendarFolder.get('store_entryid')
|
|
|
|
});
|
2012-12-30 18:18:39 +01:00
|
|
|
|
|
|
|
var busystate = new Array("FREE", "TENTATIVE", "BUSY", "OOF");
|
|
|
|
var zlabel = new Array("NONE", "IMPORTANT", "WORK", "PERSONAL", "HOLIDAY", "REQUIRED", "TRAVEL REQUIRED", "PREPARATION REQUIERED", "BIRTHDAY", "SPECIAL DATE", "PHONE INTERVIEW");
|
2013-03-30 14:55:18 +01:00
|
|
|
|
2012-12-30 18:18:39 +01:00
|
|
|
/* optional fields */
|
|
|
|
if(entry.priority !== "") {
|
|
|
|
newRecord.data.importance = entry.priority;
|
2013-03-30 14:55:18 +01:00
|
|
|
}
|
2012-12-30 18:18:39 +01:00
|
|
|
if(entry.label !== "") {
|
|
|
|
newRecord.data.label = zlabel.indexOf(entry.label);
|
|
|
|
}
|
|
|
|
if(entry.busy !== "") {
|
|
|
|
newRecord.data.busystatus = busystate.indexOf(entry.busy);
|
|
|
|
}
|
|
|
|
if(entry.privatestate !== "") {
|
|
|
|
newRecord.data["private"] = entry.privatestate == "PUBLIC" ? false : true;
|
|
|
|
}
|
|
|
|
if(entry.organizer !== "") {
|
|
|
|
newRecord.data.sent_representing_email_address = entry.organizer;
|
|
|
|
}
|
|
|
|
if(entry.trigger != null) {
|
|
|
|
newRecord.data.reminder = true;
|
|
|
|
newRecord.data.reminder_minutes = new Date((entry.start - entry.trigger)/60);
|
|
|
|
newRecord.data.reminder_time = new Date(entry.trigger);
|
|
|
|
} else {
|
|
|
|
newRecord.data.reminder = false;
|
|
|
|
}
|
|
|
|
|
2012-11-12 23:57:50 +01:00
|
|
|
return newRecord;
|
|
|
|
},
|
2012-12-30 19:18:46 +01:00
|
|
|
|
|
|
|
importCheckedEvents: function () {
|
|
|
|
var newRecords = this.eventgrid.selModel.getSelections();
|
|
|
|
this.importEvents(newRecords);
|
|
|
|
},
|
2012-11-17 12:42:48 +01:00
|
|
|
|
|
|
|
importAllEvents: function () {
|
2012-12-30 19:18:46 +01:00
|
|
|
//receive Records from grid rows
|
|
|
|
this.eventgrid.selModel.selectAll(); // select all entries
|
|
|
|
var newRecords = this.eventgrid.selModel.getSelections();
|
|
|
|
this.importEvents(newRecords);
|
2012-11-17 12:42:48 +01:00
|
|
|
},
|
2012-12-05 22:31:10 +01:00
|
|
|
|
|
|
|
exportAllEvents: function () {
|
|
|
|
//receive existing calendar store
|
|
|
|
var calValue = this.calendarselector.value;
|
2013-03-30 14:55:18 +01:00
|
|
|
|
2012-12-30 18:18:39 +01:00
|
|
|
if(calValue == undefined) { // no calendar choosen
|
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
2012-12-05 22:31:10 +01:00
|
|
|
title : _('Error'),
|
|
|
|
msg : _('You have to choose a calendar!'),
|
2012-12-30 18:18:39 +01:00
|
|
|
icon : Zarafa.common.dialogs.MessageBox.ERROR,
|
|
|
|
buttons : Zarafa.common.dialogs.MessageBox.OK
|
2012-12-05 22:31:10 +01:00
|
|
|
});
|
2012-12-29 19:49:24 +01:00
|
|
|
} else {
|
2012-12-30 18:18:39 +01:00
|
|
|
var calexist = true;
|
2012-12-05 22:31:10 +01:00
|
|
|
var calendarFolder = container.getHierarchyStore().getDefaultFolder('calendar');
|
2012-12-30 19:18:46 +01:00
|
|
|
var pubStore = container.getHierarchyStore().getPublicStore();
|
2013-03-30 23:10:58 +01:00
|
|
|
var pubSubFolders = [];
|
2013-06-13 20:49:40 +02:00
|
|
|
var pubFolder;
|
|
|
|
|
2013-03-30 23:10:58 +01:00
|
|
|
if(typeof pubStore !== "undefined") {
|
|
|
|
try {
|
2013-06-13 20:49:40 +02:00
|
|
|
pubFolder = pubStore.getDefaultFolder("publicfolders");
|
|
|
|
pubSubFolders = pubFolder.getChildren();
|
2013-03-30 23:10:58 +01:00
|
|
|
} catch (e) {
|
|
|
|
console.log("Error opening the shared folder...");
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
}
|
2012-12-30 19:18:46 +01:00
|
|
|
|
2012-12-05 22:31:10 +01:00
|
|
|
if(calValue != "calendar") {
|
|
|
|
var subFolders = calendarFolder.getChildren();
|
2012-12-30 18:18:39 +01:00
|
|
|
var i = 0;
|
2013-03-30 23:10:58 +01:00
|
|
|
|
|
|
|
/* add public folders if any exist */
|
2012-12-30 19:18:46 +01:00
|
|
|
for(i = 0; i < pubSubFolders.length; i++) {
|
|
|
|
if(pubSubFolders[i].isContainerClass("IPF.Appointment")){
|
|
|
|
subFolders.push(pubSubFolders[i]);
|
|
|
|
}
|
|
|
|
}
|
2013-03-30 23:10:58 +01:00
|
|
|
|
2012-12-05 22:31:10 +01:00
|
|
|
for(i=0;i<subFolders.length;i++) {
|
|
|
|
// loo up right folder
|
|
|
|
// TODO: improve!!
|
|
|
|
if(subFolders[i].getDisplayName() == calValue) {
|
|
|
|
calendarFolder = subFolders[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-12-30 18:18:39 +01:00
|
|
|
|
2012-12-30 19:18:46 +01:00
|
|
|
if(calendarFolder.isDefaultFolder()) {
|
2012-12-30 18:18:39 +01:00
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
|
|
|
title : _('Error'),
|
|
|
|
msg : _('Selected calendar does not exist!'),
|
|
|
|
icon : Zarafa.common.dialogs.MessageBox.ERROR,
|
|
|
|
buttons : Zarafa.common.dialogs.MessageBox.OK
|
|
|
|
});
|
|
|
|
calexist = false;
|
|
|
|
}
|
2012-12-05 22:31:10 +01:00
|
|
|
}
|
2012-12-08 01:53:21 +01:00
|
|
|
|
2012-12-30 18:18:39 +01:00
|
|
|
if(calexist) {
|
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
|
|
|
title: 'Please wait',
|
|
|
|
msg: 'Generating ical file...',
|
|
|
|
progressText: 'Exporting...',
|
|
|
|
width:300,
|
|
|
|
progress:true,
|
|
|
|
closable:false
|
|
|
|
});
|
|
|
|
|
|
|
|
// progress bar... ;)
|
|
|
|
var updateProgressBar = function(v){
|
|
|
|
return function(){
|
|
|
|
if(v == 100){
|
|
|
|
if(Zarafa.common.dialogs.MessageBox.isVisible()) {
|
|
|
|
updateTimer();
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
Zarafa.common.dialogs.MessageBox.updateProgress(v/100, 'Exporting...');
|
2012-12-08 01:53:21 +01:00
|
|
|
}
|
2012-12-30 18:18:39 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
var updateTimer = function() {
|
|
|
|
for(var i = 1; i < 101; i++){
|
|
|
|
setTimeout(updateProgressBar(i), 20*i);
|
2012-12-08 01:53:21 +01:00
|
|
|
}
|
2012-12-30 18:18:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
updateTimer();
|
2012-12-05 22:31:10 +01:00
|
|
|
|
2012-12-30 18:18:39 +01:00
|
|
|
// call export function here!
|
|
|
|
var responseHandler = new Zarafa.plugins.calendarimporter.data.ResponseHandler({
|
2013-03-30 14:55:18 +01:00
|
|
|
successCallback: this.exportPagedEvents.createDelegate(this)
|
2012-12-30 18:18:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
container.getRequest().singleRequest(
|
|
|
|
'appointmentlistmodule',
|
|
|
|
'list',
|
|
|
|
{
|
|
|
|
groupDir: "ASC",
|
|
|
|
restriction: {
|
2013-03-30 14:55:18 +01:00
|
|
|
//start: 0,
|
|
|
|
//limit: 500, // limit to 500 events.... not working because of hardcoded limit in listmodule
|
|
|
|
//startdate: 0,
|
|
|
|
//duedate: 2145826800 // 2037... nearly highest unix timestamp
|
2012-12-30 18:18:39 +01:00
|
|
|
},
|
|
|
|
sort: [{
|
|
|
|
"field": "startdate",
|
|
|
|
"direction": "DESC"
|
|
|
|
}],
|
|
|
|
store_entryid : calendarFolder.data.store_entryid,
|
|
|
|
entryid : calendarFolder.data.entryid
|
2012-12-07 00:10:23 +01:00
|
|
|
},
|
2012-12-30 18:18:39 +01:00
|
|
|
responseHandler
|
|
|
|
);
|
|
|
|
}
|
2012-12-05 22:31:10 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-03-30 14:55:18 +01:00
|
|
|
* Calculate needed Requests for all events
|
|
|
|
* Needed because the listmodule has hardcoded pageing setting -.-
|
2012-12-05 22:31:10 +01:00
|
|
|
* @param {Object} response
|
|
|
|
*/
|
2013-03-30 14:55:18 +01:00
|
|
|
exportPagedEvents:function(response) {
|
|
|
|
|
|
|
|
if(response.page.start = 0 && response.item.length <= 0) {
|
|
|
|
container.getNotifier().notify('info', 'Export Failed', 'There were no items to export!');
|
|
|
|
Zarafa.common.dialogs.MessageBox.hide();
|
|
|
|
} else {
|
|
|
|
this.exportResponse = response.item;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this.totalExportCount == null) {
|
|
|
|
this.totalExportCount = response.page.totalrowcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
var requests = Math.ceil(response.page.totalrowcount / response.page.rowcount);
|
|
|
|
this.runningRequests = requests;
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
|
2013-03-30 23:10:58 +01:00
|
|
|
//receive existing calendar store
|
|
|
|
var calValue = this.calendarselector.value;
|
|
|
|
var calendarFolder = container.getHierarchyStore().getDefaultFolder('calendar');
|
|
|
|
var pubStore = container.getHierarchyStore().getPublicStore();
|
|
|
|
var pubSubFolders = [];
|
2013-06-13 20:49:40 +02:00
|
|
|
var pubFolder;
|
|
|
|
|
2013-03-30 23:10:58 +01:00
|
|
|
if(typeof pubStore !== "undefined") {
|
|
|
|
try {
|
2013-06-13 20:49:40 +02:00
|
|
|
pubFolder = pubStore.getDefaultFolder("publicfolders");
|
|
|
|
pubSubFolders = pubFolder.getChildren();
|
2013-03-30 23:10:58 +01:00
|
|
|
} catch (e) {
|
|
|
|
console.log("Error opening the shared folder...");
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(calValue != "calendar") {
|
|
|
|
var subFolders = calendarFolder.getChildren();
|
2013-06-13 20:49:40 +02:00
|
|
|
i = 0;
|
2013-03-30 23:10:58 +01:00
|
|
|
|
|
|
|
/* add public folders if any exist */
|
|
|
|
for(i = 0; i < pubSubFolders.length; i++) {
|
|
|
|
if(pubSubFolders[i].isContainerClass("IPF.Appointment")){
|
|
|
|
subFolders.push(pubSubFolders[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;i<subFolders.length;i++) {
|
|
|
|
// loo up right folder
|
|
|
|
// TODO: improve!!
|
|
|
|
if(subFolders[i].getDisplayName() == calValue) {
|
|
|
|
calendarFolder = subFolders[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(calendarFolder.isDefaultFolder()) {
|
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
|
|
|
title : _('Error'),
|
|
|
|
msg : _('Selected calendar does not exist!'),
|
|
|
|
icon : Zarafa.common.dialogs.MessageBox.ERROR,
|
|
|
|
buttons : Zarafa.common.dialogs.MessageBox.OK
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-30 14:55:18 +01:00
|
|
|
for(i = 0; i < requests; i++) {
|
2012-12-07 00:10:23 +01:00
|
|
|
var responseHandler = new Zarafa.plugins.calendarimporter.data.ResponseHandler({
|
2013-03-30 14:55:18 +01:00
|
|
|
successCallback: this.storeResult.createDelegate(this)
|
2012-12-07 00:10:23 +01:00
|
|
|
});
|
2013-03-30 23:10:58 +01:00
|
|
|
this.requestNext(calendarFolder, responseHandler, response.page.rowcount *(i+1), response.page.rowcount);
|
2013-03-30 14:55:18 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Responsehandler for the single requests... will merge all events into one array
|
|
|
|
* @param {Object} response
|
|
|
|
*/
|
|
|
|
storeResult: function(response) {
|
|
|
|
var tmp = this.exportResponse;
|
|
|
|
|
|
|
|
this.exportResponse = tmp.concat(response.item);
|
2012-12-07 00:10:23 +01:00
|
|
|
|
2013-03-30 14:55:18 +01:00
|
|
|
if(this.runningRequests <= 1) {
|
|
|
|
// final request =)
|
|
|
|
var responseHandler = new Zarafa.plugins.calendarimporter.data.ResponseHandler({
|
|
|
|
successCallback: this.downLoadICS.createDelegate(this)
|
|
|
|
});
|
|
|
|
|
|
|
|
container.getRequest().singleRequest(
|
|
|
|
'calendarmodule',
|
|
|
|
'export',
|
|
|
|
{
|
|
|
|
data: this.exportResponse,
|
|
|
|
calendar: this.calendarselector.value
|
|
|
|
},
|
|
|
|
responseHandler
|
|
|
|
);
|
|
|
|
container.getNotifier().notify('info', 'Exported', 'Found ' + this.exportResponse.length + ' entries to export. Preparing download...');
|
|
|
|
this.dialog.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.runningRequests--;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* build a new event request for the listmodule
|
2013-03-30 23:10:58 +01:00
|
|
|
* @param {Object} calendarFolder the calendarFolder to export
|
2013-03-30 14:55:18 +01:00
|
|
|
* @param {Object} responseHandler (should be storeResult)
|
|
|
|
* @param {int} start
|
|
|
|
* @param {int} limit
|
|
|
|
*/
|
2013-03-30 23:10:58 +01:00
|
|
|
requestNext: function(calendarFolder, responseHandler, start, limit) {
|
2013-03-30 14:55:18 +01:00
|
|
|
|
|
|
|
container.getRequest().singleRequest(
|
|
|
|
'appointmentlistmodule',
|
|
|
|
'list',
|
|
|
|
{
|
|
|
|
groupDir: "ASC",
|
|
|
|
restriction: {
|
|
|
|
start: start,
|
|
|
|
limit: limit
|
|
|
|
//startdate: 0,
|
|
|
|
//duedate: 2145826800 // 2037... nearly highest unix timestamp
|
2012-12-07 00:10:23 +01:00
|
|
|
},
|
2013-03-30 14:55:18 +01:00
|
|
|
sort: [{
|
|
|
|
"field": "startdate",
|
|
|
|
"direction": "DESC"
|
|
|
|
}],
|
|
|
|
store_entryid : calendarFolder.data.store_entryid,
|
|
|
|
entryid : calendarFolder.data.entryid
|
|
|
|
},
|
|
|
|
responseHandler
|
|
|
|
);
|
|
|
|
},
|
2012-12-07 00:10:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* download ics file =)
|
|
|
|
* @param {Object} response
|
|
|
|
* @private
|
|
|
|
*/
|
2012-12-30 18:18:39 +01:00
|
|
|
downLoadICS : function(response) {
|
2012-12-08 01:53:21 +01:00
|
|
|
Zarafa.common.dialogs.MessageBox.hide();
|
2013-03-30 14:55:18 +01:00
|
|
|
if(response.status === true) {
|
2013-01-03 18:48:54 +01:00
|
|
|
if(!this.downloadFrame){
|
|
|
|
this.downloadFrame = Ext.getBody().createChild({
|
|
|
|
tag: 'iframe',
|
|
|
|
cls: 'x-hidden'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
var url = 'plugins/calendarimporter/php/download.php?fileid='+response.fileid+'&basedir='+response.basedir+'&secid='+response.secid+'&realname='+response.realname;
|
|
|
|
this.downloadFrame.dom.contentWindow.location = url;
|
2012-12-07 00:10:23 +01:00
|
|
|
} else {
|
|
|
|
container.getNotifier().notify('error', 'Export Failed', 'ICal File creation failed!');
|
2013-03-30 14:55:18 +01:00
|
|
|
}
|
2012-12-07 00:10:23 +01:00
|
|
|
},
|
2012-12-30 19:18:46 +01:00
|
|
|
|
2013-03-30 14:55:18 +01:00
|
|
|
/**
|
|
|
|
* This function stores all given events to the appointmentstore
|
|
|
|
* @param events
|
|
|
|
*/
|
2012-12-30 19:18:46 +01:00
|
|
|
importEvents: function (events) {
|
2012-11-17 12:42:48 +01:00
|
|
|
//receive existing calendar store
|
|
|
|
var calValue = this.calendarselector.value;
|
|
|
|
|
2012-12-30 18:18:39 +01:00
|
|
|
if(calValue == undefined) { // no calendar choosen
|
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
2012-11-17 12:42:48 +01:00
|
|
|
title : _('Error'),
|
|
|
|
msg : _('You have to choose a calendar!'),
|
2012-12-30 18:18:39 +01:00
|
|
|
icon : Zarafa.common.dialogs.MessageBox.ERROR,
|
|
|
|
buttons : Zarafa.common.dialogs.MessageBox.OK
|
2012-11-17 12:42:48 +01:00
|
|
|
});
|
|
|
|
} else {
|
2012-12-30 18:18:39 +01:00
|
|
|
var calexist = true;
|
2012-11-17 12:42:48 +01:00
|
|
|
if(this.eventgrid.selModel.getCount() < 1) {
|
2012-12-30 18:18:39 +01:00
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
2012-11-17 12:42:48 +01:00
|
|
|
title : _('Error'),
|
|
|
|
msg : _('You have to choose at least one event to import!'),
|
2012-12-30 18:18:39 +01:00
|
|
|
icon : Zarafa.common.dialogs.MessageBox.ERROR,
|
|
|
|
buttons : Zarafa.common.dialogs.MessageBox.OK
|
2012-11-17 12:42:48 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
var calendarStore = new Zarafa.calendar.AppointmentStore();
|
|
|
|
var calendarFolder = container.getHierarchyStore().getDefaultFolder('calendar');
|
2012-12-30 19:18:46 +01:00
|
|
|
var pubStore = container.getHierarchyStore().getPublicStore();
|
|
|
|
var pubFolder = pubStore.getDefaultFolder("publicfolders");
|
|
|
|
var pubSubFolders = pubFolder.getChildren();
|
|
|
|
|
2012-11-17 12:42:48 +01:00
|
|
|
if(calValue != "calendar") {
|
|
|
|
var subFolders = calendarFolder.getChildren();
|
2012-12-30 18:18:39 +01:00
|
|
|
var i = 0;
|
2013-03-30 14:55:18 +01:00
|
|
|
for(i = 0; i < pubSubFolders.length; i++) {
|
2012-12-30 19:18:46 +01:00
|
|
|
if(pubSubFolders[i].isContainerClass("IPF.Appointment")){
|
|
|
|
subFolders.push(pubSubFolders[i]);
|
|
|
|
}
|
|
|
|
}
|
2012-11-17 12:42:48 +01:00
|
|
|
for(i=0;i<subFolders.length;i++) {
|
2012-12-30 18:18:39 +01:00
|
|
|
// look up right folder
|
2012-11-17 12:42:48 +01:00
|
|
|
// TODO: improve!!
|
|
|
|
if(subFolders[i].getDisplayName() == calValue) {
|
|
|
|
calendarFolder = subFolders[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-12-30 18:18:39 +01:00
|
|
|
|
2012-12-30 19:18:46 +01:00
|
|
|
if(calendarFolder.isDefaultFolder()) {
|
2012-12-30 18:18:39 +01:00
|
|
|
Zarafa.common.dialogs.MessageBox.show({
|
|
|
|
title : _('Error'),
|
|
|
|
msg : _('Selected calendar does not exist!'),
|
|
|
|
icon : Zarafa.common.dialogs.MessageBox.ERROR,
|
|
|
|
buttons : Zarafa.common.dialogs.MessageBox.OK
|
|
|
|
});
|
|
|
|
calexist = false;
|
|
|
|
}
|
2012-11-17 12:42:48 +01:00
|
|
|
}
|
|
|
|
|
2012-12-30 18:18:39 +01:00
|
|
|
if(calexist) {
|
2013-03-30 14:55:18 +01:00
|
|
|
this.loadMask.show();
|
2012-12-30 18:18:39 +01:00
|
|
|
//receive Records from grid rows
|
2012-12-30 19:18:46 +01:00
|
|
|
Ext.each(events, function(newRecord) {
|
2012-12-30 18:18:39 +01:00
|
|
|
var record = this.convertToAppointmentRecord(calendarFolder,newRecord.data);
|
|
|
|
calendarStore.add(record);
|
|
|
|
}, this);
|
|
|
|
calendarStore.save();
|
2013-03-30 14:55:18 +01:00
|
|
|
this.loadMask.hide();
|
2012-12-30 18:18:39 +01:00
|
|
|
this.dialog.close();
|
2013-03-30 14:55:18 +01:00
|
|
|
container.getNotifier().notify('info', 'Imported', 'Imported ' + events.length + ' events. Please reload your calendar!');
|
2012-12-30 18:18:39 +01:00
|
|
|
}
|
2012-11-17 12:42:48 +01:00
|
|
|
}
|
|
|
|
}
|
2012-12-30 19:18:46 +01:00
|
|
|
}
|
2012-11-12 23:57:50 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
Ext.reg('calendarimporter.importpanel', Zarafa.plugins.calendarimporter.dialogs.ImportPanel);
|