2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-20 16:19:40 +02:00
|
|
|
import React from 'react';
|
2015-06-29 15:58:47 +02:00
|
|
|
|
2015-11-03 10:39:01 +01:00
|
|
|
import { Link } from 'react-router';
|
|
|
|
|
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-10-01 14:00:56 +02:00
|
|
|
import NavItem from 'react-bootstrap/lib/NavItem';
|
|
|
|
|
|
|
|
import LinkContainer from 'react-router-bootstrap/lib/LinkContainer';
|
2015-06-01 18:20:15 +02:00
|
|
|
|
2015-09-23 15:16:46 +02:00
|
|
|
import AclProxy from './acl_proxy';
|
|
|
|
|
2015-09-01 18:11:18 +02:00
|
|
|
import UserActions from '../actions/user_actions';
|
|
|
|
import UserStore from '../stores/user_store';
|
|
|
|
|
|
|
|
import WhitelabelActions from '../actions/whitelabel_actions';
|
|
|
|
import WhitelabelStore from '../stores/whitelabel_store';
|
|
|
|
import EventActions from '../actions/event_actions';
|
|
|
|
|
|
|
|
import HeaderNotifications from './header_notification';
|
|
|
|
|
2015-07-08 15:00:11 +02:00
|
|
|
import HeaderNotificationDebug from './header_notification_debug';
|
|
|
|
|
2015-08-25 16:33:26 +02:00
|
|
|
import NavRoutesLinks from './nav_routes_links';
|
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-11-03 10:39:01 +01:00
|
|
|
import { constructHead } from '../utils/dom_utils';
|
2015-05-20 16:19:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
let Header = React.createClass({
|
2015-07-14 21:06:11 +02:00
|
|
|
propTypes: {
|
2015-08-25 16:33:26 +02:00
|
|
|
showAddWork: React.PropTypes.bool,
|
2015-10-01 14:00:56 +02:00
|
|
|
routes: React.PropTypes.arrayOf(React.PropTypes.object)
|
2015-07-14 21:06:11 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps() {
|
|
|
|
return {
|
|
|
|
showAddWork: true
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-05-20 16:19:40 +02:00
|
|
|
getInitialState() {
|
2015-09-01 14:45:14 +02:00
|
|
|
return mergeOptions(
|
|
|
|
WhitelabelStore.getState(),
|
2015-09-01 18:11:18 +02:00
|
|
|
UserStore.getState()
|
2015-09-01 14:45:14 +02:00
|
|
|
);
|
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-07-08 15:00:11 +02:00
|
|
|
|
2015-10-22 12:00:59 +02:00
|
|
|
getLogo() {
|
2015-10-08 11:12:15 +02:00
|
|
|
let { whitelabel } = this.state;
|
2015-10-22 12:00:59 +02:00
|
|
|
|
2015-10-14 17:29:14 +02:00
|
|
|
if (whitelabel.head) {
|
2015-10-08 15:39:09 +02:00
|
|
|
constructHead(whitelabel.head);
|
|
|
|
}
|
2015-10-22 12:00:59 +02:00
|
|
|
|
2015-10-14 17:41:44 +02:00
|
|
|
if (whitelabel.subdomain && whitelabel.subdomain !== 'www' && whitelabel.logo){
|
2015-11-03 10:39:01 +01:00
|
|
|
return (
|
|
|
|
<Link to="/collection">
|
|
|
|
<img className="img-brand" src={whitelabel.logo} alt="Whitelabel brand"/>
|
|
|
|
</Link>
|
|
|
|
);
|
2015-06-29 15:58:47 +02:00
|
|
|
}
|
2015-10-22 12:00:59 +02:00
|
|
|
|
2015-09-29 16:48:46 +02:00
|
|
|
return (
|
2015-06-29 15:58:47 +02:00
|
|
|
<span>
|
2015-11-03 10:39:01 +01:00
|
|
|
<Link className="icon-ascribe-logo" to="/collection"/>
|
2015-09-29 16:48:46 +02:00
|
|
|
</span>
|
|
|
|
);
|
2015-06-29 15:58:47 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getPoweredBy(){
|
2015-09-29 16:48:46 +02:00
|
|
|
return (
|
|
|
|
<AclProxy
|
|
|
|
aclObject={this.state.whitelabel}
|
|
|
|
aclName="acl_view_powered_by">
|
|
|
|
<li>
|
2015-10-14 12:12:06 +02:00
|
|
|
<a className="pull-right ascribe-powered-by" href="https://www.ascribe.io/" target="_blank">
|
2015-09-29 16:48:46 +02:00
|
|
|
<span id="powered">{getLangText('powered by')} </span>
|
2015-10-13 13:32:48 +02:00
|
|
|
<span className="icon-ascribe-logo"></span>
|
2015-09-29 16:48:46 +02:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</AclProxy>
|
|
|
|
);
|
2015-06-29 15:58:47 +02:00
|
|
|
},
|
2015-09-29 16:48:46 +02:00
|
|
|
|
2015-05-20 16:19:40 +02:00
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
2015-07-14 21:47:14 +02:00
|
|
|
|
|
|
|
if(this.state.currentUser && this.state.currentUser.email) {
|
2015-07-27 18:06:02 +02:00
|
|
|
EventActions.profileDidLoad.defer(this.state.currentUser);
|
2015-07-14 21:47:14 +02:00
|
|
|
}
|
2015-05-20 16:19:40 +02:00
|
|
|
},
|
2015-06-15 15:28:53 +02:00
|
|
|
|
2015-09-23 15:16:46 +02:00
|
|
|
onMenuItemClick() {
|
2015-09-03 14:15:00 +02:00
|
|
|
/*
|
|
|
|
This is a hack to make the dropdown close after clicking on an item
|
|
|
|
The function just need to be defined
|
|
|
|
|
|
|
|
from https://github.com/react-bootstrap/react-bootstrap/issues/368:
|
|
|
|
|
|
|
|
@jvillasante - Have you tried to use onSelect with the DropdownButton?
|
|
|
|
I don't have a working example that is exactly like yours,
|
|
|
|
but I just noticed that the Dropdown closes when I've attached an event handler to OnSelect:
|
|
|
|
|
|
|
|
<DropdownButton eventKey={3} title="Admin" onSelect={ this.OnSelected } >
|
|
|
|
|
|
|
|
onSelected: function(e) {
|
|
|
|
// doesn't need to have functionality (necessarily) ... just wired up
|
|
|
|
}
|
|
|
|
Internally, a call to DropdownButton.setDropDownState(false) is made which will hide the dropdown menu.
|
|
|
|
So, you should be able to call that directly on the DropdownButton instance as well if needed.
|
|
|
|
|
|
|
|
NOW, THAT DIDN'T WORK - the onSelect routine isnt triggered in all cases
|
|
|
|
Hence, we do this manually
|
|
|
|
*/
|
|
|
|
this.refs.dropdownbutton.setDropdownState(false);
|
|
|
|
},
|
|
|
|
|
2015-05-20 16:19:40 +02:00
|
|
|
render() {
|
2015-08-28 15:29:30 +02:00
|
|
|
let account;
|
|
|
|
let signup;
|
|
|
|
let navRoutesLinks;
|
2015-06-15 12:36:27 +02:00
|
|
|
if (this.state.currentUser.username){
|
|
|
|
account = (
|
2015-09-01 18:38:24 +02:00
|
|
|
<DropdownButton
|
2015-09-03 14:15:00 +02:00
|
|
|
ref='dropdownbutton'
|
2015-09-01 18:38:24 +02:00
|
|
|
eventKey="1"
|
|
|
|
title={this.state.currentUser.username}>
|
2015-10-01 14:00:56 +02:00
|
|
|
<LinkContainer
|
|
|
|
to="/settings"
|
2015-09-03 14:15:00 +02:00
|
|
|
onClick={this.onMenuItemClick}>
|
2015-10-01 14:00:56 +02:00
|
|
|
<MenuItem
|
|
|
|
eventKey="2">
|
|
|
|
{getLangText('Account Settings')}
|
|
|
|
</MenuItem>
|
|
|
|
</LinkContainer>
|
2015-09-23 15:16:46 +02:00
|
|
|
<AclProxy
|
2015-09-23 15:41:12 +02:00
|
|
|
aclObject={this.state.currentUser.acl}
|
2015-09-23 15:16:46 +02:00
|
|
|
aclName="acl_view_settings_contract">
|
2015-10-01 14:00:56 +02:00
|
|
|
<LinkContainer
|
|
|
|
to="/contract_settings"
|
2015-09-23 15:16:46 +02:00
|
|
|
onClick={this.onMenuItemClick}>
|
2015-10-01 14:00:56 +02:00
|
|
|
<MenuItem
|
|
|
|
eventKey="2">
|
|
|
|
{getLangText('Contract Settings')}
|
|
|
|
</MenuItem>
|
|
|
|
</LinkContainer>
|
2015-09-23 15:16:46 +02:00
|
|
|
</AclProxy>
|
2015-06-22 10:50:22 +02:00
|
|
|
<MenuItem divider />
|
2015-10-01 14:00:56 +02:00
|
|
|
<LinkContainer
|
|
|
|
to="/logout">
|
|
|
|
<MenuItem
|
|
|
|
eventKey="3">
|
|
|
|
{getLangText('Log out')}
|
|
|
|
</MenuItem>
|
|
|
|
</LinkContainer>
|
2015-09-01 14:45:14 +02:00
|
|
|
</DropdownButton>
|
2015-06-15 12:36:27 +02:00
|
|
|
);
|
2015-09-08 14:20:06 +02:00
|
|
|
navRoutesLinks = <NavRoutesLinks routes={this.props.routes} userAcl={this.state.currentUser.acl} navbar right/>;
|
2015-06-15 12:36:27 +02:00
|
|
|
}
|
2015-06-15 15:28:53 +02:00
|
|
|
else {
|
2015-10-01 14:00:56 +02:00
|
|
|
account = (
|
|
|
|
<LinkContainer
|
|
|
|
to="/login">
|
|
|
|
<NavItem>
|
|
|
|
{getLangText('LOGIN')}
|
|
|
|
</NavItem>
|
|
|
|
</LinkContainer>
|
|
|
|
);
|
|
|
|
signup = (
|
|
|
|
<LinkContainer
|
|
|
|
to="/signup">
|
|
|
|
<NavItem>
|
|
|
|
{getLangText('SIGNUP')}
|
|
|
|
</NavItem>
|
|
|
|
</LinkContainer>
|
|
|
|
);
|
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
|
2015-10-01 14:00:56 +02:00
|
|
|
brand={this.getLogo()}
|
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-14 19:01:14 +02:00
|
|
|
<Nav navbar left>
|
|
|
|
{this.getPoweredBy()}
|
|
|
|
</Nav>
|
2015-06-29 15:58:47 +02:00
|
|
|
<Nav navbar right>
|
2015-11-03 10:39:01 +01:00
|
|
|
<HeaderNotificationDebug show = {false}/>
|
2015-06-29 15:58:47 +02:00
|
|
|
{account}
|
|
|
|
{signup}
|
|
|
|
</Nav>
|
2015-09-01 18:11:18 +02:00
|
|
|
<HeaderNotifications />
|
2015-08-28 15:29:30 +02:00
|
|
|
{navRoutesLinks}
|
2015-06-29 15:58:47 +02:00
|
|
|
</CollapsibleNav>
|
|
|
|
</Navbar>
|
|
|
|
</div>
|
2015-05-21 15:20:02 +02:00
|
|
|
);
|
2015-05-20 16:19:40 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default Header;
|