loader.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
  3. * This file is licensed under the Affero General Public License version 3 or
  4. * later.
  5. * See the COPYING-README file.
  6. */
  7. Calendar_Import={
  8. importdialog: function(filename){
  9. var path = $('#dir').val();
  10. $('body').append('<div id="calendar_import"></div>');
  11. $('#calendar_import').load(OC.filePath('calendar', 'ajax/import', 'dialog.php'), {filename:filename, path:path}, function(){Calendar_Import.initdialog(filename);});
  12. },
  13. initdialog: function(filename){
  14. $('#calendar_import_dialog').dialog({
  15. width : 500,
  16. close : function() {
  17. $(this).dialog('destroy').remove();
  18. $('#calendar_import').remove();
  19. }
  20. });
  21. $('#import_done_button').click(function(){
  22. $('#calendar_import_dialog').dialog('destroy').remove();
  23. $('#calendar_import').remove();
  24. });
  25. $('#progressbar').progressbar({value: 0});
  26. $('#startimport').click(function(){
  27. var filename = $('#filename').val();
  28. var path = $('#path').val();
  29. var calid = $('#calendar option:selected').val();
  30. if($('#calendar option:selected').val() == 'newcal'){
  31. var method = 'new';
  32. var calname = $('#newcalendar').val();
  33. var calname = $.trim(calname);
  34. if(calname == ''){
  35. $('#newcalendar').css('background-color', '#FF2626');
  36. $('#newcalendar').focus(function(){
  37. $('#newcalendar').css('background-color', '#F8F8F8');
  38. });
  39. return false;
  40. }
  41. }else{
  42. var method = 'old';
  43. }
  44. $('#newcalendar').attr('readonly', 'readonly');
  45. $('#calendar').attr('disabled', 'disabled');
  46. var progressfile = $('#progressfile').val();
  47. $.post(OC.filePath('calendar', 'ajax/import', 'import.php'), {method: String (method), calname: String (calname), path: String (path), file: String (filename), id: String (calid)}, function(data){
  48. if(data.status == 'success'){
  49. $('#progressbar').progressbar('option', 'value', 100);
  50. $('#import_done').css('display', 'block');
  51. }
  52. });
  53. $('#form_container').css('display', 'none');
  54. $('#progressbar_container').css('display', 'block');
  55. window.setTimeout('Calendar_Import.getimportstatus(\'' + progressfile + '\')', 500);
  56. });
  57. $('#calendar').change(function(){
  58. if($('#calendar option:selected').val() == 'newcal'){
  59. $('#newcalform').slideDown('slow');
  60. }else{
  61. $('#newcalform').slideUp('slow');
  62. }
  63. });
  64. },
  65. getimportstatus: function(progressfile){
  66. $.get(OC.filePath('calendar', 'import_tmp', progressfile), function(percent){
  67. $('#progressbar').progressbar('option', 'value', parseInt(percent));
  68. if(percent < 100){
  69. window.setTimeout('Calendar_Import.getimportstatus(\'' + progressfile + '\')', 500);
  70. }else{
  71. $('#import_done').css('display', 'block');
  72. }
  73. });
  74. }
  75. }
  76. $(document).ready(function(){
  77. if(typeof FileActions !== 'undefined'){
  78. FileActions.register('text/calendar','importcal', '', Calendar_Import.importdialog);
  79. FileActions.setDefault('text/calendar','importcal');
  80. };
  81. });