diff --git a/js/actions/contract_list_actions.js b/js/actions/contract_list_actions.js index 307706ef..60144ef6 100644 --- a/js/actions/contract_list_actions.js +++ b/js/actions/contract_list_actions.js @@ -23,8 +23,7 @@ class ContractListActions { }); } - makeContractPublic(contract){ - contract.public = true; + changeContract(contract){ return Q.Promise((resolve, reject) => { OwnershipFetcher.makeContractPublic(contract) .then((res) => { @@ -41,11 +40,9 @@ class ContractListActions { return Q.Promise((resolve, reject) => { OwnershipFetcher.deleteContract(contractId) .then((res) => { - console.log('Contract deleted'); resolve(res); }) .catch( (err) => { - console.log('Error while deleting'); console.logGlobal(err); reject(err); }); diff --git a/js/components/ascribe_settings/contract_settings.js b/js/components/ascribe_settings/contract_settings.js index e34772f2..c48ca0d7 100644 --- a/js/components/ascribe_settings/contract_settings.js +++ b/js/components/ascribe_settings/contract_settings.js @@ -39,10 +39,11 @@ let ContractSettings = React.createClass({ makeContractPublic(contract) { return () => { - ContractListActions.makeContractPublic(contract) + contract.public = true; + ContractListActions.changeContract(contract) .then(() => ContractListActions.fetchContractList()) - .catch((error) => { - let notification = new GlobalNotificationModel(error, 'success', 10000); + .catch((err) => { + let notification = new GlobalNotificationModel(err, 'danger', 10000); GlobalNotificationActions.appendGlobalNotification(notification); }); }; @@ -52,8 +53,8 @@ let ContractSettings = React.createClass({ return () => { ContractListActions.removeContract(contract.id) .then(( ) => ContractListActions.fetchContractList()) - .catch((error) => { - let notification = new GlobalNotificationModel(error, 'danger', 10000); + .catch((err) => { + let notification = new GlobalNotificationModel(err, 'danger', 10000); GlobalNotificationActions.appendGlobalNotification(notification); }); }; @@ -95,8 +96,9 @@ let ContractSettings = React.createClass({ - @@ -121,12 +123,14 @@ let ContractSettings = React.createClass({ - - diff --git a/js/utils/general_utils.js b/js/utils/general_utils.js index 673a5509..7717a96a 100644 --- a/js/utils/general_utils.js +++ b/js/utils/general_utils.js @@ -52,19 +52,6 @@ export function sumNumList(l) { return sum; } -export function excludePropFromObject(obj, propList){ - let clonedObj = mergeOptions({},obj); - for (let item in propList){ - console.log(item); - if (clonedObj[propList[item]]){ - console.log('deleting... '); - delete clonedObj[propList[item]]; - } - } - console.log(clonedObj); - return clonedObj; -} - /* Taken from http://stackoverflow.com/a/4795914/1263876 Behaves like C's format string function @@ -207,4 +194,14 @@ function _mergeOptions(obj1, obj2) { */ export function escapeHTML(s) { return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML; +} + +export function excludePropFromObject(obj, propList){ + let clonedObj = mergeOptions({}, obj); + for (let item in propList){ + if (clonedObj[propList[item]]){ + delete clonedObj[propList[item]]; + } + } + return clonedObj; } \ No newline at end of file diff --git a/js/utils/requests.js b/js/utils/requests.js index 8e846d7c..c785abf6 100644 --- a/js/utils/requests.js +++ b/js/utils/requests.js @@ -33,7 +33,7 @@ class Requests { // If this is the case, we can not try to parse it as JSON. if(responseText !== 'None') { let body = JSON.parse(responseText); - + if(body && body.errors) { let error = new Error('Form Error'); error.json = body; @@ -134,12 +134,13 @@ class Requests { delete(url, params) { let paramsCopy = this._merge(params); let newUrl = this.prepareUrl(url, paramsCopy, true); + return this.request('delete', newUrl); } _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;