diff --git a/js/actions/contract_list_actions.js b/js/actions/contract_list_actions.js index f48eb58f..aaee33c6 100644 --- a/js/actions/contract_list_actions.js +++ b/js/actions/contract_list_actions.js @@ -23,16 +23,27 @@ class ContractListActions { }); } - makeContractPublic(contract){ - contract.public = true; + + changeContract(contract){ return Q.Promise((resolve, reject) => { OwnershipFetcher.makeContractPublic(contract) .then((res) => { - console.log('Here is the result... '); resolve(res); }) .catch((err)=> { - console.log('Here we have an error'); + console.logGlobal(err); + reject(err); + }); + }); + } + + removeContract(contractId){ + return Q.Promise( (resolve, reject) => { + OwnershipFetcher.deleteContract(contractId) + .then((res) => { + resolve(res); + }) + .catch( (err) => { console.logGlobal(err); reject(err); }); diff --git a/js/components/ascribe_buttons/button_submit_close.js b/js/components/ascribe_buttons/button_submit_close.js index 11d3c0a4..cdf0ebae 100644 --- a/js/components/ascribe_buttons/button_submit_close.js +++ b/js/components/ascribe_buttons/button_submit_close.js @@ -3,7 +3,7 @@ import React from 'react'; import AppConstants from '../../constants/application_constants'; -import { getLangText } from '../../utils/lang_utils.js' +import { getLangText } from '../../utils/lang_utils.js'; let ButtonSubmitOrClose = React.createClass({ propTypes: { diff --git a/js/components/ascribe_forms/form_create_contract.js b/js/components/ascribe_forms/form_create_contract.js index 55a94511..69404055 100644 --- a/js/components/ascribe_forms/form_create_contract.js +++ b/js/components/ascribe_forms/form_create_contract.js @@ -9,11 +9,15 @@ import InputCheckbox from '../ascribe_forms/input_checkbox'; import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationActions from '../../actions/global_notification_actions'; +import ContractListActions from '../../actions/contract_list_actions'; + import ReactS3FineUploader from '../ascribe_uploader/react_s3_fine_uploader'; import AppConstants from '../../constants/application_constants'; import ApiUrls from '../../constants/api_urls'; + + import { getLangText } from '../../utils/lang_utils'; import { getCookie } from '../../utils/fetch_api_utils'; import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils'; @@ -46,8 +50,12 @@ let CreateContractForm = React.createClass({ }, handleCreateSuccess(response) { + ContractListActions.fetchContractList(); let notification = new GlobalNotificationModel(getLangText('Contract %s successfully created', response.name), 'success', 5000); GlobalNotificationActions.appendGlobalNotification(notification); + + // also refresh contract lists for the rest of the contract settings page + ContractListActions.fetchContractList(); }, @@ -109,7 +117,7 @@ let CreateContractForm = React.createClass({ label={getLangText('Contract name')}> - {' ' + getLangText('I agree to the Terms of Service') + ' '} - ( - {getLangText('read')} - ) + Make contract public (this will replace the current public contract) diff --git a/js/components/ascribe_panel/action_panel.js b/js/components/ascribe_panel/action_panel.js index 3146f1ba..f6fe9a70 100644 --- a/js/components/ascribe_panel/action_panel.js +++ b/js/components/ascribe_panel/action_panel.js @@ -12,8 +12,12 @@ let ActionPanel = React.createClass({ ]), buttons: React.PropTypes.element, onClick: React.PropTypes.func, - ignoreFocus: React.PropTypes.bool + ignoreFocus: React.PropTypes.bool, + + leftColumnWidth: React.PropTypes.string, + rightColumnWidth: React.PropTypes.string }, + getInitialState() { return { isFocused: false @@ -40,14 +44,21 @@ let ActionPanel = React.createClass({ }, render() { + + let { leftColumnWidth, rightColumnWidth } = this.props; + return (
-
+
{this.props.content}
-
+
{this.props.buttons}
diff --git a/js/components/ascribe_settings/contract_settings.js b/js/components/ascribe_settings/contract_settings.js index f38464f3..c48ca0d7 100644 --- a/js/components/ascribe_settings/contract_settings.js +++ b/js/components/ascribe_settings/contract_settings.js @@ -10,97 +10,141 @@ import ContractListActions from '../../actions/contract_list_actions'; import ActionPanel from '../ascribe_panel/action_panel'; -import { getLangText } from '../../utils/lang_utils'; import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationActions from '../../actions/global_notification_actions'; +import { getLangText } from '../../utils/lang_utils'; + let ContractSettings = React.createClass({ propTypes: { defaultExpanded: React.PropTypes.bool }, + getInitialState(){ return ContractListStore.getState(); }, + componentDidMount() { ContractListStore.listen(this.onChange); ContractListActions.fetchContractList(); }, + componentWillUnmount() { ContractListStore.unlisten(this.onChange); }, + onChange(state) { this.setState(state); }, - makeContractPublic(contract){ - console.log(contract); - ContractListActions.makeContractPublic(contract) - .then(( ) => ContractListActions.fetchContractList()) - .catch((error)=>{console.log('Error ', error); - let notification = new GlobalNotificationModel('Service is unavailable', 'danger', 10000); - GlobalNotificationActions.appendGlobalNotification(notification); -}); + + makeContractPublic(contract) { + return () => { + contract.public = true; + ContractListActions.changeContract(contract) + .then(() => ContractListActions.fetchContractList()) + .catch((err) => { + let notification = new GlobalNotificationModel(err, 'danger', 10000); + GlobalNotificationActions.appendGlobalNotification(notification); + }); + }; }, + + removeContract(contract) { + return () => { + ContractListActions.removeContract(contract.id) + .then(( ) => ContractListActions.fetchContractList()) + .catch((err) => { + let notification = new GlobalNotificationModel(err, 'danger', 10000); + GlobalNotificationActions.appendGlobalNotification(notification); + }); + }; + }, + getPublicContracts(){ return this.state.contractList.filter((contract) => contract.public); }, + getPrivateContracts(){ return this.state.contractList.filter((contract) => !contract.public); }, - getblobEndName(contract){ - return contract.blob.match(/.*\/(.*)/)[1]; - }, + render() { let publicContracts = this.getPublicContracts(); let privateContracts = this.getPrivateContracts(); - console.log(this.state.contractList); + return ( - {/* this should be this.props.defaultExpanded */} + defaultExpanded={true}> - {
-

Public Contracts

- {(publicContracts.length > 0) ? - publicContracts.map( - (contract) => { + defaultExpanded={true}> + + {publicContracts.map((contract, i) => { return ( - - - - } - />); - } - ) : null } -
} - - {
-

Private Contracts

- {(privateContracts.length > 0) ? - privateContracts.map( - (contract) => { + + + +
+ } + leftColumnWidth="40%" + rightColumnWidth="60%"/> + ); + })} +
+ + {privateContracts.map((contract, i) => { return ( - - - } - />); - } - ) : null} -
} + + + + +
+ } + leftColumnWidth="40%" + rightColumnWidth="60%"/> + ); + })} + + defaultExpanded={true}> diff --git a/js/constants/api_urls.js b/js/constants/api_urls.js index fcf9be6f..b8d6713d 100644 --- a/js/constants/api_urls.js +++ b/js/constants/api_urls.js @@ -54,7 +54,7 @@ let ApiUrls = { 'ownership_unconsigns': AppConstants.apiEndpoint + 'ownership/unconsigns/', 'ownership_unconsigns_deny': AppConstants.apiEndpoint + 'ownership/unconsigns/deny/', 'ownership_unconsigns_request': AppConstants.apiEndpoint + 'ownership/unconsigns/request/', - 'ownership_contract': AppConstants.apiEndpoint + 'ownership/contracts/${contract_id}', + 'ownership_contract': AppConstants.apiEndpoint + 'ownership/contracts/${contract_id}/', 'ownership_contract_list': AppConstants.apiEndpoint + 'ownership/contracts/', 'piece': AppConstants.apiEndpoint + 'pieces/${piece_id}/', 'piece_extradata': AppConstants.apiEndpoint + 'pieces/${piece_id}/extradata/', diff --git a/js/fetchers/ownership_fetcher.js b/js/fetchers/ownership_fetcher.js index ee71d1f0..e9ca4e50 100644 --- a/js/fetchers/ownership_fetcher.js +++ b/js/fetchers/ownership_fetcher.js @@ -25,6 +25,10 @@ let OwnershipFetcher = { makeContractPublic(contractObj){ return requests.put('ownership_contract', { body: contractObj, contract_id: contractObj.id }); + }, + + deleteContract(contractObjId){ + return requests.delete(ApiUrls.ownership_contract, {contract_id: contractObjId}); } }; diff --git a/js/utils/general_utils.js b/js/utils/general_utils.js index 673a5509..7717a96a 100644 --- a/js/utils/general_utils.js +++ b/js/utils/general_utils.js @@ -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 @@ -207,4 +194,14 @@ 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; } \ No newline at end of file diff --git a/js/utils/requests.js b/js/utils/requests.js index f9e1af04..720f184f 100644 --- a/js/utils/requests.js +++ b/js/utils/requests.js @@ -33,7 +33,7 @@ class Requests { // If this is the case, we can not try to parse it as JSON. if(responseText !== 'None') { let body = JSON.parse(responseText); - + if(body && body.errors) { let error = new Error('Form Error'); error.json = body; @@ -119,7 +119,9 @@ class Requests { return fetch(url, merged) .then(this.unpackResponse) - .catch(this.handleError); + .catch( () => { + this.handleError(); + }); } get(url, params) { @@ -134,28 +136,28 @@ 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; if (paramsCopy && paramsCopy.body) { - console.log(paramsCopy.body); body = JSON.stringify(paramsCopy.body); } return this.request(method, newUrl, { body }); } post(url, params) { - return this._putOrPost(url,params,'post') + return this._putOrPost(url, params, 'post'); } put(url, params){ - return this._putOrPost(url,params,'put') + return this._putOrPost(url, params, 'put'); } defaults(options) { diff --git a/sass/ascribe_collapsible.scss b/sass/ascribe_collapsible.scss index f6c9a623..2b65567c 100644 --- a/sass/ascribe_collapsible.scss +++ b/sass/ascribe_collapsible.scss @@ -26,8 +26,8 @@ width: 100%; /* Shrink the size of the headline for a nested element */ - .ascribe-collapsible-wrapper > div:first-child { + .ascribe-collapsible-wrapper > .ascribe-collapsible-content { padding-left: 1em; - font-size: 90%; + font-size: 95%; } } \ No newline at end of file