2018-09-15 08:14:17 +00:00
|
|
|
import React from 'react';
|
2018-09-18 02:11:37 +00:00
|
|
|
import { gettext } from '../../components/constants';
|
2018-09-21 06:16:15 +00:00
|
|
|
import editUtilties from '../../utils/editor-utilties';
|
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';
|
|
|
|
|
2018-09-21 06:16:15 +00:00
|
|
|
class DraftsView extends React.Component {
|
2018-09-15 08:14:17 +00:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-09-21 06:16:15 +00:00
|
|
|
draftList: [],
|
|
|
|
isLoadingDraft: true,
|
2018-09-15 08:14:17 +00:00
|
|
|
isMenuShow: false,
|
|
|
|
menuPosition: {top:'', left: ''},
|
|
|
|
currentDraft: null,
|
|
|
|
isItemFreezed: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2018-09-21 06:16:15 +00:00
|
|
|
this.initDraftList();
|
2018-09-15 08:14:17 +00:00
|
|
|
document.addEventListener('click', this.onHideContextMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
document.removeEventListener('click', this.onHideContextMenu);
|
|
|
|
}
|
|
|
|
|
2018-09-21 06:16:15 +00:00
|
|
|
initDraftList() {
|
|
|
|
this.setState({isLoadingDraft: true});
|
|
|
|
editUtilties.listDrafts().then(res => {
|
|
|
|
this.setState({
|
|
|
|
draftList: res.data.data,
|
|
|
|
isLoadingDraft: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteHandler = () => {
|
|
|
|
let draft = this.state.currentDraft;
|
|
|
|
editUtilties.deleteDraft(draft.id).then(res => {
|
|
|
|
this.initDraftList();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onPublishHandler = () => {
|
|
|
|
let draft = this.state.currentDraft;
|
|
|
|
editUtilties.publishDraft(draft.id).then(res => {
|
|
|
|
this.initDraftList();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-15 08:14:17 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2018-09-21 06:16:15 +00:00
|
|
|
<div className="cur-view-container">
|
|
|
|
<div className="cur-view-path panel-heading text-left">{gettext('Drafts')}</div>
|
|
|
|
<div className="cur-view-content" style={{padding: 0}}>
|
|
|
|
{this.state.isLoadingDraft && <Loading /> }
|
|
|
|
{(!this.state.isLoadingDraft && this.state.draftList.length !==0) &&
|
|
|
|
<ListView
|
|
|
|
draftList={this.state.draftList}
|
|
|
|
isItemFreezed={this.state.isItemFreezed}
|
|
|
|
onMenuToggleClick={this.onMenuToggleClick}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
{(!this.state.isLoadingDraft && this.state.draftList.length === 0) &&
|
|
|
|
<div className="message empty-tip">
|
|
|
|
<h2>{gettext('There is no draft file existing')}</h2>
|
2018-09-15 08:14:17 +00:00
|
|
|
</div>
|
|
|
|
}
|
2018-09-21 06:16:15 +00:00
|
|
|
{this.state.isMenuShow &&
|
2018-09-15 08:14:17 +00:00
|
|
|
<ListMenu
|
|
|
|
isMenuShow={this.state.isMenuShow}
|
|
|
|
currentDraft={this.state.currentDraft}
|
|
|
|
menuPosition={this.state.menuPosition}
|
|
|
|
onPublishHandler={this.onPublishHandler}
|
|
|
|
onDeleteHandler={this.onDeleteHandler}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-21 06:16:15 +00:00
|
|
|
export default DraftsView;
|