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-15 01:40:48 +02:00
|
|
|
import WhitelabelActions from '../actions/whitelabel_actions';
|
|
|
|
import WhitelabelStore from '../stores/whitelabel_store';
|
|
|
|
|
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,
|
|
|
|
whitelabel: React.PropTypes.object,
|
|
|
|
|
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
|
|
|
|
2015-07-01 11:21:43 +02:00
|
|
|
handleSuccess(response){
|
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
|
2015-07-07 15:48:09 +02:00
|
|
|
PieceListActions.fetchPieceList(
|
|
|
|
this.state.page,
|
|
|
|
this.state.pageSize,
|
|
|
|
this.state.searchTerm,
|
|
|
|
this.state.orderBy,
|
2015-08-04 11:48:12 +02:00
|
|
|
this.state.orderAsc,
|
|
|
|
this.state.filterBy
|
2015-07-21 11:09:21 +02:00
|
|
|
);
|
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-01-11 15:14:54 +01:00
|
|
|
if (this.props.whitelabel && (this.props.whitelabel.acl_create_editions || Object.keys(this.props.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)"
|
|
|
|
min={0}/>
|
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}
|
2015-10-09 13:51:21 +02:00
|
|
|
handleSuccess={this.handleSuccess}
|
|
|
|
location={this.props.location}>
|
|
|
|
{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;
|