loader.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. Contacts_Import={
  8. importdialog: function(filename){
  9. var path = $('#dir').val();
  10. $('body').append('<div id="contacts_import"></div>');
  11. $('#contacts_import').load(OC.filePath('contacts', 'ajax', 'importdialog.php'), {filename:filename, path:path}, function(){Contacts_Import.initdialog(filename);});
  12. },
  13. initdialog: function(filename){
  14. $('#contacts_import_dialog').dialog({
  15. width : 500,
  16. close : function() {
  17. $(this).dialog('destroy').remove();
  18. $('#contacts_import').remove();
  19. }
  20. });
  21. $('#import_done_button').click(function(){
  22. $('#contacts_import_dialog').dialog('destroy').remove();
  23. $('#contacts_import').remove();
  24. });
  25. $('#progressbar').progressbar({value: 0});
  26. $('#startimport').click(function(){
  27. var filename = $('#filename').val();
  28. var path = $('#path').val();
  29. var method = 'old';
  30. var addressbookid = $('#contacts option:selected').val();
  31. if($('#contacts option:selected').val() == 'newaddressbook'){
  32. var method = 'new';
  33. var addressbookname = $('#newaddressbook').val();
  34. var addressbookname = $.trim(addressbookname);
  35. if(addressbookname == ''){
  36. $('#newaddressbook').css('background-color', '#FF2626');
  37. $('#newaddressbook').focus(function(){
  38. $('#newaddressbook').css('background-color', '#F8F8F8');
  39. });
  40. return false;
  41. }
  42. }
  43. $('#newaddressbook').attr('readonly', 'readonly');
  44. $('#contacts').attr('disabled', 'disabled');
  45. var progressfile = $('#progressfile').val();
  46. $.post(OC.filePath('contacts', '', 'import.php'), {method: String (method), addressbookname: String (addressbookname), path: String (path), file: String (filename), id: String (addressbookid)}, function(jsondata){
  47. if(jsondata.status == 'success'){
  48. $('#progressbar').progressbar('option', 'value', 100);
  49. $('#import_done').find('p').html(t('contacts', 'Result: ') + jsondata.data.imported + t('contacts', ' imported, ') + jsondata.data.failed + t('contacts', ' failed.'));
  50. } else {
  51. $('#import_done').find('p').html(jsondata.message);
  52. }
  53. $('#import_done').show().find('p').addClass('bold');
  54. $('#progressbar').fadeOut('slow');
  55. });
  56. $('#form_container').css('display', 'none');
  57. $('#progressbar_container').css('display', 'block');
  58. window.setTimeout('Contacts_Import.getimportstatus(\'' + progressfile + '\')', 500);
  59. });
  60. $('#contacts').change(function(){
  61. if($('#contacts option:selected').val() == 'newaddressbook'){
  62. $('#newaddressbookform').slideDown('slow');
  63. }else{
  64. $('#newaddressbookform').slideUp('slow');
  65. }
  66. });
  67. },
  68. getimportstatus: function(progressfile){
  69. $.get(OC.filePath('contacts', 'import_tmp', progressfile), function(percent){
  70. $('#progressbar').progressbar('option', 'value', parseInt(percent));
  71. if(percent < 100){
  72. window.setTimeout('Contacts_Import.getimportstatus(\'' + progressfile + '\')', 500);
  73. }else{
  74. $('#import_done').css('display', 'block');
  75. }
  76. });
  77. }
  78. }
  79. $(document).ready(function(){
  80. if(typeof FileActions !== 'undefined'){
  81. FileActions.register('text/vcard','importaddressbook', '', Contacts_Import.importdialog);
  82. FileActions.setDefault('text/vcard','importaddressbook');
  83. FileActions.register('text/x-vcard','importaddressbook', '', Contacts_Import.importdialog);
  84. FileActions.setDefault('text/x-vcard','importaddressbook');
  85. };
  86. });