2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-22 12:58:06 +02:00
|
|
|
import React from 'react';
|
2015-09-30 18:30:50 +02:00
|
|
|
import { Link } from 'react-router';
|
2015-05-22 12:58:06 +02:00
|
|
|
|
2015-10-16 13:00:19 +02:00
|
|
|
import Glyphicon from 'react-bootstrap/lib/Glyphicon';
|
2015-06-02 14:25:26 +02:00
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
|
|
|
|
2015-05-22 12:58:06 +02:00
|
|
|
|
|
|
|
let PaginationButton = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
direction: React.PropTypes.oneOf(['previous', 'next']),
|
2015-05-22 13:43:53 +02:00
|
|
|
goToPage: React.PropTypes.func.isRequired,
|
2015-05-22 17:11:17 +02:00
|
|
|
currentPage: React.PropTypes.number.isRequired,
|
|
|
|
totalPages: React.PropTypes.number.isRequired
|
|
|
|
},
|
|
|
|
|
|
|
|
isInRange(page) {
|
|
|
|
return page > 0 && page <= this.props.totalPages;
|
2015-05-22 12:58:06 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let directionDisplay;
|
2015-05-22 17:11:17 +02:00
|
|
|
let page = this.props.currentPage;
|
2015-05-22 13:43:53 +02:00
|
|
|
let isDisabled = '';
|
2015-05-22 17:11:17 +02:00
|
|
|
let anchor;
|
2015-05-22 13:43:53 +02:00
|
|
|
|
2015-05-22 12:58:06 +02:00
|
|
|
if(this.props.direction === 'previous') {
|
|
|
|
page -= 1;
|
|
|
|
directionDisplay = (
|
|
|
|
<span>
|
2015-10-16 13:00:19 +02:00
|
|
|
<span aria-hidden="true"><Glyphicon glyph='chevron-left'/></span> {getLangText('Previous')}
|
2015-05-22 12:58:06 +02:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
page += 1;
|
|
|
|
directionDisplay = (
|
|
|
|
<span>
|
2015-10-16 13:00:19 +02:00
|
|
|
{getLangText('Next')} <span aria-hidden="true"><Glyphicon glyph='chevron-right'/></span>
|
2015-05-22 12:58:06 +02:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-05-22 17:11:17 +02:00
|
|
|
if (this.isInRange(page)) {
|
|
|
|
anchor = (
|
2015-10-01 14:30:11 +02:00
|
|
|
<Link to="/collection"
|
2015-05-22 12:58:06 +02:00
|
|
|
query={{page}}
|
|
|
|
onClick={this.props.goToPage(page)}>
|
|
|
|
{directionDisplay}
|
|
|
|
</Link>
|
2015-05-22 17:11:17 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
isDisabled += ' disabled';
|
|
|
|
anchor = (
|
|
|
|
<a>
|
|
|
|
{directionDisplay}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li className={this.props.direction + isDisabled }>
|
|
|
|
{anchor}
|
2015-05-22 12:58:06 +02:00
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-22 17:11:17 +02:00
|
|
|
export default PaginationButton;
|