2015-06-17 17:48:52 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
2015-10-01 11:16:38 +02:00
|
|
|
import { History } from 'react-router';
|
2015-08-12 09:52:51 +02:00
|
|
|
|
2015-10-09 13:51:21 +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';
|
|
|
|
|
2015-11-18 16:31:37 +01:00
|
|
|
import Property from './ascribe_forms/property';
|
2015-07-13 18:13:47 +02:00
|
|
|
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';
|
2015-10-13 16:42:40 +02:00
|
|
|
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),
|
2015-08-07 15:54:36 +02:00
|
|
|
React.PropTypes.element,
|
|
|
|
React.PropTypes.string
|
2015-09-30 18:30:50 +02:00
|
|
|
]),
|
2016-01-11 12:54:15 +01:00
|
|
|
|
|
|
|
// Provided from AscribeApp
|
|
|
|
currentUser: React.PropTypes.object,
|
2016-02-05 11:53:33 +01:00
|
|
|
whitelabel: React.PropTypes.object.isRequired,
|
2016-01-11 12:54:15 +01:00
|
|
|
|
2016-01-11 16:26:36 +01:00
|
|
|
// Provided from router
|
2015-09-30 18:30:50 +02:00
|
|
|
location: React.PropTypes.object
|
2015-07-13 22:58:53 +02:00
|
|
|
},
|
|
|
|
|
2015-10-01 11:16:38 +02:00
|
|
|
mixins: [History],
|
2015-06-20 16:43:18 +02:00
|
|
|
|
2015-06-23 13:55:05 +02:00
|
|
|
getInitialState(){
|
2016-01-11 12:54:15 +01:00
|
|
|
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;
|
|
|
|
|
2016-01-11 12:54:15 +01:00
|
|
|
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() {
|
2016-02-05 11:53:33 +01:00
|
|
|
const { whitelabel } = this.props;
|
|
|
|
|
|
|
|
if (whitelabel.acl_create_editions || Object.keys(whitelabel).length) {
|
2015-07-13 22:58:53 +02:00
|
|
|
return (
|
2015-11-18 16:31:37 +01:00
|
|
|
<Property
|
2015-07-14 00:12:33 +02:00
|
|
|
name="num_editions"
|
2015-11-18 16:31:37 +01:00
|
|
|
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} />
|
2015-11-18 16:31:37 +01:00
|
|
|
</Property>
|
2015-07-13 22:58:53 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-23 13:55:05 +02:00
|
|
|
render() {
|
2015-10-13 16:42:40 +02:00
|
|
|
setDocumentTitle(getLangText('Register a new piece'));
|
|
|
|
|
2015-06-17 17:48:52 +02:00
|
|
|
return (
|
2015-10-09 13:51:21 +02:00
|
|
|
<Row className="no-margin">
|
|
|
|
<Col xs={12} sm={10} md={8} smOffset={1} mdOffset={2}>
|
|
|
|
<RegisterPieceForm
|
|
|
|
{...this.props}
|
2015-12-02 12:37:21 +01:00
|
|
|
isFineUploaderActive={true}
|
2016-01-11 18:16:46 +01:00
|
|
|
handleSuccess={this.handleSuccess}>
|
2015-10-09 13:51:21 +02:00
|
|
|
{this.props.children}
|
|
|
|
{this.getSpecifyEditions()}
|
|
|
|
</RegisterPieceForm>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
2015-06-17 17:48:52 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-22 10:50:22 +02:00
|
|
|
|
2015-06-19 14:05:56 +02:00
|
|
|
export default RegisterPiece;
|