From 58294687f9b255eadf9357a91d3ca21980da5aa7 Mon Sep 17 00:00:00 2001 From: diminator Date: Wed, 15 Jul 2015 17:51:09 +0200 Subject: [PATCH] fix acl and editions --- js/components/ascribe_buttons/acl_button.js | 2 +- .../ascribe_buttons/delete_button.js | 4 +- js/components/ascribe_forms/form_loan.js | 260 ++++++++++-------- js/components/ascribe_forms/form_loan_new.js | 168 ----------- js/components/ascribe_forms/input_checkbox.js | 2 +- 5 files changed, 142 insertions(+), 294 deletions(-) delete mode 100644 js/components/ascribe_forms/form_loan_new.js diff --git a/js/components/ascribe_buttons/acl_button.js b/js/components/ascribe_buttons/acl_button.js index 053320f5..c4826f86 100644 --- a/js/components/ascribe_buttons/acl_button.js +++ b/js/components/ascribe_buttons/acl_button.js @@ -5,7 +5,7 @@ import React from 'react'; import ConsignForm from '../ascribe_forms/form_consign'; import UnConsignForm from '../ascribe_forms/form_unconsign'; import TransferForm from '../ascribe_forms/form_transfer'; -import LoanForm from '../ascribe_forms/form_loan_new'; +import LoanForm from '../ascribe_forms/form_loan'; import ShareForm from '../ascribe_forms/form_share_email'; import ModalWrapper from '../ascribe_modal/modal_wrapper'; import AppConstants from '../../constants/application_constants'; diff --git a/js/components/ascribe_buttons/delete_button.js b/js/components/ascribe_buttons/delete_button.js index 085f153a..a60344df 100644 --- a/js/components/ascribe_buttons/delete_button.js +++ b/js/components/ascribe_buttons/delete_button.js @@ -52,10 +52,10 @@ let DeleteButton = React.createClass({ } else if(availableAcls.acl_unshare){ - if(this.props.editions && this.props.editions.constructor !== Array && this.props.editions.acl.acl_unshare) { + if(this.props.editions) { content = ; title = getLangText('Remove Edition from Collection'); - } else if(this.props.piece && this.props.piece.acl.acl_unshare) { + } else if(this.props.piece) { content = ; title = getLangText('Remove Piece from Collection'); } diff --git a/js/components/ascribe_forms/form_loan.js b/js/components/ascribe_forms/form_loan.js index 44240f76..f28aa28f 100644 --- a/js/components/ascribe_forms/form_loan.js +++ b/js/components/ascribe_forms/form_loan.js @@ -2,151 +2,167 @@ import React from 'react'; -import ApiUrls from '../../constants/api_urls'; -import FormMixin from '../../mixins/form_mixin'; -import InputText from './input_text'; -import InputHidden from './input_hidden'; -import InputCheckbox from './input_checkbox'; +import Button from 'react-bootstrap/lib/Button'; + +import Form from './form'; +import Property from './property'; +import InputTextAreaToggable from './input_textarea_toggable'; import InputDate from './input_date'; -import InputTextArea from './input_textarea'; +import InputCheckbox from './input_checkbox'; -import OwnershipFetcher from '../../fetchers/ownership_fetcher'; -import ButtonSubmitOrClose from '../ascribe_buttons/button_submit_close'; +import LoanContractStore from '../../stores/loan_contract_store'; +import LoanContractActions from '../../actions/loan_contract_actions'; + +import AppConstants from '../../constants/application_constants'; + +import { mergeOptions } from '../../utils/general_utils'; +import { getLangText } from '../../utils/lang_utils'; -import { getLangText } from '../../utils/lang_utils.js'; let LoanForm = React.createClass({ - + propTypes: { + url: React.PropTypes.string, + id: React.PropTypes.object, + message: React.PropTypes.string, + onRequestHide: React.PropTypes.func, + handleSuccess: React.PropTypes.func + }, + getInitialState() { - this.setState({ - contract_key: null, - contract_url: null, - loaneeHasContract: false - }); + return LoanContractStore.getState(); }, - mixins: [FormMixin], - - url() { - return ApiUrls.ownership_loans; + componentDidMount() { + LoanContractStore.listen(this.onChange); }, - getFormData() { - return { - bitcoin_id: this.getBitcoinIds().join(), - loanee: this.refs.loanee.state.value, - gallery_name: this.refs.gallery_name.state.value, - startdate: this.refs.startdate.state.value_formatted, - enddate: this.refs.enddate.state.value_formatted, - loan_message: this.refs.loan_message.state.value, - password: this.refs.password.state.value, - terms: this.refs.terms.state.value - }; + componentWillUnmount() { + LoanContractStore.unlisten(this.onChange); }, - handleLoanEmailBlur(){ - OwnershipFetcher.fetchLoanContract(this.refs.loanee.state.value) - .then((res) => { - if (res && res.length > 0) { - this.setState({ - contract_key: res[0].s3Key, - contract_url: res[0].s3Url, - loaneeHasContract: true - }); - } - else { - this.resetLoanContract(); - } - }) - .catch((err) => { - console.log(err); - this.resetLoanContract(); - }); + onChange(state) { + this.setState(state); }, - resetLoanContract(){ - this.setState({ - contract_key: null, - contract_url: null, - loaneeHasContract: false - }); + getFormData(){ + return this.props.id; }, - - renderForm() { - let title = this.getTitlesString().join(''); - let username = this.props.currentUser.username; - let message = -`${getLangText('Hi')}, -${getLangText('I loan')} : -${title}${getLangText('to you')}. + handleOnBlur(event) { + LoanContractActions.fetchLoanContract(event.target.value); + }, -${getLangText('Truly yours')}, -${username}`; - - let contract = ; - if (this.state.loaneeHasContract){ - let label = (
+ getContractCheckbox() { + if(this.state.contractKey && this.state.contractUrl) { + return ( + + + {getLangText('I agree to the')}  - - {getLangText('terms of')} {this.refs.loanee.state.value} + + {getLangText('terms of')} {this.state.contractEmail} -
); - contract = (); + + + + ); } + }, + + onRequestHide() { + // Since the modal can be opened without sending it to the server + // and therefore clearing the store, + // we'll need to make sure to flush the store once the + // modal unmounts + LoanContractActions.updateLoanContract({ + contractUrl: null, + contractEmail: null, + contractKey: null + }); + + this.props.onRequestHide(); + }, + + render() { return ( -
- - - - -
-
- -
-
- -
-
- - - {contract} - - +
+

+ + +

+ } + spinner={ +
+ +
}> + + + + + + + + + + + + + + + + + + + + {this.getContractCheckbox()} +
); } }); -export default LoanForm; +export default LoanForm; \ No newline at end of file diff --git a/js/components/ascribe_forms/form_loan_new.js b/js/components/ascribe_forms/form_loan_new.js deleted file mode 100644 index f28aa28f..00000000 --- a/js/components/ascribe_forms/form_loan_new.js +++ /dev/null @@ -1,168 +0,0 @@ -'use strict'; - -import React from 'react'; - -import Button from 'react-bootstrap/lib/Button'; - -import Form from './form'; -import Property from './property'; -import InputTextAreaToggable from './input_textarea_toggable'; -import InputDate from './input_date'; -import InputCheckbox from './input_checkbox'; - -import LoanContractStore from '../../stores/loan_contract_store'; -import LoanContractActions from '../../actions/loan_contract_actions'; - -import AppConstants from '../../constants/application_constants'; - -import { mergeOptions } from '../../utils/general_utils'; -import { getLangText } from '../../utils/lang_utils'; - - -let LoanForm = React.createClass({ - propTypes: { - url: React.PropTypes.string, - id: React.PropTypes.object, - message: React.PropTypes.string, - onRequestHide: React.PropTypes.func, - handleSuccess: React.PropTypes.func - }, - - getInitialState() { - return LoanContractStore.getState(); - }, - - componentDidMount() { - LoanContractStore.listen(this.onChange); - }, - - componentWillUnmount() { - LoanContractStore.unlisten(this.onChange); - }, - - onChange(state) { - this.setState(state); - }, - - getFormData(){ - return this.props.id; - }, - - handleOnBlur(event) { - LoanContractActions.fetchLoanContract(event.target.value); - }, - - getContractCheckbox() { - if(this.state.contractKey && this.state.contractUrl) { - return ( - - - - {getLangText('I agree to the')}  - - {getLangText('terms of')} {this.state.contractEmail} - - - - - ); - } - }, - - onRequestHide() { - // Since the modal can be opened without sending it to the server - // and therefore clearing the store, - // we'll need to make sure to flush the store once the - // modal unmounts - LoanContractActions.updateLoanContract({ - contractUrl: null, - contractEmail: null, - contractKey: null - }); - - this.props.onRequestHide(); - }, - - render() { - - return ( -
-

- - -

- } - spinner={ -
- -
}> - - - - - - - - - - - - - - - - - - - - {this.getContractCheckbox()} -
- ); - } -}); - -export default LoanForm; \ No newline at end of file diff --git a/js/components/ascribe_forms/input_checkbox.js b/js/components/ascribe_forms/input_checkbox.js index aafba067..6237fa6c 100644 --- a/js/components/ascribe_forms/input_checkbox.js +++ b/js/components/ascribe_forms/input_checkbox.js @@ -40,7 +40,7 @@ let InputCheckbox = React.createClass({ - + {this.props.children}