toolbar.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import React from 'react'; // jshint ignore:line
  2. import CategoryPicker from 'misago/components/threads/category-picker'; // jshint ignore:line
  3. import ModerationControls from 'misago/components/threads/moderation/controls'; // jshint ignore:line
  4. import SelectionControls from 'misago/components/threads/moderation/selection'; // jshint ignore:line
  5. export default class extends React.Component {
  6. getCategoryPicker() {
  7. if (this.props.subcategories.length) {
  8. /* jshint ignore:start */
  9. return <div className="toolbar-left">
  10. <CategoryPicker choices={this.props.subcategories}
  11. categories={this.props.categoriesMap}
  12. list={this.props.list} />
  13. </div>;
  14. /* jshint ignore:end */
  15. } else {
  16. return null;
  17. }
  18. }
  19. showModerationOptions() {
  20. return this.props.user.id && this.props.moderation.allow;
  21. }
  22. getSelectionButton() {
  23. if (this.showModerationOptions()) {
  24. /* jshint ignore:start */
  25. return <div className="toolbar-right dropdown">
  26. <button type="button"
  27. className="btn btn-default btn-icon dropdown-toggle"
  28. data-toggle="dropdown"
  29. aria-haspopup="true"
  30. aria-expanded="false"
  31. disabled={this.props.disabled}>
  32. <span className="material-icon">
  33. select_all
  34. </span>
  35. </button>
  36. <SelectionControls className="dropdown-menu dropdown-menu-right"
  37. threads={this.props.threads} />
  38. </div>;
  39. /* jshint ignore:end */
  40. } else {
  41. return null;
  42. }
  43. }
  44. getSelectedThreads() {
  45. return this.props.threads.filter((thread) => {
  46. return this.props.selection.indexOf(thread.id) >= 0;
  47. });
  48. }
  49. getModerationButton() {
  50. if (this.showModerationOptions()) {
  51. /* jshint ignore:start */
  52. return <div className="toolbar-right dropdown">
  53. <button type="button"
  54. className="btn btn-default dropdown-toggle"
  55. data-toggle="dropdown"
  56. aria-haspopup="true"
  57. aria-expanded="false"
  58. disabled={this.props.disabled || !this.props.selection.length}>
  59. <span className="material-icon">
  60. settings
  61. </span>
  62. {gettext("Moderation")}
  63. </button>
  64. <ModerationControls
  65. addThreads={this.props.addThreads}
  66. categories={this.props.categories}
  67. categoriesMap={this.props.categoriesMap}
  68. className="dropdown-menu dropdown-menu-right"
  69. deleteThread={this.props.deleteThread}
  70. freezeThread={this.props.freezeThread}
  71. moderation={this.props.moderation}
  72. route={this.props.route}
  73. threads={this.getSelectedThreads()}
  74. updateThread={this.props.updateThread}
  75. user={this.props.user}
  76. />
  77. </div>;
  78. /* jshint ignore:end */
  79. } else {
  80. return null;
  81. }
  82. }
  83. render() {
  84. /* jshint ignore:start */
  85. return <div className="toolbar with-js">
  86. {this.getCategoryPicker()}
  87. <p className="toolbar-left hidden-xs hidden-sm">
  88. {this.props.children}
  89. </p>
  90. {this.getSelectionButton()}
  91. {this.getModerationButton()}
  92. </div>;
  93. /* jshint ignore:end */
  94. }
  95. }