switched to sabre / vobject library

This commit is contained in:
Christoph Haas 2016-06-20 19:42:07 +02:00
parent 2c18071de4
commit 2606bf75b1
10 changed files with 113 additions and 46 deletions

View File

@ -52,7 +52,7 @@ Zarafa.plugins.calendarimporter.data.ResponseHandler = Ext.extend(Zarafa.core.da
* Call the successCallback callback function. * Call the successCallback callback function.
* @param {Object} response Object contained the response data. * @param {Object} response Object contained the response data.
*/ */
doList: function (response) { doLoad: function (response) {
this.successCallback(response); this.successCallback(response);
}, },

View File

@ -77,17 +77,19 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
// create the data store // create the data store
this.store = new Ext.data.ArrayStore({ this.store = new Ext.data.ArrayStore({
fields: [ fields: [
{name: 'title'}, {name: 'subject'},
{name: 'start'}, {name: 'startdate'},
{name: 'end'}, {name: 'enddate'},
{name: 'location'}, {name: 'location'},
{name: 'description'}, {name: 'body'},
{name: 'priority'}, {name: 'priority'},
{name: 'label'}, {name: 'label'},
{name: 'busy'}, {name: 'busy'},
{name: 'privatestate'}, {name: 'class'},
{name: 'organizer'}, {name: 'organizer'},
{name: 'trigger'} {name: 'alarms'},
{name: 'timezone'},
{name: 'record'}
] ]
}); });
@ -285,13 +287,21 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
parsedData = new Array(eventdata.events.length); parsedData = new Array(eventdata.events.length);
var i = 0; var i = 0;
for(i = 0; i < eventdata.events.length; i++) { for(i = 0; i < eventdata.events.length; i++) {
var trigger = null; parsedData[i] = [
eventdata.events[i]["subject"],
if(eventdata.events[i]["VALARM"]) { new Date(parseInt(eventdata.events[i]["startdate"]) * 1000 + local_tz_offset),
trigger = eventdata.events[i]["VALARM"]["TRIGGER"]; new Date(parseInt(eventdata.events[i]["enddate"]) * 1000 + local_tz_offset),
trigger = new Date(parseInt(trigger) + local_tz_offset); eventdata.events[i]["location"],
} eventdata.events[i]["body"],
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); eventdata.events[i]["priority"],
eventdata.events[i]["label"],
eventdata.events[i]["busy"],
eventdata.events[i]["class"],
eventdata.events[i]["organizer"],
eventdata.events[i]["alarms"],
eventdata.events[i]["timezone"],
eventdata.events[i]
];
} }
} else { } else {
return null; return null;
@ -325,17 +335,18 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
sortable: true sortable: true
}, },
columns: [ columns: [
{id: 'Summary', header: 'Title', width: 200, sortable: true, dataIndex: 'title'}, {id: 'Summary', header: 'Title', width: 200, sortable: true, dataIndex: 'subject'},
{header: 'Start', width: 200, sortable: true, dataIndex: 'start', renderer : Zarafa.common.ui.grid.Renderers.datetime}, {header: 'Start', width: 200, sortable: true, dataIndex: 'startdate', renderer : Zarafa.common.ui.grid.Renderers.datetime},
{header: 'End', width: 200, sortable: true, dataIndex: 'end', renderer : Zarafa.common.ui.grid.Renderers.datetime}, {header: 'End', width: 200, sortable: true, dataIndex: 'enddate', renderer : Zarafa.common.ui.grid.Renderers.datetime},
{header: 'Location', width: 150, sortable: true, dataIndex: 'location'}, {header: 'Location', width: 150, sortable: true, dataIndex: 'location'},
{header: 'Description', sortable: true, dataIndex: 'description'}, {header: 'Description', sortable: true, dataIndex: 'body'},
{header: "Priority", dataIndex: 'priority', hidden: true}, {header: "Priority", dataIndex: 'priority', hidden: true},
{header: "Label", dataIndex: 'label', hidden: true}, {header: "Label", dataIndex: 'label', hidden: true},
{header: "Busystatus", dataIndex: 'busy', hidden: true}, {header: "Busystatus", dataIndex: 'busy', hidden: true},
{header: "Privacystatus", dataIndex: 'privatestate', hidden: true}, {header: "Privacystatus", dataIndex: 'class', hidden: true},
{header: "Organizer", dataIndex: 'organizer', hidden: true}, {header: "Organizer", dataIndex: 'organizer', hidden: true},
{header: "Alarm", dataIndex: 'trigger', hidden: true, renderer : Zarafa.common.ui.grid.Renderers.datetime} {header: "Alarm", dataIndex: 'alarms', hidden: true, renderer : Zarafa.common.ui.grid.Renderers.datetime},
{header: "Timezone", dataIndex: 'timezone', hidden: true}
] ]
}), }),
sm: new Ext.grid.RowSelectionModel({multiSelect:true}) sm: new Ext.grid.RowSelectionModel({multiSelect:true})
@ -430,7 +441,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
createSubmitButton: function() { createSubmitButton: function() {
return { return {
xtype: "button", xtype: "button",
ref: "submitButton", ref: "../submitButton",
disabled: true, disabled: true,
width: 100, width: 100,
border: false, border: false,
@ -444,7 +455,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
createSubmitAllButton: function() { createSubmitAllButton: function() {
return { return {
xtype: "button", xtype: "button",
ref: "submitAllButton", ref: "../submitAllButton",
disabled: true, disabled: true,
width: 100, width: 100,
border: false, border: false,
@ -548,20 +559,22 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
}, },
handleParsingResult: function(response) { handleParsingResult: function(response) {
this.loadMask.hide(); var self = this.scope;
self.loadMask.hide();
if(response["status"] == true) { if(response["status"] == true) {
this.submitButton.enable(); self.submitButton.enable();
this.submitAllButton.enable(); self.submitAllButton.enable();
if(typeof response.parsed.calendar["X-WR-TIMEZONE"] !== "undefined") { if(typeof response.parsed.calendar["X-WR-TIMEZONE"] !== "undefined") {
this.timezone = response.parsed.calendar["X-WR-TIMEZONE"]; self.timezone = response.parsed.calendar["X-WR-TIMEZONE"];
this.timezoneselector.setValue(Zarafa.plugins.calendarimporter.data.Timezones.unMap(this.timezone)); self.timezoneselector.setValue(Zarafa.plugins.calendarimporter.data.Timezones.unMap(this.timezone));
} }
this.reloadGridStore(response.parsed); self.reloadGridStore(response.parsed);
} else { } else {
this.submitButton.disable(); self.submitButton.disable();
this.submitAllButton.disable(); self.submitAllButton.disable();
Zarafa.common.dialogs.MessageBox.show({ Zarafa.common.dialogs.MessageBox.show({
title : _('Parser Error'), title : _('Parser Error'),
msg : _(response["message"]), msg : _(response["message"]),

View File

@ -20,7 +20,7 @@
<serverfile type="module" module="calendarmodule">php/module.calendar.php</serverfile> <serverfile type="module" module="calendarmodule">php/module.calendar.php</serverfile>
</server> </server>
<client> <client>
<clientfile load="release">js/calendarimporter.js</clientfile> <clientfile load="release">js/calendarimporter-debug.js</clientfile>
<clientfile load="debug">js/calendarimporter-debug.js</clientfile> <clientfile load="debug">js/calendarimporter-debug.js</clientfile>
<clientfile load="source">js/data/timezones.js</clientfile> <clientfile load="source">js/data/timezones.js</clientfile>
@ -39,7 +39,7 @@
<clientfile load="source">js/plugin.calendarimporter.js</clientfile> <clientfile load="source">js/plugin.calendarimporter.js</clientfile>
</client> </client>
<resources> <resources>
<resourcefile load="release">resources/css/calendarimporter-min.css</resourcefile> <resourcefile load="release">resources/css/calendarimporter.css</resourcefile>
<resourcefile load="debug">resources/css/calendarimporter.css</resourcefile> <resourcefile load="debug">resources/css/calendarimporter.css</resourcefile>
<resourcefile load="source">resources/css/calendarimporter-main.css</resourcefile> <resourcefile load="source">resources/css/calendarimporter-main.css</resourcefile>
</resources> </resources>

View File

@ -1,5 +1,5 @@
{ {
"require": { "require": {
"kigkonsult/icalcreator": "dev-master" "sabre/vobject": "4.1"
} }
} }

View File

@ -23,6 +23,8 @@
include_once('vendor/autoload.php'); include_once('vendor/autoload.php');
use Sabre\VObject;
class CalendarModule extends Module class CalendarModule extends Module
{ {
@ -585,13 +587,10 @@ class CalendarModule extends Module
$parser = null; $parser = null;
try { try {
$parser = new vcalendar([ $parser = VObject\Reader::read(
"unique_id" => md5($actionData["ics_filepath"]), fopen($actionData["ics_filepath"],'r')
"directory" => dirname($actionData["ics_filepath"]), );
"filename" => basename($actionData["ics_filepath"]) error_log(print_r($parser->VTIMEZONE, true));
]);
$parser->parse();
error_log(print_r($parser, true));
} catch (Exception $e) { } catch (Exception $e) {
$error = true; $error = true;
$error_msg = $e->getMessage(); $error_msg = $e->getMessage();
@ -600,14 +599,16 @@ class CalendarModule extends Module
$response['status'] = false; $response['status'] = false;
$response['message'] = $error_msg; $response['message'] = $error_msg;
} else { } else {
if (count($parser->components) == 0) { if (count($parser->VEVENT) == 0) {
$response['status'] = false; $response['status'] = false;
$response['message'] = "No event in ics file"; $response['message'] = "No event in ics file";
} else { } else {
$response['status'] = true; $response['status'] = true;
$response['parsed_file'] = $actionData["ics_filepath"]; $response['parsed_file'] = $actionData["ics_filepath"];
$response['parsed'] = array( $response['parsed'] = array(
'contacts' => $this->parseCalendarToArray($parser) 'events' => $this->parseCalendarToArray($parser),
'timezone' => $parser->VTIMEZONE->TZID,
'calendar' => $parser
); );
} }
} }
@ -627,13 +628,42 @@ class CalendarModule extends Module
/** /**
* Create a array with contacts * Create a array with contacts
* *
* @param calendar ics parser object * @param {VObject} $calendar ics parser object
* @return array parsed events * @return array parsed events
* @private * @private
*/ */
private function parseCalendarToArray($calendar) private function parseCalendarToArray($calendar)
{ {
return false; $events = array();
foreach ($calendar->VEVENT as $Index => $vEvent) {
// Sabre\VObject\Parser\XML\Element\VEvent
$properties = array();
//uid - used for front/backend communication
$properties["internal_fields"] = array();
$properties["internal_fields"]["event_uid"] = base64_encode($Index . $vEvent->UID);
$properties["startdate"] = (string)$vEvent->DTSTART->getDateTime()->getTimestamp();
$properties["enddate"] = (string)$vEvent->DTEND->getDateTime()->getTimestamp();
$properties["location"] = (string)$vEvent->LOCATION;
$properties["subject"] = (string)$vEvent->SUMMARY;
$properties["body"] = (string)$vEvent->DESCRIPTION;
$properties["comment"] = (string)$vEvent->COMMENT;
$properties["timezone"] = (string)$vEvent->DTSTART["TZID"];
$properties["organizer"] = (string)$vEvent->ORGANIZER;
$properties["busy"] = (string)$vEvent->{'X-MICROSOFT-CDO-INTENDEDSTATUS'}; // X-MICROSOFT-CDO-BUSYSTATUS
$properties["transp"] = (string)$vEvent->TRANSP;
//$properties["trigger"] = (string)$vEvent->COMMENT;
$properties["priority"] = (string)$vEvent->PRIORITY;
$properties["class"] = (string)$vEvent->CLASS;
$properties["label"] = (string)$vEvent->COMMENT;
$properties["lastmodified"] = (string)$vEvent->{'LAST-MODIFIED'};
$properties["created"] = (string)$vEvent->CREATED;
array_push($events, $properties);
}
return $events;
} }
} }

View File

@ -2,5 +2,29 @@
background: url(../images/import_icon.png) no-repeat !important; background: url(../images/import_icon.png) no-repeat !important;
background-repeat: no-repeat; background-repeat: no-repeat;
background-position: center; background-position: center;
background-size: 18px!important; }
.icon_calendarimporter_export {
background: url(../images/download.png) no-repeat;
background-repeat: no-repeat;
background-position: center;
}
.icon_calendarimporter_import {
background: url(../images/upload.png) no-repeat;
background-repeat: no-repeat;
background-position: center;
}
.zarafa-caiplg-container {
width: 100%;
height: 50px;
}
.zarafa-caiplg-button .x-btn-small {
width: 80%;
height: 30px;
margin-left: 10%;
margin-right: 10%;
margin-top: 10px;
} }

BIN
resources/images/download.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

BIN
resources/images/download.xcf Executable file

Binary file not shown.

BIN
resources/images/upload.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

BIN
resources/images/upload.xcf Executable file

Binary file not shown.