1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

fixed tests

refactored contractagreement actions
This commit is contained in:
diminator 2015-09-14 17:53:50 +02:00
parent 7fd5516b79
commit 0ce298879b
2 changed files with 38 additions and 18 deletions

View File

@ -36,18 +36,28 @@ class ContractAgreementListActions {
}
fetchAvailableContractAgreementList(issuer){
return Q.Promise((resolve, reject) => {
this.actions.fetchContractAgreementList(issuer, 'True', null)
.then((contractAgreementListAccepted) => {
if (!contractAgreementListAccepted) {
// fetch pending agreements if no accepted ones
return this.actions.fetchContractAgreementList(issuer, null, 'True');
}
}).then((contractAgreementListPending) => {
// fetch public contract if no accepted nor pending agreements
if (!contractAgreementListPending) {
return ContractListActions.fetchContractList(null, null, issuer);
else {
resolve(contractAgreementListAccepted);
}
}).then((publicContract) => {
}).then((contractAgreementListPending) => {
resolve(contractAgreementListPending);
}).catch((err) => {
console.logGlobal(err);
reject(err);
});
});
}
createContractAgreementFromPublicContract(issuer){
ContractListActions.fetchContractList(null, null, issuer)
.then((publicContract) => {
// create an agreement with the public contract if there is one
if (publicContract && publicContract.length > 0) {
return this.actions.createContractAgreement(null, publicContract[0]);

View File

@ -54,9 +54,7 @@ let LoanForm = React.createClass({
componentDidMount() {
ContractAgreementListStore.listen(this.onChange);
if (this.props.email){
ContractAgreementListActions.fetchAvailableContractAgreementList.defer(this.props.email);
}
this.getContractAgreementsOrCreatePublic(this.props.email);
},
componentWillUnmount() {
@ -67,6 +65,18 @@ let LoanForm = React.createClass({
this.setState(state);
},
getContractAgreementsOrCreatePublic(email){
if (email) {
ContractAgreementListActions.fetchAvailableContractAgreementList(email).then(
(contractAgreementList) => {
if (!contractAgreementList) {
ContractAgreementListActions.createContractAgreementFromPublicContract.defer(email);
}
}
);
}
},
getFormData(){
return mergeOptions(
this.props.id,
@ -76,8 +86,8 @@ let LoanForm = React.createClass({
handleOnChange(event) {
// event.target.value is the submitted email of the loanee
if(event && event.target && event.target.value && event.target.value.match(/.*@.*/)) {
ContractAgreementListActions.fetchContractAgreementList(event.target.value, 'True', null);
if(event && event.target && event.target.value && event.target.value.match(/.*@.*\..*/)) {
this.getContractAgreementsOrCreatePublic(event.target.value);
} else {
ContractAgreementListActions.flushContractAgreementList();
}
@ -172,8 +182,8 @@ let LoanForm = React.createClass({
<Property
name='loanee'
label={getLangText('Loanee Email')}
onChange={this.handleOnChange}
editable={!this.props.email}
onBlur={this.handleOnChange}
overrideForm={!!this.props.email}>
<input
value={this.props.email}