summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2013-10-16 11:01:55 (GMT)
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-10-31 11:58:04 (GMT)
commitf35a6119c071d5c15c16cde1949979cb0f8f6fe2 (patch)
tree3197498046fdbd736eb23fc3a595e9388fd261ac
parentfa9921726c07d273b567855351f7d70a6533c206 (diff)
downloadroundcubemail-plugins-kolab-f35a6119c071d5c15c16cde1949979cb0f8f6fe2.tar.gz
Catch errors on iCal import and provide appropriate feedback to the user (#2353)
-rw-r--r--plugins/calendar/calendar.php21
-rw-r--r--plugins/calendar/calendar_ui.js17
2 files changed, 32 insertions, 6 deletions
diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php
index f038caf..11821d7 100644
--- a/plugins/calendar/calendar.php
+++ b/plugins/calendar/calendar.php
@@ -975,10 +975,18 @@ class calendar extends rcube_plugin
if (!$err && $_FILES['_data']['tmp_name']) {
$calendar = get_input_value('calendar', RCUBE_INPUT_GPC);
- $events = $this->get_ical()->import_from_file($_FILES['_data']['tmp_name']);
-
- $count = $errors = 0;
$rangestart = $_REQUEST['_range'] ? date_create("now -" . intval($_REQUEST['_range']) . " months") : 0;
+ $count = $errors = 0;
+
+ try {
+ $events = $this->get_ical()->import_from_file($_FILES['_data']['tmp_name'], 'UTF-8', true);
+ }
+ catch (Exception $e) {
+ $errors = 1;
+ $msg = $e->getMessage();
+ $events = array();
+ }
+
foreach ($events as $event) {
// TODO: correctly handle recurring events which start before $rangestart
if ($event['end'] < $rangestart && (!$event['recurrence'] || ($event['recurrence']['until'] && $event['recurrence']['until'] < $rangestart)))
@@ -1000,8 +1008,9 @@ class calendar extends rcube_plugin
$this->rc->output->command('display_message', $this->gettext('importnone'), 'notice');
$this->rc->output->command('plugin.import_success', array('source' => $calendar));
}
- else
- $this->rc->output->command('display_message', $this->gettext('importerror'), 'error');
+ else {
+ $this->rc->output->command('plugin.import_error', array('message' => $this->gettext('importerror') . ($msg ? ': ' . $msg : '')));
+ }
}
else {
if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) {
@@ -1012,7 +1021,7 @@ class calendar extends rcube_plugin
$msg = rcube_label('fileuploaderror');
}
- $this->rc->output->command('display_message', $msg, 'error');
+ $this->rc->output->command('plugin.import_error', array('message' => $msg));
$this->rc->output->command('plugin.unlock_saving', false);
}
diff --git a/plugins/calendar/calendar_ui.js b/plugins/calendar/calendar_ui.js
index 986113f..72243e0 100644
--- a/plugins/calendar/calendar_ui.js
+++ b/plugins/calendar/calendar_ui.js
@@ -1981,10 +1981,17 @@ function rcube_calendar_ui(settings)
if (form && form.elements._data.value) {
rcmail.async_upload_form(form, 'import_events', function(e) {
rcmail.set_busy(false, null, me.saving_lock);
+ $('.ui-dialog-buttonpane button', $dialog.parent()).button('enable');
+
+ // display error message if no sophisticated response from server arrived (e.g. iframe load error)
+ if (me.import_succeeded === null)
+ rcmail.display_message(rcmail.get_label('importerror', 'calendar'), 'error');
});
// display upload indicator
+ me.import_succeeded = null;
me.saving_lock = rcmail.set_busy(true, 'uploading');
+ $('.ui-dialog-buttonpane button', $dialog.parent()).button('disable');
}
};
@@ -1999,6 +2006,7 @@ function rcube_calendar_ui(settings)
closeOnEscape: false,
title: rcmail.gettext('importevents', 'calendar'),
close: function() {
+ $('.ui-dialog-buttonpane button', $dialog.parent()).button('enable');
$dialog.dialog("destroy").hide();
},
buttons: buttons,
@@ -2010,6 +2018,7 @@ function rcube_calendar_ui(settings)
// callback from server if import succeeded
this.import_success = function(p)
{
+ this.import_succeeded = true;
$("#eventsimport:ui-dialog").dialog('close');
rcmail.set_busy(false, null, me.saving_lock);
rcmail.gui_objects.importform.reset();
@@ -2018,6 +2027,13 @@ function rcube_calendar_ui(settings)
this.refresh(p);
};
+ // callback from server to report errors on import
+ this.import_error = function(p)
+ {
+ this.import_succeeded = false;
+ rcmail.display_message(p.message || rcmail.get_label('importerror', 'calendar'), 'error');
+ }
+
// show URL of the given calendar in a dialog box
this.showurl = function(calendar)
{
@@ -2780,6 +2796,7 @@ window.rcmail && rcmail.addEventListener('init', function(evt) {
rcmail.addEventListener('plugin.unlock_saving', function(p){ cal.unlock_saving(); });
rcmail.addEventListener('plugin.refresh_calendar', function(p){ cal.refresh(p); });
rcmail.addEventListener('plugin.import_success', function(p){ cal.import_success(p); });
+ rcmail.addEventListener('plugin.import_error', function(p){ cal.import_error(p); });
// let's go
var cal = new rcube_calendar_ui($.extend(rcmail.env.calendar_settings, rcmail.env.libcal_settings));