1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-28 08:37:59 +02:00

finalize contract update button

This commit is contained in:
Tim Daubenschütz 2015-09-16 09:47:22 +02:00
parent f0936b9074
commit 17cb2223c2
5 changed files with 38 additions and 33 deletions

View File

@ -30,7 +30,7 @@ class ContractListActions {
changeContract(contract){ changeContract(contract){
return Q.Promise((resolve, reject) => { return Q.Promise((resolve, reject) => {
OwnershipFetcher.makeContractPublic(contract) OwnershipFetcher.changeContract(contract)
.then((res) => { .then((res) => {
resolve(res); resolve(res);
}) })

View File

@ -39,23 +39,6 @@ let ContractSettings = React.createClass({
this.setState(state); this.setState(state);
}, },
makeContractPublic(contract) {
return () => {
contract.is_public = true;
ContractListActions.changeContract(contract)
.then(() => {
ContractListActions.fetchContractList(true);
let notification = getLangText('Contract %s is now public', contract.name);
notification = new GlobalNotificationModel(notification, 'success', 4000);
GlobalNotificationActions.appendGlobalNotification(notification);
})
.catch((err) => {
let notification = new GlobalNotificationModel(err, 'danger', 10000);
GlobalNotificationActions.appendGlobalNotification(notification);
});
};
},
removeContract(contract) { removeContract(contract) {
return () => { return () => {
ContractListActions.removeContract(contract.id) ContractListActions.removeContract(contract.id)
@ -113,7 +96,7 @@ let ContractSettings = React.createClass({
content={contract.name} content={contract.name}
buttons={ buttons={
<div className="pull-right"> <div className="pull-right">
<ContractSettingsUpdateButton /> <ContractSettingsUpdateButton contract={contract}/>
<a <a
className="btn btn-default btn-sm margin-left-2px" className="btn btn-default btn-sm margin-left-2px"
href={contract.blob.url_safe} href={contract.blob.url_safe}
@ -150,12 +133,7 @@ let ContractSettings = React.createClass({
content={contract.name} content={contract.name}
buttons={ buttons={
<div className="pull-right"> <div className="pull-right">
<button <ContractSettingsUpdateButton contract={contract} />
className="btn btn-default btn-sm margin-left-2px"
onClick={this.makeContractPublic(contract)}>
MAKE PUBLIC
</button>
<ContractSettingsUpdateButton />
<a <a
className="btn btn-default btn-sm margin-left-2px" className="btn btn-default btn-sm margin-left-2px"
href={contract.blob.url_safe} href={contract.blob.url_safe}

View File

@ -8,24 +8,50 @@ import UploadButton from '../ascribe_uploader/ascribe_upload_button/upload_butto
import AppConstants from '../../constants/application_constants'; import AppConstants from '../../constants/application_constants';
import ApiUrls from '../../constants/api_urls'; import ApiUrls from '../../constants/api_urls';
import ContractListActions from '../../actions/contract_list_actions';
import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions';
import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils'; import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils';
import { getCookie } from '../../utils/fetch_api_utils'; import { getCookie } from '../../utils/fetch_api_utils';
import { getLangText } from '../../utils/lang_utils'; import { getLangText } from '../../utils/lang_utils';
let ContractSettingsUpdateButton = React.createClass({ let ContractSettingsUpdateButton = React.createClass({
propTypes: {
setIsUploadReady() { contract: React.PropTypes.object
console.log('upload done');
}, },
submitFile(file) { submitFile(file) {
console.log(file); let contract = this.props.contract;
// override the blob with the key's value
contract.blob = file.key;
// send it to the server
ContractListActions
.changeContract(contract)
.then((res) => {
let notification = new GlobalNotificationModel(getLangText('Contract %s successfully updated', res.name), 'success', 5000);
GlobalNotificationActions.appendGlobalNotification(notification);
return ContractListActions.fetchContractList(true);
})
.then(() => {
this.refs.fineuploader.reset();
})
.catch((err) => {
console.logGlobal(err);
let notification = new GlobalNotificationModel(getLangText('Contract could not be updated'), 'success', 5000);
GlobalNotificationActions.appendGlobalNotification(notification);
});
}, },
render() { render() {
return ( return (
<ReactS3FineUploader <ReactS3FineUploader
ref="fineuploader"
fileInputElement={UploadButton} fileInputElement={UploadButton}
keyRoutine={{ keyRoutine={{
url: AppConstants.serverUrl + 's3/key/', url: AppConstants.serverUrl + 's3/key/',
@ -39,7 +65,7 @@ let ContractSettingsUpdateButton = React.createClass({
sizeLimit: '50000000', sizeLimit: '50000000',
allowedExtensions: ['pdf'] allowedExtensions: ['pdf']
}} }}
setIsUploadReady={this.setIsUploadReady} setIsUploadReady={() =>{/* So that ReactS3FineUploader is not complaining */}}
signature={{ signature={{
endpoint: AppConstants.serverUrl + 's3/signature/', endpoint: AppConstants.serverUrl + 's3/signature/',
customHeaders: { customHeaders: {

View File

@ -3,6 +3,8 @@
import React from 'react'; import React from 'react';
import { displayValidProgressFilesFilter } from '../react_s3_fine_uploader_utils'; import { displayValidProgressFilesFilter } from '../react_s3_fine_uploader_utils';
import { getLangText } from '../../../utils/lang_utils';
let UploadButton = React.createClass({ let UploadButton = React.createClass({
propTypes: { propTypes: {
@ -22,7 +24,6 @@ let UploadButton = React.createClass({
handleResumeFile: React.PropTypes.func, handleResumeFile: React.PropTypes.func,
multiple: React.PropTypes.bool, multiple: React.PropTypes.bool,
// For simplification purposes we're just going to use this prop as a // For simplification purposes we're just going to use this prop as a
// label for the upload button // label for the upload button
fileClassToUpload: React.PropTypes.shape({ fileClassToUpload: React.PropTypes.shape({
@ -76,7 +77,7 @@ let UploadButton = React.createClass({
// Depending on wether there is an upload going on or not we // Depending on wether there is an upload going on or not we
// display the progress // display the progress
if(filesToUpload.length > 0) { if(filesToUpload.length > 0) {
return 'Upload progress: ' + Math.ceil(filesToUpload[0].progress) + '%'; return getLangText('Upload progress') + ': ' + Math.ceil(filesToUpload[0].progress) + '%';
} else { } else {
return fileClassToUpload.singular; return fileClassToUpload.singular;
} }

View File

@ -48,7 +48,7 @@ let OwnershipFetcher = {
return requests.get(ApiUrls.ownership_loans_pieces_request); return requests.get(ApiUrls.ownership_loans_pieces_request);
}, },
makeContractPublic(contractObj){ changeContract(contractObj){
return requests.put(ApiUrls.ownership_contract, { body: contractObj, contract_id: contractObj.id }); return requests.put(ApiUrls.ownership_contract, { body: contractObj, contract_id: contractObj.id });
}, },