1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +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){ changeContract(contract){
contract.public = true;
return Q.Promise((resolve, reject) => { return Q.Promise((resolve, reject) => {
OwnershipFetcher.makeContractPublic(contract) OwnershipFetcher.makeContractPublic(contract)
.then((res) => { .then((res) => {
@ -41,11 +40,9 @@ class ContractListActions {
return Q.Promise((resolve, reject) => { return Q.Promise((resolve, reject) => {
OwnershipFetcher.deleteContract(contractId) OwnershipFetcher.deleteContract(contractId)
.then((res) => { .then((res) => {
console.log('Contract deleted');
resolve(res); resolve(res);
}) })
.catch( (err) => { .catch( (err) => {
console.log('Error while deleting');
console.logGlobal(err); console.logGlobal(err);
reject(err); reject(err);
}); });

View File

@ -39,10 +39,11 @@ let ContractSettings = React.createClass({
makeContractPublic(contract) { makeContractPublic(contract) {
return () => { return () => {
ContractListActions.makeContractPublic(contract) contract.public = true;
ContractListActions.changeContract(contract)
.then(() => ContractListActions.fetchContractList()) .then(() => ContractListActions.fetchContractList())
.catch((error) => { .catch((err) => {
let notification = new GlobalNotificationModel(error, 'success', 10000); let notification = new GlobalNotificationModel(err, 'danger', 10000);
GlobalNotificationActions.appendGlobalNotification(notification); GlobalNotificationActions.appendGlobalNotification(notification);
}); });
}; };
@ -52,8 +53,8 @@ let ContractSettings = React.createClass({
return () => { return () => {
ContractListActions.removeContract(contract.id) ContractListActions.removeContract(contract.id)
.then(( ) => ContractListActions.fetchContractList()) .then(( ) => ContractListActions.fetchContractList())
.catch((error) => { .catch((err) => {
let notification = new GlobalNotificationModel(error, 'danger', 10000); let notification = new GlobalNotificationModel(err, 'danger', 10000);
GlobalNotificationActions.appendGlobalNotification(notification); GlobalNotificationActions.appendGlobalNotification(notification);
}); });
}; };
@ -95,7 +96,8 @@ let ContractSettings = React.createClass({
<button className="btn btn-default btn-sm margin-left-2px"> <button className="btn btn-default btn-sm margin-left-2px">
UPDATE UPDATE
</button> </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)}> onClick={this.removeContract(contract)}>
REMOVE REMOVE
</button> </button>
@ -121,11 +123,13 @@ let ContractSettings = React.createClass({
<button className="btn btn-default btn-sm margin-left-2px"> <button className="btn btn-default btn-sm margin-left-2px">
UPDATE UPDATE
</button> </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)}> onClick={this.removeContract(contract)}>
REMOVE REMOVE
</button> </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)}> onClick={this.makeContractPublic(contract)}>
MAKE PUBLIC MAKE PUBLIC
</button> </button>

View File

@ -52,19 +52,6 @@ export function sumNumList(l) {
return sum; 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 Taken from http://stackoverflow.com/a/4795914/1263876
Behaves like C's format string function Behaves like C's format string function
@ -208,3 +195,13 @@ function _mergeOptions(obj1, obj2) {
export function escapeHTML(s) { export function escapeHTML(s) {
return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML; 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

@ -134,12 +134,13 @@ class Requests {
delete(url, params) { delete(url, params) {
let paramsCopy = this._merge(params); let paramsCopy = this._merge(params);
let newUrl = this.prepareUrl(url, paramsCopy, true); let newUrl = this.prepareUrl(url, paramsCopy, true);
return this.request('delete', newUrl); return this.request('delete', newUrl);
} }
_putOrPost(url, paramsAndBody, method){ _putOrPost(url, paramsAndBody, method){
let paramsCopy = this._merge(paramsAndBody); let paramsCopy = this._merge(paramsAndBody);
let params = excludePropFromObject(paramsAndBody,['body']); let params = excludePropFromObject(paramsAndBody, ['body']);
let newUrl = this.prepareUrl(url, params); let newUrl = this.prepareUrl(url, params);
let body = null; let body = null;