import React from 'react'; import { Alert, Row, Col } from 'react-bootstrap'; import { Card, Profile, WaitIcon, ReactGrid } from '../../../components'; import Form from '../../../forms/form'; import SessionUtils from '../../session-utils'; import CrudPagination from '../crud/crud-pagination'; import CrudCounter from '../crud/crud-counter'; import CrudController from '../crud/crud-controller'; import FakeCRUD from '../../../commons/fake-crud'; /** * Display a list of untis */ export default class UnitsCard extends React.Component { constructor(props) { super(props); this.loadList = this.loadList.bind(this); this.eventHandler = this.eventHandler.bind(this); // create fake-crud controller const unitFakeCRUD = new FakeCRUD('/api/tbl/unit/query'); const opts = { pageSize: 50, readOnly: true, editorSchema: {}, refreshAll: false }; const controller = new CrudController(unitFakeCRUD, opts); this.state = { controller: controller }; } componentWillMount() { const self = this; const handler = this.state.controller.on(evt => { self.eventHandler(evt); }); this.setState({ handler: handler }); this.loadList(); } componentWillUnmount() { // remove registration this.state.controller.removeListener(this.state.handler); } eventHandler(evt) { if (evt === 'list' || evt === 'fetching-list') { this.forceUpdate(); } } loadList() { const self = this; const params = { type: 'TBUNIT', adminUnitId: this.props.scope === 'ADMINUNIT' ? this.props.scopeId : null }; this.state.controller .initList(params) .then(() => self.forceUpdate()); } cellRender(item) { const auname = Form.types.adminUnit.controlClass().displayText(item.adminUnit); return ( ); } onCellClick(item) { window.location.hash = SessionUtils.unitHash(item.id, '/cases'); } render() { const controller = this.state.controller; if (controller.isFetching()) { return ; } return ( { // no results found (!controller.getList() || controller.getList().length < 1) ? {__('form.norecordfound')} : null } { // show case list controller.getList() && controller.getList().length > 0 ? : null } ); } } UnitsCard.propTypes = { scope: React.PropTypes.oneOf(['WORKSPACE', 'ADMINUNIT']).isRequired, scopeId: React.PropTypes.string, route: React.PropTypes.object.isRequired };