v1.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. $(document).ready(function()
  2. {
  3. $('li.file').on('mouseover', function()
  4. {
  5. $(this).children('span.right-icon').removeClass("hidden");
  6. $(this).addClass('backgroundColor');
  7. });
  8. $('li.file').on('mouseout', function()
  9. {
  10. $(this).children('span.right-icon').addClass("hidden");
  11. $(this).removeClass('backgroundColor');
  12. });
  13. });
  14. /**
  15. * Delete a file.
  16. *
  17. * @param int $fileID
  18. * @param object $obj
  19. * @access public
  20. * @return void
  21. */
  22. window.deleteFile = function(fileID, obj)
  23. {
  24. if(!fileID) return;
  25. const method = $(obj).closest('.files-list').parent().data('method');
  26. const showDelete = $(obj).closest('.files-list').parent().data('showdelete');
  27. const objectType = $(obj).closest('.files-list').parent().data('objecttype');
  28. if(showDelete && method == 'edit')
  29. {
  30. $('<input />').attr('type', 'hidden').attr('name', 'deleteFiles[' + fileID + ']').attr('value', fileID).appendTo('ul.files-list');
  31. $(obj).closest('li.file').addClass('hidden');
  32. }
  33. else
  34. {
  35. const deleteModule = objectType == 'doc' ? 'doc' : 'file';
  36. const deleteMethod = objectType == 'doc' ? 'deleteFile' : 'delete';
  37. const objectID = $(obj).closest('.files-list').parent().data('objectid');
  38. const deleteParams = objectType == 'doc' ? `docID=${objectID}&fileID=${fileID}` : `fileID=${fileID}`;
  39. $.ajaxSubmit(
  40. {
  41. url:$.createLink(deleteModule, deleteMethod, deleteParams),
  42. load: ['release', 'build'].includes(config.currentModule) && config.currentMethod == 'view' ? false : true
  43. })
  44. }
  45. }
  46. /**
  47. * Download a file, append the mouse to the link. Thus we call decide to open the file in browser no download it.
  48. *
  49. * @param int $fileID
  50. * @param string $extension
  51. * @param int $imageWidth
  52. * @param string $fileTitle
  53. * @access public
  54. * @return bool
  55. */
  56. window.downloadFile = function(fileID, extension, imageWidth, fileTitle)
  57. {
  58. if(!fileID) return true;
  59. const sessionString = $('ul.files-list').parent().data('session');
  60. var fileTypes = 'txt,jpg,jpeg,gif,png,bmp'.split(',');
  61. var windowWidth = $(window).width();
  62. var width = (windowWidth > imageWidth) ? ((imageWidth < windowWidth * 0.5) ? windowWidth * 0.5 : imageWidth) : windowWidth;
  63. var checkExtension = fileTitle.lastIndexOf('.' + extension) == (fileTitle.length - extension.length - 1);
  64. var url = $.createLink('file', 'download', 'fileID=' + fileID + '&mouse=left');
  65. url += url.indexOf('?') >= 0 ? '&' : '?';
  66. url += sessionString;
  67. if(fileTypes.includes(extension) && checkExtension)
  68. {
  69. zui.Modal.open({url, key: 'previewFile'});
  70. }
  71. else
  72. {
  73. open(url, '_blank');
  74. }
  75. return false;
  76. }
  77. /**
  78. * Show edit box for editing file name.
  79. *
  80. * @param int $fileID
  81. * @access public
  82. * @return void
  83. */
  84. window.showRenameBox = function(fileID)
  85. {
  86. $('#renameFile' + fileID).closest('li').addClass('hidden');
  87. $('#renameBox' + fileID).closest('li').removeClass('hidden');
  88. }
  89. /**
  90. * Show File.
  91. *
  92. * @param int $fileID
  93. * @access public
  94. * @return void
  95. */
  96. window.showFile = function(fileID)
  97. {
  98. $('#renameBox' + fileID).closest('li').addClass('hidden');
  99. $('#renameFile' + fileID).closest('li').removeClass('hidden');
  100. }
  101. /**
  102. * Smooth refresh file name.
  103. *
  104. * @param int $fileID
  105. * @access public
  106. * @return void
  107. */
  108. window.setFileName = function(fileID)
  109. {
  110. var fileName = $('#fileName' + fileID).val();
  111. var extension = $('#extension' + fileID).val();
  112. var postData = {'fileName' : fileName, 'extension' : extension};
  113. $.ajaxSubmit(
  114. {
  115. url:$.createLink('file', 'edit', 'fileID=' + fileID),
  116. dataType: 'json',
  117. method: 'post',
  118. data: postData,
  119. load: typeof loadFileUrl !== 'undefined' ? loadFileUrl : true
  120. })
  121. }