1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

code restructuring

This commit is contained in:
Tim Daubenschütz 2015-09-08 11:44:05 +02:00
parent 2c1ad6dc46
commit ba2ebe81fd
4 changed files with 29 additions and 30 deletions

View File

@ -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);
});

View File

@ -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({
<button className="btn btn-default btn-sm margin-left-2px">
UPDATE
</button>
<button className="btn btn-default btn-sm margin-left-2px"
onClick={this.removeContract(contract)}>
<button
className="btn btn-default btn-sm margin-left-2px"
onClick={this.removeContract(contract)}>
REMOVE
</button>
</div>
@ -121,12 +123,14 @@ let ContractSettings = React.createClass({
<button className="btn btn-default btn-sm margin-left-2px">
UPDATE
</button>
<button className="btn btn-default btn-sm margin-left-2px"
onClick={this.removeContract(contract)}>
<button
className="btn btn-default btn-sm margin-left-2px"
onClick={this.removeContract(contract)}>
REMOVE
</button>
<button className="btn btn-default btn-sm margin-left-2px"
onClick={this.makeContractPublic(contract)}>
<button
className="btn btn-default btn-sm margin-left-2px"
onClick={this.makeContractPublic(contract)}>
MAKE PUBLIC
</button>
</div>

View File

@ -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;
}

View File

@ -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;