diff --git a/app/static/app/js/Dashboard.jsx b/app/static/app/js/Dashboard.jsx index ce124628..91b043bd 100644 --- a/app/static/app/js/Dashboard.jsx +++ b/app/static/app/js/Dashboard.jsx @@ -48,7 +48,7 @@ class Dashboard extends React.Component { ref={(domNode) => { this.projectDialog = domNode; }} /> { this.projectList = domNode; }} /> ); diff --git a/app/static/app/js/components/EditProjectDialog.jsx b/app/static/app/js/components/EditProjectDialog.jsx index 46054f01..59d00652 100644 --- a/app/static/app/js/components/EditProjectDialog.jsx +++ b/app/static/app/js/components/EditProjectDialog.jsx @@ -60,7 +60,8 @@ class EditProjectDialog extends React.Component { } componentWillUnmount(){ - $(this.modal).off('hidden.bs.modal hidden.bs.modal'); + $(this.modal).off('hidden.bs.modal hidden.bs.modal') + .modal('hide'); } componentDidUpdate(){ diff --git a/app/static/app/js/components/Map.jsx b/app/static/app/js/components/Map.jsx index 7cd5369e..5eeb3019 100644 --- a/app/static/app/js/components/Map.jsx +++ b/app/static/app/js/components/Map.jsx @@ -2,7 +2,7 @@ import React from 'react'; import '../css/Map.scss'; import 'leaflet/dist/leaflet.css'; import Leaflet from 'leaflet'; -import async from 'async/dist/async'; +import async from 'async'; import 'leaflet-measure/dist/leaflet-measure.css'; import 'leaflet-measure/dist/leaflet-measure'; import '../vendor/leaflet/L.Control.MousePosition.css'; diff --git a/app/static/app/js/components/Paginated.jsx b/app/static/app/js/components/Paginated.jsx index 889673c1..43d98391 100644 --- a/app/static/app/js/components/Paginated.jsx +++ b/app/static/app/js/components/Paginated.jsx @@ -1,28 +1,80 @@ import React from 'react'; +import update from 'react-addons-update'; /*abstract*/ class Paginated extends React.Component{ constructor(){ super(); } - setupPagination(itemsPerPage, totalItems){ + updatePagination(itemsPerPage, totalItems){ let currentPage = 1; + const totalPages = this.totalPages(itemsPerPage, totalItems); + if (this.state.pagination && this.state.pagination.currentPage !== undefined){ currentPage = this.state.pagination.currentPage; } + if (currentPage > totalPages) currentPage = totalPages; + this.setState({pagination: { - itemsPerPage: itemsPerPage, - totalItems: totalItems, - currentPage: currentPage + switchingPages: false, + itemsPerPage: itemsPerPage, + totalItems: totalItems, + currentPage: currentPage } }); + + this.handlePageChange = this.handlePageChange.bind(this); } - getPaginatedUrl(base, page){ + totalPages(itemsPerPage, totalItems){ + return Math.ceil(totalItems / itemsPerPage); + } + + getPaginatedUrl(base){ + const page = this.state.pagination && this.state.pagination.currentPage !== undefined + ? this.state.pagination.currentPage + : 1; + return base.replace(/#\{PAGE\}/g, page); } + setPaginationState(props, done){ + this.setState(update(this.state, { + pagination: { + $merge: props + } + }), done); + } + + handlePageChange(pageNum){ + return (e) => { + // Update current page, once rendering is completed, raise + // on page changed event + this.setPaginationState({ + currentPage: pageNum, + switchingPages: true + }, () => { + if (this.onPageChanged) this.onPageChanged(pageNum); + }); + } + } + + handlePageItemsNumChange(delta, needsRefreshCallback){ + const pagesBefore = this.totalPages(this.state.pagination.itemsPerPage, this.state.pagination.totalItems), + pagesAfter = this.totalPages(this.state.pagination.itemsPerPage, this.state.pagination.totalItems + delta); + let currentPage = this.state.pagination.currentPage; + + if (currentPage > pagesAfter) currentPage = pagesAfter; + + this.setPaginationState({ + totalItems: this.state.pagination.totalItems + delta, + currentPage: currentPage + }, () => { + if (pagesBefore !== pagesAfter) needsRefreshCallback(pagesAfter); + }); + } + render(){ throw new Error("Override me"); } diff --git a/app/static/app/js/components/Paginator.jsx b/app/static/app/js/components/Paginator.jsx index a878c30f..880e93d3 100644 --- a/app/static/app/js/components/Paginator.jsx +++ b/app/static/app/js/components/Paginator.jsx @@ -14,7 +14,7 @@ class Paginator extends React.Component {