1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-26 03:06:28 +02:00
onion/js/components/register_piece.js

112 lines
3.3 KiB
JavaScript
Raw Normal View History

2015-06-17 17:48:52 +02:00
'use strict';
import React from 'react';
import { History } from 'react-router';
2015-08-12 09:52:51 +02:00
import Col from 'react-bootstrap/lib/Col';
import Row from 'react-bootstrap/lib/Row';
2015-07-01 16:19:02 +02:00
import PieceListStore from '../stores/piece_list_store';
import PieceListActions from '../actions/piece_list_actions';
2015-06-22 10:50:22 +02:00
import GlobalNotificationModel from '../models/global_notification_model';
import GlobalNotificationActions from '../actions/global_notification_actions';
import Property from './ascribe_forms/property';
import RegisterPieceForm from './ascribe_forms/form_register_piece';
2015-06-22 10:50:22 +02:00
2015-07-03 19:08:56 +02:00
import { getLangText } from '../utils/lang_utils';
import { setDocumentTitle } from '../utils/dom_utils';
2015-06-29 10:00:26 +02:00
2015-07-13 22:58:53 +02:00
2015-06-17 17:48:52 +02:00
let RegisterPiece = React.createClass( {
2015-07-13 22:58:53 +02:00
propTypes: {
headerMessage: React.PropTypes.string,
submitMessage: React.PropTypes.string,
children: React.PropTypes.oneOfType([
React.PropTypes.arrayOf(React.PropTypes.element),
React.PropTypes.element,
React.PropTypes.string
]),
// Provided from AscribeApp
currentUser: React.PropTypes.object,
whitelabel: React.PropTypes.object.isRequired,
2016-01-11 16:26:36 +01:00
// Provided from router
location: React.PropTypes.object
2015-07-13 22:58:53 +02:00
},
mixins: [History],
2015-06-20 16:43:18 +02:00
2015-06-23 13:55:05 +02:00
getInitialState(){
return PieceListStore.getState();
2015-06-30 10:42:58 +02:00
},
componentDidMount() {
2015-07-01 16:19:02 +02:00
PieceListStore.listen(this.onChange);
2015-06-30 10:42:58 +02:00
},
componentWillUnmount() {
2015-07-01 16:19:02 +02:00
PieceListStore.unlisten(this.onChange);
2015-06-30 10:42:58 +02:00
},
onChange(state) {
this.setState(state);
2015-06-23 13:55:05 +02:00
},
2015-06-29 11:44:16 +02:00
2016-02-05 10:38:59 +01:00
handleSuccess(response) {
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
const notification = new GlobalNotificationModel(response.notification, 'success', 10000);
2015-06-23 13:55:05 +02:00
GlobalNotificationActions.appendGlobalNotification(notification);
2015-07-01 16:19:02 +02:00
// once the user was able to register a piece successfully, we need to make sure to keep
// the piece list up to date
2016-02-05 10:38:59 +01:00
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
2015-07-07 15:48:09 +02:00
2016-01-11 17:52:32 +01:00
this.history.push(`/pieces/${response.piece.id}`);
2015-06-23 13:55:05 +02:00
},
2015-07-13 22:58:53 +02:00
getSpecifyEditions() {
const { whitelabel } = this.props;
if (whitelabel.acl_create_editions || Object.keys(whitelabel).length) {
2015-07-13 22:58:53 +02:00
return (
<Property
2015-07-14 00:12:33 +02:00
name="num_editions"
checkboxLabel={getLangText('Specify editions')}
expanded={false}>
2015-07-13 22:58:53 +02:00
<span>{getLangText('Editions')}</span>
<input
type="number"
placeholder="(e.g. 32)"
2016-02-05 10:38:59 +01:00
min={1}
max={100} />
</Property>
2015-07-13 22:58:53 +02:00
);
}
},
2015-06-23 13:55:05 +02:00
render() {
setDocumentTitle(getLangText('Register a new piece'));
2015-06-17 17:48:52 +02:00
return (
<Row className="no-margin">
<Col xs={12} sm={10} md={8} smOffset={1} mdOffset={2}>
<RegisterPieceForm
{...this.props}
isFineUploaderActive={true}
handleSuccess={this.handleSuccess}>
{this.props.children}
{this.getSpecifyEditions()}
</RegisterPieceForm>
</Col>
</Row>
2015-06-17 17:48:52 +02:00
);
}
});
2015-06-22 10:50:22 +02:00
export default RegisterPiece;