From 501d7ac7c03d3f125a3e0474dd33ba70290f8a68 Mon Sep 17 00:00:00 2001 From: Cevo Date: Mon, 7 Sep 2015 11:38:23 +0200 Subject: [PATCH] now committing the remove contract --- js/actions/contract_list_actions.js | 15 +++++++++++ .../ascribe_settings/contract_settings.js | 25 +++++++++++++------ js/constants/api_urls.js | 2 +- js/fetchers/ownership_fetcher.js | 4 +++ 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/js/actions/contract_list_actions.js b/js/actions/contract_list_actions.js index 608b5df1..b9dad5db 100644 --- a/js/actions/contract_list_actions.js +++ b/js/actions/contract_list_actions.js @@ -38,6 +38,21 @@ class ContractListActions { }); }); } + + removeContract(contract){ + return Q.Promise((resolve, reject) => { + OwnershipFetcher.deleteContract(contract) + .then((res) => { + console.log('Contract deleted'); + resolve(res); + }) + .catch( (err) => { + console.log('Error while deleting'); + console.logGlobal(err); + reject(err); + }); + }); + } } export default alt.createActions(ContractListActions); diff --git a/js/components/ascribe_settings/contract_settings.js b/js/components/ascribe_settings/contract_settings.js index f38464f3..95130f28 100644 --- a/js/components/ascribe_settings/contract_settings.js +++ b/js/components/ascribe_settings/contract_settings.js @@ -36,9 +36,18 @@ let ContractSettings = React.createClass({ ContractListActions.makeContractPublic(contract) .then(( ) => ContractListActions.fetchContractList()) .catch((error)=>{console.log('Error ', error); - let notification = new GlobalNotificationModel('Service is unavailable', 'danger', 10000); - GlobalNotificationActions.appendGlobalNotification(notification); -}); + let notification = new GlobalNotificationModel('Service is unavailable', 'danger', 10000); + GlobalNotificationActions.appendGlobalNotification(notification); + }); + }, + removeContract(contract){ + console.log(contract); + ContractListActions.removeContract(contract) + .then(( ) => ContractListActions.fetchContractList()) + .catch((error) => {console.log('Error', error); + let notification = new GlobalNotificationModel('Service is unavailable', 'danger', 10000); + GlobalNotificationActions.appendGlobalNotification(notification); + }); }, getPublicContracts(){ return this.state.contractList.filter((contract) => contract.public); @@ -70,10 +79,11 @@ let ContractSettings = React.createClass({ (contract) => { return ( - + } />); } @@ -87,9 +97,10 @@ let ContractSettings = React.createClass({ (contract) => { return ( - + } />); diff --git a/js/constants/api_urls.js b/js/constants/api_urls.js index 1af9c609..5af07ba6 100644 --- a/js/constants/api_urls.js +++ b/js/constants/api_urls.js @@ -48,7 +48,7 @@ let ApiUrls = { 'ownership_unconsigns_deny': AppConstants.apiEndpoint + 'ownership/unconsigns/deny/', 'ownership_unconsigns_request': AppConstants.apiEndpoint + 'ownership/unconsigns/request/', 'ownership_contract': AppConstants.apiEndpoint + 'ownership/contracts/${contract_id}/', - "ownership_contract_list": AppConstants.apiEndpoint + 'ownership/contracts/', + 'ownership_contract_list': AppConstants.apiEndpoint + 'ownership/contracts/', 'piece': AppConstants.apiEndpoint + 'pieces/${piece_id}/', 'piece_extradata': AppConstants.apiEndpoint + 'pieces/${piece_id}/extradata/', 'piece_first_edition_id': AppConstants.apiEndpoint + 'pieces/${piece_id}/edition_index/', diff --git a/js/fetchers/ownership_fetcher.js b/js/fetchers/ownership_fetcher.js index 9b5e81f7..751790ba 100644 --- a/js/fetchers/ownership_fetcher.js +++ b/js/fetchers/ownership_fetcher.js @@ -25,6 +25,10 @@ let OwnershipFetcher = { makeContractPublic(contractObj){ return requests.put('ownership_contract', { body: contractObj, contract_id: contractObj.id }); + }, + + deleteContract(contractObj){ + return requests.delete('ownership_contract', {body: contractObj, contract_id: contractObj.id}); } };