dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #09519
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2545: use ajax paging for load list of operand in add/update indicator
------------------------------------------------------------
revno: 2545
committer: Tri <Tri@Tri-Laptop>
branch nick: dhis2
timestamp: Wed 2011-01-12 18:07:48 +0700
message:
use ajax paging for load list of operand in add/update indicator
added:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonPaging.vm
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOperands.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.ajax.js
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm
--
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-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOperands.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOperands.vm 2010-12-12 19:49:23 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOperands.vm 2011-01-12 11:07:48 +0000
@@ -8,4 +8,6 @@
"operandName": "$!encoder.jsonEncode( ${operand.operandName} )"
}#if( $velocityCount < $size ),#end
#end
-] }
\ No newline at end of file
+] ,
+ "paging":#parse( "/dhis-web-commons/ajax/jsonPaging.vm" )
+}
\ No newline at end of file
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonPaging.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonPaging.vm 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonPaging.vm 2011-01-12 11:07:48 +0000
@@ -0,0 +1,12 @@
+#set ( $baseLink = $paging.baseLink )
+#set ( $pageSize = $paging.pageSize )
+#set ( $currentPage = $paging.currentPage )
+#set ( $startPage = $paging.startPage )
+#set ( $numberOfPages = $paging.numberOfPages )
+{
+ "numberOfPages": "${numberOfPages}",
+ "currentPage":"${currentPage}",
+ "baseLink":"$!encoder.jsonEncode( ${baseLink} )",
+ "pageSize":"${pageSize}",
+ "startPage":"${startPage}"
+}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.ajax.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.ajax.js 2010-12-10 07:45:59 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.ajax.js 2011-01-12 11:07:48 +0000
@@ -18,6 +18,12 @@
var operandsByDataElementGroup = new Array();
+ var params = {};
+
+ var jQuerySelectionString;
+
+ var url;
+
this.loadDataElementGroups = function( jQuerySelectionString )
{
var target = jQuery( jQuerySelectionString );
@@ -160,6 +166,18 @@
});
}
+ }
+
+ this.reloadOperands = function( currentpage )
+ {
+ this.params.currentPage = currentpage;
+ this.loadOperands( this.jQuerySelectionString, this.params );
+ }
+
+ this.changeOperandsPageSize = function( pagesize )
+ {
+ this.params.pageSize = pagesize;
+ this.loadOperands( this.jQuerySelectionString, this.params );
}
this.loadOperands = function ( jQuerySelectionString, params )
@@ -167,12 +185,34 @@
var target = jQuery( jQuerySelectionString );
target.children().remove();
- jQuery.getJSON('../dhis-web-commons-ajax-json/getOperands.action'
- , params
+ this.params = params;
+ this.jQuerySelectionString = jQuerySelectionString;
+
+ jQuery.getJSON( '../dhis-web-commons-ajax-json/getOperands.action'
+ , this.params
, function( json ){
jQuery.each( json.operands, function(i, item){
target.append('<option value="[' + item.operandId + ']">' + item.operandName + '</option>');
- });
+ });
+ if( params.usepaging ){
+ var numberOfPages = json.paging.numberOfPages;
+ var currentPage = json.paging.currentPage;
+ var baseLink = json.paging.baseLink;
+ var pageSize = json.paging.pageSize;
+ var startPage = json.paging.startPage;
+
+ var html = '<div id="abcd1234">';
+ if( numberOfPages > 1 ){
+ html += 'Page: <select onchange="dataDictionary.reloadOperands( this.value )">';
+ for(var i=1;i<=numberOfPages;i++){
+ html += '<option value="' + i + '"' + ( currentPage==i?'selected=true':'' ) + '>' + i + '</option>';
+ }
+ html += '</select>';
+ }
+ html += 'Size: <input type="text" style="width:50px" onchange="dataDictionary.changeOperandsPageSize( this.value )" value="' + pageSize + '"/></div>';
+ jQuery( '#abcd1234' ).remove();;
+ jQuery( html ).insertAfter( target );
+ }
});
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java 2010-12-07 17:02:27 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java 2011-01-12 11:07:48 +0000
@@ -38,14 +38,13 @@
import org.hisp.dhis.dataelement.comparator.DataElementOperandNameComparator;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
-
-import com.opensymphony.xwork2.Action;
+import org.hisp.dhis.paging.ActionPagingSupport;
/**
* @author Lars Helge Overland
*/
public class GetOperandsAction
- implements Action
+ extends ActionPagingSupport<DataElementOperand>
{
// -------------------------------------------------------------------------
// Dependencies
@@ -98,7 +97,7 @@
}
private boolean includeTotals = false;
-
+
public void setIncludeTotals( boolean includeTotals )
{
this.includeTotals = includeTotals;
@@ -140,10 +139,20 @@
dataElements.retainAll( dataElementService.getDataElementsByAggregationOperator( aggregationOperator ) );
}
- operands = new ArrayList<DataElementOperand>( dataElementCategoryService.getOperands( dataElements, includeTotals ) );
+ operands = new ArrayList<DataElementOperand>( dataElementCategoryService.getOperands( dataElements,
+ includeTotals ) );
Collections.sort( operands, new DataElementOperandNameComparator() );
+ if ( this.usepaging )
+ {
+
+ this.paging = createPaging( operands.size() );
+
+ operands = operands.subList( paging.getStartPos(), paging.getEndPos() );
+
+ }
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java 2010-10-30 05:54:51 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/paging/ActionPagingSupport.java 2011-01-12 11:07:48 +0000
@@ -65,16 +65,28 @@
{
return paging;
}
-
- @SuppressWarnings("unchecked")
+
+ protected boolean usepaging;
+
+ public boolean isUsepaging()
+ {
+ return usepaging;
+ }
+
+ public void setUsepaging( boolean usepaging )
+ {
+ this.usepaging = usepaging;
+ }
+
+ @SuppressWarnings( "unchecked" )
private String getCurrentLink()
{
HttpServletRequest request = ServletActionContext.getRequest();
-
+
String baseLink = request.getRequestURI() + "?";
Enumeration<String> paramNames = request.getParameterNames();
-
+
while ( paramNames.hasMoreElements() )
{
String paramName = paramNames.nextElement();
@@ -85,7 +97,7 @@
}
}
- return baseLink.substring( 0, baseLink.length()-1 );
+ return baseLink.substring( 0, baseLink.length() - 1 );
}
protected Paging createPaging( Integer totalRecord )
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm 2010-12-12 20:39:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm 2011-01-12 11:07:48 +0000
@@ -137,7 +137,7 @@
var id = getFieldValue( "indicator-expression-container select[id=dataElementGroupId]");
- dataDictionary.loadOperands( "#indicator-expression-container select[id=dataElementId]", {id: id, aggregationOperator: aggregationOperator} );
+ dataDictionary.loadOperands( "#indicator-expression-container select[id=dataElementId]", {id: id, aggregationOperator: aggregationOperator} , usepaging:true );
checkAggregationOperator();
}