ShowFolder.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright (C) 2015 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. import React from 'react'
  19. import _ from 'underscore'
  20. import I18n from 'i18n!react_files'
  21. import ShowFolder from 'compiled/react_files/components/ShowFolder'
  22. import FilePreview from 'jsx/files/FilePreview'
  23. import FolderChild from 'jsx/files/FolderChild'
  24. import UploadDropZone from 'jsx/files/UploadDropZone'
  25. import ColumnHeaders from 'jsx/files/ColumnHeaders'
  26. import CurrentUploads from 'jsx/files/CurrentUploads'
  27. import LoadingIndicator from 'jsx/files/LoadingIndicator'
  28. import page from 'page'
  29. import FocusStore from 'compiled/react_files/modules/FocusStore'
  30. ShowFolder.closeFilePreview = function (url) {
  31. page(url)
  32. FocusStore.setFocusToItem();
  33. }
  34. ShowFolder.renderFilePreview = function () {
  35. /* Prepare and render the FilePreview if needed.
  36. As long as ?preview is present in the url.
  37. */
  38. if (this.props.query.preview != null) {
  39. return (
  40. <FilePreview
  41. isOpen={true}
  42. usageRightsRequiredForContext={this.props.usageRightsRequiredForContext}
  43. currentFolder={this.props.currentFolder}
  44. params={this.props.params}
  45. query={this.props.query}
  46. pathname={this.props.pathname}
  47. splat={this.props.splat}
  48. closePreview={this.closeFilePreview}
  49. />
  50. );
  51. }
  52. }
  53. ShowFolder.renderFolderChildOrEmptyContainer = function () {
  54. if(this.props.currentFolder.isEmpty()) {
  55. return (
  56. <div ref='folderEmpty' className='muted'>
  57. {I18n.t('this_folder_is_empty', 'This folder is empty')}
  58. </div>
  59. );
  60. }
  61. else {
  62. return (
  63. this.props.currentFolder.children(this.props.query).map((child) => {
  64. return(
  65. <FolderChild
  66. key={child.cid}
  67. model={child}
  68. isSelected={(_.indexOf(this.props.selectedItems, child)) >= 0}
  69. toggleSelected={ this.props.toggleItemSelected.bind(null, child) }
  70. userCanManageFilesForContext={this.props.userCanManageFilesForContext}
  71. userCanRestrictFilesForContext={this.props.userCanRestrictFilesForContext}
  72. usageRightsRequiredForContext={this.props.usageRightsRequiredForContext}
  73. externalToolsForContext={this.props.externalToolsForContext}
  74. previewItem={this.props.previewItem.bind(null, child)}
  75. dndOptions={this.props.dndOptions}
  76. modalOptions={this.props.modalOptions}
  77. clearSelectedItems={this.props.clearSelectedItems}
  78. onMove={this.props.onMove}
  79. />
  80. );
  81. })
  82. );
  83. }
  84. }
  85. ShowFolder.render = function () {
  86. var currentState = this.state || {};
  87. if (currentState.errorMessages) {
  88. return (
  89. <div>
  90. {
  91. currentState.errorMessages.map(function(error){
  92. <div className='muted'>
  93. {error.message}
  94. </div>
  95. })
  96. }
  97. </div>
  98. );
  99. }
  100. if (!this.props.currentFolder) {
  101. return(<div ref='emptyDiv'></div>);
  102. }
  103. var folderOrRootFolder;
  104. if (this.props.params.splat){
  105. folderOrRootFolder = 'folder';
  106. }else{
  107. folderOrRootFolder = 'rootFolder';
  108. }
  109. var foldersNextPageOrFilesNextPage = this.props.currentFolder.folders.fetchingNextPage || this.props.currentFolder.files.fetchingNextPage;
  110. return (
  111. <div role='grid' style={{flex: "1 1 auto"}} >
  112. <div
  113. ref='accessibilityMessage'
  114. className='ShowFolder__accessbilityMessage col-xs'
  115. tabIndex={0}
  116. >
  117. {I18n.t("Warning: For improved accessibility in moving files, please use the Move To Dialog option found in the menu.")}
  118. </div>
  119. <UploadDropZone currentFolder={this.props.currentFolder} />
  120. <CurrentUploads />
  121. <ColumnHeaders
  122. ref='columnHeaders'
  123. query={this.props.query}
  124. pathname={this.props.pathname}
  125. toggleAllSelected={this.props.toggleAllSelected}
  126. areAllItemsSelected={this.props.areAllItemsSelected}
  127. usageRightsRequiredForContext={this.props.usageRightsRequiredForContext}
  128. />
  129. { this.renderFolderChildOrEmptyContainer() }
  130. <LoadingIndicator isLoading={foldersNextPageOrFilesNextPage} />
  131. {this.renderFilePreview() }
  132. </div>
  133. );
  134. }
  135. export default React.createClass(ShowFolder)