nextcloud/apps/calendar/js/loader.js

123 lines
3.8 KiB
JavaScript
Raw Normal View History

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: '',
progresskey: '',
percentage: 0
}
Dialog:{
open: function(filename){
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(){
$(this).dialog('destroy').remove();
2012-01-14 17:22:30 +04:00
$('#calendar_import').remove();
2012-07-01 23:36:09 +04:00
},
init: function(){
//init dialog
$('#calendar_import_dialog').dialog({
width : 500,
close : function() {
Calendar_Import.Dialog.close();
2012-01-13 16:57:46 +04:00
}
2012-07-01 23:36:09 +04:00
});
//init buttons
$('#import_done_button').click(function(){
Calendar_Import.closedialog();
});
$('#startimport').click(function(){
Calendar_import.Core.process();
}
$('#calendar').change(function(){
if($('#calendar option:selected').val() == 'newcal'){
$('#newcalform').slideDown('slow');
}else{
$('#newcalform').slideUp('slow');
}
});
//init progressbar
$('#progressbar').progressbar({value: Calendar_Import.Store.percentage});
Calendar_Import.Store.progresskey = $('#progresskey').val();
},
mergewarning: function(){
},
update: function(){
/*$.post(OC.filePath('calendar', 'ajax/import', 'import.php'), {progress:1,progresskey: progresskey}, function(percent){
$('#progressbar').progressbar('option', 'value', parseInt(percent));
if(percent < 100){
window.setTimeout('Calendar_Import.getimportstatus(\'' + progresskey + '\')', 500);
}else{
$('#import_done').css('display', 'block');
}
});*/
return 0;
},
warning: function(validation){
}
},
Core:{
process: function(){
var validation = Calendar.Core.prepare();
if(validation){
$('#newcalendar').attr('readonly', 'readonly');
$('#calendar').attr('disabled', 'disabled');
Calendar.Core.send();
2012-01-13 16:57:46 +04:00
}else{
2012-07-01 23:36:09 +04:00
Calendar.Dialog.warning(validation);
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'),
{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){
2012-01-14 17:22:30 +04:00
if(data.status == 'success'){
$('#progressbar').progressbar('option', 'value', 100);
$('#import_done').css('display', 'block');
2012-07-01 23:36:09 +04:00
$('#status').html(data.message);
2012-01-14 17:22:30 +04:00
}
});
$('#form_container').css('display', 'none');
$('#progressbar_container').css('display', 'block');
2012-07-01 23:36:09 +04:00
window.setTimeout('Calendar_Import.Dialog.update', 500);
},
prepare: function(){
Calendar_Import.Store.id = $('#calendar option:selected').val();
2012-01-13 16:57:46 +04:00
if($('#calendar option:selected').val() == 'newcal'){
2012-07-01 23:36:09 +04:00
Calendar_Import.Store.method = 'new';
Calendar_Import.Store.calname = $.trim($('#newcalendar').val());
if(Calendar_Import.Store.calname == ''){
$('#newcalendar').css('background-color', '#FF2626');
$('#newcalendar').focus(function(){
$('#newcalendar').css('background-color', '#F8F8F8');
});
return false;
}
2012-01-14 17:22:30 +04:00
}else{
2012-07-01 23:36:09 +04:00
var method = 'old';
2012-01-14 17:22:30 +04:00
}
2012-07-01 23:36:09 +04:00
}
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'){
FileActions.register('text/calendar','importcal', '', Calendar_Import.importdialog);
FileActions.setDefault('text/calendar','importcal');
};
2012-02-20 14:27:25 +04:00
});