mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 01:25:17 +01:00
Include PropertyCollapsible's functionality into Property
This commit is contained in:
parent
6d828ac959
commit
25372a3edf
@ -11,7 +11,6 @@ import GlobalNotificationActions from '../../actions/global_notification_actions
|
|||||||
|
|
||||||
import Form from './form';
|
import Form from './form';
|
||||||
import Property from './property';
|
import Property from './property';
|
||||||
import PropertyCollapsible from './property_collapsible';
|
|
||||||
import InputTextAreaToggable from './input_textarea_toggable';
|
import InputTextAreaToggable from './input_textarea_toggable';
|
||||||
|
|
||||||
import ApiUrls from '../../constants/api_urls';
|
import ApiUrls from '../../constants/api_urls';
|
||||||
@ -122,9 +121,10 @@ let ContractAgreementForm = React.createClass({
|
|||||||
required/>
|
required/>
|
||||||
</Property>
|
</Property>
|
||||||
{this.getContracts()}
|
{this.getContracts()}
|
||||||
<PropertyCollapsible
|
<Property
|
||||||
name='appendix'
|
name='appendix'
|
||||||
checkboxLabel={getLangText('Add appendix to the contract')}>
|
checkboxLabel={getLangText('Add appendix to the contract')}
|
||||||
|
expanded={false}>
|
||||||
<span>{getLangText('Appendix')}</span>
|
<span>{getLangText('Appendix')}</span>
|
||||||
{/* We're using disabled on a form here as PropertyCollapsible currently
|
{/* We're using disabled on a form here as PropertyCollapsible currently
|
||||||
does not support the disabled + overrideForm functionality */}
|
does not support the disabled + overrideForm functionality */}
|
||||||
@ -132,7 +132,7 @@ let ContractAgreementForm = React.createClass({
|
|||||||
rows={1}
|
rows={1}
|
||||||
disabled={false}
|
disabled={false}
|
||||||
placeholder={getLangText('This will be appended to the contract selected above')}/>
|
placeholder={getLangText('This will be appended to the contract selected above')}/>
|
||||||
</PropertyCollapsible>
|
</Property>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import UserActions from '../../actions/user_actions';
|
|||||||
|
|
||||||
import Form from './form';
|
import Form from './form';
|
||||||
import Property from './property';
|
import Property from './property';
|
||||||
import PropertyCollapsible from './property_collapsible';
|
|
||||||
import InputFineUploader from './input_fineuploader';
|
import InputFineUploader from './input_fineuploader';
|
||||||
import UploadButton from '../ascribe_uploader/ascribe_upload_button/upload_button';
|
import UploadButton from '../ascribe_uploader/ascribe_upload_button/upload_button';
|
||||||
|
|
||||||
|
@ -41,7 +41,8 @@ const Property = React.createClass({
|
|||||||
element
|
element
|
||||||
]),
|
]),
|
||||||
style: object,
|
style: object,
|
||||||
expanded: bool
|
expanded: bool,
|
||||||
|
checkboxLabel: string
|
||||||
},
|
},
|
||||||
|
|
||||||
getDefaultProps() {
|
getDefaultProps() {
|
||||||
@ -53,7 +54,17 @@ const Property = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
|
const { expanded, ignoreFocus, checkboxLabel } = this.props;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
// We're mirroring expanded here as a state
|
||||||
|
// React's docs do NOT consider this an antipattern as long as it's
|
||||||
|
// not a "source of truth"-duplication
|
||||||
|
expanded,
|
||||||
|
|
||||||
|
// When a checkboxLabel is defined in the props, we want to set
|
||||||
|
// `ignoreFocus` to true
|
||||||
|
ignoreFocus: ignoreFocus || checkboxLabel,
|
||||||
// Please don't confuse initialValue with react's defaultValue.
|
// Please don't confuse initialValue with react's defaultValue.
|
||||||
// initialValue is set by us to ensure that a user can reset a specific
|
// initialValue is set by us to ensure that a user can reset a specific
|
||||||
// property (after editing) to its initial value
|
// property (after editing) to its initial value
|
||||||
@ -64,9 +75,19 @@ const Property = React.createClass({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillReceiveProps() {
|
componentWillReceiveProps(nextProps) {
|
||||||
let childInput = this.refs.input;
|
let childInput = this.refs.input;
|
||||||
|
|
||||||
|
// For expanded there are actually two use cases:
|
||||||
|
//
|
||||||
|
// 1. Control its value from the outside completely (do not define `checkboxLabel`)
|
||||||
|
// 2. Let it be controlled from the inside (default value can be set though via `expanded`)
|
||||||
|
//
|
||||||
|
// This handles case 1.
|
||||||
|
if(nextProps.expanded !== this.state.expanded && !this.props.checkboxLabel) {
|
||||||
|
this.setState({ expanded: nextProps.expanded });
|
||||||
|
}
|
||||||
|
|
||||||
// In order to set this.state.value from another component
|
// In order to set this.state.value from another component
|
||||||
// the state of value should only be set if its not undefined and
|
// the state of value should only be set if its not undefined and
|
||||||
// actually references something
|
// actually references something
|
||||||
@ -137,7 +158,7 @@ const Property = React.createClass({
|
|||||||
handleFocus() {
|
handleFocus() {
|
||||||
// if ignoreFocus (bool) is defined, then just ignore focusing on
|
// if ignoreFocus (bool) is defined, then just ignore focusing on
|
||||||
// the property and input
|
// the property and input
|
||||||
if(this.props.ignoreFocus) {
|
if(this.state.ignoreFocus) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +210,7 @@ const Property = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getClassName() {
|
getClassName() {
|
||||||
if(!this.props.expanded){
|
if(!this.state.expanded && !this.props.checkboxLabel){
|
||||||
return 'is-hidden';
|
return 'is-hidden';
|
||||||
}
|
}
|
||||||
if(!this.props.editable){
|
if(!this.props.editable){
|
||||||
@ -232,6 +253,31 @@ const Property = React.createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleCheckboxToggle() {
|
||||||
|
this.setState({expanded: !this.state.expanded});
|
||||||
|
},
|
||||||
|
|
||||||
|
getCheckbox() {
|
||||||
|
const { checkboxLabel } = this.props;
|
||||||
|
|
||||||
|
if(checkboxLabel) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="ascribe-property-collapsible-toggle"
|
||||||
|
onClick={this.handleCheckboxToggle}>
|
||||||
|
<input
|
||||||
|
onChange={this.handleCheckboxToggle}
|
||||||
|
type="checkbox"
|
||||||
|
checked={this.state.expanded}
|
||||||
|
ref="checkboxCollapsible"/>
|
||||||
|
<span className="checkbox">{' ' + checkboxLabel}</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let footer = null;
|
let footer = null;
|
||||||
let style = this.props.style ? mergeOptions({}, this.props.style) : {};
|
let style = this.props.style ? mergeOptions({}, this.props.style) : {};
|
||||||
@ -243,18 +289,18 @@ const Property = React.createClass({
|
|||||||
</div>);
|
</div>);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.props.editable) {
|
style.paddingBottom = !this.state.expanded ? 0 : null;
|
||||||
style.cursor = 'not-allowed';
|
style.cursor = !this.props.editable ? 'not-allowed' : null;
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={'ascribe-property-wrapper ' + this.getClassName()}
|
className={'ascribe-property-wrapper ' + this.getClassName()}
|
||||||
onClick={this.handleFocus}
|
onClick={this.handleFocus}
|
||||||
style={style}>
|
style={style}>
|
||||||
|
{this.getCheckbox()}
|
||||||
<Panel
|
<Panel
|
||||||
collapsible
|
collapsible
|
||||||
expanded={this.props.expanded}
|
expanded={this.state.expanded}
|
||||||
className="bs-custom-panel">
|
className="bs-custom-panel">
|
||||||
<div className={'ascribe-property ' + this.props.className}>
|
<div className={'ascribe-property ' + this.props.className}>
|
||||||
{this.getLabelAndErrors()}
|
{this.getLabelAndErrors()}
|
||||||
|
@ -17,7 +17,7 @@ import UserStore from '../stores/user_store';
|
|||||||
import GlobalNotificationModel from '../models/global_notification_model';
|
import GlobalNotificationModel from '../models/global_notification_model';
|
||||||
import GlobalNotificationActions from '../actions/global_notification_actions';
|
import GlobalNotificationActions from '../actions/global_notification_actions';
|
||||||
|
|
||||||
import PropertyCollapsible from './ascribe_forms/property_collapsible';
|
import Property from './ascribe_forms/property';
|
||||||
import RegisterPieceForm from './ascribe_forms/form_register_piece';
|
import RegisterPieceForm from './ascribe_forms/form_register_piece';
|
||||||
|
|
||||||
import { mergeOptions } from '../utils/general_utils';
|
import { mergeOptions } from '../utils/general_utils';
|
||||||
@ -96,15 +96,16 @@ let RegisterPiece = React.createClass( {
|
|||||||
getSpecifyEditions() {
|
getSpecifyEditions() {
|
||||||
if(this.state.whitelabel && this.state.whitelabel.acl_create_editions || Object.keys(this.state.whitelabel).length === 0) {
|
if(this.state.whitelabel && this.state.whitelabel.acl_create_editions || Object.keys(this.state.whitelabel).length === 0) {
|
||||||
return (
|
return (
|
||||||
<PropertyCollapsible
|
<Property
|
||||||
name="num_editions"
|
name="num_editions"
|
||||||
checkboxLabel={getLangText('Specify editions')}>
|
checkboxLabel={getLangText('Specify editions')}
|
||||||
|
expanded={false}>
|
||||||
<span>{getLangText('Editions')}</span>
|
<span>{getLangText('Editions')}</span>
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
placeholder="(e.g. 32)"
|
placeholder="(e.g. 32)"
|
||||||
min={0}/>
|
min={0}/>
|
||||||
</PropertyCollapsible>
|
</Property>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -166,7 +166,7 @@ $ascribe-red-error: rgb(169, 68, 66);
|
|||||||
.ascribe-property-collapsible-toggle {
|
.ascribe-property-collapsible-toggle {
|
||||||
border-top: 1px solid rgba(0, 0, 0, .05);
|
border-top: 1px solid rgba(0, 0, 0, .05);
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: .5em 1.5em;
|
padding: .75em 0 .75em 1.5em;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user