2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-20 16:19:40 +02:00
|
|
|
import React from 'react';
|
2015-06-11 15:57:19 +02:00
|
|
|
import Router from 'react-router';
|
2015-05-21 15:14:05 +02:00
|
|
|
|
2015-05-20 16:19:40 +02:00
|
|
|
import UserActions from '../actions/user_actions';
|
|
|
|
import UserStore from '../stores/user_store';
|
|
|
|
|
2015-06-29 15:58:47 +02:00
|
|
|
import WhitelabelActions from '../actions/whitelabel_actions';
|
|
|
|
import WhitelabelStore from '../stores/whitelabel_store';
|
|
|
|
|
2015-06-20 16:43:18 +02:00
|
|
|
import Alt from '../alt';
|
2015-06-15 11:02:49 +02:00
|
|
|
|
2015-06-01 18:20:15 +02:00
|
|
|
import Nav from 'react-bootstrap/lib/Nav';
|
|
|
|
import Navbar from 'react-bootstrap/lib/Navbar';
|
2015-06-22 10:50:22 +02:00
|
|
|
import CollapsibleNav from 'react-bootstrap/lib/CollapsibleNav';
|
2015-06-01 18:20:15 +02:00
|
|
|
import DropdownButton from 'react-bootstrap/lib/DropdownButton';
|
|
|
|
import MenuItem from 'react-bootstrap/lib/MenuItem';
|
2015-06-17 17:48:23 +02:00
|
|
|
import MenuItemLink from 'react-router-bootstrap/lib/MenuItemLink';
|
2015-06-20 16:43:18 +02:00
|
|
|
import NavItemLink from 'react-router-bootstrap/lib/NavItemLink';
|
2015-06-01 18:20:15 +02:00
|
|
|
|
2015-06-11 15:35:18 +02:00
|
|
|
|
2015-06-29 15:58:47 +02:00
|
|
|
import { mergeOptions } from '../utils/general_utils';
|
2015-06-02 14:25:26 +02:00
|
|
|
import { getLangText } from '../utils/lang_utils';
|
|
|
|
|
2015-06-11 15:57:19 +02:00
|
|
|
let Link = Router.Link;
|
2015-05-20 16:19:40 +02:00
|
|
|
|
|
|
|
let Header = React.createClass({
|
2015-06-20 16:43:18 +02:00
|
|
|
mixins: [Router.Navigation],
|
2015-05-20 16:19:40 +02:00
|
|
|
|
|
|
|
getInitialState() {
|
2015-06-29 15:58:47 +02:00
|
|
|
return mergeOptions(WhitelabelStore.getState(), UserStore.getState());
|
2015-05-20 16:19:40 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
UserActions.fetchCurrentUser();
|
2015-06-05 11:40:49 +02:00
|
|
|
UserStore.listen(this.onChange);
|
2015-06-29 15:58:47 +02:00
|
|
|
WhitelabelActions.fetchWhitelabel();
|
|
|
|
WhitelabelStore.listen(this.onChange);
|
2015-06-03 11:49:39 +02:00
|
|
|
},
|
|
|
|
|
2015-06-04 13:17:59 +02:00
|
|
|
componentWillUnmount() {
|
2015-06-04 13:16:19 +02:00
|
|
|
UserStore.unlisten(this.onChange);
|
2015-06-29 15:58:47 +02:00
|
|
|
WhitelabelStore.unlisten(this.onChange);
|
2015-05-20 16:19:40 +02:00
|
|
|
},
|
2015-06-16 20:35:19 +02:00
|
|
|
handleLogout(){
|
2015-06-20 16:43:18 +02:00
|
|
|
UserActions.logoutCurrentUser();
|
|
|
|
Alt.flush();
|
2015-06-22 23:32:41 +02:00
|
|
|
this.transitionTo('login');
|
2015-06-16 20:35:19 +02:00
|
|
|
},
|
2015-06-29 15:58:47 +02:00
|
|
|
getLogo(){
|
|
|
|
let logo = (
|
|
|
|
<span>
|
|
|
|
<span>ascribe </span>
|
|
|
|
<span className="glyph-ascribe-spool-chunked ascribe-color"></span>
|
|
|
|
</span>);
|
|
|
|
if (this.state.whitelabel.logo){
|
|
|
|
logo = <img className="img-brand" src={this.state.whitelabel.logo} />;
|
|
|
|
}
|
|
|
|
return logo;
|
|
|
|
},
|
|
|
|
|
|
|
|
getPoweredBy(){
|
2015-06-30 10:42:58 +02:00
|
|
|
if (this.state.whitelabel.logo) {
|
|
|
|
return (
|
|
|
|
<div className="row no-margin ascribe-subheader">
|
|
|
|
<a className="pull-right" href="https://www.ascribe.io/" target="_blank">
|
2015-07-03 19:08:56 +02:00
|
|
|
<span id="powered">{getLangText('powered by')} </span>
|
2015-06-30 10:42:58 +02:00
|
|
|
<span>ascribe </span>
|
|
|
|
<span className="glyph-ascribe-spool-chunked ascribe-color"></span>
|
|
|
|
</a>
|
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
return null;
|
2015-06-29 15:58:47 +02:00
|
|
|
},
|
2015-05-20 16:19:40 +02:00
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
|
|
|
},
|
2015-06-15 15:28:53 +02:00
|
|
|
|
2015-05-20 16:19:40 +02:00
|
|
|
render() {
|
2015-06-15 15:28:53 +02:00
|
|
|
let account = null;
|
|
|
|
let signup = null;
|
2015-07-01 19:05:47 +02:00
|
|
|
let collection = null;
|
2015-07-07 10:28:39 +02:00
|
|
|
let addNewWork = null;
|
2015-06-15 12:36:27 +02:00
|
|
|
if (this.state.currentUser.username){
|
|
|
|
account = (
|
|
|
|
<DropdownButton eventKey="1" title={this.state.currentUser.username}>
|
2015-07-07 10:28:39 +02:00
|
|
|
<MenuItemLink eventKey="2" to="settings">{getLangText('Account Settings')}</MenuItemLink>
|
2015-06-22 10:50:22 +02:00
|
|
|
<MenuItem divider />
|
2015-07-07 10:28:39 +02:00
|
|
|
<MenuItem eventKey="3" onClick={this.handleLogout}>{getLangText('Log out')}</MenuItem>
|
2015-06-15 12:36:27 +02:00
|
|
|
</DropdownButton>
|
|
|
|
);
|
2015-07-03 19:08:56 +02:00
|
|
|
collection = <NavItemLink to="pieces">{getLangText('COLLECTION')}</NavItemLink>;
|
|
|
|
addNewWork = <NavItemLink to="register_piece">+ {getLangText('NEW WORK')}</NavItemLink>;
|
2015-06-15 12:36:27 +02:00
|
|
|
}
|
2015-06-15 15:28:53 +02:00
|
|
|
else {
|
2015-07-01 18:58:13 +02:00
|
|
|
account = <NavItemLink to="login">{getLangText('LOGIN')}</NavItemLink>;
|
|
|
|
signup = <NavItemLink to="signup">{getLangText('SIGNUP')}</NavItemLink>;
|
2015-06-15 15:28:53 +02:00
|
|
|
}
|
2015-06-22 10:50:22 +02:00
|
|
|
|
2015-06-29 15:58:47 +02:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Navbar
|
|
|
|
brand={
|
2015-07-01 19:05:47 +02:00
|
|
|
<Link className="navbar-brand" to="pieces">
|
2015-06-29 15:58:47 +02:00
|
|
|
{this.getLogo()}
|
|
|
|
</Link>}
|
2015-07-07 10:28:39 +02:00
|
|
|
toggleNavKey={0}
|
|
|
|
fixedTop={true}>
|
2015-06-29 15:58:47 +02:00
|
|
|
<CollapsibleNav eventKey={0}>
|
2015-07-01 19:05:47 +02:00
|
|
|
<Nav navbar left>
|
|
|
|
</Nav>
|
2015-06-29 15:58:47 +02:00
|
|
|
<Nav navbar right>
|
2015-07-07 10:28:39 +02:00
|
|
|
{addNewWork}
|
|
|
|
{collection}
|
2015-06-29 15:58:47 +02:00
|
|
|
{account}
|
|
|
|
{signup}
|
|
|
|
</Nav>
|
|
|
|
</CollapsibleNav>
|
|
|
|
</Navbar>
|
|
|
|
{this.getPoweredBy()}
|
|
|
|
</div>
|
2015-05-21 15:20:02 +02:00
|
|
|
);
|
2015-05-20 16:19:40 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default Header;
|