From 29a9559fa9df7f08947dabbba270bd97c3419d54 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 3 Jul 2012 13:43:18 +0200 Subject: [PATCH] some work on calendar import dialog --- apps/calendar/ajax/import/calendarcheck.php | 18 ++++ apps/calendar/ajax/import/dropimport.php | 2 +- apps/calendar/ajax/import/import.php | 10 +- apps/calendar/css/import.css | 12 +++ apps/calendar/js/loader.js | 102 ++++++++++++-------- apps/calendar/templates/part.import.php | 58 +++++------ 6 files changed, 132 insertions(+), 70 deletions(-) create mode 100644 apps/calendar/ajax/import/calendarcheck.php create mode 100644 apps/calendar/css/import.css diff --git a/apps/calendar/ajax/import/calendarcheck.php b/apps/calendar/ajax/import/calendarcheck.php new file mode 100644 index 0000000000..a91bab7057 --- /dev/null +++ b/apps/calendar/ajax/import/calendarcheck.php @@ -0,0 +1,18 @@ + + * 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(); \ No newline at end of file diff --git a/apps/calendar/ajax/import/dropimport.php b/apps/calendar/ajax/import/dropimport.php index b58b3f91cc..f46e731409 100644 --- a/apps/calendar/ajax/import/dropimport.php +++ b/apps/calendar/ajax/import/dropimport.php @@ -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)))); } \ No newline at end of file diff --git a/apps/calendar/ajax/import/import.php b/apps/calendar/ajax/import/import.php index 210bcb34d2..b251c94f4f 100644 --- a/apps/calendar/ajax/import/import.php +++ b/apps/calendar/ajax/import/import.php @@ -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'); diff --git a/apps/calendar/css/import.css b/apps/calendar/css/import.css new file mode 100644 index 0000000000..d60d54253a --- /dev/null +++ b/apps/calendar/css/import.css @@ -0,0 +1,12 @@ +/** + * Copyright (c) 2012 Georg Ehrke + * 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;} \ No newline at end of file diff --git a/apps/calendar/js/loader.js b/apps/calendar/js/loader.js index f54e3fa262..9f18ea8726 100644 --- a/apps/calendar/js/loader.js +++ b/apps/calendar/js/loader.js @@ -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('
'); @@ -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'); }; }); diff --git a/apps/calendar/templates/part.import.php b/apps/calendar/templates/part.import.php index 2a3ca9dae9..c7156c79d7 100644 --- a/apps/calendar/templates/part.import.php +++ b/apps/calendar/templates/part.import.php @@ -7,37 +7,39 @@ if(!$file){ $import = new OC_Calendar_Import($file); $newcalendarname = strip_tags($import->createCalendarName()); $guessedcalendarname = $import->guessCalendarName(); -?> -
"> -
- - - -

t('Please choose a calendar'); ?>

- - - -!" id="startimport"> -
-