1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-28 16:48:04 +02:00

Add resizing functionality to AclButtonList and AclInformation

This commit is contained in:
Tim Daubenschütz 2015-10-23 09:29:17 +02:00
parent d4de2434ee
commit e8a9cd89a4
6 changed files with 107 additions and 38 deletions

View File

@ -1,12 +1,14 @@
'use strict'; 'use strict';
import React from 'react'; import React from 'react/addons';
import UserActions from '../../actions/user_actions'; import UserActions from '../../actions/user_actions';
import UserStore from '../../stores/user_store'; import UserStore from '../../stores/user_store';
import AclButton from '../ascribe_buttons/acl_button'; import AclButton from '../ascribe_buttons/acl_button';
import { mergeOptions } from '../../utils/general_utils';
let AclButtonList = React.createClass({ let AclButtonList = React.createClass({
propTypes: { propTypes: {
@ -25,57 +27,90 @@ let AclButtonList = React.createClass({
}, },
getInitialState() { getInitialState() {
return UserStore.getState(); return mergeOptions(
UserStore.getState(),
{
buttonListSize: 0
}
);
}, },
componentDidMount() { componentDidMount() {
UserStore.listen(this.onChange); UserStore.listen(this.onChange);
UserActions.fetchCurrentUser(); UserActions.fetchCurrentUser();
window.addEventListener('resize', this.handleResize);
window.dispatchEvent(new Event('resize'));
}, },
componentWillUnmount() { componentWillUnmount() {
UserStore.unlisten(this.onChange); UserStore.unlisten(this.onChange);
window.removeEventListener('resize', this.handleResize);
},
handleResize() {
this.setState({
buttonListSize: this.refs.buttonList.getDOMNode().offsetWidth
});
}, },
onChange(state) { onChange(state) {
this.setState(state); this.setState(state);
}, },
renderChildren() {
const { children } = this.props;
const { buttonListSize } = this.state;
return React.Children.map(children, (child) => {
return React.addons.cloneWithProps(child, { buttonListSize });
});
},
render() { render() {
const { className,
buttonsStyle,
availableAcls,
editions,
handleSuccess } = this.props;
const { currentUser } = this.state;
return ( return (
<div className={this.props.className}> <div className={className}>
<span style={this.props.buttonsStyle}> <span ref="buttonList" style={buttonsStyle}>
<AclButton <AclButton
availableAcls={this.props.availableAcls} availableAcls={availableAcls}
action="acl_share" action="acl_share"
pieceOrEditions={this.props.editions} pieceOrEditions={editions}
currentUser={this.state.currentUser} currentUser={currentUser}
handleSuccess={this.props.handleSuccess} /> handleSuccess={handleSuccess} />
<AclButton <AclButton
availableAcls={this.props.availableAcls} availableAcls={availableAcls}
action="acl_transfer" action="acl_transfer"
pieceOrEditions={this.props.editions} pieceOrEditions={editions}
currentUser={this.state.currentUser} currentUser={currentUser}
handleSuccess={this.props.handleSuccess}/> handleSuccess={handleSuccess}/>
<AclButton <AclButton
availableAcls={this.props.availableAcls} availableAcls={availableAcls}
action="acl_consign" action="acl_consign"
pieceOrEditions={this.props.editions} pieceOrEditions={editions}
currentUser={this.state.currentUser} currentUser={currentUser}
handleSuccess={this.props.handleSuccess} /> handleSuccess={handleSuccess} />
<AclButton <AclButton
availableAcls={this.props.availableAcls} availableAcls={availableAcls}
action="acl_unconsign" action="acl_unconsign"
pieceOrEditions={this.props.editions} pieceOrEditions={editions}
currentUser={this.state.currentUser} currentUser={currentUser}
handleSuccess={this.props.handleSuccess} /> handleSuccess={handleSuccess} />
<AclButton <AclButton
availableAcls={this.props.availableAcls} availableAcls={availableAcls}
action="acl_loan" action="acl_loan"
pieceOrEditions={this.props.editions} pieceOrEditions={editions}
currentUser={this.state.currentUser} currentUser={currentUser}
handleSuccess={this.props.handleSuccess} /> handleSuccess={handleSuccess} />
{this.props.children} {this.renderChildren()}
</span> </span>
</div> </div>
); );

View File

@ -12,7 +12,16 @@ let AclInformation = React.createClass({
propTypes: { propTypes: {
verbs: React.PropTypes.arrayOf(React.PropTypes.string), verbs: React.PropTypes.arrayOf(React.PropTypes.string),
aim: React.PropTypes.string.isRequired, aim: React.PropTypes.string.isRequired,
aclObject: React.PropTypes.object aclObject: React.PropTypes.object,
// Must be inserted from the outside
buttonListSize: React.PropTypes.number.isRequired
},
getDefaultProps() {
return {
buttonListSize: 400
};
}, },
getInitialState() { getInitialState() {
@ -99,13 +108,19 @@ let AclInformation = React.createClass({
}, },
render() { render() {
const { aim } = this.props; const { aim, buttonListSize } = this.props;
const { isVisible } = this.state; const { isVisible } = this.state;
/* Lets just fucking get this widget out... */
const aclInformationSize = buttonListSize - 33;
return ( return (
<span > <span >
{this.getButton()} {this.getButton()}
<div <div
style={{
width: aclInformationSize > 300 ? aclInformationSize : 400
}}
className={classnames({'acl-information-dropdown-list': true, 'hidden': aim === 'button' && !isVisible})}> className={classnames({'acl-information-dropdown-list': true, 'hidden': aim === 'button' && !isVisible})}>
<span>{this.produceInformationBlock()}</span> <span>{this.produceInformationBlock()}</span>
</div> </div>

View File

@ -45,7 +45,7 @@ let DeleteButton = React.createClass({
title = getLangText('Delete Edition'); title = getLangText('Delete Edition');
} }
btnDelete = <Button bsStyle="danger" className="btn-delete" bsSize="small">{getLangText('DELETE')}</Button>; btnDelete = <Button bsStyle="default" bsSize="small">{getLangText('DELETE')}</Button>;
} else if(availableAcls.acl_unshare){ } else if(availableAcls.acl_unshare){
@ -57,7 +57,7 @@ let DeleteButton = React.createClass({
title = getLangText('Remove Piece from Collection'); title = getLangText('Remove Piece from Collection');
} }
btnDelete = <Button bsStyle="danger" className="btn-delete" bsSize="small">{getLangText('REMOVE FROM COLLECTION')}</Button>; btnDelete = <Button bsStyle="default" bsSize="small">{getLangText('REMOVE FROM COLLECTION')}</Button>;
} else { } else {
return null; return null;

View File

@ -211,10 +211,30 @@ let EditionSummary = React.createClass({
value={ edition.owner } /> value={ edition.owner } />
<LicenseDetail license={edition.license_type}/> <LicenseDetail license={edition.license_type}/>
{this.getStatus()} {this.getStatus()}
<EditionActionPanel <div className="row ascribe-detail-property">
edition={edition} <div className="row-same-height">
currentUser={currentUser} <div className={this.props.labelClassName}>
handleSuccess={this.handleSuccess} /> { this.props.label } { this.props.separator}
</div>
<div
className={this.props.valueClassName}
style={styles}>
{value}
</div>
</div>
</div>
<div className="row">
<div className="col-xs-4 no-padding">
Actions
</div>
<div
className="col-xs-8">
<EditionActionPanel
edition={edition}
currentUser={currentUser}
handleSuccess={this.handleSuccess} />
</div>
</div>);
<hr/> <hr/>
</div> </div>
); );

View File

@ -124,7 +124,7 @@ let EditionActionPanel = React.createClass({
type="text" type="text"
value={edition.bitcoin_id} /> value={edition.bitcoin_id} />
</Property> </Property>
<Button bsStyle="danger" className="btn-delete pull-center" bsSize="small" type="submit"> <Button bsStyle="default" className="pull-center" bsSize="small" type="submit">
{getLangText('WITHDRAW TRANSFER')} {getLangText('WITHDRAW TRANSFER')}
</Button> </Button>
</Form> </Form>

View File

@ -1,6 +1,5 @@
.acl-information-dropdown-list { .acl-information-dropdown-list {
text-align: justify; text-align: justify;
background-color: white;
padding: .5em .5em .5em 0; padding: .5em .5em .5em 0;
p { p {
@ -15,14 +14,14 @@
} }
.title { .title {
color: #02B6A3; color: $ascribe-dark-blue;
} }
.info { .info {
color: #333333; color: #212121;
} }
.example { .example {
color: #B2B2B2; color: #616161;
} }
} }