1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-26 03:06:28 +02:00
onion/js/components/ascribe_pagination/pagination_button.js
Tim Daubenschütz f0d8e32ecf Merge remote-tracking branch 'origin/master' into AD-1080-restyle-webapp-with-new-corporate-identity
Conflicts:
	js/components/ascribe_accordion_list/accordion_list_item_piece.js
	js/components/ascribe_app.js
	js/components/ascribe_piece_list_toolbar/piece_list_toolbar.js
	js/components/logout_container.js
	js/components/whitelabel/wallet/wallet_app.js
2015-10-19 10:30:14 +02:00

70 lines
1.8 KiB
JavaScript

'use strict';
import React from 'react';
import { Link } from 'react-router';
import Glyphicon from 'react-bootstrap/lib/Glyphicon';
import { getLangText } from '../../utils/lang_utils';
let PaginationButton = React.createClass({
propTypes: {
direction: React.PropTypes.oneOf(['previous', 'next']),
goToPage: React.PropTypes.func.isRequired,
currentPage: React.PropTypes.number.isRequired,
totalPages: React.PropTypes.number.isRequired
},
isInRange(page) {
return page > 0 && page <= this.props.totalPages;
},
render() {
let directionDisplay;
let page = this.props.currentPage;
let isDisabled = '';
let anchor;
if(this.props.direction === 'previous') {
page -= 1;
directionDisplay = (
<span>
<span aria-hidden="true"><Glyphicon glyph='chevron-left'/></span> {getLangText('Previous')}
</span>
);
} else {
page += 1;
directionDisplay = (
<span>
{getLangText('Next')} <span aria-hidden="true"><Glyphicon glyph='chevron-right'/></span>
</span>
);
}
if (this.isInRange(page)) {
anchor = (
<Link to="/collection"
query={{page}}
onClick={this.props.goToPage(page)}>
{directionDisplay}
</Link>
);
} else {
isDisabled += ' disabled';
anchor = (
<a>
{directionDisplay}
</a>
);
}
return (
<li className={this.props.direction + isDisabled }>
{anchor}
</li>
);
}
});
export default PaginationButton;