dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19242
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8308: Impl auto pagination on page scroll for interpretations
------------------------------------------------------------
revno: 8308
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-09-30 22:23:50 +0200
message:
Impl auto pagination on page scroll for interpretations
modified:
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/interpretation/action/GetInterpretationsAction.java
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/interpretation.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/interpretation/action/GetInterpretationsAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/interpretation/action/GetInterpretationsAction.java 2012-05-29 21:23:47 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/interpretation/action/GetInterpretationsAction.java 2012-09-30 20:23:50 +0000
@@ -40,6 +40,8 @@
public class GetInterpretationsAction
implements Action
{
+ private static final int PAGE_SIZE = 6;
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -52,6 +54,17 @@
}
// -------------------------------------------------------------------------
+ // Input
+ // -------------------------------------------------------------------------
+
+ private Integer page;
+
+ public void setPage( Integer page )
+ {
+ this.page = page;
+ }
+
+ // -------------------------------------------------------------------------
// Output
// -------------------------------------------------------------------------
@@ -61,16 +74,18 @@
{
return interpretations;
}
-
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
public String execute()
{
+ int first = page != null ? ( page * PAGE_SIZE ) : 0;
+
interpretationService.updateCurrentUserLastChecked();
- interpretations = interpretationService.getInterpretations( 0, 20 );
+ interpretations = interpretationService.getInterpretations( first, PAGE_SIZE );
return SUCCESS;
}
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/interpretation.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/interpretation.js 2012-09-30 17:45:22 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/interpretation.js 2012-09-30 20:23:50 +0000
@@ -1,9 +1,52 @@
+var currentPage = 0;
+var pageLock = false;
+
$( document ).ready( function() {
$( ".commentArea" ).autogrow();
+
+ $( document ).scroll( function() {
+ isNextPage();
+ } );
+
$( "#interpretationFeed" ).load( "getInterpretations.action" );
} );
+function isNextPage()
+{
+ var fromTop = $( document ).scrollTop();
+ var height = $( document ).height();
+ var threshold = 0.7;
+ var loaded = parseFloat( parseFloat( fromTop ) / parseFloat( height ) );
+
+ if ( loaded >= threshold )
+ {
+ loadNextPage();
+ }
+}
+
+function loadNextPage()
+{
+ if ( pageLock == true )
+ {
+ return false;
+ }
+
+ pageLock = true;
+ currentPage++;
+
+ $.get( "getInterpretations.action", { page: currentPage }, function( data ) {
+ $( "#interpretationFeed" ).append( data );
+
+ if ( !isDefined ( data ) || $.trim( data ).length == 0 )
+ {
+ $( document ).off( "scroll" );
+ }
+
+ pageLock = false;
+ } );
+}
+
function showUserInfo( id )
{
$( "#userInfo" ).load( "../dhis-web-commons-ajax-html/getUser.action?id=" + id, function() {