import React from 'react'; import { Alert, Badge } from 'react-bootstrap'; import controlWrapper from './crud-control-wrapper'; /** * Simple crud component to display the number of records in the controller. * It also supports pagination */ class CrudCounter extends React.Component { eventHandler(evt) { if (evt === 'page' || evt === 'fetching-list' || evt === 'list') { this.forceUpdate(); } } render() { const controller = this.props.controller; if (!controller.getList()) { return null; } if (this.props.counterOnly) { return React.createElement( Badge, { className: 'tbl-counter' }, controller.getCount() > 0 ? controller.getCount() : '-' ); } // any result found ? if (!controller.getCount()) { return React.createElement( Alert, { bsStyle: 'warning' }, __('form.norecordfound') ); } const msg = ' ' + __('form.resultlist'); const className = this.props.className ? this.props.className : 'text-muted'; // is paging enabled ? if (controller.isPaging() && controller.getCount() > controller.options.pageSize) { return React.createElement( 'div', { className: className }, React.createElement( 'b', null, controller.getPageIni() + 1 ), ' - ', React.createElement( 'b', null, controller.getPageEnd() + 1 ), ' of ', React.createElement( 'b', null, controller.getCount() ), msg ); } // render simple counter return React.createElement( 'span', { className: className }, React.createElement( 'b', null, controller.getCount() ), msg ); } } CrudCounter.propTypes = { controller: React.PropTypes.object.isRequired, counterOnly: React.PropTypes.bool, className: React.PropTypes.string }; export default controlWrapper(CrudCounter);