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-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-08 11:19:11 +02:00
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
|
|
|
|
2015-08-31 16:36:24 +02:00
|
|
|
let ContractSettings = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
defaultExpanded: React.PropTypes.bool
|
|
|
|
},
|
2015-09-08 11:19:11 +02:00
|
|
|
|
2015-09-02 14:02:23 +02:00
|
|
|
getInitialState(){
|
|
|
|
return ContractListStore.getState();
|
|
|
|
},
|
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
|
|
|
|
|
|
|
makeContractPublic(contract) {
|
|
|
|
return () => {
|
2015-09-08 14:43:06 +02:00
|
|
|
contract.is_public = true;
|
2015-09-08 11:44:05 +02:00
|
|
|
ContractListActions.changeContract(contract)
|
2015-09-09 11:11:16 +02:00
|
|
|
.then(() => {
|
2015-09-15 17:18:38 +02:00
|
|
|
ContractListActions.fetchContractList(true);
|
2015-09-09 11:11:16 +02:00
|
|
|
let notification = getLangText('Contract %s is now public', contract.name);
|
|
|
|
notification = new GlobalNotificationModel(notification, 'success', 4000);
|
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
})
|
2015-09-08 11:44:05 +02:00
|
|
|
.catch((err) => {
|
|
|
|
let 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-07 11:38:23 +02:00
|
|
|
},
|
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);
|
2015-09-09 11:11:16 +02:00
|
|
|
let notification = new GlobalNotificationModel(response.notification, 'success', 4000);
|
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
})
|
2015-09-08 11:44:05 +02:00
|
|
|
.catch((err) => {
|
|
|
|
let 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
|
|
|
|
2015-09-03 15:53:02 +02: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
|
|
|
|
2015-09-03 15:53:02 +02: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() {
|
2015-09-03 15:53:02 +02:00
|
|
|
let publicContracts = this.getPublicContracts();
|
|
|
|
let privateContracts = this.getPrivateContracts();
|
2015-09-08 10:03:20 +02:00
|
|
|
|
2015-08-31 16:36:24 +02:00
|
|
|
return (
|
|
|
|
<CollapsibleParagraph
|
|
|
|
title={getLangText('Contract Settings')}
|
|
|
|
show={true}
|
2015-09-08 10:03:20 +02:00
|
|
|
defaultExpanded={true}>
|
2015-09-02 14:02:23 +02:00
|
|
|
<CollapsibleParagraph
|
|
|
|
title={getLangText('List Contracts')}
|
|
|
|
show={true}
|
2015-09-08 10:03:20 +02:00
|
|
|
defaultExpanded={true}>
|
|
|
|
<CollapsibleParagraph
|
|
|
|
title={getLangText('Public Contracts')}
|
|
|
|
show={true}
|
|
|
|
defaultExpanded={true}>
|
2015-09-08 11:19:11 +02:00
|
|
|
{publicContracts.map((contract, i) => {
|
2015-09-03 18:25:12 +02:00
|
|
|
return (
|
2015-09-08 10:03:20 +02:00
|
|
|
<ActionPanel
|
2015-09-08 11:19:11 +02:00
|
|
|
key={i}
|
2015-09-08 10:03:20 +02:00
|
|
|
title={contract.name}
|
|
|
|
content={contract.name}
|
|
|
|
buttons={
|
2015-09-08 10:15:26 +02:00
|
|
|
<div className="pull-right">
|
2015-09-08 10:03:20 +02:00
|
|
|
<button className="btn btn-default btn-sm margin-left-2px">
|
|
|
|
UPDATE
|
|
|
|
</button>
|
2015-09-08 11:44:05 +02:00
|
|
|
<button
|
|
|
|
className="btn btn-default btn-sm margin-left-2px"
|
|
|
|
onClick={this.removeContract(contract)}>
|
2015-09-08 10:03:20 +02:00
|
|
|
REMOVE
|
|
|
|
</button>
|
2015-09-08 10:15:26 +02:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
leftColumnWidth="40%"
|
2015-09-08 11:19:11 +02:00
|
|
|
rightColumnWidth="60%"/>
|
2015-09-08 10:03:20 +02:00
|
|
|
);
|
|
|
|
})}
|
|
|
|
</CollapsibleParagraph>
|
|
|
|
<CollapsibleParagraph
|
|
|
|
title={getLangText('Private Contracts')}
|
|
|
|
show={true}
|
|
|
|
defaultExpanded={true}>
|
2015-09-08 11:19:11 +02:00
|
|
|
{privateContracts.map((contract, i) => {
|
2015-09-03 18:25:12 +02:00
|
|
|
return (
|
2015-09-08 10:03:20 +02:00
|
|
|
<ActionPanel
|
2015-09-08 11:19:11 +02:00
|
|
|
key={i}
|
2015-09-08 10:03:20 +02:00
|
|
|
title={contract.name}
|
|
|
|
content={contract.name}
|
|
|
|
buttons={
|
2015-09-08 10:15:26 +02:00
|
|
|
<div className="pull-right">
|
2015-09-08 10:03:20 +02:00
|
|
|
<button className="btn btn-default btn-sm margin-left-2px">
|
2015-09-08 10:15:26 +02:00
|
|
|
UPDATE
|
|
|
|
</button>
|
2015-09-08 11:44:05 +02:00
|
|
|
<button
|
|
|
|
className="btn btn-default btn-sm margin-left-2px"
|
|
|
|
onClick={this.removeContract(contract)}>
|
2015-09-08 10:15:26 +02:00
|
|
|
REMOVE
|
|
|
|
</button>
|
2015-09-08 11:44:05 +02:00
|
|
|
<button
|
|
|
|
className="btn btn-default btn-sm margin-left-2px"
|
|
|
|
onClick={this.makeContractPublic(contract)}>
|
2015-09-08 10:15:26 +02:00
|
|
|
MAKE PUBLIC
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
leftColumnWidth="40%"
|
|
|
|
rightColumnWidth="60%"/>
|
2015-09-08 10:03:20 +02:00
|
|
|
);
|
|
|
|
})}
|
|
|
|
</CollapsibleParagraph>
|
2015-09-02 14:02:23 +02:00
|
|
|
</CollapsibleParagraph>
|
|
|
|
<CollapsibleParagraph
|
|
|
|
title={getLangText('Create Contract')}
|
|
|
|
show={true}
|
2015-09-08 10:03:20 +02:00
|
|
|
defaultExpanded={true}>
|
2015-09-02 14:02:23 +02:00
|
|
|
<CreateContractForm />
|
|
|
|
</CollapsibleParagraph>
|
2015-08-31 16:36:24 +02:00
|
|
|
</CollapsibleParagraph>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default ContractSettings;
|