some work on calendar import dialog

This commit is contained in:
Georg Ehrke 2012-07-03 13:43:18 +02:00
parent e89a0949c4
commit 29a9559fa9
6 changed files with 132 additions and 70 deletions

View file

@ -0,0 +1,18 @@
<?php
/**
* Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
OCP\JSON::checkLoggedIn();
OCP\App::checkAppEnabled('calendar');
$calname = strip_tags($_POST['calname']);
$calendars = OC_Calendar_Calendar::allCalendars(OCP\User::getUser());
foreach($calendars as $calendar){
if($calendar['displayname'] == $calname){
OCP\JSON::success(array('message'=>'exists'));
exit;
}
}
OCP\JSON::error();

View file

@ -26,7 +26,7 @@ $import->import();
$count = $import->getCount();
if($count == 0){
OC_Calendar_Calendar::deleteCalendar($newid);
OCP\JSON::error(array('message'=>OC_Calendar_App::$l10n->t('The file contained either no events or all events are already saved in your account')));
OCP\JSON::error(array('message'=>OC_Calendar_App::$l10n->t('The file contained either no events or all events are already saved in your calendar.')));
}else{
OCP\JSON::success(array('message'=>$count . ' ' . OC_Calendar_App::$l10n->t('events has been saved in the new calendar') . ' ' . $newcalendarname, 'eventSource'=>OC_Calendar_Calendar::getEventSourceInfo(OC_Calendar_Calendar::find($newid))));
}

View file

@ -32,7 +32,7 @@ if($_POST['method'] == 'new'){
$newcal = true;
}
if($newcal){
$id = OC_Calendar_Calendar::addCalendar(OCP\USER::getUser(), strip_tags($_POST['calname'],'VEVENT,VTODO,VJOURNAL',null,0,$import->createCalendarColor()));
$id = OC_Calendar_Calendar::addCalendar(OCP\USER::getUser(), strip_tags($_POST['calname']),'VEVENT,VTODO,VJOURNAL',null,0,$import->createCalendarColor());
OC_Calendar_Calendar::setCalendarActive($id, 1);
}
}else{
@ -50,9 +50,13 @@ if($count == 0){
if($newcal){
OC_Calendar_Calendar::deleteCalendar($id);
}
OCP\JSON::error(array('message'=>OC_Calendar_App::$l10n->t('The file contained either no events or all events are already saved in your account')));
OCP\JSON::error(array('message'=>OC_Calendar_App::$l10n->t('The file contained either no events or all events are already saved in your calendar.')));
}else{
OCP\JSON::success(array('message'=>$count . ' ' . OC_Calendar_App::$l10n->t('events has been saved in the new calendar') . ' ' . $newcalendarname));
if($newcal){
OCP\JSON::success(array('message'=>$count . ' ' . OC_Calendar_App::$l10n->t('events has been saved in the new calendar') . ' ' . strip_tags($_POST['calname'])));
}else{
OCP\JSON::success(array('message'=>$count . ' ' . OC_Calendar_App::$l10n->t('events has been saved in your calendar')));
}
}
/* //////////////////////////// Attention: following code is quite painfull !!! ///////////////////////
writeProgress('20');

12
apps/calendar/css/import.css vendored Normal file
View file

@ -0,0 +1,12 @@
/**
* Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
#calendar_import_newcalform, #calendar_import_mergewarning, #calendar_import_process, #calendar_import_done{display:none;}
#calendar_import_process_message, #calendar_import_status, #calendar_import_form_message, #calendar_import_mergewarning{text-align:center;}
#calendar_import_form_message{font-weight: bold;}
#calendar_import_newcalendar{width:480px;}
.calendar_import_warning{background-color: rgba(216,22,22,0.7);}
.calendar_import_revertwarning{background-color: #ffffff;}

View file

@ -13,9 +13,10 @@ Calendar_Import={
calname: '',
progresskey: '',
percentage: 0
}
},
Dialog:{
open: function(filename){
OC.addStyle('calendar', 'import');
Calendar_Import.Store.file = filename;
Calendar_Import.Store.path = $('#dir').val();
$('body').append('<div id="calendar_import"></div>');
@ -24,8 +25,9 @@ Calendar_Import={
});
},
close: function(){
Calendar_Import.reset();
$(this).dialog('destroy').remove();
$('#calendar_import').remove();
$('#calendar_import_dialog').remove();
},
init: function(){
//init dialog
@ -36,25 +38,36 @@ Calendar_Import={
}
});
//init buttons
$('#import_done_button').click(function(){
Calendar_Import.closedialog();
$('#calendar_import_done').click(function(){
Calendar_Import.Dialog.close();
});
$('#startimport').click(function(){
Calendar_import.Core.process();
}
$('#calendar').change(function(){
if($('#calendar option:selected').val() == 'newcal'){
$('#newcalform').slideDown('slow');
$('#calendar_import_submit').click(function(){
Calendar_Import.Core.process();
});
$('#calendar_import_calendar').change(function(){
if($('#calendar_import_calendar option:selected').val() == 'newcal'){
$('#calendar_import_newcalform').slideDown('slow');
Calendar_Import.Dialog.mergewarning($('#calendar_import_newcalendar').val());
}else{
$('#newcalform').slideUp('slow');
$('#calendar_import_newcalform').slideUp('slow');
$('#calendar_import_mergewarning').slideUp('slow');
}
});
$('#calendar_import_newcalendar').keyup(function(){
Calendar_Import.Dialog.mergewarning($('#calendar_import_newcalendar').val());
});
//init progressbar
$('#progressbar').progressbar({value: Calendar_Import.Store.percentage});
Calendar_Import.Store.progresskey = $('#progresskey').val();
$('#calendar_import_progressbar').progressbar({value: Calendar_Import.Store.percentage});
Calendar_Import.Store.progresskey = $('#calendar_import_progresskey').val();
},
mergewarning: function(){
mergewarning: function(newcalname){
$.post(OC.filePath('calendar', 'ajax/import', 'calendarcheck.php'), {calname: newcalname}, function(data){
if(data.message == 'exists'){
$('#calendar_import_mergewarning').slideDown('slow');
}else{
$('#calendar_import_mergewarning').slideUp('slow');
}
});
},
update: function(){
/*$.post(OC.filePath('calendar', 'ajax/import', 'import.php'), {progress:1,progresskey: progresskey}, function(percent){
@ -67,28 +80,35 @@ Calendar_Import={
});*/
return 0;
},
warning: function(validation){
warning: function(selector){
$(selector).css('background-color', '#FF2626');
$(selector).focus(function(){
$(selector).css('background-color', '#F8F8F8');
});
}
},
Core:{
process: function(){
var validation = Calendar.Core.prepare();
var validation = Calendar_Import.Core.prepare();
$('#calendar_import_form').css('display', 'none');
$('#calendar_import_process').css('display', 'block');
if(validation){
$('#newcalendar').attr('readonly', 'readonly');
$('#calendar').attr('disabled', 'disabled');
Calendar.Core.send();
}else{
Calendar.Dialog.warning(validation);
$('#calendar_import_newcalendar').attr('readonly', 'readonly');
$('#calendar_import_calendar').attr('disabled', 'disabled');
Calendar_Import.Core.send();
}
},
send: function(){
$.post(OC.filePath('calendar', 'ajax/import', 'import.php'),
{progresskey: Calendar_Import.Store.progresskey, method: String (Calendar_Import.Store.method), calname: String (Calendar_Import.Store.calname), path: String (Calendar_Import.Store.path), file: String (Calendar_Import.Store.filename), id: String (Calendar_Import.Store.calid)}, function(data){
{progresskey: Calendar_Import.Store.progresskey, method: String (Calendar_Import.Store.method), calname: String (Calendar_Import.Store.calname), path: String (Calendar_Import.Store.path), file: String (Calendar_Import.Store.file), id: String (Calendar_Import.Store.id)}, function(data){
if(data.status == 'success'){
$('#progressbar').progressbar('option', 'value', 100);
$('#import_done').css('display', 'block');
$('#status').html(data.message);
$('#calendar_import_progressbar').progressbar('option', 'value', 100);
$('#calendar_import_done').css('display', 'block');
$('#calendar_import_status').html(data.message);
}else{
$('#calendar_import_progressbar').progressbar('option', 'value', 100);
$("#calendar_import_progressbar > div").css('background-color', '#FF2626');
$('#calendar_import_status').html(data.message);
}
});
$('#form_container').css('display', 'none');
@ -96,27 +116,33 @@ Calendar_Import={
window.setTimeout('Calendar_Import.Dialog.update', 500);
},
prepare: function(){
Calendar_Import.Store.id = $('#calendar option:selected').val();
if($('#calendar option:selected').val() == 'newcal'){
Calendar_Import.Store.id = $('#calendar_import_calendar option:selected').val();
if($('#calendar_import_calendar option:selected').val() == 'newcal'){
Calendar_Import.Store.method = 'new';
Calendar_Import.Store.calname = $.trim($('#newcalendar').val());
Calendar_Import.Store.calname = $.trim($('#calendar_import_newcalendar').val());
if(Calendar_Import.Store.calname == ''){
$('#newcalendar').css('background-color', '#FF2626');
$('#newcalendar').focus(function(){
$('#newcalendar').css('background-color', '#F8F8F8');
});
Calendar_Import.Dialog.warning('#calendar_import_newcalendar');
return false;
}
}else{
var method = 'old';
Calendar_Import.Store.method = 'old';
}
return true;
}
},
reset: function(){
Calendar_Import.Store.file = '';
Calendar_Import.Store.path = '';
Calendar_Import.Store.id = 0;
Calendar_Import.Store.method = '';
Calendar_Import.Store.calname = '';
Calendar_Import.Store.progresskey = '';
Calendar_Import.Store.percentage = 0;
}
}
$(document).ready(function(){
if(typeof FileActions !== 'undefined'){
FileActions.register('text/calendar','importcal', '', Calendar_Import.importdialog);
FileActions.setDefault('text/calendar','importcal');
FileActions.register('text/calendar','importCalendar', '', Calendar_Import.Dialog.open);
FileActions.setDefault('text/calendar','importCalendar');
};
});

View file

@ -7,37 +7,39 @@ if(!$file){
$import = new OC_Calendar_Import($file);
$newcalendarname = strip_tags($import->createCalendarName());
$guessedcalendarname = $import->guessCalendarName();
?>
<div id="calendar_import_dialog" title="<?php echo $l->t("Import a calendar file");?>">
<div id="form_container">
<input type="hidden" id="filename" value="<?php echo $_['filename'];?>">
<input type="hidden" id="path" value="<?php echo $_['path'];?>">
<input type="hidden" id="progresskey" value="<?php echo rand() ?>">
<p style="text-align:center;"><b><?php echo $l->t('Please choose a calendar'); ?></b></p>
<select style="width:100%;" id="calendar" name="calendar">
<?php
//loading calendars for select box
$calendar_options = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser());
$calendar_options[] = array('id'=>'newcal', 'displayname'=>$l->t('create a new calendar'));
for($i = 0;$i<count($calendar_options);$i++){
$calendar_options[$i]['displayname'] = $calendar_options[$i]['displayname'];
}
echo OCP\html_select_options($calendar_options, $calendar_options[0]['id'], array('value'=>'id', 'label'=>'displayname'));
?>
</select>
<div id="newcalform" style="display: none;">
<input type="text" style="width: 97%;" placeholder="<?php echo $l->t('Name of new calendar'); ?>" id="newcalendar" name="newcalendar" value="<?php echo $newcalendarname ?>">
</div>
<div id="namealreadyused" style="display: none;text-align:center;">
<span class="hint"><?php echo $l->t('A Calendar with this name already exists. If you continue anyhow, these calendars will be merged.'); ?></span>
</div>
<input type="button" value="<?php echo $l->t("Import") . ' ' . $_['filename']; ?>!" id="startimport">
</div>
<div id="progressbar_container" style="display: none">
<p style="text-align:center;"><b><?php echo $l->t('Importing calendar'); ?></b></p>
<div id="progressbar"></div>
<div id="import_done" style="display: none;">
<p style="text-align:center;"><b><?php echo $l->t('Calendar imported successfully'); ?></b></p>
<input type="button" value="<?php echo $l->t('Close Dialog'); ?>" id="import_done_button">
<div id="calendar_import_dialog" title="<?php echo $l->t("Import a calendar file");?>">
<div id="calendar_import_form">
<form>
<input type="hidden" id="calendar_import_filename" value="<?php echo $_['filename'];?>">
<input type="hidden" id="calendar_import_path" value="<?php echo $_['path'];?>">
<input type="hidden" id="calendar_import_progresskey" value="<?php echo rand() ?>">
<span id="calendar_import_form_message"><?php echo $l->t('Please choose a calendar'); ?></span>
<select style="width:100%;" id="calendar_import_calendar" name="calendar_import_calendar">
<?php
for($i = 0;$i<count($calendar_options);$i++){
$calendar_options[$i]['displayname'] = $calendar_options[$i]['displayname'];
}
echo OCP\html_select_options($calendar_options, $calendar_options[0]['id'], array('value'=>'id', 'label'=>'displayname'));
?>
</select>
<div id="calendar_import_newcalform">
<input id="calendar_import_newcalendar" type="text" placeholder="<?php echo $l->t('Name of new calendar'); ?>" value="<?php echo $newcalendarname ?>"><br>
<!--<input id="calendar_import_generatename" type="button" class="button" value="<?php echo $l->t('Take an available name!'); ?>"><br>-->
<span id="calendar_import_mergewarning" class="hint"><?php echo $l->t('A Calendar with this name already exists. If you continue anyhow, these calendars will be merged.'); ?></span>
</div>
<input id="calendar_import_submit" type="button" class="button" value="&raquo; <?php echo $l->t('Import'); ?> &raquo;" id="startimport">
<form>
</div>
<div id="calendar_import_process">
<span id="calendar_import_process_message"></span>
<div id="calendar_import_progressbar"></div>
<br>
<div id="calendar_import_status" class="hint"></div>
<br>
<input id="calendar_import_done" type="button" value="<?php echo $l->t('Close Dialog'); ?>">
</div>
</div>