Small fixes for components using pieces and editions

This commit is contained in:
Brett Sun 2016-01-14 16:31:19 +01:00
parent 3e67e2d2ee
commit 7a53d539a6
4 changed files with 33 additions and 27 deletions

View File

@ -90,7 +90,7 @@ let EditionContainer = React.createClass({
const { edition, currentUser, coaMeta } = this.state;
const { actionPanelButtonListType, furtherDetailsType } = this.props;
if (Object.keys(edition).length && edition.id) {
if (edition.id) {
setDocumentTitle([edition.artist_name, edition.title].join(', '));
return (

View File

@ -19,11 +19,12 @@ import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uplo
let FurtherDetails = React.createClass({
propTypes: {
pieceId: React.PropTypes.number.isRequired,
editable: React.PropTypes.bool,
pieceId: React.PropTypes.number,
extraData: React.PropTypes.object,
handleSuccess: React.PropTypes.func,
otherData: React.PropTypes.arrayOf(React.PropTypes.object),
handleSuccess: React.PropTypes.func
},
getInitialState() {
@ -32,13 +33,16 @@ let FurtherDetails = React.createClass({
};
},
showNotification(){
this.props.handleSuccess();
let notification = new GlobalNotificationModel('Details updated', 'success');
showNotification() {
if (typeof this.props.handleSucess === 'function') {
this.props.handleSuccess();
}
const notification = new GlobalNotificationModel('Details updated', 'success');
GlobalNotificationActions.appendGlobalNotification(notification);
},
submitFile(file){
submitFile(file) {
this.setState({
otherDataKey: file.key
});
@ -60,8 +64,7 @@ let FurtherDetails = React.createClass({
handleSuccess={this.showNotification}
editable={this.props.editable}
pieceId={this.props.pieceId}
extraData={this.props.extraData}
/>
extraData={this.props.extraData} />
<PieceExtraDataForm
name='display_instructions'
title='Display Instructions'

View File

@ -13,43 +13,46 @@ import InputTextAreaToggable from './input_textarea_toggable';
let PieceExtraDataForm = React.createClass({
propTypes: {
pieceId: React.PropTypes.number,
name: React.PropTypes.string.isRequired,
pieceId: React.PropTypes.number.isRequired,
editable: React.PropTypes.bool,
extraData: React.PropTypes.object,
handleSuccess: React.PropTypes.func,
name: React.PropTypes.string,
title: React.PropTypes.string,
editable: React.PropTypes.bool
title: React.PropTypes.string
},
getFormData() {
let extradata = {};
extradata[this.props.name] = this.refs.form.refs[this.props.name].state.value;
return {
extradata: extradata,
extradata: {
[this.props.name]: this.refs.form.refs[this.props.name].state.value
},
piece_id: this.props.pieceId
};
},
render() {
let defaultValue = this.props.extraData[this.props.name] || '';
if (defaultValue.length === 0 && !this.props.editable){
const { editable, extraData, handleSuccess, name, pieceId, title } = this.props;
const defaultValue = (extraData && extraData[name]) || null;
if (!defaultValue && !editable) {
return null;
}
let url = requests.prepareUrl(ApiUrls.piece_extradata, {piece_id: this.props.pieceId});
return (
<Form
ref='form'
url={url}
handleSuccess={this.props.handleSuccess}
url={requests.prepareUrl(ApiUrls.piece_extradata, { piece_id: pieceId })}
handleSuccess={handleSuccess}
getFormData={this.getFormData}
disabled={!this.props.editable}>
disabled={!editable}>
<Property
name={this.props.name}
label={this.props.title}>
name={name}
label={title}>
<InputTextAreaToggable
rows={1}
defaultValue={defaultValue}
placeholder={getLangText('Fill in%s', ' ') + this.props.title}
placeholder={getLangText('Fill in%s', ' ') + title}
required />
</Property>
<hr />

View File

@ -126,7 +126,7 @@ let MarketSubmitButton = React.createClass({
aclName='acl_consign'>
<ModalWrapper
trigger={triggerButton}
handleSuccess={this.handleAdditionalDataSuccess.bind(this, solePieceId)}
handleSuccess={() => this.handleAdditionalDataSuccess(solePieceId)}
title={getLangText('Add additional information')}>
<MarketAdditionalDataForm
pieceId={solePieceId}