header.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. import React from 'react';
  2. import Avatar from 'misago/components/avatar'; // jshint ignore:line
  3. import DropdownToggle from 'misago/components/dropdown-toggle'; // jshint ignore:line
  4. import FollowButton from './follow-button'; // jshint ignore:line
  5. import MessageButton from './message-button'; // jshint ignore:line
  6. import ModerationNav from './moderation/nav'; // jshint ignore:line
  7. import { CompactNav } from './navs'; // jshint ignore:line
  8. import Status, { StatusIcon, StatusLabel } from 'misago/components/user-status'; // jshint ignore:line
  9. export default class extends React.Component {
  10. getUserStatus() {
  11. /* jshint ignore:start */
  12. return (
  13. <li className="user-status-display">
  14. <Status
  15. user={this.props.profile}
  16. status={this.props.profile.status}
  17. >
  18. <StatusIcon
  19. user={this.props.profile}
  20. status={this.props.profile.status}
  21. />
  22. <StatusLabel
  23. user={this.props.profile}
  24. status={this.props.profile.status}
  25. className="status-label"
  26. />
  27. </Status>
  28. </li>
  29. );
  30. /* jshint ignore:end */
  31. }
  32. getUserRank() {
  33. if (this.props.profile.rank.is_tab) {
  34. /* jshint ignore:start */
  35. return (
  36. <li className="user-rank">
  37. <a href={this.props.profile.rank.absolute_url} className="item-title">
  38. {this.props.profile.rank.name}
  39. </a>
  40. </li>
  41. );
  42. /* jshint ignore:end */
  43. } else {
  44. /* jshint ignore:start */
  45. return (
  46. <li className="user-rank">
  47. <span className="item-title">{this.props.profile.rank.name}</span>
  48. </li>
  49. );
  50. /* jshint ignore:end */
  51. }
  52. }
  53. getUserTitle() {
  54. if (this.props.profile.title) {
  55. /* jshint ignore:start */
  56. return (
  57. <li className="user-title">
  58. {this.props.profile.title}
  59. </li>
  60. );
  61. /* jshint ignore:end */
  62. } else if (this.props.profile.rank.title) {
  63. /* jshint ignore:start */
  64. return (
  65. <li className="user-title">
  66. {this.props.profile.rank.title}
  67. </li>
  68. );
  69. /* jshint ignore:end */
  70. } else {
  71. return null;
  72. }
  73. }
  74. getJoinedOn() {
  75. /* jshint ignore:start */
  76. let title = interpolate(gettext("Joined on %(joined_on)s"), {
  77. 'joined_on': this.props.profile.joined_on.format('LL, LT')
  78. }, true);
  79. let age = interpolate(gettext("Joined %(joined_on)s"), {
  80. 'joined_on': this.props.profile.joined_on.fromNow()
  81. }, true);
  82. return (
  83. <li className="user-joined-on">
  84. <abbr title={title}>
  85. {age}
  86. </abbr>
  87. </li>
  88. );
  89. /* jshint ignore:end */
  90. }
  91. getEmail() {
  92. if (this.props.profile.email) {
  93. /* jshint ignore:start */
  94. return (
  95. <li className="user-email">
  96. <a href={'mailto:' + this.props.profile.email} className="item-title">
  97. {this.props.profile.email}
  98. </a>
  99. </li>
  100. );
  101. /* jshint ignore:end */
  102. } else {
  103. return null;
  104. }
  105. }
  106. getFollowButton() {
  107. if (this.props.profile.acl.can_follow) {
  108. /* jshint ignore:start */
  109. return (
  110. <FollowButton
  111. className="btn btn-block btn-outline"
  112. profile={this.props.profile}
  113. />
  114. );
  115. /* jshint ignore:end */
  116. } else {
  117. return null;
  118. }
  119. }
  120. getModerationButton() {
  121. if (this.props.profile.acl.can_moderate) {
  122. /* jshint ignore:start */
  123. return (
  124. <div className="btn-group btn-group-justified">
  125. <div className="btn-group">
  126. <button
  127. className="btn btn-default btn-moderate btn-outline dropdown-toggle"
  128. type="button"
  129. data-toggle="dropdown"
  130. aria-haspopup="true"
  131. aria-expanded="false"
  132. >
  133. <span className="material-icon">
  134. tonality
  135. </span>
  136. {gettext("Moderation")}
  137. </button>
  138. <ModerationNav profile={this.props.profile} />
  139. </div>
  140. </div>
  141. );
  142. /* jshint ignore:end */
  143. } else {
  144. return null;
  145. }
  146. }
  147. render() {
  148. /* jshint ignore:start */
  149. const canFollow = this.props.profile.acl.can_follow;
  150. const canModerate = this.props.profile.acl.can_moderate;
  151. const isProfileOwner = this.props.user.id === this.props.profile.id;
  152. const canMessage = !isProfileOwner && this.props.user.acl.can_start_private_threads;
  153. let cols = 0;
  154. if (canFollow) cols += 1;
  155. if (canModerate) cols += 1;
  156. if (canMessage) cols += 1;
  157. const colsWidth = cols ? 2 * cols + 1 : 0;
  158. let headerClassName = 'page-header';
  159. if (this.props.profile.rank.css_class) {
  160. headerClassName += ' page-header-rank-' + this.props.profile.rank.css_class;
  161. }
  162. return (
  163. <div className="page-header-bg">
  164. <div className={headerClassName}>
  165. <div className="container">
  166. <IsDisabledMessage
  167. isActive={this.props.profile.is_active}
  168. />
  169. <div className="row">
  170. <div className="col-md-9 col-md-offset-3">
  171. <div className="row">
  172. <div className={"col-sm-" + (12 - colsWidth)}>
  173. <Avatar
  174. className="user-avatar user-avatar-sm"
  175. user={this.props.profile}
  176. size="100"
  177. size2x="200"
  178. />
  179. <h1>{this.props.profile.username}</h1>
  180. </div>
  181. {!!cols && (
  182. <div className={"col-sm-" + colsWidth}>
  183. <div className="row xs-margin-top sm-margin-top">
  184. {canMessage && (
  185. <div className={getColStyle(cols, 0)}>
  186. <MessageButton
  187. className="btn btn-default btn-block btn-outline"
  188. profile={this.props.profile}
  189. user={this.props.user}
  190. />
  191. </div>
  192. )}
  193. {canFollow && (
  194. <div className={getColStyle(cols, 1)}>
  195. {this.getFollowButton()}
  196. </div>
  197. )}
  198. {canModerate && (
  199. <div className={getColStyle(cols, 2)}>
  200. {this.getModerationButton()}
  201. </div>
  202. )}
  203. </div>
  204. </div>
  205. )}
  206. </div>
  207. </div>
  208. </div>
  209. </div>
  210. <div className="header-stats">
  211. <div className="container">
  212. <div className="row">
  213. <div className="col-md-9 col-md-offset-3">
  214. <ul className="list-inline">
  215. {this.getUserStatus()}
  216. {this.getUserRank()}
  217. {this.getUserTitle()}
  218. {this.getJoinedOn()}
  219. {this.getEmail()}
  220. </ul>
  221. </div>
  222. </div>
  223. </div>
  224. </div>
  225. <CompactNav
  226. baseUrl={this.props.baseUrl}
  227. pages={this.props.pages}
  228. profile={this.props.profile}
  229. />
  230. </div>
  231. </div>
  232. );
  233. /* jshint ignore:end */
  234. }
  235. }
  236. /* jshint ignore:start */
  237. export function IsDisabledMessage(props) {
  238. if (props.isActive !== false) return null;
  239. return (
  240. <div className="alert alert-danger">
  241. <p>{gettext("This user's account has been disabled by administrator.")}</p>
  242. </div>
  243. );
  244. }
  245. export function getColStyle(cols, col) {
  246. let colStyle = "";
  247. if (cols == 1) {
  248. colStyle = "col-xs-12";
  249. }
  250. if (cols == 2) {
  251. colStyle = "col-xs-6 col-sm-6";
  252. }
  253. if (cols == 3) {
  254. if (col == 2) {
  255. colStyle = "col-xs-12 col-sm-4 xs-margin-top";
  256. } else {
  257. colStyle += "col-xs-6 col-sm-4";
  258. }
  259. }
  260. return colStyle;
  261. }
  262. /* jshint ignore:end */