← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11431: wip, persist page/filter on save/edit lists

 

------------------------------------------------------------
revno: 11431
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-07-18 12:21:15 +0700
message:
  wip, persist page/filter on save/edit lists
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/ContextInterceptor.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml


--
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/javascripts/commons.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2013-07-17 16:50:42 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2013-07-18 05:21:15 +0000
@@ -31,12 +31,25 @@
 	return $.cookie( "currentPage" );
 }
 
+dhis2.commons.getCurrentKey = function() {
+	return $.cookie( "currentKey" );
+}
+
 dhis2.commons.redirectCurrentPage = function( url ) {
 	var currentPage = dhis2.commons.getCurrentPage();
+	var currentKey = dhis2.commons.getCurrentKey();
 	var separator = url && url.indexOf( "?" ) == -1 ? "?" : "&";
-	var redirect = currentPage ? ( url + separator + "currentPage=" + currentPage ) : url;
-	window.location.href = redirect;
-}
+
+    var redirect = url;
+
+    if ( currentPage && currentKey ) {
+        redirect = currentPage ? ( url + separator + "currentPage=" + currentPage + "&key=" + currentKey ) : url;
+    } else if ( currentPage ) {
+        redirect = currentPage ? ( url + separator + "currentPage=" + currentPage ) : url;
+    }
+
+    window.location.href = redirect;
+};
 
 // -----------------------------------------------------------------------------
 // Global variables

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm	2013-07-17 15:23:18 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm	2013-07-18 05:21:15 +0000
@@ -89,12 +89,23 @@
 #end
 
 #macro( filterDiv $action )
-<form id="filterKeyForm" action="${action}.action" method="POST">	
+<form id="filterKeyForm" action="${action}.action" method="GET" onsubmit="submitFilter()">
 	<input type="text" id="key" name="key" value="$!encoder.htmlEncode( $key )" placeholder="$i18n.getString( 'filter_by_name' )" class="filterInput" />
 	<input type="hidden" id="curKey" name="curKey" value="$!encoder.htmlEncode( $key )"/>
-	<input type="submit" value="$i18n.getString( 'filter' )" class="filterButton" />
-	<input type="button" value="$i18n.getString( 'clear' )" onclick="window.location.href='${action}.action'" class="filterButton" />
+	<input type="submit" id="filterButton" value="$i18n.getString( 'filter' )" class="filterButton" />
+	<input type="button" value="$i18n.getString( 'clear' )" onclick="javascript:clearFilter()" class="filterButton" />
 </form>
+<script>
+function submitFilter() {
+    jQuery.cookie( "currentKey", $( '#key' ).val() );
+}
+
+function clearFilter() {
+    jQuery.cookie( "currentPage", null );
+    jQuery.cookie( "currentKey", null );
+    window.location.href = '${action}.action';
+}
+</script>
 #end
 
 #macro( trHeader $text )

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/ContextInterceptor.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/ContextInterceptor.java	2012-02-13 20:04:18 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/ContextInterceptor.java	2013-07-18 05:21:15 +0000
@@ -27,17 +27,16 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.util.ContextUtils.getCookieValue;
-
-import java.util.HashMap;
-import java.util.Map;
-
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.Interceptor;
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.system.database.DatabaseInfoProvider;
 import org.hisp.dhis.system.util.TextUtils;
 
-import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.interceptor.Interceptor;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hisp.dhis.util.ContextUtils.getCookieValue;
 
 /**
  * @author Lars Helge Overland
@@ -48,14 +47,15 @@
     private static final String KEY_IN_MEMORY_DATABASE = "inMemoryDatabase";
     private static final String KEY_TEXT_UTILS = "dhisTextUtils";
     private static final String KEY_CURRENT_PAGE = "keyCurrentPage";
-    
+    private static final String KEY_CURRENT_KEY = "keyCurrentKey";
+
     private DatabaseInfoProvider databaseInfoProvider;
 
     public void setDatabaseInfoProvider( DatabaseInfoProvider databaseInfoProvider )
     {
         this.databaseInfoProvider = databaseInfoProvider;
     }
-    
+
     @Override
     public void destroy()
     {
@@ -71,13 +71,14 @@
         throws Exception
     {
         Map<String, Object> map = new HashMap<String, Object>();
-        
+
         map.put( KEY_IN_MEMORY_DATABASE, databaseInfoProvider.isInMemory() );
         map.put( KEY_TEXT_UTILS, TextUtils.INSTANCE );
         map.put( KEY_CURRENT_PAGE, getCookieValue( ServletActionContext.getRequest(), "currentPage" ) );
-        
+        map.put( KEY_CURRENT_KEY, getCookieValue( ServletActionContext.getRequest(), "currentKey" ) );
+
         invocation.getStack().push( map );
-        
+
         return invocation.invoke();
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml	2013-07-12 09:21:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml	2013-07-18 05:21:15 +0000
@@ -58,7 +58,7 @@
     </action>
 
     <action name="addDataElement" class="org.hisp.dhis.dd.action.dataelement.AddDataElementAction">
-      <result name="success" type="redirect">dataElement.action</result>
+      <result name="success" type="redirect">dataElement.action?currentPage=${keyCurrentPage}&amp;key=${keyCurrentKey}</result>
       <param name="anyAuthorities">F_DATAELEMENT_PUBLIC_ADD, F_DATAELEMENT_PRIVATE_ADD</param>
     </action>
 
@@ -70,7 +70,7 @@
     </action>
 
     <action name="updateDataElement" class="org.hisp.dhis.dd.action.dataelement.UpdateDataElementAction">
-      <result name="success" type="redirect">dataElement.action?currentPage=${keyCurrentPage}</result>
+      <result name="success" type="redirect">dataElement.action?currentPage=${keyCurrentPage}&amp;key=${keyCurrentKey}</result>
       <param name="requiredAuthorities">F_DATAELEMENT_UPDATE</param>
     </action>