2012-01-14 17:22:30 +04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-01-13 01:06:53 +04:00
|
|
|
Calendar_Import={
|
2012-07-01 23:36:09 +04:00
|
|
|
Store:{
|
|
|
|
file: '',
|
|
|
|
path: '',
|
|
|
|
id: 0,
|
|
|
|
method: '',
|
|
|
|
calname: '',
|
2012-07-04 23:14:40 +04:00
|
|
|
calcolor: '',
|
2012-07-01 23:36:09 +04:00
|
|
|
progresskey: '',
|
|
|
|
percentage: 0
|
2012-01-13 01:06:53 +04:00
|
|
|
},
|
2012-07-01 23:36:09 +04:00
|
|
|
Dialog:{
|
|
|
|
open: function(filename){
|
2012-07-03 15:43:18 +04:00
|
|
|
OC.addStyle('calendar', 'import');
|
2012-07-01 23:36:09 +04:00
|
|
|
Calendar_Import.Store.file = filename;
|
|
|
|
Calendar_Import.Store.path = $('#dir').val();
|
|
|
|
$('body').append('<div id="calendar_import"></div>');
|
|
|
|
$('#calendar_import').load(OC.filePath('calendar', 'ajax/import', 'dialog.php'), {filename:Calendar_Import.Store.file, path:Calendar_Import.Store.path},function(){
|
|
|
|
Calendar_Import.Dialog.init();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
close: function(){
|
2012-07-03 15:43:18 +04:00
|
|
|
Calendar_Import.reset();
|
2012-07-01 23:36:09 +04:00
|
|
|
$(this).dialog('destroy').remove();
|
2012-07-03 15:43:18 +04:00
|
|
|
$('#calendar_import_dialog').remove();
|
2012-07-01 23:36:09 +04:00
|
|
|
},
|
|
|
|
init: function(){
|
|
|
|
//init dialog
|
|
|
|
$('#calendar_import_dialog').dialog({
|
|
|
|
width : 500,
|
2012-07-04 23:14:40 +04:00
|
|
|
resizable: false,
|
2012-07-01 23:36:09 +04:00
|
|
|
close : function() {
|
|
|
|
Calendar_Import.Dialog.close();
|
2012-01-13 16:57:46 +04:00
|
|
|
}
|
2012-07-01 23:36:09 +04:00
|
|
|
});
|
|
|
|
//init buttons
|
2012-07-03 15:43:18 +04:00
|
|
|
$('#calendar_import_done').click(function(){
|
|
|
|
Calendar_Import.Dialog.close();
|
2012-07-01 23:36:09 +04:00
|
|
|
});
|
2012-07-03 15:43:18 +04:00
|
|
|
$('#calendar_import_submit').click(function(){
|
|
|
|
Calendar_Import.Core.process();
|
|
|
|
});
|
2012-07-04 23:14:40 +04:00
|
|
|
$('#calendar_import_mergewarning').click(function(){
|
|
|
|
$('#calendar_import_newcalendar').attr('value', $('#calendar_import_availablename').val());
|
|
|
|
Calendar_Import.Dialog.mergewarning($('#calendar_import_newcalendar').val());
|
|
|
|
});
|
2012-07-03 15:43:18 +04:00
|
|
|
$('#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());
|
2012-07-01 23:36:09 +04:00
|
|
|
}else{
|
2012-07-03 15:43:18 +04:00
|
|
|
$('#calendar_import_newcalform').slideUp('slow');
|
|
|
|
$('#calendar_import_mergewarning').slideUp('slow');
|
2012-07-01 23:36:09 +04:00
|
|
|
}
|
|
|
|
});
|
2012-07-03 15:43:18 +04:00
|
|
|
$('#calendar_import_newcalendar').keyup(function(){
|
2012-07-04 23:14:40 +04:00
|
|
|
Calendar_Import.Dialog.mergewarning($.trim($('#calendar_import_newcalendar').val()));
|
|
|
|
});
|
|
|
|
$('#calendar_import_newcalendar_color').miniColors({
|
|
|
|
letterCase: 'uppercase'
|
|
|
|
});
|
|
|
|
$('.calendar-colorpicker-color').click(function(){
|
|
|
|
var str = $(this).attr('rel');
|
|
|
|
str = str.substr(1);
|
|
|
|
$('#calendar_import_newcalendar_color').attr('value', str);
|
|
|
|
$(".color-picker").miniColors('value', '#' + str);
|
2012-07-03 15:43:18 +04:00
|
|
|
});
|
2012-07-01 23:36:09 +04:00
|
|
|
//init progressbar
|
2012-07-03 15:43:18 +04:00
|
|
|
$('#calendar_import_progressbar').progressbar({value: Calendar_Import.Store.percentage});
|
|
|
|
Calendar_Import.Store.progresskey = $('#calendar_import_progresskey').val();
|
2012-07-01 23:36:09 +04:00
|
|
|
},
|
2012-07-03 15:43:18 +04:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
});
|
2012-07-01 23:36:09 +04:00
|
|
|
},
|
|
|
|
update: function(){
|
2012-07-04 00:33:24 +04:00
|
|
|
if(Calendar_Import.Store.percentage == 100){
|
|
|
|
return false;
|
2012-01-13 16:57:46 +04:00
|
|
|
}
|
2012-07-04 00:33:24 +04:00
|
|
|
$.post(OC.filePath('calendar', 'ajax/import', 'import.php'), {progresskey: Calendar_Import.Store.progresskey, getprogress: true}, function(data){
|
|
|
|
if(data.status == 'success'){
|
|
|
|
if(data.percent == null){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Calendar_Import.Store.percentage = parseInt(data.percent);
|
|
|
|
$('#calendar_import_progressbar').progressbar('option', 'value', parseInt(data.percent));
|
|
|
|
if(data.percent < 100 ){
|
|
|
|
window.setTimeout('Calendar_Import.Dialog.update()', 250);
|
|
|
|
}else{
|
|
|
|
$('#calendar_import_done').css('display', 'block');
|
|
|
|
}
|
2012-07-01 23:36:09 +04:00
|
|
|
}else{
|
2012-07-04 00:33:24 +04:00
|
|
|
$('#calendar_import_progressbar').progressbar('option', 'value', 100);
|
|
|
|
$('#calendar_import_progressbar > div').css('background-color', '#FF2626');
|
|
|
|
$('#calendar_import_status').html(data.message);
|
2012-01-13 16:57:46 +04:00
|
|
|
}
|
2012-07-04 00:33:24 +04:00
|
|
|
});
|
|
|
|
return 0;
|
2012-07-01 23:36:09 +04:00
|
|
|
},
|
2012-07-03 15:43:18 +04:00
|
|
|
warning: function(selector){
|
2012-07-04 00:33:24 +04:00
|
|
|
$(selector).addClass('calendar_import_warning');
|
2012-07-03 15:43:18 +04:00
|
|
|
$(selector).focus(function(){
|
2012-07-04 00:33:24 +04:00
|
|
|
$(selector).removeClass('calendar_import_warning');
|
2012-07-03 15:43:18 +04:00
|
|
|
});
|
2012-07-01 23:36:09 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
Core:{
|
|
|
|
process: function(){
|
2012-07-03 15:43:18 +04:00
|
|
|
var validation = Calendar_Import.Core.prepare();
|
2012-07-01 23:36:09 +04:00
|
|
|
if(validation){
|
2012-07-04 00:33:24 +04:00
|
|
|
$('#calendar_import_form').css('display', 'none');
|
|
|
|
$('#calendar_import_process').css('display', 'block');
|
2012-07-03 15:43:18 +04:00
|
|
|
$('#calendar_import_newcalendar').attr('readonly', 'readonly');
|
|
|
|
$('#calendar_import_calendar').attr('disabled', 'disabled');
|
|
|
|
Calendar_Import.Core.send();
|
2012-07-04 00:33:24 +04:00
|
|
|
window.setTimeout('Calendar_Import.Dialog.update()', 250);
|
2012-01-13 16:57:46 +04:00
|
|
|
}
|
2012-07-01 23:36:09 +04:00
|
|
|
},
|
|
|
|
send: function(){
|
|
|
|
$.post(OC.filePath('calendar', 'ajax/import', 'import.php'),
|
2012-07-04 23:14:40 +04:00
|
|
|
{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), calcolor: String (Calendar_Import.Store.calcolor)}, function(data){
|
2012-01-14 17:22:30 +04:00
|
|
|
if(data.status == 'success'){
|
2012-07-03 15:43:18 +04:00
|
|
|
$('#calendar_import_progressbar').progressbar('option', 'value', 100);
|
2012-07-04 00:33:24 +04:00
|
|
|
Calendar_Import.Store.percentage = 100;
|
2012-07-03 15:43:18 +04:00
|
|
|
$('#calendar_import_done').css('display', 'block');
|
|
|
|
$('#calendar_import_status').html(data.message);
|
|
|
|
}else{
|
|
|
|
$('#calendar_import_progressbar').progressbar('option', 'value', 100);
|
2012-07-04 00:33:24 +04:00
|
|
|
$('#calendar_import_progressbar > div').css('background-color', '#FF2626');
|
2012-07-03 15:43:18 +04:00
|
|
|
$('#calendar_import_status').html(data.message);
|
2012-01-14 17:22:30 +04:00
|
|
|
}
|
|
|
|
});
|
2012-07-01 23:36:09 +04:00
|
|
|
},
|
|
|
|
prepare: function(){
|
2012-07-03 15:43:18 +04:00
|
|
|
Calendar_Import.Store.id = $('#calendar_import_calendar option:selected').val();
|
|
|
|
if($('#calendar_import_calendar option:selected').val() == 'newcal'){
|
2012-07-01 23:36:09 +04:00
|
|
|
Calendar_Import.Store.method = 'new';
|
2012-07-03 15:43:18 +04:00
|
|
|
Calendar_Import.Store.calname = $.trim($('#calendar_import_newcalendar').val());
|
2012-07-01 23:36:09 +04:00
|
|
|
if(Calendar_Import.Store.calname == ''){
|
2012-07-03 15:43:18 +04:00
|
|
|
Calendar_Import.Dialog.warning('#calendar_import_newcalendar');
|
2012-07-01 23:36:09 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-07-04 23:14:40 +04:00
|
|
|
Calendar_Import.Store.calcolor = $.trim($('#calendar_import_newcalendar_color').val());
|
|
|
|
if(Calendar_Import.Store.calcolor == ''){
|
|
|
|
Calendar_Import.Store.calcolor = $('.calendar-colorpicker-color:first').attr('rel');
|
|
|
|
}
|
2012-01-13 16:57:46 +04:00
|
|
|
}else{
|
2012-07-03 15:43:18 +04:00
|
|
|
Calendar_Import.Store.method = 'old';
|
2012-01-13 16:57:46 +04:00
|
|
|
}
|
2012-07-03 15:43:18 +04:00
|
|
|
return true;
|
2012-07-01 23:36:09 +04:00
|
|
|
}
|
2012-01-13 01:06:53 +04:00
|
|
|
},
|
2012-07-03 15:43:18 +04:00
|
|
|
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;
|
2012-01-13 01:06:53 +04:00
|
|
|
}
|
2011-10-04 00:50:10 +04:00
|
|
|
}
|
|
|
|
$(document).ready(function(){
|
2012-01-13 01:06:53 +04:00
|
|
|
if(typeof FileActions !== 'undefined'){
|
2012-07-26 01:08:18 +04:00
|
|
|
FileActions.register('text/calendar','importCalendar', FileActions.PERMISSION_READ, '', Calendar_Import.Dialog.open);
|
2012-07-03 15:43:18 +04:00
|
|
|
FileActions.setDefault('text/calendar','importCalendar');
|
2012-01-13 01:06:53 +04:00
|
|
|
};
|
2012-02-20 14:27:25 +04:00
|
|
|
});
|