RestrictedDialogForm.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 _ from 'underscore'
  19. import React from 'react'
  20. import I18n from 'i18n!restrict_student_access'
  21. import $ from 'jquery'
  22. import classNames from 'classnames'
  23. import UsageRightsSelectBox from 'jsx/files/UsageRightsSelectBox'
  24. import RestrictedRadioButtons from 'jsx/files/RestrictedRadioButtons'
  25. import DialogPreview from 'jsx/files/DialogPreview'
  26. import RestrictedDialogForm from 'compiled/react_files/components/RestrictedDialogForm'
  27. RestrictedDialogForm.renderUsageRightsWarning = function () {
  28. return (
  29. <div className='RestrictedDialogForm__banner col-xs-12'>
  30. <span className='alert'>
  31. <i className='icon-warning RestrictedDialogForm__warning'></i>
  32. {I18n.t('Before publishing, you must set usage rights on your files.')}
  33. </span>
  34. </div>
  35. );
  36. };
  37. // Renders out the restricted access form
  38. // - options is an object which can be used to conditionally set certain aspects
  39. // of rendering.
  40. // Future Refactor: Move this to another component should it's use elsewhere
  41. // be meritted.
  42. RestrictedDialogForm.renderRestrictedAccessForm = function (options) {
  43. var formContainerClasses = classNames({
  44. 'RestrictedDialogForm__form': true,
  45. 'col-xs-9': true,
  46. 'off-xs-3': options && options.offset
  47. });
  48. return (
  49. <div className={formContainerClasses}>
  50. <form
  51. ref='dialogForm'
  52. onSubmit={this.handleSubmit}
  53. className='form-horizontal form-dialog permissions-dialog-form'
  54. >
  55. <RestrictedRadioButtons
  56. ref='restrictedSelection'
  57. models={this.props.models}
  58. radioStateChange={this.radioStateChange}
  59. >
  60. </RestrictedRadioButtons>
  61. <div className='form-controls'>
  62. <button
  63. type='button'
  64. onClick={this.props.closeDialog}
  65. className='btn'
  66. >
  67. {I18n.t('Cancel')}
  68. </button>
  69. <button
  70. ref='updateBtn'
  71. type='submit'
  72. className='btn btn-primary'
  73. disabled={!this.state.submitable}
  74. >
  75. {I18n.t('Update')}
  76. </button>
  77. </div>
  78. </form>
  79. </div>
  80. );
  81. };
  82. RestrictedDialogForm.render = function () {
  83. // Doing this here to prevent possible repeat runs of this.usageRightsOnAll and this.allFolders
  84. var showUsageRights = this.props.usageRightsRequiredForContext && !this.usageRightsOnAll() && !this.allFolders();
  85. return (
  86. <div className='RestrictedDialogForm__container'>
  87. {/* If showUsageRights then show the Usage Rights Warning */}
  88. {!!showUsageRights && (
  89. <div className='RestrictedDialogForm__firstRow grid-row'>
  90. {this.renderUsageRightsWarning()}
  91. </div>
  92. )}
  93. <div className='RestrictedDialogForm__secondRow grid-row'>
  94. <div className='RestrictedDialogForm__preview col-xs-3'>
  95. <DialogPreview itemsToShow={this.props.models} />
  96. </div>
  97. {/* If showUsageRights then show the select box for it.*/}
  98. {!!showUsageRights && (
  99. <div className='RestrictedDialogForm__usageRights col-xs-9'>
  100. <UsageRightsSelectBox ref='usageSelection' />
  101. <hr />
  102. </div>
  103. )}
  104. {/* Not showing usage rights?, then show the form here.*/}
  105. {!showUsageRights && this.renderRestrictedAccessForm()}
  106. </div>
  107. {/* If showUsageRights,] it needs to be here instead */}
  108. {!!showUsageRights && (
  109. <div className='RestrictedDialogForm__thirdRow grid-row'>
  110. {this.renderRestrictedAccessForm({offset: true})}
  111. </div>
  112. )}
  113. </div>
  114. );
  115. };
  116. export default React.createClass(RestrictedDialogForm)