Skip to content

Commit

Permalink
[jan] Add importing of calendar data from a URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Jun 18, 2014
1 parent eb482d6 commit 823d82d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
26 changes: 21 additions & 5 deletions kronolith/data.php
Expand Up @@ -71,6 +71,7 @@

switch ($actionID) {
case Horde_Data::IMPORT_FILE:
case Horde_Data::IMPORT_URL:
$storage->set('import_cal', Horde_Util::getFormData('importCal'));
$storage->set('purge', Horde_Util::getFormData('purge'));
break;
Expand All @@ -79,9 +80,15 @@
if ($import_format) {
$data = null;
try {
$data = $injector->getInstance('Horde_Core_Factory_Data')->create($import_format, array('cleanup' => array($app_ob, 'cleanupData')));
$data = $injector
->getInstance('Horde_Core_Factory_Data')
->create(
$import_format,
array('cleanup' => array($app_ob, 'cleanupData'))
);

if ($actionID == Horde_Data::IMPORT_FILE) {
if ($actionID == Horde_Data::IMPORT_FILE ||
$actionID == Horde_Data::IMPORT_URL) {
$cleanup = true;
try {
if (!in_array($storage->get('import_cal'), array_keys(Kronolith::listCalendars(Horde_Perms::EDIT)))) {
Expand All @@ -106,11 +113,21 @@
$next_step = $data->cleanup();
} else {
$notification->push(_("This file format is not supported."), 'horde.error');
$next_step = Horde_Data::IMPORT_FILE;
$next_step = in_array(
$actionID,
array(Horde_Data::IMPORT_FILE, Horde_Data::IMPORT_URL)
)
? $actionID
: Horde_Data::IMPORT_FILE;
}
}
}

if (Horde_Util::getFormData('import_ajax')) {
$page_output->includeScriptFiles();
$page_output->addInlineScript('(function(window){window.KronolithCore.loading--;if(!window.KronolithCore.loading)window.$(\'kronolithLoading\').hide();})(window.parent)');
}

/* We have a final result set. */
if (is_array($next_step)) {
$events = array();
Expand Down Expand Up @@ -211,8 +228,7 @@
$file_types[$storage->get('format')]), 'horde.success');
}
if (Horde_Util::getFormData('import_ajax')) {
$page_output->includeScriptFiles();
$page_output->addInlineScript('(function(window){window.KronolithCore.loading--;if(!window.KronolithCore.loading)window.$(\'kronolithLoading\').hide();window.KronolithCore.loadCalendar(\'' . $type . '\', \'' . $calendar . '\');})(window.parent)');
$page_output->addInlineScript('(function(window){window.KronolithCore.loadCalendar(\'' . $type . '\', \'' . $calendar . '\');})(window.parent)');
}
$next_step = $data->cleanup();
}
Expand Down
1 change: 1 addition & 0 deletions kronolith/docs/CHANGES
Expand Up @@ -2,6 +2,7 @@
v4.3.0-git
----------

[jan] Add importing of calendar data from a URL.


-----------
Expand Down
8 changes: 7 additions & 1 deletion kronolith/js/kronolith.js
Expand Up @@ -3769,7 +3769,13 @@ KronolithCore = {
delete data.calendar;
}
if (r.saved) {
if ($F('kronolithCalendarinternalImport')) {
if ($F('kronolithCalendarinternalImport') ||
$F('kronolithCalendarinternalImportUrl')) {
$('kronolithCalendarinternalImportAction').setValue(
$F('kronolithCalendarinternalImport')
? Kronolith.conf.import_file
: Kronolith.conf.import_url
);
HordeCore.notify(Kronolith.text.import_warning, 'horde.message');
this.loading++;
$('kronolithLoading').show();
Expand Down
2 changes: 2 additions & 0 deletions kronolith/lib/Ajax.php
Expand Up @@ -97,6 +97,8 @@ protected function _addBaseVars()
Horde_Nls::getLangInfo(D_FMT)
),
'time_format' => $prefs->getValue('twentyFour') ? 'HH:mm' : 'hh:mm tt',
'import_file' => Horde_Data::IMPORT_FILE,
'import_url' => Horde_Data::IMPORT_URL,
'show_time' => Kronolith::viewShowTime(),
'default_alarm' => intval($prefs->getValue('default_alarm')),
'status' => array(
Expand Down
4 changes: 2 additions & 2 deletions kronolith/package.xml
Expand Up @@ -33,7 +33,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
*
* [jan] Add importing of calendar data from a URL.
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -2383,7 +2383,7 @@
<date>2014-06-04</date>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
*
* [jan] Add importing of calendar data from a URL.
</notes>
</release>
</changelog>
Expand Down
6 changes: 5 additions & 1 deletion kronolith/templates/chunks/calendar.php
Expand Up @@ -43,7 +43,7 @@
<?php if ($file_upload): ?>
<input type="hidden" id="kronolithCalendarinternalImportCal" name="importCal" />
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $file_upload ?>" />
<input type="hidden" name="actionID" value="<?php echo Horde_Data::IMPORT_FILE ?>" />
<input type="hidden" id="kronolithCalendarinternalImportAction" name="actionID" value="<?php echo Horde_Data::IMPORT_FILE ?>" />
<input type="hidden" name="import_step" value="1" />
<input type="hidden" name="import_format" value="icalendar" />
<input type="hidden" name="import_ajax" value="1" />
Expand Down Expand Up @@ -144,6 +144,10 @@
<label for="kronolithCalendarinternalImport"><?php echo _("Import ICS file") ?>:</label>
<input type="file" id="kronolithCalendarinternalImport" name="import_file" /><br />
</div>
<div>
<label for="kronolithCalendarinternalImportURL"><?php echo _("Import ICS URL") ?>:</label>
<input type="text" id="kronolithCalendarinternalImportUrl" name="import_url" /><br />
</div>
<div>
<?php printf(_("Importing should %s %sreplace this calendar%s."),
'<input type="checkbox" id="kronolithCalendarinternalImportOver" name="purge" />',
Expand Down

0 comments on commit 823d82d

Please sign in to comment.