mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
code restructuring
This commit is contained in:
parent
2c1ad6dc46
commit
ba2ebe81fd
@ -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);
|
||||
});
|
||||
|
@ -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,7 +96,8 @@ 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"
|
||||
<button
|
||||
className="btn btn-default btn-sm margin-left-2px"
|
||||
onClick={this.removeContract(contract)}>
|
||||
REMOVE
|
||||
</button>
|
||||
@ -121,11 +123,13 @@ 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"
|
||||
<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"
|
||||
<button
|
||||
className="btn btn-default btn-sm margin-left-2px"
|
||||
onClick={this.makeContractPublic(contract)}>
|
||||
MAKE PUBLIC
|
||||
</button>
|
||||
|
@ -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
|
||||
@ -208,3 +195,13 @@ 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;
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user