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() {
if(this.props.content.num_editions !== 0) {
if(this.props.content.num_editions > 0) {
PieceListActions.fetchFirstEditionForPiece(this.props.content.id);
}
},
@ -66,6 +66,7 @@ let AccordionListItem = React.createClass({
handleEditionCreationSuccess(response) {
let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
GlobalNotificationActions.appendGlobalNotification(notification);
PieceListActions.updatePropertyForPiece({pieceId: this.props.content.id, key: 'num_editions', value: 0});
this.setState({
creatingEditions: true
@ -106,7 +107,7 @@ let AccordionListItem = React.createClass({
render() {
let linkData;
if(this.props.content.num_editions === 0) {
if(this.props.content.num_editions < 1) {
linkData = {
to: 'piece',
params: {
@ -157,7 +158,7 @@ let AccordionListItem = React.createClass({
</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}

View File

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

View File

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

View File

@ -19,7 +19,8 @@ let InputCheckbox = React.createClass({
handleFocus() {
this.refs.checkbox.getDOMNode().checked = !this.refs.checkbox.getDOMNode().checked;
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') + '.');
},
getFormData(){
return {terms: this.refs.form.refs.terms.refs.input.state.value};
},
render() {
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 ' +
@ -101,6 +104,7 @@ let SignupForm = React.createClass({
ref='form'
url={apiUrls.users_signup}
handleSuccess={this.handleSuccess}
getFormData={this.getFormData}
buttons={
<button type="submit" className="btn ascribe-btn ascribe-btn-login">
{getLangText('Sign up to ascribe')}
@ -153,7 +157,7 @@ let SignupForm = React.createClass({
name="terms"
className="ascribe-settings-property-collapsible-toggle"
style={{paddingBottom: 0}}>
<InputCheckbox />
<InputCheckbox/>
</Property>
</Form>
);

View File

@ -112,6 +112,24 @@ export function mergeOptions(...l) {
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
* @param obj1