1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

add acl buttons for selection

This commit is contained in:
Tim Daubenschütz 2015-05-27 14:35:33 +02:00
parent f85d4fd106
commit b9620d00aa
3 changed files with 43 additions and 9 deletions

View File

@ -0,0 +1,32 @@
import React from 'react';
import AppConstants from '../constants/application_constants';
let AclButton = React.createClass({
propTypes: {
action: React.PropTypes.oneOf(AppConstants.aclList).isRequired,
availableAcls: React.PropTypes.array.isRequired
},
render() {
let shouldDisplay = this.props.availableAcls.indexOf(this.props.action) > -1;
let styles = {};
if(shouldDisplay) {
styles.display = 'inline-block';
} else {
styles.display = 'none';
}
return (
<button
style={styles}
type="button"
className="btn btn-default btn-sm">
{this.props.action.toUpperCase()}
</button>
);
}
});
export default AclButton;

View File

@ -2,6 +2,8 @@ import React from 'react';
import EditionListStore from '../../stores/edition_list_store'; import EditionListStore from '../../stores/edition_list_store';
import AclButton from '../acl_button';
let PieceListToolbar = React.createClass({ let PieceListToolbar = React.createClass({
getInitialState() { getInitialState() {
return EditionListStore.getState(); return EditionListStore.getState();
@ -29,8 +31,7 @@ let PieceListToolbar = React.createClass({
Object Object
.keys(this.state.editionList) .keys(this.state.editionList)
.forEach((key) => { .forEach((key) => {
let filteredEditionsForPiece = this.state.editionList[key] let filteredEditionsForPiece = this.state.editionList[key].filter(this.filterForSelected);
.filter(this.filterForSelected);
selectedEditionList = selectedEditionList.concat(filteredEditionsForPiece); selectedEditionList = selectedEditionList.concat(filteredEditionsForPiece);
}); });
@ -38,7 +39,6 @@ let PieceListToolbar = React.createClass({
}, },
intersectAcls(a, b) { intersectAcls(a, b) {
//console.log(a, b);
return a.filter((val) => b.indexOf(val) > -1); return a.filter((val) => b.indexOf(val) > -1);
}, },
@ -48,6 +48,7 @@ let PieceListToolbar = React.createClass({
// If no edition has been selected, availableActions is empty // If no edition has been selected, availableActions is empty
// If only one edition has been selected, their actions are available // If only one edition has been selected, their actions are available
// If more than one editions have been selected, their acl properties are intersected
if(selectedEditionList.length >= 1) { if(selectedEditionList.length >= 1) {
availableAcls = selectedEditionList[0].acl; availableAcls = selectedEditionList[0].acl;
} }
@ -61,16 +62,16 @@ let PieceListToolbar = React.createClass({
}, },
render() { render() {
this.getAvailableAcls(); let availableAcls = this.getAvailableAcls();
return ( return (
<div className="row no-margin"> <div className="row no-margin">
<div className="col-xs-12 col-sm-12 col-md-12 col-lg-12 piece-list-toolbar"> <div className="col-xs-12 col-sm-12 col-md-12 col-lg-12 piece-list-toolbar">
<div className="pull-right"> <div className="pull-right">
<button type="button" className="btn btn-default btn-sm">Transfer</button> <AclButton availableAcls={availableAcls} action="transfer" />
<button type="button" className="btn btn-default btn-sm">Consign</button> <AclButton availableAcls={availableAcls} action="consign" />
<button type="button" className="btn btn-default btn-sm">Share</button> <AclButton availableAcls={availableAcls} action="share" />
<button type="button" className="btn btn-default btn-sm">Loan</button> <AclButton availableAcls={availableAcls} action="loan" />
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,6 +1,7 @@
let constants = { let constants = {
'baseUrl': 'http://staging.ascribe.io/api/', 'baseUrl': 'http://staging.ascribe.io/api/',
'debugCredentialBase64': 'ZGltaUBtYWlsaW5hdG9yLmNvbTowMDAwMDAwMDAw' // dimi@mailinator:0000000000 'debugCredentialBase64': 'ZGltaUBtYWlsaW5hdG9yLmNvbTowMDAwMDAwMDAw', // dimi@mailinator:0000000000
'aclList': ['edit', 'consign', 'transfer', 'loan', 'share', 'download', 'view', 'delete', 'del_from_collection', 'add_to_collection']
}; };
export default constants; export default constants;