2015-08-31 16:36:24 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import CollapsibleParagraph from '../ascribe_collapsible/collapsible_paragraph';
|
2015-09-01 14:42:09 +02:00
|
|
|
import CreateContractForm from '../ascribe_forms/form_create_contract';
|
2015-08-31 16:36:24 +02:00
|
|
|
|
2015-09-02 14:02:23 +02:00
|
|
|
import ContractListStore from '../../stores/contract_list_store';
|
|
|
|
import ContractListActions from '../../actions/contract_list_actions';
|
2015-08-31 16:36:24 +02:00
|
|
|
|
2015-09-03 15:53:02 +02:00
|
|
|
import ActionPanel from '../ascribe_panel/action_panel';
|
2015-09-15 11:50:23 +02:00
|
|
|
import ContractSettingsUpdateButton from './contract_settings_update_button';
|
2015-09-03 15:53:02 +02:00
|
|
|
|
2015-09-03 17:19:29 +02:00
|
|
|
import GlobalNotificationModel from '../../models/global_notification_model';
|
|
|
|
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
2015-08-31 16:36:24 +02:00
|
|
|
|
2015-09-18 09:46:37 +02:00
|
|
|
import AclProxy from '../acl_proxy';
|
|
|
|
|
2015-09-08 11:19:11 +02:00
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
2015-10-13 16:42:40 +02:00
|
|
|
import { setDocumentTitle } from '../../utils/dom_utils';
|
2016-02-05 10:38:59 +01:00
|
|
|
import { truncateTextAtCharIndex } from '../../utils/general_utils';
|
2015-09-08 11:19:11 +02:00
|
|
|
|
2015-09-15 11:50:23 +02:00
|
|
|
|
2015-08-31 16:36:24 +02:00
|
|
|
let ContractSettings = React.createClass({
|
2015-09-30 18:30:50 +02:00
|
|
|
propTypes: {
|
2016-01-11 12:54:15 +01:00
|
|
|
// Provided from AscribeApp
|
2016-02-05 11:53:33 +01:00
|
|
|
currentUser: React.PropTypes.object.isRequired,
|
|
|
|
whitelabel: React.PropTypes.object.isRequired,
|
2016-01-11 12:54:15 +01:00
|
|
|
|
2016-01-11 16:26:36 +01:00
|
|
|
// Provided from router
|
2015-09-30 18:30:50 +02:00
|
|
|
location: React.PropTypes.object
|
|
|
|
},
|
|
|
|
|
2016-01-11 12:54:15 +01:00
|
|
|
getInitialState() {
|
|
|
|
return ContractListStore.getState();
|
2015-09-02 14:02:23 +02:00
|
|
|
},
|
2015-09-08 11:19:11 +02:00
|
|
|
|
2015-09-02 14:02:23 +02:00
|
|
|
componentDidMount() {
|
|
|
|
ContractListStore.listen(this.onChange);
|
2015-09-15 17:18:38 +02:00
|
|
|
ContractListActions.fetchContractList(true);
|
2015-09-02 14:02:23 +02:00
|
|
|
},
|
2015-09-08 11:19:11 +02:00
|
|
|
|
2015-09-02 14:02:23 +02:00
|
|
|
componentWillUnmount() {
|
|
|
|
ContractListStore.unlisten(this.onChange);
|
|
|
|
},
|
2015-09-08 11:19:11 +02:00
|
|
|
|
2015-09-02 14:02:23 +02:00
|
|
|
onChange(state) {
|
|
|
|
this.setState(state);
|
|
|
|
},
|
2015-09-08 11:19:11 +02:00
|
|
|
|
|
|
|
removeContract(contract) {
|
|
|
|
return () => {
|
|
|
|
ContractListActions.removeContract(contract.id)
|
2015-09-09 11:11:16 +02:00
|
|
|
.then((response) => {
|
2015-09-15 17:18:38 +02:00
|
|
|
ContractListActions.fetchContractList(true);
|
2016-02-05 10:38:59 +01:00
|
|
|
const notification = new GlobalNotificationModel(response.notification, 'success', 4000);
|
2015-09-09 11:11:16 +02:00
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
})
|
2015-09-08 11:44:05 +02:00
|
|
|
.catch((err) => {
|
2016-02-05 10:38:59 +01:00
|
|
|
const notification = new GlobalNotificationModel(err, 'danger', 10000);
|
2015-09-08 11:19:11 +02:00
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
2015-09-09 11:11:16 +02:00
|
|
|
});
|
2015-09-08 11:19:11 +02:00
|
|
|
};
|
2015-09-03 15:53:02 +02:00
|
|
|
},
|
2015-09-08 11:19:11 +02:00
|
|
|
|
2016-01-11 12:54:15 +01:00
|
|
|
getPublicContracts() {
|
2015-09-08 15:06:19 +02:00
|
|
|
return this.state.contractList.filter((contract) => contract.is_public);
|
2015-09-03 15:53:02 +02:00
|
|
|
},
|
2015-09-08 11:19:11 +02:00
|
|
|
|
2016-01-11 12:54:15 +01:00
|
|
|
getPrivateContracts() {
|
2015-09-08 15:06:19 +02:00
|
|
|
return this.state.contractList.filter((contract) => !contract.is_public);
|
2015-09-03 15:53:02 +02:00
|
|
|
},
|
2015-09-08 11:19:11 +02:00
|
|
|
|
2015-08-31 16:36:24 +02:00
|
|
|
render() {
|
2016-01-11 12:54:15 +01:00
|
|
|
const { currentUser, location, whitelabel } = this.props;
|
|
|
|
const publicContracts = this.getPublicContracts();
|
|
|
|
const privateContracts = this.getPrivateContracts();
|
2015-09-14 17:02:47 +02:00
|
|
|
let createPublicContractForm = null;
|
|
|
|
|
2015-10-13 16:42:40 +02:00
|
|
|
setDocumentTitle(getLangText('Contracts settings'));
|
|
|
|
|
2016-01-11 12:54:15 +01:00
|
|
|
if (publicContracts.length === 0) {
|
2015-09-14 17:02:47 +02:00
|
|
|
createPublicContractForm = (
|
|
|
|
<CreateContractForm
|
|
|
|
fileClassToUpload={{
|
2015-09-18 15:17:24 +02:00
|
|
|
singular: 'new contract',
|
|
|
|
plural: 'new contracts'
|
2015-09-30 18:30:50 +02:00
|
|
|
}}
|
2016-02-05 10:38:59 +01:00
|
|
|
isPublic={true} />
|
2015-09-14 17:02:47 +02:00
|
|
|
);
|
|
|
|
}
|
2015-09-08 10:03:20 +02:00
|
|
|
|
2015-08-31 16:36:24 +02:00
|
|
|
return (
|
2015-09-23 15:16:46 +02:00
|
|
|
<div className="settings-container">
|
2015-09-14 17:38:26 +02:00
|
|
|
<CollapsibleParagraph
|
2015-09-18 09:46:37 +02:00
|
|
|
title={getLangText('Contracts')}
|
2015-09-23 15:41:12 +02:00
|
|
|
defaultExpanded={true}>
|
2015-09-18 09:46:37 +02:00
|
|
|
<AclProxy
|
|
|
|
aclName="acl_edit_public_contract"
|
2016-01-11 12:54:15 +01:00
|
|
|
aclObject={currentUser.acl}>
|
2015-09-18 15:17:24 +02:00
|
|
|
<div>
|
2015-09-18 09:46:37 +02:00
|
|
|
{createPublicContractForm}
|
|
|
|
{publicContracts.map((contract, i) => {
|
|
|
|
return (
|
|
|
|
<ActionPanel
|
2016-02-05 10:38:59 +01:00
|
|
|
key={contract.id}
|
2015-09-18 09:46:37 +02:00
|
|
|
title={contract.name}
|
2015-09-25 15:22:16 +02:00
|
|
|
content={truncateTextAtCharIndex(contract.name, 120, '(...).pdf')}
|
2015-09-18 09:46:37 +02:00
|
|
|
buttons={
|
|
|
|
<div className="pull-right">
|
2015-09-23 16:09:12 +02:00
|
|
|
<AclProxy
|
2016-01-11 12:54:15 +01:00
|
|
|
aclObject={whitelabel}
|
2015-09-23 16:09:12 +02:00
|
|
|
aclName="acl_update_public_contract">
|
2016-02-05 10:38:59 +01:00
|
|
|
<ContractSettingsUpdateButton contract={contract} />
|
2015-09-23 16:09:12 +02:00
|
|
|
</AclProxy>
|
2015-09-18 09:46:37 +02:00
|
|
|
<a
|
|
|
|
className="btn btn-default btn-sm margin-left-2px"
|
|
|
|
href={contract.blob.url_safe}
|
|
|
|
target="_blank">
|
|
|
|
{getLangText('PREVIEW')}
|
|
|
|
</a>
|
|
|
|
<button
|
2015-09-18 15:22:57 +02:00
|
|
|
className="btn btn-danger btn-sm margin-left-2px"
|
2015-09-18 09:46:37 +02:00
|
|
|
onClick={this.removeContract(contract)}>
|
|
|
|
{getLangText('REMOVE')}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
leftColumnWidth="40%"
|
|
|
|
rightColumnWidth="60%"/>
|
|
|
|
);
|
|
|
|
})}
|
2015-09-18 15:17:24 +02:00
|
|
|
</div>
|
2015-09-18 09:46:37 +02:00
|
|
|
</AclProxy>
|
|
|
|
<AclProxy
|
|
|
|
aclName="acl_edit_private_contract"
|
2016-01-11 12:54:15 +01:00
|
|
|
aclObject={currentUser.acl}>
|
2015-09-18 15:17:24 +02:00
|
|
|
<div>
|
2015-09-18 09:46:37 +02:00
|
|
|
<CreateContractForm
|
2016-02-05 10:38:59 +01:00
|
|
|
fileClassToUpload={{
|
|
|
|
singular: getLangText('new contract'),
|
|
|
|
plural: getLangText('new contracts')
|
|
|
|
}}
|
|
|
|
isPublic={false} />
|
2015-09-18 09:46:37 +02:00
|
|
|
{privateContracts.map((contract, i) => {
|
|
|
|
return (
|
|
|
|
<ActionPanel
|
2016-02-05 10:38:59 +01:00
|
|
|
key={contract.id}
|
2015-09-18 09:46:37 +02:00
|
|
|
title={contract.name}
|
2015-09-25 15:22:16 +02:00
|
|
|
content={truncateTextAtCharIndex(contract.name, 120, '(...).pdf')}
|
2015-09-18 09:46:37 +02:00
|
|
|
buttons={
|
|
|
|
<div className="pull-right">
|
2015-09-23 16:09:12 +02:00
|
|
|
<AclProxy
|
2016-01-11 12:54:15 +01:00
|
|
|
aclObject={whitelabel}
|
2015-09-23 16:09:12 +02:00
|
|
|
aclName="acl_update_private_contract">
|
2016-02-05 10:38:59 +01:00
|
|
|
<ContractSettingsUpdateButton contract={contract} />
|
2015-09-23 16:09:12 +02:00
|
|
|
</AclProxy>
|
2015-09-18 09:46:37 +02:00
|
|
|
<a
|
|
|
|
className="btn btn-default btn-sm margin-left-2px"
|
|
|
|
href={contract.blob.url_safe}
|
|
|
|
target="_blank">
|
|
|
|
{getLangText('PREVIEW')}
|
|
|
|
</a>
|
|
|
|
<button
|
2015-09-18 15:22:57 +02:00
|
|
|
className="btn btn-danger btn-sm margin-left-2px"
|
2015-09-18 09:46:37 +02:00
|
|
|
onClick={this.removeContract(contract)}>
|
|
|
|
{getLangText('REMOVE')}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
}
|
2015-09-25 11:20:12 +02:00
|
|
|
leftColumnWidth="60%"
|
|
|
|
rightColumnWidth="40%"/>
|
2015-09-18 09:46:37 +02:00
|
|
|
);
|
|
|
|
})}
|
2015-09-18 15:17:24 +02:00
|
|
|
</div>
|
2015-09-18 09:46:37 +02:00
|
|
|
</AclProxy>
|
2015-09-02 14:02:23 +02:00
|
|
|
</CollapsibleParagraph>
|
2015-09-23 15:16:46 +02:00
|
|
|
</div>
|
2015-08-31 16:36:24 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-13 16:42:40 +02:00
|
|
|
export default ContractSettings;
|