ColumnHeaders.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 'jquery'
  19. import _ from 'underscore'
  20. import I18n from 'i18n!react_files'
  21. import React from 'react'
  22. import classnames from 'classnames'
  23. import ColumnHeaders from 'compiled/react_files/components/ColumnHeaders'
  24. ColumnHeaders.renderColumns = function (sort, order) {
  25. return this.columns.map((column) => {
  26. if (column.property === 'usage_rights' && !this.props.usageRightsRequiredForContext) {
  27. return;
  28. }
  29. var isSortedCol = sort === column.property;
  30. var columnClassNameObj = {
  31. "current-filter": isSortedCol
  32. };
  33. columnClassNameObj[column.className] = true;
  34. var columnClassName = classnames(columnClassNameObj);
  35. var linkClassName = classnames({
  36. 'visible-desktop': column.displayNameShort,
  37. 'ef-usage-rights-col-offset': (column.property === 'usage_rights')
  38. });
  39. const href = `${this.props.pathname}?${$.param(this.queryParamsFor(this.props.query, column.property))}`;
  40. const linkProps = {
  41. className: 'ef-plain-link',
  42. href
  43. };
  44. var linkText;
  45. if (column.property === 'select') {
  46. linkText = <span className='screenreader-only'>{column.displayName}</span>;
  47. } else if (column.property == 'usage_rights') {
  48. linkText = (<i className='icon-files-copyright'>
  49. <span className='screenreader-only'>{column.displayName}</span>
  50. </i>
  51. );
  52. } else {
  53. linkText = column.displayName;
  54. }
  55. return (
  56. <div
  57. key={column.property}
  58. className={columnClassName}
  59. role='columnheader'
  60. aria-sort={{asc: 'ascending', desc: 'descending'}[isSortedCol && order] || 'none'}
  61. >
  62. <a {...linkProps}>
  63. <span className={linkClassName}>
  64. {linkText}
  65. </span>
  66. {column.displayNameShort && (
  67. <span className='hidden-desktop'>{column.displayNameShort}</span>
  68. )}
  69. {isSortedCol && order === 'asc' && (
  70. <i className='icon-mini-arrow-up'>
  71. <span className='screenreader-only'>
  72. {I18n.t('sorted_ascending', "Sorted Ascending")}
  73. </span>
  74. </i>
  75. )}
  76. {isSortedCol && order === 'desc' && (
  77. <i className='icon-mini-arrow-down'>
  78. <span className='screenreader-only'>
  79. {I18n.t('sorted_desending', "Sorted Descending")}
  80. </span>
  81. </i>
  82. )}
  83. </a>
  84. </div>
  85. );
  86. })
  87. }
  88. ColumnHeaders.render = function () {
  89. const sort = this.props.query.sort || 'name';
  90. const order = this.props.query.order || 'asc';
  91. const selectAllCheckboxClass = classnames({
  92. 'screenreader-only': this.state.hideToggleAll
  93. });
  94. const selectAllLabelClass = classnames({
  95. 'screenreader-only': !this.state.hideToggleAll
  96. });
  97. return (
  98. <header className='ef-directory-header' role='row'>
  99. <div className={selectAllCheckboxClass} role='gridcell'>
  100. <label htmlFor='selectAllCheckbox' className={selectAllLabelClass}>
  101. {I18n.t('select_all', 'Select All')}
  102. </label>
  103. <input
  104. id='selectAllCheckbox'
  105. className={selectAllCheckboxClass}
  106. type='checkbox'
  107. onFocus={(event) => this.setState({hideToggleAll: false})}
  108. onBlur={(event) => this.setState({hideToggleAll: true})}
  109. checked={this.props.areAllItemsSelected()}
  110. onChange={(event) => this.props.toggleAllSelected(event.target.checked)}
  111. />
  112. </div>
  113. {this.renderColumns(sort, order)}
  114. <div
  115. className='ef-links-col'
  116. role='columnheader'
  117. >
  118. <span className='screenreader-only'>
  119. {I18n.t('Links')}
  120. </span>
  121. </div>
  122. </header>
  123. );
  124. }
  125. export default React.createClass(ColumnHeaders)