1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

licenses in registration

This commit is contained in:
diminator 2015-06-30 10:42:58 +02:00
parent c6bc34c2f7
commit 8fc400bb01
9 changed files with 153 additions and 20 deletions

View File

@ -0,0 +1,25 @@
'use strict';
import alt from '../alt';
import LicenseFetcher from '../fetchers/license_fetcher';
class LicenseActions {
constructor() {
this.generateActions(
'updateLicenses'
);
}
fetchLicense() {
LicenseFetcher.fetch()
.then((res) => {
this.actions.updateLicenses(res.licenses);
})
.catch((err) => {
console.log(err);
});
}
}
export default alt.createActions(LicenseActions);

View File

@ -130,15 +130,17 @@ let Form = React.createClass({
}, },
renderChildren() { renderChildren() {
return ReactAddons.Children.map(this.props.children, (child) => { return ReactAddons.Children.map(this.props.children, (child) => {
return ReactAddons.addons.cloneWithProps(child, { if (child) {
handleChange: this.handleChangeChild, return ReactAddons.addons.cloneWithProps(child, {
ref: child.props.name handleChange: this.handleChangeChild,
}); ref: child.props.name
});
}
}); });
}, },
render() { render() {
return ( return (
<form <form
role="form" role="form"
className="ascribe-form" className="ascribe-form"
onSubmit={this.submit} onSubmit={this.submit}

View File

@ -16,13 +16,14 @@ let Property = React.createClass({
React.PropTypes.string, React.PropTypes.string,
React.PropTypes.element React.PropTypes.element
]), ]),
footer: React.PropTypes.element,
handleChange: React.PropTypes.func handleChange: React.PropTypes.func
}, },
getDefaultProps() { getDefaultProps() {
return { return {
editable: true, editable: true,
hidden: false hidden: false,
}; };
}, },
@ -55,6 +56,9 @@ let Property = React.createClass({
handleChange(event) { handleChange(event) {
this.props.handleChange(event); this.props.handleChange(event);
if ('onChange' in this.props) {
this.props.onChange(event);
}
this.setState({value: event.target.value}); this.setState({value: event.target.value});
}, },
handleFocus() { handleFocus() {
@ -120,6 +124,13 @@ let Property = React.createClass({
{this.props.tooltip} {this.props.tooltip}
</Tooltip>); </Tooltip>);
} }
let footer = null;
if (this.props.footer){
footer = (
<div className="ascribe-property-footer">
{this.props.footer}
</div>);
}
return ( return (
<div <div
className={'ascribe-settings-wrapper ' + this.getClassName()} className={'ascribe-settings-wrapper ' + this.getClassName()}
@ -132,6 +143,7 @@ let Property = React.createClass({
{this.state.errors} {this.state.errors}
<span>{ this.props.label}</span> <span>{ this.props.label}</span>
{this.renderChildren()} {this.renderChildren()}
{footer}
</div> </div>
</OverlayTrigger> </OverlayTrigger>
</div> </div>

View File

@ -61,14 +61,17 @@ let Header = React.createClass({
}, },
getPoweredBy(){ getPoweredBy(){
return ( if (this.state.whitelabel.logo) {
<div className="row no-margin ascribe-subheader"> return (
<a className="pull-right" href="https://www.ascribe.io/" target="_blank"> <div className="row no-margin ascribe-subheader">
<span id="powered">powered by </span> <a className="pull-right" href="https://www.ascribe.io/" target="_blank">
<span>ascribe </span> <span id="powered">powered by </span>
<span className="glyph-ascribe-spool-chunked ascribe-color"></span> <span>ascribe </span>
</a> <span className="glyph-ascribe-spool-chunked ascribe-color"></span>
</div>); </a>
</div>);
}
return null;
}, },
onChange(state) { onChange(state) {
this.setState(state); this.setState(state);

View File

@ -7,6 +7,9 @@ import AppConstants from '../constants/application_constants';
import Router from 'react-router'; import Router from 'react-router';
import LicenseActions from '../actions/license_actions';
import LicenseStore from '../stores/license_store';
import GlobalNotificationModel from '../models/global_notification_model'; import GlobalNotificationModel from '../models/global_notification_model';
import GlobalNotificationActions from '../actions/global_notification_actions'; import GlobalNotificationActions from '../actions/global_notification_actions';
@ -19,15 +22,32 @@ import ReactS3FineUploader from './ascribe_uploader/react_s3_fine_uploader';
import DatePicker from 'react-datepicker/dist/react-datepicker'; import DatePicker from 'react-datepicker/dist/react-datepicker';
import { mergeOptions } from '../utils/general_utils';
let RegisterPiece = React.createClass( { let RegisterPiece = React.createClass( {
mixins: [Router.Navigation], mixins: [Router.Navigation],
getInitialState(){ getInitialState(){
return { return mergeOptions(
digitalWorkKey: null, LicenseStore.getState(),
uploadStatus: false {
}; digitalWorkKey: null,
uploadStatus: false,
selectedLicense: 0
});
},
componentDidMount() {
LicenseActions.fetchLicense();
LicenseStore.listen(this.onChange);
},
componentWillUnmount() {
LicenseStore.unlisten(this.onChange);
},
onChange(state) {
this.setState(state);
}, },
handleSuccess(){ handleSuccess(){
@ -59,15 +79,46 @@ let RegisterPiece = React.createClass( {
isReadyForFormSubmission(files) { isReadyForFormSubmission(files) {
files = files.filter((file) => file.status !== 'deleted' && file.status !== 'canceled'); files = files.filter((file) => file.status !== 'deleted' && file.status !== 'canceled');
if(files.length > 0 && files[0].status === 'upload successful') { if (files.length > 0 && files[0].status === 'upload successful') {
return true; return true;
} else { } else {
return false; return false;
} }
}, },
onLicenseChange(event){
console.log(this.state.licenses[event.target.selectedIndex].url);
this.setState({selectedLicense: event.target.selectedIndex});
},
getLicenses() {
if (this.state.licenses && this.state.licenses.length > 0) {
return (
<Property
name='license'
label="Copyright license..."
onChange={this.onLicenseChange}
footer={
<a className="pull-right" href={this.state.licenses[this.state.selectedLicense].url} target="_blank">
Learn more about this license
</a>}>
<select name="license">
{this.state.licenses.map((license, i) => {
return (
<option
name={i}
key={i}
value={ license.code }>
{ license.code.toUpperCase() }: { license.name }
</option>
);
})}
</select>
</Property>);
}
return null;
},
render() { render() {
let buttons = null; let buttons = <span />;
if (this.state.uploadStatus){ if (this.state.uploadStatus){
buttons = ( buttons = (
@ -132,6 +183,7 @@ let RegisterPiece = React.createClass( {
min={1} min={1}
required/> required/>
</Property> </Property>
{this.getLicenses()}
<hr /> <hr />
</Form> </Form>
</div> </div>

View File

@ -14,6 +14,7 @@ let apiUrls = {
'edition_delete': AppConstants.apiEndpoint + 'editions/${edition_id}/', 'edition_delete': AppConstants.apiEndpoint + 'editions/${edition_id}/',
'edition_remove_from_collection': AppConstants.apiEndpoint + 'ownership/shares/${edition_id}/', 'edition_remove_from_collection': AppConstants.apiEndpoint + 'ownership/shares/${edition_id}/',
'editions_list': AppConstants.apiEndpoint + 'pieces/${piece_id}/editions/', 'editions_list': AppConstants.apiEndpoint + 'pieces/${piece_id}/editions/',
'licenses': AppConstants.apiEndpoint + 'ownership/licenses/',
'note_notes': AppConstants.apiEndpoint + 'note/notes/', 'note_notes': AppConstants.apiEndpoint + 'note/notes/',
'note_edition': AppConstants.apiEndpoint + 'note/edition_notes/', 'note_edition': AppConstants.apiEndpoint + 'note/edition_notes/',
'ownership_consigns': AppConstants.apiEndpoint + 'ownership/consigns/', 'ownership_consigns': AppConstants.apiEndpoint + 'ownership/consigns/',

View File

@ -0,0 +1,14 @@
'use strict';
import requests from '../utils/requests';
let LicenseFetcher = {
/**
* Fetch the available licenses from the API (might be bound to the subdomain e.g. cc.ascribe.io).
*/
fetch() {
return requests.get('licenses', {'subdomain': window.location.host.split('.')[0]});
}
};
export default LicenseFetcher;

View File

@ -0,0 +1,18 @@
'use strict';
import alt from '../alt';
import LicenseActions from '../actions/license_actions';
class LicenseStore {
constructor() {
this.licenses = {};
this.bindActions(LicenseActions);
}
onUpdateLicenses(licenses) {
this.licenses = licenses;
}
}
export default alt.createStore(LicenseStore, 'LicenseStore');

View File

@ -127,3 +127,9 @@
padding: 0; padding: 0;
} }
} }
.ascribe-property-footer{
font-size: 0.8em;
margin-top: 10px;
width: 100%;
}