'use strict'; import React from 'react'; import CollapsibleParagraph from '../ascribe_collapsible/collapsible_paragraph'; import CreateContractForm from '../ascribe_forms/form_create_contract'; import ContractListStore from '../../stores/contract_list_store'; import ContractListActions from '../../actions/contract_list_actions'; import ActionPanel from '../ascribe_panel/action_panel'; import ContractSettingsUpdateButton from './contract_settings_update_button'; import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationActions from '../../actions/global_notification_actions'; import AclProxy from '../acl_proxy'; import { getLangText } from '../../utils/lang_utils'; import { setDocumentTitle } from '../../utils/dom_utils'; import { truncateTextAtCharIndex } from '../../utils/general_utils'; let ContractSettings = React.createClass({ propTypes: { // Provided from AscribeApp currentUser: React.PropTypes.object.isRequired, whitelabel: React.PropTypes.object.isRequired, // Provided from router location: React.PropTypes.object }, getInitialState() { return ContractListStore.getState(); }, componentDidMount() { ContractListStore.listen(this.onChange); ContractListActions.fetchContractList(true); }, componentWillUnmount() { ContractListStore.unlisten(this.onChange); }, onChange(state) { this.setState(state); }, removeContract(contract) { return () => { ContractListActions.removeContract(contract.id) .then((response) => { ContractListActions.fetchContractList(true); const notification = new GlobalNotificationModel(response.notification, 'success', 4000); GlobalNotificationActions.appendGlobalNotification(notification); }) .catch((err) => { const notification = new GlobalNotificationModel(err, 'danger', 10000); GlobalNotificationActions.appendGlobalNotification(notification); }); }; }, getPublicContracts() { return this.state.contractList.filter((contract) => contract.is_public); }, getPrivateContracts() { return this.state.contractList.filter((contract) => !contract.is_public); }, render() { const { currentUser, location, whitelabel } = this.props; const publicContracts = this.getPublicContracts(); const privateContracts = this.getPrivateContracts(); let createPublicContractForm = null; setDocumentTitle(getLangText('Contracts settings')); if (publicContracts.length === 0) { createPublicContractForm = ( ); } return (
{createPublicContractForm} {publicContracts.map((contract, i) => { return ( {getLangText('PREVIEW')}
} leftColumnWidth="40%" rightColumnWidth="60%"/> ); })}
{privateContracts.map((contract, i) => { return ( {getLangText('PREVIEW')}
} leftColumnWidth="60%" rightColumnWidth="40%"/> ); })}
); } }); export default ContractSettings;