dropdown.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* jshint ignore:start */
  2. import React from 'react';
  3. import modal from 'misago/services/modal';
  4. import * as moderation from './actions';
  5. import MoveModal from './move';
  6. import SplitModal from './split';
  7. export default function(props) {
  8. return (
  9. <ul className="dropdown-menu">
  10. <Approve {...props} />
  11. <Merge {...props} />
  12. <Move {...props} />
  13. <Split {...props} />
  14. <Protect {...props} />
  15. <Unprotect {...props} />
  16. <Hide {...props} />
  17. <Unhide {...props} />
  18. <Delete {...props} />
  19. </ul>
  20. );
  21. }
  22. export class Approve extends React.Component {
  23. onClick = () => {
  24. moderation.approve(this.props);
  25. };
  26. render() {
  27. const isVisible = this.props.selection.find((post) => {
  28. return post.acl.can_approve;
  29. });
  30. if (!isVisible) {
  31. return null;
  32. }
  33. return (
  34. <li>
  35. <button type="button" className="btn btn-link" onClick={this.onClick}>
  36. {gettext("Approve")}
  37. </button>
  38. </li>
  39. );
  40. }
  41. }
  42. export class Merge extends React.Component {
  43. onClick = () => {
  44. moderation.merge(this.props);
  45. };
  46. render() {
  47. if (this.props.selection.length < 2 || !this.props.thread.acl.can_merge_posts) {
  48. return null;
  49. }
  50. return (
  51. <li>
  52. <button type="button" className="btn btn-link" onClick={this.onClick}>
  53. {gettext("Merge")}
  54. </button>
  55. </li>
  56. );
  57. }
  58. }
  59. export class Move extends React.Component {
  60. onClick = () => {
  61. modal.show(
  62. <MoveModal {...this.props} />
  63. );
  64. };
  65. render() {
  66. const isVisible = this.props.selection.find((post) => {
  67. return post.acl.can_move;
  68. });
  69. if (!isVisible) {
  70. return null;
  71. }
  72. return (
  73. <li>
  74. <button type="button" className="btn btn-link" onClick={this.onClick}>
  75. {gettext("Move")}
  76. </button>
  77. </li>
  78. );
  79. }
  80. }
  81. export class Split extends React.Component {
  82. onClick = () => {
  83. modal.show(
  84. <SplitModal {...this.props} />
  85. );
  86. };
  87. render() {
  88. const isVisible = this.props.selection.find((post) => {
  89. return post.acl.can_move;
  90. });
  91. if (!isVisible) {
  92. return null;
  93. }
  94. return (
  95. <li>
  96. <button type="button" className="btn btn-link" onClick={this.onClick}>
  97. {gettext("Split")}
  98. </button>
  99. </li>
  100. );
  101. }
  102. }
  103. export class Protect extends React.Component {
  104. onClick = () => {
  105. moderation.protect(this.props);
  106. };
  107. render() {
  108. const isVisible = this.props.selection.find((post) => {
  109. return post.acl.can_protect;
  110. });
  111. if (!isVisible) {
  112. return null;
  113. }
  114. return (
  115. <li>
  116. <button type="button" className="btn btn-link" onClick={this.onClick}>
  117. {gettext("Protect")}
  118. </button>
  119. </li>
  120. );
  121. }
  122. }
  123. export class Unprotect extends React.Component {
  124. onClick = () => {
  125. moderation.unprotect(this.props);
  126. };
  127. render() {
  128. const isVisible = this.props.selection.find((post) => {
  129. return post.acl.can_protect;
  130. });
  131. if (!isVisible) {
  132. return null;
  133. }
  134. return (
  135. <li>
  136. <button type="button" className="btn btn-link" onClick={this.onClick}>
  137. {gettext("Unprotect")}
  138. </button>
  139. </li>
  140. );
  141. }
  142. }
  143. export class Hide extends React.Component {
  144. onClick = () => {
  145. moderation.hide(this.props);
  146. };
  147. render() {
  148. const isVisible = this.props.selection.find((post) => {
  149. return post.acl.can_hide;
  150. });
  151. if (!isVisible) {
  152. return null;
  153. }
  154. return (
  155. <li>
  156. <button type="button" className="btn btn-link" onClick={this.onClick}>
  157. {gettext("Hide")}
  158. </button>
  159. </li>
  160. );
  161. }
  162. }
  163. export class Unhide extends React.Component {
  164. onClick = () => {
  165. moderation.unhide(this.props);
  166. };
  167. render() {
  168. const isVisible = this.props.selection.find((post) => {
  169. return post.acl.can_unhide;
  170. });
  171. if (!isVisible) {
  172. return null;
  173. }
  174. return (
  175. <li>
  176. <button type="button" className="btn btn-link" onClick={this.onClick}>
  177. {gettext("Unhide")}
  178. </button>
  179. </li>
  180. );
  181. }
  182. }
  183. export class Delete extends React.Component {
  184. onClick = () => {
  185. moderation.remove(this.props);
  186. };
  187. render() {
  188. const isVisible = this.props.selection.find((post) => {
  189. return post.acl.can_delete;
  190. });
  191. if (!isVisible) {
  192. return null;
  193. }
  194. return (
  195. <li>
  196. <button type="button" className="btn btn-link" onClick={this.onClick}>
  197. {gettext("Delete")}
  198. </button>
  199. </li>
  200. );
  201. }
  202. }