1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 01:25:17 +01: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){
return Q.Promise((resolve, reject) => {
OwnershipFetcher.makeContractPublic(contract)
OwnershipFetcher.changeContract(contract)
.then((res) => {
resolve(res);
})

View File

@ -39,23 +39,6 @@ let ContractSettings = React.createClass({
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) {
return () => {
ContractListActions.removeContract(contract.id)
@ -113,7 +96,7 @@ let ContractSettings = React.createClass({
content={contract.name}
buttons={
<div className="pull-right">
<ContractSettingsUpdateButton />
<ContractSettingsUpdateButton contract={contract}/>
<a
className="btn btn-default btn-sm margin-left-2px"
href={contract.blob.url_safe}
@ -150,12 +133,7 @@ let ContractSettings = React.createClass({
content={contract.name}
buttons={
<div className="pull-right">
<button
className="btn btn-default btn-sm margin-left-2px"
onClick={this.makeContractPublic(contract)}>
MAKE PUBLIC
</button>
<ContractSettingsUpdateButton />
<ContractSettingsUpdateButton contract={contract} />
<a
className="btn btn-default btn-sm margin-left-2px"
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 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 { getCookie } from '../../utils/fetch_api_utils';
import { getLangText } from '../../utils/lang_utils';
let ContractSettingsUpdateButton = React.createClass({
setIsUploadReady() {
console.log('upload done');
propTypes: {
contract: React.PropTypes.object
},
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() {
return (
<ReactS3FineUploader
ref="fineuploader"
fileInputElement={UploadButton}
keyRoutine={{
url: AppConstants.serverUrl + 's3/key/',
@ -39,7 +65,7 @@ let ContractSettingsUpdateButton = React.createClass({
sizeLimit: '50000000',
allowedExtensions: ['pdf']
}}
setIsUploadReady={this.setIsUploadReady}
setIsUploadReady={() =>{/* So that ReactS3FineUploader is not complaining */}}
signature={{
endpoint: AppConstants.serverUrl + 's3/signature/',
customHeaders: {

View File

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

View File

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