printfile.html.php 4.2 KB

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