forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsageRightsDialog.js
More file actions
209 lines (194 loc) · 6.85 KB
/
Copy pathUsageRightsDialog.js
File metadata and controls
209 lines (194 loc) · 6.85 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
/*
* 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 UsageRightsDialog from 'compiled/react_files/components/UsageRightsDialog'
import I18n from 'i18n!usage_rights_modal'
import UsageRightsSelectBox from 'jsx/files/UsageRightsSelectBox'
import RestrictedRadioButtons from 'jsx/files/RestrictedRadioButtons'
import DialogPreview from 'jsx/files/DialogPreview'
import Folder from 'compiled/models/Folder'
import htmlEscape from 'str/htmlEscape'
var MAX_THUMBNAILS_TO_SHOW = 5;
var MAX_FOLDERS_TO_SHOW = 2;
UsageRightsDialog.renderFileName = function () {
var textToShow = (this.props.itemsToManage.length > 1) ?
I18n.t('%{items} items selected', {items: this.props.itemsToManage.length}) :
this.props.itemsToManage[0].displayName();
return (
<span ref='fileName' className='UsageRightsDialog__fileName'>{textToShow}</span>
);
};
UsageRightsDialog.renderFolderList = function (folders) {
if (folders.length) {
var foldersToShow = folders.slice(0, MAX_FOLDERS_TO_SHOW);
return (
<div>
<span>{I18n.t("Usage rights will be set for all of the files contained in:")}</span>
<ul ref='folderBulletList' className='UsageRightsDialog__folderBulletList'>
{foldersToShow.map((item) => {
return (<li>{item.displayName()}</li>);
})}
</ul>
</div>
);
} else {
return null;
}
};
UsageRightsDialog.renderFolderTooltip = function (folders) {
var toolTipFolders = folders.slice(MAX_FOLDERS_TO_SHOW);
if (toolTipFolders.length) {
var displayNames = toolTipFolders.map((item) => {return htmlEscape(item.displayName()).toString();});
// Doing it this way so commas, don't show up when rendering the list out in the tooltip.
var renderedNames = displayNames.join('<br />');
return (
<span
className='UsageRightsDialog__andMore'
tabIndex='0'
ref='folderTooltip'
data-html-tooltip-title={renderedNames}
data-tooltip='right'
data-tooltip-class='UsageRightsDialog__tooltip'
>
{I18n.t('and %{count} more…', {count: toolTipFolders.length})}
<span className='screenreader-only'>
<ul>
{displayNames.map((item) => {
return (<li ref='displayNameTooltip-screenreader'> {item}</li>);
})}
</ul>
</span>
</span>
);
} else {
return null;
}
}
UsageRightsDialog.renderFolderMessage = function () {
var folders = this.props.itemsToManage.filter((item) => {
return item instanceof Folder;
});
return (
<div>
{this.renderFolderList(folders)}
{this.renderFolderTooltip(folders)}
<hr />
</div>
);
};
UsageRightsDialog.renderDifferentRightsMessage = function () {
if ((this.copyright == null || this.use_justification === 'choose') &&
this.props.itemsToManage.length > 1) {
return (
<span ref='differentRightsMessage' className='UsageRightsDialog__differentRightsMessage alert'>
<i className='icon-warning UsageRightsDialog__warning' />
{I18n.t('Items selected have different usage rights.')}
</span>
);
}
};
UsageRightsDialog.renderAccessManagement = function () {
if (this.props.userCanRestrictFilesForContext) {
return (
<div>
<hr />
<div className='form-horizontal'>
<p className="manage-access">{I18n.t("You can also manage access at this time:")}</p>
<RestrictedRadioButtons
ref='restrictedSelection'
models={this.props.itemsToManage}
>
</RestrictedRadioButtons>
</div>
</div>
);
}
};
UsageRightsDialog.render = function () {
return (
<div className='ReactModal__Layout'>
<div className='ReactModal__Header'>
<div className='ReactModal__Header-Title'>
<h4>
{I18n.t('Manage Usage Rights')}
</h4>
</div>
<div className='ReactModal__Header-Actions'>
<button
ref='cancelXButton'
className='Button Button--icon-action'
type='button'
onClick={this.props.closeModal}
>
<i className='icon-x'>
<span className='screenreader-only'>
{I18n.t('Close')}
</span>
</i>
</button>
</div>
</div>
<div className='ReactModal__Body'>
<div ref='form'>
<div>
<div className='UsageRightsDialog__paddingFix grid-row'>
<div className='UsageRightsDialog__previewColumn col-xs-3'>
<DialogPreview itemsToShow={this.props.itemsToManage} >
</DialogPreview>
</div>
<div className='UsageRightsDialog__contentColumn off-xs-1 col-xs-8'>
{this.renderDifferentRightsMessage()}
{this.renderFileName()}
{this.renderFolderMessage()}
<UsageRightsSelectBox
ref='usageSelection'
use_justification={this.use_justification}
copyright={this.copyright || ''}
cc_value={this.cc_value}
>
</UsageRightsSelectBox>
{this.renderAccessManagement()}
</div>
</div>
</div>
</div>
</div>
<div className='ReactModal__Footer'>
<div className='ReactModal__Footer-Actions'>
<button
ref='cancelButton'
type='button'
className='btn'
onClick={this.props.closeModal}
>
{I18n.t('Cancel')}
</button>
<button
ref='saveButton'
type='button'
className='btn btn-primary'
onClick={this.submit}
>
{I18n.t('Save')}
</button>
</div>
</div>
</div>
);
};
export default React.createClass(UsageRightsDialog)