diff --git a/.gitignore~ b/.gitignore~ new file mode 100644 index 00000000..41b217c2 --- /dev/null +++ b/.gitignore~ @@ -0,0 +1,24 @@ +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz +*.sublime-project +.idea +spool-project.sublime-project +*.sublime-workspace +*.sublime-workspace +webapp-dependencies.txt + +pids +logs +results +README.md~ +node_modules/* + +build + +.DS_Store diff --git a/js/actions/contract_actions.js b/js/actions/contract_actions.js index e14dbf83..c6055ffc 100644 --- a/js/actions/contract_actions.js +++ b/js/actions/contract_actions.js @@ -43,6 +43,7 @@ class ContractActions { /* No email was entered - Ignore and keep going*/ } } + } export default alt.createActions(ContractActions); diff --git a/js/actions/contract_list_actions.js b/js/actions/contract_list_actions.js index f4257d37..c57bceb9 100644 --- a/js/actions/contract_list_actions.js +++ b/js/actions/contract_list_actions.js @@ -2,7 +2,7 @@ import alt from '../alt'; import OwnershipFetcher from '../fetchers/ownership_fetcher'; - +import Q from 'q'; class ContractListActions { constructor() { @@ -15,13 +15,27 @@ class ContractListActions { fetchContractList() { OwnershipFetcher.fetchContractList() .then((contracts) => { - this.actions.updateContractList(contracts); + this.actions.updateContractList(contracts.results); }) .catch((err) => { console.logGlobal(err); this.actions.updateContractList([]); }); } + + makeContractPublic(contract){ + contract.public=true; + return Q.Promise((resolve, reject) => { + OwnershipFetcher.makeContractPublic(contract) + .then((res) => { + resolve(res); + }) + .catch((err)=> { + console.logGlobal(err); + reject(err); + }); + }); + } } export default alt.createActions(ContractListActions); diff --git a/js/components/ascribe_forms/form_create_contract.js b/js/components/ascribe_forms/form_create_contract.js index a5f719e2..55a94511 100644 --- a/js/components/ascribe_forms/form_create_contract.js +++ b/js/components/ascribe_forms/form_create_contract.js @@ -4,6 +4,7 @@ import React from 'react'; import Form from '../ascribe_forms/form'; import Property from '../ascribe_forms/property'; +import InputCheckbox from '../ascribe_forms/input_checkbox'; import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationActions from '../../actions/global_notification_actions'; @@ -53,7 +54,7 @@ let CreateContractForm = React.createClass({ render() { return (
+ + + + {' ' + getLangText('I agree to the Terms of Service') + ' '} + ( + {getLangText('read')} + ) + + +
); } diff --git a/js/components/ascribe_panel/action_panel.js b/js/components/ascribe_panel/action_panel.js index 148ea03d..3146f1ba 100644 --- a/js/components/ascribe_panel/action_panel.js +++ b/js/components/ascribe_panel/action_panel.js @@ -14,7 +14,6 @@ let ActionPanel = React.createClass({ onClick: React.PropTypes.func, ignoreFocus: React.PropTypes.bool }, - getInitialState() { return { isFocused: false diff --git a/js/components/ascribe_settings/contract_settings.js b/js/components/ascribe_settings/contract_settings.js index 8f11cafd..222bd42e 100644 --- a/js/components/ascribe_settings/contract_settings.js +++ b/js/components/ascribe_settings/contract_settings.js @@ -8,7 +8,11 @@ import CreateContractForm from '../ascribe_forms/form_create_contract'; import ContractListStore from '../../stores/contract_list_store'; 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'; let ContractSettings = React.createClass({ propTypes: { @@ -27,23 +31,76 @@ let ContractSettings = React.createClass({ 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); +}) + }, + 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 ( + defaultExpanded={false}> {/* this should be this.props.defaultExpanded */} - {this.state.contractList} + defaultExpanded={false}> + {
+

Public Contracts

+ {(publicContracts.length > 0) ? + publicContracts.map( + (contract) => { + return( + + + + } + />) + } + ) : null } +
} + + {
+

Private Contracts

+ {(privateContracts.length>0) ? + privateContracts.map( + (contract) => { + return( + + + } + />) + } + ) : null} +
}
+ defaultExpanded={false}>
diff --git a/js/constants/api_urls.js b/js/constants/api_urls.js index 6b1d7dee..aa484142 100644 --- a/js/constants/api_urls.js +++ b/js/constants/api_urls.js @@ -51,7 +51,8 @@ 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/', + '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/', 'piece_first_edition_id': AppConstants.apiEndpoint + 'pieces/${piece_id}/edition_index/', diff --git a/js/fetchers/ownership_fetcher.js b/js/fetchers/ownership_fetcher.js index 051f2d08..9b5e81f7 100644 --- a/js/fetchers/ownership_fetcher.js +++ b/js/fetchers/ownership_fetcher.js @@ -16,11 +16,15 @@ let OwnershipFetcher = { * Fetch the contracts of the logged-in user from the API. */ fetchContractList(){ - return requests.get(ApiUrls.ownership_contract); + return requests.get(ApiUrls.ownership_contract_list); }, fetchLoanPieceRequestList(){ return requests.get(ApiUrls.ownership_loans_pieces_request); + }, + + makeContractPublic(contractObj){ + return requests.put('ownership_contract', { body: contractObj, contract_id: contractObj.id }); } }; diff --git a/js/utils/general_utils.js b/js/utils/general_utils.js index 15b0e85f..673a5509 100644 --- a/js/utils/general_utils.js +++ b/js/utils/general_utils.js @@ -52,6 +52,19 @@ 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 diff --git a/js/utils/requests.js b/js/utils/requests.js index 793e1f21..f9e1af04 100644 --- a/js/utils/requests.js +++ b/js/utils/requests.js @@ -6,6 +6,7 @@ import { argsToQueryParams, getCookie } from '../utils/fetch_api_utils'; import AppConstants from '../constants/application_constants'; +import {excludePropFromObject} from '../utils/general_utils'; class Requests { _merge(defaults, options) { @@ -77,7 +78,6 @@ class Requests { throw new Error(`Cannot find a mapping for "${name}"`); } } - return url; } @@ -137,15 +137,25 @@ class Requests { return this.request('delete', newUrl); } - post(url, params) { - let paramsCopy = this._merge(params); - let newUrl = this.prepareUrl(url, paramsCopy); - let body = null; + _putOrPost(url, paramsAndBody, method){ + let paramsCopy = this._merge(paramsAndBody); + 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('post', newUrl, { body }); + return this.request(method, newUrl, { body }); + } + + post(url, params) { + return this._putOrPost(url,params,'post') + } + + put(url, params){ + return this._putOrPost(url,params,'put') } defaults(options) {