← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5048: fixes bug 876251: filter with ()

 

------------------------------------------------------------
revno: 5048
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-10-26 15:22:09 +0200
message:
  fixes bug 876251: filter with ()
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.select.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.util.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-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.select.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.select.js	2011-10-26 12:44:55 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.select.js	2011-10-26 13:22:09 +0000
@@ -80,13 +80,13 @@
 
         if ( caseSensitive )
         {
-            $select_ghost_matched = $select_ghost_options.filter( ':contains(' + key + ')' );
-            $select_not_matched = $select_options.filter( ':not( :contains(' + key + ') )' );
+            $select_ghost_matched = $select_ghost_options.filter( dhis2.util.jqTextFilterCaseSensitive( key, false ) );
+            $select_not_matched = $select_options.filter( dhis2.util.jqTextFilterCaseSensitive( key, true ) );
         }
         else
         {
-            $select_ghost_matched = $select_ghost_options.filter( ':containsNC(' + key + ')' );
-            $select_not_matched = $select_options.filter( ':not( :containsNC(' + key + ') )' );
+            $select_ghost_matched = $select_ghost_options.filter( dhis2.util.jqTextFilter( key, false ) );
+            $select_not_matched = $select_options.filter( dhis2.util.jqTextFilter( key, true ) );
         }
 
         dhis2.select.moveSorted( $select_ghost, $select_not_matched );

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.util.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.util.js	2011-10-26 12:55:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.util.js	2011-10-26 13:22:09 +0000
@@ -52,6 +52,60 @@
 };
 
 /**
+ * Escape function for regular expressions.
+ */
+dhis2.util.escape = function( text )
+{
+    return text.replace( /[-[\]{}()*+?.,\/\\^$|#\s]/g, "\\$&" );
+};
+
+/**
+ * jQuery cannot correctly filter strings with () in them, so here is a fix
+ * until jQuery gets updated.
+ */
+dhis2.util.jqTextFilterCaseSensitive = function( key, not )
+{
+    key = dhis2.util.escape(key);
+    not = not || false;
+
+    if ( not )
+    {
+        return function( i, el )
+        {
+            return !!!$( el ).text().match( "" + key );
+        };
+    }
+    else
+    {
+        return function( i, el )
+        {
+            return !!$( el ).text().match( "" + key );
+        };
+    }
+};
+
+dhis2.util.jqTextFilter = function( key, not )
+{
+    key = dhis2.util.escape(key).toLowerCase();
+    not = not || false;
+
+    if ( not )
+    {
+        return function( i, el )
+        {
+            return !!!$( el ).text().toLowerCase().match( "" + key );
+        };
+    }
+    else
+    {
+        return function( i, el )
+        {
+            return !!$( el ).text().toLowerCase().match( "" + key );
+        };
+    }
+};
+
+/**
  * adds ':containsNC' to filtering.
  * $(sel).find(':containsNC(key)').doSomething();
  */
@@ -110,11 +164,3 @@
         console.log( str );
     }
 };
-
-/**
- * Escape function for regular expressions.
- */
-dhis2.util.escape = function( text )
-{
-    return text.replace( /[-[\]{}()*+?.,\/\\^$|#\s]/g, "\\$&" );
-};