Catch errors on iCal import and provide appropriate feedback to the user (#2353)
This commit is contained in:
parent
1f851a7663
commit
6951f8d4a4
2 changed files with 32 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1963,10 +1963,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');
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1981,6 +1988,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,
|
||||
|
@ -1992,6 +2000,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();
|
||||
|
@ -2000,6 +2009,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)
|
||||
{
|
||||
|
@ -2762,6 +2778,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));
|
||||
|
|
Loading…
Add table
Reference in a new issue