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

polling for editions

This commit is contained in:
diminator 2015-07-10 18:51:35 +02:00
parent e282da8474
commit 62289be5ce
6 changed files with 46 additions and 21 deletions

View File

@ -37,7 +37,7 @@ let AccordionListItem = React.createClass({
}, },
componentDidMount() { componentDidMount() {
if(this.props.content.num_editions !== 0) { if(this.props.content.num_editions > 0) {
PieceListActions.fetchFirstEditionForPiece(this.props.content.id); PieceListActions.fetchFirstEditionForPiece(this.props.content.id);
} }
}, },
@ -66,6 +66,7 @@ let AccordionListItem = React.createClass({
handleEditionCreationSuccess(response) { handleEditionCreationSuccess(response) {
let notification = new GlobalNotificationModel(response.notification, 'success', 10000); let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
GlobalNotificationActions.appendGlobalNotification(notification); GlobalNotificationActions.appendGlobalNotification(notification);
PieceListActions.updatePropertyForPiece({pieceId: this.props.content.id, key: 'num_editions', value: 0});
this.setState({ this.setState({
creatingEditions: true creatingEditions: true
@ -106,7 +107,7 @@ let AccordionListItem = React.createClass({
render() { render() {
let linkData; let linkData;
if(this.props.content.num_editions === 0) { if(this.props.content.num_editions < 1) {
linkData = { linkData = {
to: 'piece', to: 'piece',
params: { params: {
@ -157,7 +158,7 @@ let AccordionListItem = React.createClass({
</div> </div>
</div> </div>
</div> </div>
{this.props.content.num_editions === 0 && this.state.showCreateEditionsDialog ? <AccordionListItemCreateEditions pieceId={this.props.content.id} handleSuccess={this.handleEditionCreationSuccess}/> : null} {this.props.content.num_editions < 1 && this.state.showCreateEditionsDialog ? <AccordionListItemCreateEditions pieceId={this.props.content.id} handleSuccess={this.handleEditionCreationSuccess}/> : null}
{/* this.props.children is AccordionListItemTableEditions */} {/* this.props.children is AccordionListItemTableEditions */}
{this.props.children} {this.props.children}

View File

@ -75,23 +75,23 @@ let AccordionListItemEditionWidget = React.createClass({
let piece = this.props.piece; let piece = this.props.piece;
let numEditions = piece.num_editions; let numEditions = piece.num_editions;
if(numEditions === 0) { if(numEditions === -1) {
if(this.props.creatingEditions) { return (
return ( <span
onClick={this.props.toggleCreateEditionsDialog}
className="ascribe-accordion-list-item-edition-widget">
+ Editions
</span>
);
}
else if(numEditions === 0) {
return (
<span> <span>
Creating Editions <span className="glyph-ascribe-spool-chunked ascribe-color spin"/> Creating Editions <span className="glyph-ascribe-spool-chunked ascribe-color spin"/>
</span> </span>
); );
} else { }
return ( else if(numEditions === 1) {
<span
onClick={this.props.toggleCreateEditionsDialog}
className="ascribe-accordion-list-item-edition-widget">
+ Editions
</span>
);
}
} else if(numEditions === 1) {
let editionMapping = piece && piece.firstEdition ? piece.firstEdition.edition_number + '/' + piece.num_editions : ''; let editionMapping = piece && piece.firstEdition ? piece.firstEdition.edition_number + '/' + piece.num_editions : '';
return ( return (

View File

@ -7,6 +7,7 @@ import Button from 'react-bootstrap/lib/Button';
import requests from '../../utils/requests'; import requests from '../../utils/requests';
import { getLangText } from '../../utils/lang_utils'; import { getLangText } from '../../utils/lang_utils';
import { mergeOptionsWithDuplicates } from '../../utils/general_utils';
import AlertDismissable from './alert'; import AlertDismissable from './alert';
@ -55,12 +56,12 @@ let Form = React.createClass({
getFormData(){ getFormData(){
let data = {}; let data = {};
if ('getFormData' in this.props){
data = this.props.getFormData();
}
for (let ref in this.refs){ for (let ref in this.refs){
data[this.refs[ref].props.name] = this.refs[ref].state.value; data[this.refs[ref].props.name] = this.refs[ref].state.value;
} }
if ('getFormData' in this.props){
data = mergeOptionsWithDuplicates(data, this.props.getFormData());
}
return data; return data;
}, },

View File

@ -19,7 +19,8 @@ let InputCheckbox = React.createClass({
handleFocus() { handleFocus() {
this.refs.checkbox.getDOMNode().checked = !this.refs.checkbox.getDOMNode().checked; this.refs.checkbox.getDOMNode().checked = !this.refs.checkbox.getDOMNode().checked;
this.setState({ this.setState({
show: this.refs.checkbox.getDOMNode().checked show: this.refs.checkbox.getDOMNode().checked,
value: this.refs.checkbox.getDOMNode().checked
}); });
}, },

View File

@ -91,6 +91,9 @@ let SignupForm = React.createClass({
', ' + getLangText('please confirm') + '.'); ', ' + getLangText('please confirm') + '.');
}, },
getFormData(){
return {terms: this.refs.form.refs.terms.refs.input.state.value};
},
render() { render() {
let tooltipPassword = getLangText('Your password must be at least 10 characters') + '.\n ' + let tooltipPassword = getLangText('Your password must be at least 10 characters') + '.\n ' +
getLangText('This password is securing your digital property like a bank account') + '.\n ' + getLangText('This password is securing your digital property like a bank account') + '.\n ' +
@ -101,6 +104,7 @@ let SignupForm = React.createClass({
ref='form' ref='form'
url={apiUrls.users_signup} url={apiUrls.users_signup}
handleSuccess={this.handleSuccess} handleSuccess={this.handleSuccess}
getFormData={this.getFormData}
buttons={ buttons={
<button type="submit" className="btn ascribe-btn ascribe-btn-login"> <button type="submit" className="btn ascribe-btn ascribe-btn-login">
{getLangText('Sign up to ascribe')} {getLangText('Sign up to ascribe')}
@ -153,7 +157,7 @@ let SignupForm = React.createClass({
name="terms" name="terms"
className="ascribe-settings-property-collapsible-toggle" className="ascribe-settings-property-collapsible-toggle"
style={{paddingBottom: 0}}> style={{paddingBottom: 0}}>
<InputCheckbox /> <InputCheckbox/>
</Property> </Property>
</Form> </Form>
); );

View File

@ -112,6 +112,24 @@ export function mergeOptions(...l) {
return newObj; return newObj;
} }
/**
* Takes a list of object and merges their keys to one object.
* Uses mergeOptions for two objects.
* @param {[type]} l [description]
* @return {[type]} [description]
*/
export function mergeOptionsWithDuplicates(...l) {
// If the objects submitted in the list have duplicates,in their key names,
// abort the merge and tell the function's user to check his objects.
let newObj = {};
for(let i = 1; i < l.length; i++) {
newObj = _mergeOptions(newObj, _mergeOptions(l[i - 1], l[i]));
}
return newObj;
}
/** /**
* Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1 * Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1
* @param obj1 * @param obj1