UsageRightsDialog.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 UsageRightsDialog from 'compiled/react_files/components/UsageRightsDialog'
  20. import I18n from 'i18n!usage_rights_modal'
  21. import UsageRightsSelectBox from 'jsx/files/UsageRightsSelectBox'
  22. import RestrictedRadioButtons from 'jsx/files/RestrictedRadioButtons'
  23. import DialogPreview from 'jsx/files/DialogPreview'
  24. import Folder from 'compiled/models/Folder'
  25. import htmlEscape from 'str/htmlEscape'
  26. var MAX_THUMBNAILS_TO_SHOW = 5;
  27. var MAX_FOLDERS_TO_SHOW = 2;
  28. UsageRightsDialog.renderFileName = function () {
  29. var textToShow = (this.props.itemsToManage.length > 1) ?
  30. I18n.t('%{items} items selected', {items: this.props.itemsToManage.length}) :
  31. this.props.itemsToManage[0].displayName();
  32. return (
  33. <span ref='fileName' className='UsageRightsDialog__fileName'>{textToShow}</span>
  34. );
  35. };
  36. UsageRightsDialog.renderFolderList = function (folders) {
  37. if (folders.length) {
  38. var foldersToShow = folders.slice(0, MAX_FOLDERS_TO_SHOW);
  39. return (
  40. <div>
  41. <span>{I18n.t("Usage rights will be set for all of the files contained in:")}</span>
  42. <ul ref='folderBulletList' className='UsageRightsDialog__folderBulletList'>
  43. {foldersToShow.map((item) => {
  44. return (<li>{item.displayName()}</li>);
  45. })}
  46. </ul>
  47. </div>
  48. );
  49. } else {
  50. return null;
  51. }
  52. };
  53. UsageRightsDialog.renderFolderTooltip = function (folders) {
  54. var toolTipFolders = folders.slice(MAX_FOLDERS_TO_SHOW);
  55. if (toolTipFolders.length) {
  56. var displayNames = toolTipFolders.map((item) => {return htmlEscape(item.displayName()).toString();});
  57. // Doing it this way so commas, don't show up when rendering the list out in the tooltip.
  58. var renderedNames = displayNames.join('<br />');
  59. return (
  60. <span
  61. className='UsageRightsDialog__andMore'
  62. tabIndex='0'
  63. ref='folderTooltip'
  64. data-html-tooltip-title={renderedNames}
  65. data-tooltip='right'
  66. data-tooltip-class='UsageRightsDialog__tooltip'
  67. >
  68. {I18n.t('and %{count} more…', {count: toolTipFolders.length})}
  69. <span className='screenreader-only'>
  70. <ul>
  71. {displayNames.map((item) => {
  72. return (<li ref='displayNameTooltip-screenreader'> {item}</li>);
  73. })}
  74. </ul>
  75. </span>
  76. </span>
  77. );
  78. } else {
  79. return null;
  80. }
  81. }
  82. UsageRightsDialog.renderFolderMessage = function () {
  83. var folders = this.props.itemsToManage.filter((item) => {
  84. return item instanceof Folder;
  85. });
  86. return (
  87. <div>
  88. {this.renderFolderList(folders)}
  89. {this.renderFolderTooltip(folders)}
  90. <hr />
  91. </div>
  92. );
  93. };
  94. UsageRightsDialog.renderDifferentRightsMessage = function () {
  95. if ((this.copyright == null || this.use_justification === 'choose') &&
  96. this.props.itemsToManage.length > 1) {
  97. return (
  98. <span ref='differentRightsMessage' className='UsageRightsDialog__differentRightsMessage alert'>
  99. <i className='icon-warning UsageRightsDialog__warning' />
  100. {I18n.t('Items selected have different usage rights.')}
  101. </span>
  102. );
  103. }
  104. };
  105. UsageRightsDialog.renderAccessManagement = function () {
  106. if (this.props.userCanRestrictFilesForContext) {
  107. return (
  108. <div>
  109. <hr />
  110. <div className='form-horizontal'>
  111. <p className="manage-access">{I18n.t("You can also manage access at this time:")}</p>
  112. <RestrictedRadioButtons
  113. ref='restrictedSelection'
  114. models={this.props.itemsToManage}
  115. >
  116. </RestrictedRadioButtons>
  117. </div>
  118. </div>
  119. );
  120. }
  121. };
  122. UsageRightsDialog.render = function () {
  123. return (
  124. <div className='ReactModal__Layout'>
  125. <div className='ReactModal__Header'>
  126. <div className='ReactModal__Header-Title'>
  127. <h4>
  128. {I18n.t('Manage Usage Rights')}
  129. </h4>
  130. </div>
  131. <div className='ReactModal__Header-Actions'>
  132. <button
  133. ref='cancelXButton'
  134. className='Button Button--icon-action'
  135. type='button'
  136. onClick={this.props.closeModal}
  137. >
  138. <i className='icon-x'>
  139. <span className='screenreader-only'>
  140. {I18n.t('Close')}
  141. </span>
  142. </i>
  143. </button>
  144. </div>
  145. </div>
  146. <div className='ReactModal__Body'>
  147. <div ref='form'>
  148. <div>
  149. <div className='UsageRightsDialog__paddingFix grid-row'>
  150. <div className='UsageRightsDialog__previewColumn col-xs-3'>
  151. <DialogPreview itemsToShow={this.props.itemsToManage} >
  152. </DialogPreview>
  153. </div>
  154. <div className='UsageRightsDialog__contentColumn off-xs-1 col-xs-8'>
  155. {this.renderDifferentRightsMessage()}
  156. {this.renderFileName()}
  157. {this.renderFolderMessage()}
  158. <UsageRightsSelectBox
  159. ref='usageSelection'
  160. use_justification={this.use_justification}
  161. copyright={this.copyright || ''}
  162. cc_value={this.cc_value}
  163. >
  164. </UsageRightsSelectBox>
  165. {this.renderAccessManagement()}
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. </div>
  171. <div className='ReactModal__Footer'>
  172. <div className='ReactModal__Footer-Actions'>
  173. <button
  174. ref='cancelButton'
  175. type='button'
  176. className='btn'
  177. onClick={this.props.closeModal}
  178. >
  179. {I18n.t('Cancel')}
  180. </button>
  181. <button
  182. ref='saveButton'
  183. type='button'
  184. className='btn btn-primary'
  185. onClick={this.submit}
  186. >
  187. {I18n.t('Save')}
  188. </button>
  189. </div>
  190. </div>
  191. </div>
  192. );
  193. };
  194. export default React.createClass(UsageRightsDialog)