UsageRightsIndicator.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 I18n from 'i18n!react_files'
  19. import React from 'react'
  20. import PropTypes from 'prop-types'
  21. import ReactDOM from 'react-dom'
  22. import customPropTypes from 'compiled/react_files/modules/customPropTypes'
  23. import Folder from 'compiled/models/Folder'
  24. import filesEnv from 'compiled/react_files/modules/filesEnv'
  25. import UsageRightsDialog from 'jsx/files/UsageRightsDialog'
  26. var UsageRightsIndicator = React.createClass({
  27. displayName: 'UsageRightsIndicator',
  28. warningMessage: I18n.t('Before publishing this file, you must specify usage rights.'),
  29. propTypes: {
  30. model: customPropTypes.filesystemObject.isRequired,
  31. userCanManageFilesForContext: PropTypes.bool.isRequired,
  32. userCanRestrictFilesForContext: PropTypes.bool.isRequired,
  33. usageRightsRequiredForContext: PropTypes.bool.isRequired,
  34. modalOptions: PropTypes.object.isRequired
  35. },
  36. handleClick (event) {
  37. event.preventDefault();
  38. var contents = (
  39. <UsageRightsDialog
  40. closeModal={this.props.modalOptions.closeModal}
  41. itemsToManage={[this.props.model]}
  42. userCanRestrictFilesForContext={this.props.userCanRestrictFilesForContext}
  43. />
  44. );
  45. this.props.modalOptions.openModal(contents, () => {
  46. ReactDOM.findDOMNode(this).focus();
  47. });
  48. },
  49. getIconData (useJustification) {
  50. switch (useJustification) {
  51. case 'own_copyright':
  52. return {iconClass: 'icon-files-copyright', text: I18n.t('Own Copyright')};
  53. case 'public_domain':
  54. return {iconClass: 'icon-files-public-domain', text: I18n.t('Public Domain')};
  55. case 'used_by_permission':
  56. return {iconClass: 'icon-files-obtained-permission', text: I18n.t('Used by Permission')};
  57. case 'fair_use':
  58. return {iconClass: 'icon-files-fair-use', text: I18n.t('Fair Use')};
  59. case 'creative_commons':
  60. return {iconClass: 'icon-files-creative-commons', text: I18n.t('Creative Commons')};
  61. }
  62. },
  63. render () {
  64. if ((this.props.model instanceof Folder) || (!this.props.usageRightsRequiredForContext && !this.props.model.get('usage_rights'))) {
  65. return null;
  66. } else if (this.props.usageRightsRequiredForContext && !this.props.model.get('usage_rights')) {
  67. if (this.props.userCanManageFilesForContext) {
  68. return (
  69. <button
  70. className='UsageRightsIndicator__openModal btn-link'
  71. onClick={this.handleClick}
  72. title={this.warningMessage}
  73. data-tooltip='top'
  74. >
  75. <span className='screenreader-only'>
  76. {this.warningMessage}
  77. </span>
  78. <i className='UsageRightsIndicator__warning icon-warning' />
  79. </button>
  80. );
  81. } else {
  82. return null;
  83. }
  84. } else {
  85. var useJustification = this.props.model.get('usage_rights').use_justification;
  86. var iconData = this.getIconData(useJustification);
  87. return (
  88. <button
  89. className='UsageRightsIndicator__openModal btn-link'
  90. onClick={this.handleClick}
  91. disabled={!this.props.userCanManageFilesForContext}
  92. title={this.props.model.get('usage_rights').license_name}
  93. data-tooltip='top'
  94. >
  95. <span
  96. ref='screenreaderText'
  97. className='screenreader-only'
  98. >
  99. {iconData.text}
  100. </span>
  101. <span className='screenreader-only'>
  102. {this.props.model.get('usage_rights').license_name}
  103. </span>
  104. <i ref='icon' className={iconData.iconClass} />
  105. </button>
  106. );
  107. }
  108. }
  109. });
  110. export default UsageRightsIndicator