2015-08-28 16:18:10 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import alt from '../alt';
|
|
|
|
import OwnershipFetcher from '../fetchers/ownership_fetcher';
|
2015-09-03 17:19:29 +02:00
|
|
|
import Q from 'q';
|
2015-08-28 16:18:10 +02:00
|
|
|
|
|
|
|
class ContractListActions {
|
|
|
|
constructor() {
|
|
|
|
this.generateActions(
|
|
|
|
'updateContractList',
|
|
|
|
'flushContractList'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchContractList() {
|
|
|
|
OwnershipFetcher.fetchContractList()
|
|
|
|
.then((contracts) => {
|
2015-09-03 15:53:02 +02:00
|
|
|
this.actions.updateContractList(contracts.results);
|
2015-08-28 16:18:10 +02:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.logGlobal(err);
|
|
|
|
this.actions.updateContractList([]);
|
|
|
|
});
|
|
|
|
}
|
2015-09-03 15:53:02 +02:00
|
|
|
|
|
|
|
makeContractPublic(contract){
|
2015-09-04 11:31:53 +02:00
|
|
|
contract.public = true;
|
2015-09-03 17:19:29 +02:00
|
|
|
return Q.Promise((resolve, reject) => {
|
|
|
|
OwnershipFetcher.makeContractPublic(contract)
|
|
|
|
.then((res) => {
|
|
|
|
resolve(res);
|
|
|
|
})
|
|
|
|
.catch((err)=> {
|
|
|
|
console.logGlobal(err);
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
});
|
2015-09-03 15:53:02 +02:00
|
|
|
}
|
2015-09-07 11:38:23 +02:00
|
|
|
|
2015-09-07 15:43:44 +02:00
|
|
|
removeContract(contractId){
|
2015-09-07 11:38:23 +02:00
|
|
|
return Q.Promise((resolve, reject) => {
|
2015-09-07 15:43:44 +02:00
|
|
|
OwnershipFetcher.deleteContract(contractId)
|
2015-09-07 11:38:23 +02:00
|
|
|
.then((res) => {
|
|
|
|
console.log('Contract deleted');
|
|
|
|
resolve(res);
|
|
|
|
})
|
|
|
|
.catch( (err) => {
|
|
|
|
console.log('Error while deleting');
|
|
|
|
console.logGlobal(err);
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2015-08-28 16:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default alt.createActions(ContractListActions);
|