diff --git a/config.php b/config.php index 34bd778..6796ccf 100644 --- a/config.php +++ b/config.php @@ -1,13 +1,11 @@ + * Copyright (C) 2012-2016 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 + * + */ + +/** + * ResponseHandler + * + * This class handles all responses from the php backend + */ +Ext.namespace('Zarafa.plugins.calendarimporter.data'); + +/** + * @class Zarafa.plugins.calendarimporter.data.Actions + * Common actions which can be used within {@link Ext.Button buttons} + * or other {@link Ext.Component components} with action handlers. + * @singleton + */ +Zarafa.plugins.calendarimporter.data.Actions = { + /** + * Callback for the export request. + * @param {Object} response + */ + downloadICS: function (response) { + if (response.status == false) { + Zarafa.common.dialogs.MessageBox.show({ + title : dgettext('plugin_files', 'Warning'), + msg : dgettext('plugin_files', response.message), + icon : Zarafa.common.dialogs.MessageBox.WARNING, + buttons: Zarafa.common.dialogs.MessageBox.OK + }); + } else { + var downloadFrame = Ext.getBody().createChild({ + tag: 'iframe', + cls: 'x-hidden' + }); + + var url = document.URL; + var link = url.substring(0, url.lastIndexOf('/') + 1); + + link += "index.php?sessionid=" + container.getUser().getSessionId() + "&load=custom&name=download_ics"; + link = Ext.urlAppend(link, "token=" + encodeURIComponent(response.download_token)); + link = Ext.urlAppend(link, "filename=" + encodeURIComponent(response.filename)); + + downloadFrame.dom.contentWindow.location = link; + } + } +}; \ No newline at end of file diff --git a/js/data/ResponseHandler.js b/js/data/ResponseHandler.js index 6fc4f9f..1d338c1 100644 --- a/js/data/ResponseHandler.js +++ b/js/data/ResponseHandler.js @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ - + /** * ResponseHandler * @@ -38,46 +38,46 @@ Zarafa.plugins.calendarimporter.data.ResponseHandler = Ext.extend(Zarafa.core.da * @cfg {Function} successCallback The function which * will be called after success request. */ - successCallback : null, - + successCallback: null, + /** * Call the successCallback callback function. * @param {Object} response Object contained the response data. */ - doExport : function(response) { + doExport: function (response) { this.successCallback(response); }, - + /** * Call the successCallback callback function. * @param {Object} response Object contained the response data. */ - doList : function(response) { + doList: function (response) { this.successCallback(response); }, - + /** * Call the successCallback callback function. * @param {Object} response Object contained the response data. */ - doImport : function(response) { + doImport: function (response) { this.successCallback(response); }, - + /** * Call the successCallback callback function. * @param {Object} response Object contained the response data. */ - doAttachmentpath : function(response) { + doImportattachment: function (response) { this.successCallback(response); }, - + /** * In case exception happened on server, server will return * exception response with the code of exception. * @param {Object} response Object contained the response data. */ - doError: function(response) { + doError: function (response) { alert("error response code: " + response.error.info.code); } }); diff --git a/js/dialogs/ImportPanel.js b/js/dialogs/ImportPanel.js index 190d7a8..cf3a3cc 100644 --- a/js/dialogs/ImportPanel.js +++ b/js/dialogs/ImportPanel.js @@ -372,7 +372,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, { name: "choosen_timezone", value: Zarafa.plugins.calendarimporter.data.Timezones.unMap(container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/default_timezone")), width: 100, - fieldLabel: "Select a timezone (optional)", + fieldLabel: "Timezone", store: Zarafa.plugins.calendarimporter.data.Timezones.store, labelSeperator: ":", mode: 'local', @@ -393,7 +393,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, { ref: 'dstcheck', name: "dst_check", width: 100, - fieldLabel: "Ignore DST (optional)", + fieldLabel: "Ignore DST", boxLabel: 'This will ignore "Daylight saving time" offsets.', labelSeperator: ":", border: false, @@ -529,14 +529,15 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, { 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) + successCallback: this.handleParsingResult, + scope: this }); container.getRequest().singleRequest( 'calendarmodule', - 'import', + 'load', { ics_filepath: icsPath, timezone: timezone, @@ -550,17 +551,17 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, { 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.submitButton.enable(); + this.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)); } this.reloadGridStore(response.parsed); } else { - Ext.getCmp('submitButton').disable(); - Ext.getCmp('submitAllButton').disable(); + this.submitButton.disable(); + this.submitAllButton.disable(); Zarafa.common.dialogs.MessageBox.show({ title : _('Parser Error'), msg : _(response["message"]), @@ -575,54 +576,6 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, { this.dialog.close() }, - convertToAppointmentRecord: function (calendarFolder,entry) { - var newRecord = Zarafa.core.data.RecordFactory.createRecordObjectByMessageClass('IPM.Appointment', { - startdate: new Date(entry.start), - duedate: (entry.end != null) ? - 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), - commonend: (entry.end != null) ? - new Date(entry.end) : - new Date(entry.start).add(Date.HOUR, 1), - timezone: this.timezone, - parent_entryid: calendarFolder.get('entryid'), - store_entryid: calendarFolder.get('store_entryid') - }); - - 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"); - - /* optional fields */ - if(entry.priority !== "") { - newRecord.data.importance = entry.priority; - } - 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; - } - - return newRecord; - }, - importCheckedEvents: function () { var newRecords = this.eventgrid.selModel.getSelections(); this.importEvents(newRecords); @@ -635,295 +588,15 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, { this.importEvents(newRecords); }, - exportAllEvents: function () { - //receive existing calendar store - var calValue = this.calendarselector.value; - - if(calValue == undefined) { // no calendar choosen - Zarafa.common.dialogs.MessageBox.show({ - title : _('Error'), - msg : _('You have to choose a calendar!'), - icon : Zarafa.common.dialogs.MessageBox.ERROR, - buttons : Zarafa.common.dialogs.MessageBox.OK - }); - } else { - var calexist = true; - var calendarFolder = container.getHierarchyStore().getDefaultFolder('calendar'); - var pubStore = container.getHierarchyStore().getPublicStore(); - var pubSubFolders = []; - var pubFolder; - - if(typeof pubStore !== "undefined") { - try { - pubFolder = pubStore.getDefaultFolder("publicfolders"); - pubSubFolders = pubFolder.getChildren(); - } catch (e) { - console.log("Error opening the shared folder..."); - console.log(e); - } - } - - if(calValue != "calendar") { - var subFolders = calendarFolder.getChildren(); - var i = 0; - - /* 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;ijs/calendarimporter-debug.js js/data/timezones.js - js/external/Ext.util.base64.js - js/plugin.calendarimporter.js + js/data/Actions.js js/data/ResponseHandler.js + js/external/Ext.util.base64.js + js/ui/ContextMenu.js js/dialogs/ImportContentPanel.js js/dialogs/ImportPanel.js js/dialogs/settings/SettingsWidget.js @@ -35,6 +36,7 @@ js/dialogs/settings/ui/CalSyncPanel.js js/dialogs/settings/dialogs/CalSyncEditContentPanel.js js/dialogs/settings/dialogs/CalSyncEditPanel.js + js/plugin.calendarimporter.js resources/css/calendarimporter-min.css diff --git a/php/module.calendar.php b/php/module.calendar.php index 6735aca..a5529a1 100644 --- a/php/module.calendar.php +++ b/php/module.calendar.php @@ -63,7 +63,7 @@ class CalendarModule extends Module { case "import": $result = $this->importCalendar($actionType, $actionData); break; - case "attachmentpath": + case "importattachment": $result = $this->getAttachmentPath($actionType, $actionData); break; default: diff --git a/php/plugin.calendarimporter.php b/php/plugin.calendarimporter.php index ba28d83..fcb688c 100644 --- a/php/plugin.calendarimporter.php +++ b/php/plugin.calendarimporter.php @@ -67,7 +67,6 @@ class Plugincalendarimporter extends Plugin { 'plugins' => Array( 'calendarimporter' => Array( 'enable' => PLUGIN_CALENDARIMPORTER_USER_DEFAULT_ENABLE, - 'enable_export' => PLUGIN_CALENDARIMPORTER_USER_DEFAULT_ENABLE_EXPORT, 'enable_sync' => PLUGIN_CALENDARIMPORTER_USER_DEFAULT_ENABLE_SYNC, 'default_calendar' => PLUGIN_CALENDARIMPORTER_DEFAULT, 'default_timezone' => PLUGIN_CALENDARIMPORTER_DEFAULT_TIMEZONE