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