From a8fce698a63e542a4219da6fc69f1514c8ed89d5 Mon Sep 17 00:00:00 2001 From: Cevo Date: Tue, 8 Sep 2015 11:53:09 +0200 Subject: [PATCH] createcontract refresh added --- js/actions/contract_list_actions.js | 7 +++---- js/components/ascribe_forms/form_create_contract.js | 5 ++++- js/components/ascribe_settings/contract_settings.js | 8 +++++--- js/fetchers/ownership_fetcher.js | 4 ++-- js/utils/requests.js | 6 ++++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/js/actions/contract_list_actions.js b/js/actions/contract_list_actions.js index 307706ef..fd7b01c0 100644 --- a/js/actions/contract_list_actions.js +++ b/js/actions/contract_list_actions.js @@ -24,7 +24,6 @@ class ContractListActions { } makeContractPublic(contract){ - contract.public = true; return Q.Promise((resolve, reject) => { OwnershipFetcher.makeContractPublic(contract) .then((res) => { @@ -38,14 +37,14 @@ class ContractListActions { } removeContract(contractId){ - return Q.Promise((resolve, reject) => { + return Q.Promise( (resolve, reject) => { OwnershipFetcher.deleteContract(contractId) .then((res) => { - console.log('Contract deleted'); + console.log('Success...'); resolve(res); }) .catch( (err) => { - console.log('Error while deleting'); + console.log('Bad news...'); console.logGlobal(err); reject(err); }); diff --git a/js/components/ascribe_forms/form_create_contract.js b/js/components/ascribe_forms/form_create_contract.js index 55a94511..82c80485 100644 --- a/js/components/ascribe_forms/form_create_contract.js +++ b/js/components/ascribe_forms/form_create_contract.js @@ -8,12 +8,14 @@ import InputCheckbox from '../ascribe_forms/input_checkbox'; import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationActions from '../../actions/global_notification_actions'; - +import ContractListActions from '../../actions/contract_list_actions'; import ReactS3FineUploader from '../ascribe_uploader/react_s3_fine_uploader'; import AppConstants from '../../constants/application_constants'; import ApiUrls from '../../constants/api_urls'; + + import { getLangText } from '../../utils/lang_utils'; import { getCookie } from '../../utils/fetch_api_utils'; import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils'; @@ -46,6 +48,7 @@ let CreateContractForm = React.createClass({ }, handleCreateSuccess(response) { + ContractListActions.fetchContractList(); let notification = new GlobalNotificationModel(getLangText('Contract %s successfully created', response.name), 'success', 5000); GlobalNotificationActions.appendGlobalNotification(notification); }, diff --git a/js/components/ascribe_settings/contract_settings.js b/js/components/ascribe_settings/contract_settings.js index 880cd744..7b981250 100644 --- a/js/components/ascribe_settings/contract_settings.js +++ b/js/components/ascribe_settings/contract_settings.js @@ -33,7 +33,7 @@ let ContractSettings = React.createClass({ }, makeContractPublic(contract){ ContractListActions.makeContractPublic(contract) - .then(( ) => ContractListActions.fetchContractList()) + .then( ( ) => ContractListActions.fetchContractList()) .catch((error)=>{ let notification = new GlobalNotificationModel(error, 'danger', 10000); GlobalNotificationActions.appendGlobalNotification(notification); @@ -42,9 +42,11 @@ let ContractSettings = React.createClass({ removeContract(contract){ console.log(contract); ContractListActions.removeContract(contract.id) - .then(( ) => ContractListActions.fetchContractList()) + .then( + () => { + ContractListActions.fetchContractList(); + }) .catch((error) => { - console.log('Error', error); let notification = new GlobalNotificationModel(error, 'danger', 10000); GlobalNotificationActions.appendGlobalNotification(notification); }); diff --git a/js/fetchers/ownership_fetcher.js b/js/fetchers/ownership_fetcher.js index 07b37bf5..46588c5d 100644 --- a/js/fetchers/ownership_fetcher.js +++ b/js/fetchers/ownership_fetcher.js @@ -24,11 +24,11 @@ let OwnershipFetcher = { }, makeContractPublic(contractObj){ - return requests.put('ownership_csontract', { body: contractObj, contract_id: contractObj.id }); + return requests.put('ownership_contract', { body: contractObj, contract_id: contractObj.id }); }, deleteContract(contractObjId){ - return requests.delete('ownership_contract', {contract_id: contractObjId}); + return requests.delete(ApiUrls.ownership_contract, {contract_id: contractObjId}); } }; diff --git a/js/utils/requests.js b/js/utils/requests.js index 8e846d7c..c66dfd27 100644 --- a/js/utils/requests.js +++ b/js/utils/requests.js @@ -119,7 +119,9 @@ class Requests { return fetch(url, merged) .then(this.unpackResponse) - .catch(this.handleError); + .catch( () => { + this.handleError(); + }); } get(url, params) { @@ -139,7 +141,7 @@ class Requests { _putOrPost(url, paramsAndBody, method){ let paramsCopy = this._merge(paramsAndBody); - let params = excludePropFromObject(paramsAndBody,['body']); + let params = excludePropFromObject(paramsAndBody, ['body']); let newUrl = this.prepareUrl(url, params); let body = null;