loader.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. Store:{
  9. file: '',
  10. path: '',
  11. id: 0,
  12. method: '',
  13. calname: '',
  14. calcolor: '',
  15. progresskey: '',
  16. percentage: 0
  17. },
  18. Dialog:{
  19. open: function(filename){
  20. OC.addStyle('calendar', 'import');
  21. Calendar_Import.Store.file = filename;
  22. Calendar_Import.Store.path = $('#dir').val();
  23. $('body').append('<div id="calendar_import"></div>');
  24. $('#calendar_import').load(OC.filePath('calendar', 'ajax/import', 'dialog.php'), {filename:Calendar_Import.Store.file, path:Calendar_Import.Store.path},function(){
  25. Calendar_Import.Dialog.init();
  26. });
  27. },
  28. close: function(){
  29. Calendar_Import.reset();
  30. $(this).dialog('destroy').remove();
  31. $('#calendar_import_dialog').remove();
  32. },
  33. init: function(){
  34. //init dialog
  35. $('#calendar_import_dialog').dialog({
  36. width : 500,
  37. resizable: false,
  38. close : function() {
  39. Calendar_Import.Dialog.close();
  40. }
  41. });
  42. //init buttons
  43. $('#calendar_import_done').click(function(){
  44. Calendar_Import.Dialog.close();
  45. });
  46. $('#calendar_import_submit').click(function(){
  47. Calendar_Import.Core.process();
  48. });
  49. $('#calendar_import_mergewarning').click(function(){
  50. $('#calendar_import_newcalendar').attr('value', $('#calendar_import_availablename').val());
  51. Calendar_Import.Dialog.mergewarning($('#calendar_import_newcalendar').val());
  52. });
  53. $('#calendar_import_calendar').change(function(){
  54. if($('#calendar_import_calendar option:selected').val() == 'newcal'){
  55. $('#calendar_import_newcalform').slideDown('slow');
  56. Calendar_Import.Dialog.mergewarning($('#calendar_import_newcalendar').val());
  57. }else{
  58. $('#calendar_import_newcalform').slideUp('slow');
  59. $('#calendar_import_mergewarning').slideUp('slow');
  60. }
  61. });
  62. $('#calendar_import_newcalendar').keyup(function(){
  63. Calendar_Import.Dialog.mergewarning($.trim($('#calendar_import_newcalendar').val()));
  64. });
  65. $('#calendar_import_newcalendar_color').miniColors({
  66. letterCase: 'uppercase'
  67. });
  68. $('.calendar-colorpicker-color').click(function(){
  69. var str = $(this).attr('rel');
  70. str = str.substr(1);
  71. $('#calendar_import_newcalendar_color').attr('value', str);
  72. $(".color-picker").miniColors('value', '#' + str);
  73. });
  74. //init progressbar
  75. $('#calendar_import_progressbar').progressbar({value: Calendar_Import.Store.percentage});
  76. Calendar_Import.Store.progresskey = $('#calendar_import_progresskey').val();
  77. },
  78. mergewarning: function(newcalname){
  79. $.post(OC.filePath('calendar', 'ajax/import', 'calendarcheck.php'), {calname: newcalname}, function(data){
  80. if(data.message == 'exists'){
  81. $('#calendar_import_mergewarning').slideDown('slow');
  82. }else{
  83. $('#calendar_import_mergewarning').slideUp('slow');
  84. }
  85. });
  86. },
  87. update: function(){
  88. if(Calendar_Import.Store.percentage == 100){
  89. return false;
  90. }
  91. $.post(OC.filePath('calendar', 'ajax/import', 'import.php'), {progresskey: Calendar_Import.Store.progresskey, getprogress: true}, function(data){
  92. if(data.status == 'success'){
  93. if(data.percent == null){
  94. return false;
  95. }
  96. Calendar_Import.Store.percentage = parseInt(data.percent);
  97. $('#calendar_import_progressbar').progressbar('option', 'value', parseInt(data.percent));
  98. if(data.percent < 100 ){
  99. window.setTimeout('Calendar_Import.Dialog.update()', 250);
  100. }else{
  101. $('#calendar_import_done').css('display', 'block');
  102. }
  103. }else{
  104. $('#calendar_import_progressbar').progressbar('option', 'value', 100);
  105. $('#calendar_import_progressbar > div').css('background-color', '#FF2626');
  106. $('#calendar_import_status').html(data.message);
  107. }
  108. });
  109. return 0;
  110. },
  111. warning: function(selector){
  112. $(selector).addClass('calendar_import_warning');
  113. $(selector).focus(function(){
  114. $(selector).removeClass('calendar_import_warning');
  115. });
  116. }
  117. },
  118. Core:{
  119. process: function(){
  120. var validation = Calendar_Import.Core.prepare();
  121. if(validation){
  122. $('#calendar_import_form').css('display', 'none');
  123. $('#calendar_import_process').css('display', 'block');
  124. $('#calendar_import_newcalendar').attr('readonly', 'readonly');
  125. $('#calendar_import_calendar').attr('disabled', 'disabled');
  126. Calendar_Import.Core.send();
  127. window.setTimeout('Calendar_Import.Dialog.update()', 250);
  128. }
  129. },
  130. send: function(){
  131. $.post(OC.filePath('calendar', 'ajax/import', 'import.php'),
  132. {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){
  133. if(data.status == 'success'){
  134. $('#calendar_import_progressbar').progressbar('option', 'value', 100);
  135. Calendar_Import.Store.percentage = 100;
  136. $('#calendar_import_done').css('display', 'block');
  137. $('#calendar_import_status').html(data.message);
  138. }else{
  139. $('#calendar_import_progressbar').progressbar('option', 'value', 100);
  140. $('#calendar_import_progressbar > div').css('background-color', '#FF2626');
  141. $('#calendar_import_status').html(data.message);
  142. }
  143. });
  144. },
  145. prepare: function(){
  146. Calendar_Import.Store.id = $('#calendar_import_calendar option:selected').val();
  147. if($('#calendar_import_calendar option:selected').val() == 'newcal'){
  148. Calendar_Import.Store.method = 'new';
  149. Calendar_Import.Store.calname = $.trim($('#calendar_import_newcalendar').val());
  150. if(Calendar_Import.Store.calname == ''){
  151. Calendar_Import.Dialog.warning('#calendar_import_newcalendar');
  152. return false;
  153. }
  154. Calendar_Import.Store.calcolor = $.trim($('#calendar_import_newcalendar_color').val());
  155. if(Calendar_Import.Store.calcolor == ''){
  156. Calendar_Import.Store.calcolor = $('.calendar-colorpicker-color:first').attr('rel');
  157. }
  158. }else{
  159. Calendar_Import.Store.method = 'old';
  160. }
  161. return true;
  162. }
  163. },
  164. reset: function(){
  165. Calendar_Import.Store.file = '';
  166. Calendar_Import.Store.path = '';
  167. Calendar_Import.Store.id = 0;
  168. Calendar_Import.Store.method = '';
  169. Calendar_Import.Store.calname = '';
  170. Calendar_Import.Store.progresskey = '';
  171. Calendar_Import.Store.percentage = 0;
  172. }
  173. }
  174. $(document).ready(function(){
  175. if(typeof FileActions !== 'undefined'){
  176. FileActions.register('text/calendar','importCalendar', '', Calendar_Import.Dialog.open);
  177. FileActions.setDefault('text/calendar','importCalendar');
  178. };
  179. });