forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolbar.js
More file actions
294 lines (275 loc) · 9.71 KB
/
Copy pathToolbar.js
File metadata and controls
294 lines (275 loc) · 9.71 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
* 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 $ from 'jquery'
import I18n from 'i18n!react_files'
import React from 'react'
import ReactDOM from 'react-dom'
import page from 'page'
import Toolbar from 'compiled/react_files/components/Toolbar'
import FocusStore from 'compiled/react_files/modules/FocusStore'
import openMoveDialog from 'jsx/files/utils/openMoveDialog'
import deleteStuff from 'compiled/react_files/utils/deleteStuff'
import UploadButton from 'jsx/files/UploadButton'
import classnames from 'classnames'
import preventDefault from 'compiled/fn/preventDefault'
import Folder from 'compiled/models/Folder'
Toolbar.openPreview = function () {
FocusStore.setItemToFocus(ReactDOM.findDOMNode(this.refs.previewLink));
const queryString = $.param(this.props.getPreviewQuery());
page(`${this.props.getPreviewRoute()}?${queryString}`);
};
Toolbar.onSubmitSearch = function (event) {
event.preventDefault();
const searchTerm = ReactDOM.findDOMNode(this.refs.searchTerm).value;
page(`/search?search_term=${searchTerm}`);
};
Toolbar.renderUploadAddFolderButtons = function (canManage) {
var phoneHiddenSet = classnames({
'hidden-phone' : this.showingButtons
});
if (canManage) {
return (
<div className='ef-actions'>
<button
type= 'button'
onClick= {this.addFolder}
className='btn btn-add-folder'
aria-label= {I18n.t('Add Folder')}
>
<i className='icon-plus' />
<span className= {phoneHiddenSet} >
{I18n.t('Folder')}
</span>
</button>
<UploadButton
currentFolder= {this.props.currentFolder}
showingButtons= {this.showingButtons}
contextId= {this.props.contextId}
contextType= {this.props.contextType}
/>
</div>
);
}
}
Toolbar.renderDeleteButton = function (canManage) {
if (canManage) {
return (
<button
type= 'button'
disabled= {!this.showingButtons}
className= 'ui-button btn-delete'
onClick= { function () {
this.props.clearSelectedItems()
deleteStuff(this.props.selectedItems)
}.bind(this)
}
title= {I18n.t('Delete')}
aria-label= {I18n.t('Delete')}
data-tooltip=""
>
<i className='icon-trash' />
</button>
);
}
}
Toolbar.renderManageUsageRightsButton = function () {
if (this.props.userCanManageFilesForContext && this.props.usageRightsRequiredForContext) {
return (
<button
ref= 'usageRightsBtn'
type= 'button'
disabled= {!this.showingButtons}
className= 'Toolbar__ManageUsageRights ui-button btn-rights'
onClick= {this.openUsageRightsDialog}
title= {I18n.t('Manage Usage Rights')}
aria-label= {I18n.t('Manage Usage Rights')}
data-tooltip=""
>
<i className= 'icon-files-copyright' />
</button>
);
}
}
Toolbar.renderCopyCourseButton = function (canManage) {
if (canManage) {
return (
<button
type='button'
disabled= {!this.showingButtons}
className= 'ui-button btn-move'
onClick= {function(event) {
openMoveDialog(this.props.selectedItems, {
contextType: this.props.contextType,
contextId: this.props.contextId,
returnFocusTo: event.target,
clearSelectedItems: this.props.clearSelectedItems,
onMove: this.props.onMove
})
}.bind(this)}
title= {I18n.t('Move')}
aria-label= {I18n.t('Move')}
data-tooltip=""
>
<i className='icon-updown' />
</button>
);
}
}
Toolbar.renderDownloadButton = function () {
if (this.getItemsToDownload().length) {
if ((this.props.selectedItems.length === 1) && this.props.selectedItems[0].get('url')) {
return (
<a
className= 'ui-button btn-download'
href= {this.props.selectedItems[0].get('url')}
download= {true}
title= {this.downloadTitle}
aria-label= {this.downloadTitle}
data-tooltip=""
>
<i className='icon-download' />
</a>
);
} else {
return (
<button
type= 'button'
disabled= {!this.showingButtons}
className='ui-button btn-download'
onClick= {this.downloadSelectedAsZip}
title= {this.downloadTitle}
aria-label= {this.downloadTitle}
data-tooltip=""
>
<i className='icon-download'/>
</button>
);
}
}
}
Toolbar.componentDidUpdate = function (prevProps) {
if (prevProps.selectedItems.length !== this.props.selectedItems.length){
$.screenReaderFlashMessageExclusive(I18n.t({one: '%{count} item selected', other: '%{count} items selected'}, {count: this.props.selectedItems.length}))
}
}
Toolbar.renderRestrictedAccessButtons = function (canManage) {
if (canManage){
return (
<button
type= 'button'
disabled= {!this.showingButtons}
className= 'ui-button btn-restrict'
onClick= {this.openRestrictedDialog}
title= {I18n.t('Manage Access')}
aria-label= {I18n.t('Manage Access')}
data-tooltip=""
>
<i className= 'icon-cloud-lock' />
</button>
);
}
}
Toolbar.render = function () {
var selectedItemIsFolder = this.props.selectedItems.every(function(item) {
return item instanceof Folder;
});
var submissionsFolderSelected = this.props.currentFolder && this.props.currentFolder.get('for_submissions');
submissionsFolderSelected = submissionsFolderSelected || this.props.selectedItems.some(function(item) {
return item.get('for_submissions');
});
var restrictedByMasterCourse = this.props.selectedItems.some(function(item) {
return item.get('restricted_by_master_course') && item.get('is_master_course_child_content');
});
var canManage = this.props.userCanManageFilesForContext && !submissionsFolderSelected && !restrictedByMasterCourse;
this.showingButtons = this.props.selectedItems.length
if (this.showingButtons === 1) {
this.downloadTitle = I18n.t('Download');
}
var formClassName = classnames({
"ic-Input-group" : true,
"ef-search-form" : true,
"ef-search-form--showing-buttons" : this.showingButtons
});
var buttonSetClasses = classnames({
"ui-buttonset" : true,
"screenreader-only" : !this.showingButtons
});
var viewBtnClasses = classnames({
'ui-button': true,
'btn-view': true,
'Toolbar__ViewBtn--onlyfolders': selectedItemIsFolder
});
return (
<header
className='ef-header'
role='region'
aria-label= {I18n.t('Files Toolbar')}
>
<form
className= { formClassName }
onSubmit={this.onSubmitSearch}
>
<input
placeholder= {I18n.t('Search for files')}
aria-label= {I18n.t('Search for files')}
type= 'search'
ref='searchTerm'
className='ic-Input'
defaultValue= {this.props.query.search_term}
/>
<button
className='Button'
type='submit'
>
<i className='icon-search' />
<span className='screenreader-only'>
{I18n.t('Search for files') }
</span>
</button>
</form>
<div className='ef-header__secondary'>
<div className={buttonSetClasses}>
<a
ref= 'previewLink'
href= '#'
onClick= {!selectedItemIsFolder && preventDefault(this.openPreview)}
className= {viewBtnClasses}
title= {selectedItemIsFolder ? I18n.t('Viewing folders is not available') : I18n.t('View')}
role= 'button'
aria-label= {selectedItemIsFolder ? I18n.t('Viewing folders is not available') : I18n.t('View')}
data-tooltip=""
disabled= {!this.showingButtons || selectedItemIsFolder}
tabIndex= {selectedItemIsFolder ? -1 : 0}
>
<i className= 'icon-eye' />
</a>
{ this.renderRestrictedAccessButtons(canManage && this.props.userCanRestrictFilesForContext) }
{ this.renderDownloadButton() }
{ this.renderCopyCourseButton(canManage) }
{ this.renderManageUsageRightsButton(canManage) }
{ this.renderDeleteButton(canManage) }
</div>
<span className= 'ef-selected-count hidden-tablet hidden-phone'>
{I18n.t({one: '%{count} item selected', other: '%{count} items selected'}, {count: this.props.selectedItems.length})}
</span>
{ this.renderUploadAddFolderButtons(canManage) }
</div>
</header>
);
}
export default React.createClass(Toolbar)