2015-08-14 14:58:23 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import DropdownButton from 'react-bootstrap/lib/DropdownButton';
|
|
|
|
|
|
|
|
import { getLangText } from '../../utils/lang_utils.js';
|
|
|
|
|
|
|
|
let PieceListToolbarOrderWidget = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
// An array of either strings (which represent acl enums) or objects of the form
|
|
|
|
//
|
|
|
|
// {
|
|
|
|
// key: <acl enum>,
|
|
|
|
// label: <a human readable string>
|
|
|
|
// }
|
|
|
|
orderParams: React.PropTypes.arrayOf(React.PropTypes.any).isRequired,
|
|
|
|
orderBy: React.PropTypes.string,
|
|
|
|
applyOrderBy: React.PropTypes.func
|
|
|
|
},
|
|
|
|
|
|
|
|
generateOrderByStatement(param) {
|
|
|
|
let orderBy = this.props.orderBy;
|
|
|
|
return orderBy;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We need overloading here to find the correct parameter of the label
|
|
|
|
* the user is clicking on.
|
|
|
|
*/
|
|
|
|
orderBy(orderBy) {
|
|
|
|
return () => {
|
|
|
|
this.props.applyOrderBy(orderBy);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
isOrderActive() {
|
|
|
|
// We're hiding the star in that complicated matter so that,
|
|
|
|
// the surrounding button is not resized up on appearance
|
2015-12-09 16:17:08 +01:00
|
|
|
if (this.props.orderBy && this.props.orderBy.length) {
|
2015-08-14 14:58:23 +02:00
|
|
|
return { visibility: 'visible'};
|
|
|
|
} else {
|
|
|
|
return { visibility: 'hidden' };
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let filterIcon = (
|
|
|
|
<span>
|
2015-10-09 13:14:29 +02:00
|
|
|
<span className="ascribe-icon icon-ascribe-sort" aria-hidden="true"></span>
|
|
|
|
<span style={this.isOrderActive()}>·</span>
|
2015-08-14 14:58:23 +02:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
|
2015-12-09 16:17:08 +01:00
|
|
|
if (this.props.orderParams && this.props.orderParams.length) {
|
|
|
|
return (
|
|
|
|
<DropdownButton
|
|
|
|
pullRight={true}
|
|
|
|
title={filterIcon}
|
|
|
|
className="ascribe-piece-list-toolbar-filter-widget">
|
|
|
|
<li style={{'textAlign': 'center'}}>
|
|
|
|
<em>{getLangText('Sort by')}:</em>
|
|
|
|
</li>
|
|
|
|
{this.props.orderParams.map((param) => {
|
|
|
|
return (
|
2016-01-11 11:49:27 +01:00
|
|
|
<li
|
|
|
|
key={param}
|
|
|
|
onClick={this.orderBy(param)}
|
|
|
|
className="filter-widget-item">
|
|
|
|
<div className="checkbox-line">
|
|
|
|
<span>
|
|
|
|
{getLangText(param.replace('_', ' '))}
|
|
|
|
</span>
|
|
|
|
<input
|
|
|
|
readOnly
|
|
|
|
type="radio"
|
|
|
|
checked={param.indexOf(this.props.orderBy) > -1} />
|
|
|
|
</div>
|
|
|
|
</li>
|
2015-12-09 16:17:08 +01:00
|
|
|
);
|
|
|
|
})}
|
|
|
|
</DropdownButton>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2015-08-14 14:58:23 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-18 14:59:15 +01:00
|
|
|
export default PieceListToolbarOrderWidget;
|