ModerationHeader.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 PropTypes from 'prop-types'
  20. import I18n from 'i18n!moderated_grading'
  21. var Header = React.createClass({
  22. displayName: 'Header',
  23. propTypes: {
  24. onPublishClick: PropTypes.func.isRequired,
  25. onReviewClick: PropTypes.func.isRequired,
  26. published: PropTypes.bool.isRequired,
  27. selectedStudentCount: PropTypes.number.isRequired,
  28. inflightAction: PropTypes.shape({
  29. review: PropTypes.bool.isRequired,
  30. publish: PropTypes.bool.isRequired
  31. }).isRequired,
  32. permissions: PropTypes.shape({
  33. editGrades: PropTypes.bool.isRequired
  34. }).isRequired
  35. },
  36. noStudentSelected () {
  37. return this.props.selectedStudentCount === 0;
  38. },
  39. handlePublishClick () {
  40. // TODO: Make a better looking confirm one day
  41. var confirmMessage = I18n.t('Are you sure you want to do this? It cannot be undone and will override existing grades in the gradebook.')
  42. if (window.confirm(confirmMessage)) {
  43. this.props.onPublishClick();
  44. }
  45. },
  46. renderPublishedMessage () {
  47. if (this.props.published) {
  48. return (
  49. <div className="ic-notification">
  50. <div className="ic-notification__icon" aria-hidden='true' role="presentation">
  51. <i className="icon-info"></i>
  52. </div>
  53. <div className="ic-notification__content">
  54. <div className="ic-notification__message">
  55. <div className="ic-notification__title">
  56. {I18n.t('Attention!')}
  57. </div>
  58. <span className="notification_message">
  59. {I18n.t('This page cannot be modified because grades have already been posted.')}
  60. </span>
  61. </div>
  62. </div>
  63. </div>
  64. );
  65. }
  66. },
  67. renderPostButton () {
  68. return this.props.permissions.editGrades && (
  69. <button
  70. ref={(p) => { this.publishBtn = p; }}
  71. type="button"
  72. className="ModeratedGrading__Header-PublishBtn Button Button--primary"
  73. onClick={this.handlePublishClick}
  74. disabled={this.props.published || this.props.inflightAction.publish}
  75. >
  76. {I18n.t('Post')}
  77. </button>
  78. );
  79. },
  80. render () {
  81. return (
  82. <div>
  83. {this.renderPublishedMessage()}
  84. <div className='ModeratedGrading__Header ic-Action-header'>
  85. <div className='ic-Action-header__Primary'>
  86. <div className='ic-Action-header__Heading ModeratedGrading__Header-Instructions'>
  87. {I18n.t('Select students for review')}
  88. </div>
  89. </div>
  90. <div className='ic-Action-header__Secondary ModeratedGrading__Header-Buttons '>
  91. <button
  92. ref='addReviewerBtn'
  93. type='button'
  94. className='ModeratedGrading__Header-AddReviewerBtn Button'
  95. onClick={this.props.onReviewClick}
  96. disabled={
  97. this.props.published ||
  98. this.noStudentSelected() ||
  99. this.props.inflightAction.review
  100. }
  101. >
  102. <span className='screenreader-only'>{I18n.t('Add a reviewer for the selected students')}</span>
  103. <span aria-hidden='true'>
  104. <i className='icon-plus' />
  105. {I18n.t(' Reviewer')}
  106. </span>
  107. </button>
  108. {this.renderPostButton()}
  109. </div>
  110. </div>
  111. </div>
  112. );
  113. }
  114. });
  115. export default Header