2018-09-15 08:14:17 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-09-18 02:11:37 +00:00
|
|
|
import { gettext } from '../../components/constants';
|
2018-09-20 02:19:11 +00:00
|
|
|
import CommonToolbar from '../../components/toolbar/common-toolbar';
|
2018-09-15 08:14:17 +00:00
|
|
|
import Loading from '../../components/loading';
|
|
|
|
import ListView from '../../components/list-view/list-view';
|
|
|
|
import ListMenu from '../../components/list-view/list-menu';
|
|
|
|
|
|
|
|
const propTypes = {
|
2018-09-20 02:19:11 +00:00
|
|
|
isLoadingDraft: PropTypes.bool.isRequired,
|
2018-09-15 08:14:17 +00:00
|
|
|
draftList: PropTypes.array.isRequired,
|
2018-09-20 02:19:11 +00:00
|
|
|
publishDraft: PropTypes.func.isRequired,
|
|
|
|
deleteDraft: PropTypes.func.isRequired
|
2018-09-15 08:14:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MainPanel extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
isMenuShow: false,
|
|
|
|
menuPosition: {top:'', left: ''},
|
|
|
|
currentDraft: null,
|
|
|
|
isItemFreezed: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
document.addEventListener('click', this.onHideContextMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
document.removeEventListener('click', this.onHideContextMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
onMenuToggleClick = (e, draft) => {
|
|
|
|
if (this.state.isMenuShow) {
|
|
|
|
this.onHideContextMenu();
|
|
|
|
} else {
|
|
|
|
this.onShowContextMenu(e, draft);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onShowContextMenu = (e, draft) => {
|
|
|
|
let left = e.clientX - 8*16;
|
|
|
|
let top = e.clientY + 10;
|
|
|
|
let position = {top: top, left: left};
|
|
|
|
this.setState({
|
|
|
|
isMenuShow: true,
|
|
|
|
menuPosition: position,
|
|
|
|
currentDraft: draft,
|
|
|
|
isItemFreezed: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onHideContextMenu = () => {
|
|
|
|
this.setState({
|
|
|
|
isMenuShow: false,
|
|
|
|
currentDraft: null,
|
|
|
|
isItemFreezed: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onPublishHandler = () => {
|
|
|
|
this.props.publishDraft(this.state.currentDraft);
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteHandler = () => {
|
|
|
|
this.props.deleteDraft(this.state.currentDraft);
|
|
|
|
}
|
2018-09-20 02:19:11 +00:00
|
|
|
|
|
|
|
onSearchedClick = () => {
|
|
|
|
//todos;
|
|
|
|
}
|
2018-09-15 08:14:17 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="main-panel">
|
|
|
|
<div className="main-panel-north flex-right">
|
2018-09-20 02:19:11 +00:00
|
|
|
<CommonToolbar onSearchedClick={this.onSearchedClick}/>
|
2018-09-15 08:14:17 +00:00
|
|
|
</div>
|
|
|
|
<div className="main-panel-center">
|
|
|
|
<div className="panel-heading text-left">{gettext('Drafts')}</div>
|
|
|
|
{this.props.isLoadingDraft ?
|
|
|
|
<Loading /> :
|
|
|
|
<div className="table-container">
|
|
|
|
{this.props.draftList.length ?
|
|
|
|
<ListView
|
|
|
|
draftList={this.props.draftList}
|
|
|
|
isItemFreezed={this.state.isItemFreezed}
|
|
|
|
onMenuToggleClick={this.onMenuToggleClick}
|
|
|
|
/> :
|
|
|
|
<div className="message empty-tip">
|
|
|
|
<h2>{gettext('There is no draft file existing')}</h2>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
{
|
|
|
|
this.state.isMenuShow &&
|
|
|
|
<ListMenu
|
|
|
|
isMenuShow={this.state.isMenuShow}
|
|
|
|
currentDraft={this.state.currentDraft}
|
|
|
|
menuPosition={this.state.menuPosition}
|
|
|
|
onPublishHandler={this.onPublishHandler}
|
|
|
|
onDeleteHandler={this.onDeleteHandler}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MainPanel.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default MainPanel;
|