← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9805: added uuid generator to dhis2.util.js

 

------------------------------------------------------------
revno: 9805
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-02-14 16:02:33 +0700
message:
  added uuid generator to dhis2.util.js
modified:
  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.util.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.util.js	2012-02-17 06:19:09 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.util.js	2013-02-14 09:02:33 +0000
@@ -30,19 +30,17 @@
 
 /**
  * Creates namespace object based on path
- * 
+ *
  * @param path {String} The path of the namespace, i.e. 'a.b.c'
- * 
+ *
  * @returns {object} Namespace object
  */
-dhis2.util.namespace = function( path )
-{
+dhis2.util.namespace = function ( path ) {
     var parts = path.split( '.' );
     var parent = window;
     var currentPart = '';
 
-    for ( var i = 0, length = parts.length; i < length; i++ )
-    {
+    for ( var i = 0, length = parts.length; i < length; i++ ) {
         currentPart = parts[i];
         parent[currentPart] = parent[currentPart] || {};
         parent = parent[currentPart];
@@ -54,8 +52,7 @@
 /**
  * Escape function for regular expressions.
  */
-dhis2.util.escape = function( text )
-{
+dhis2.util.escape = function ( text ) {
     return text.replace( /[-[\]{}()*+?.,\/\\^$|#\s]/g, "\\$&" );
 };
 
@@ -63,54 +60,51 @@
  * 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);
+dhis2.util.jqTextFilterCaseSensitive = function ( key, not ) {
+    key = dhis2.util.escape( key );
     not = not || false;
 
-    if ( not )
-    {
-        return function( i, el )
-        {
+    if ( not ) {
+        return function ( i, el ) {
             return !!!$( el ).text().match( "" + key );
         };
     }
-    else
-    {
-        return function( i, el )
-        {
+    else {
+        return function ( i, el ) {
             return !!$( el ).text().match( "" + key );
         };
     }
 };
 
-dhis2.util.jqTextFilter = function( key, not )
-{
-    key = dhis2.util.escape(key).toLowerCase();
+dhis2.util.jqTextFilter = function ( key, not ) {
+    key = dhis2.util.escape( key ).toLowerCase();
     not = not || false;
 
-    if ( not )
-    {
-        return function( i, el )
-        {
+    if ( not ) {
+        return function ( i, el ) {
             return !!!$( el ).text().toLowerCase().match( "" + key );
         };
     }
-    else
-    {
-        return function( i, el )
-        {
+    else {
+        return function ( i, el ) {
             return !!$( el ).text().toLowerCase().match( "" + key );
         };
     }
 };
 
+dhis2.util.uuid = function () {
+    var S4 = function () {
+        return (((1 + Math.random()) * 0x10000) | 0).toString( 16 ).substring( 1 );
+    };
+
+    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
+}
+
 /**
  * adds ':containsNC' to filtering.
  * $(sel).find(':containsNC(key)').doSomething();
  */
-$.expr[":"].containsNC = function( a, i, m, r )
-{
+$.expr[":"].containsNC = function ( a, i, m, r ) {
     var search = dhis2.util.escape( m[3] );
     return jQuery( a ).text().toUpperCase().indexOf( m[search].toUpperCase() ) >= 0;
 };
@@ -118,19 +112,17 @@
 /**
  * adds ':regex' to filtering, use to filter by regular expression
  */
-$.expr[":"].regex = function( a, i, m, r )
-{
+$.expr[":"].regex = function ( a, i, m, r ) {
     var re = new RegExp( m[3], 'i' );
     return re.test( jQuery( a ).text() );
 };
 
 /**
  * adds ':regex' to filtering, use to filter by regular expression
- * 
+ *
  * (this is the case sensitive version)
  */
-$.expr[":"].regexCS = function( a, i, m, r )
-{
+$.expr[":"].regexCS = function ( a, i, m, r ) {
     var re = new RegExp( m[3] );
     return re.test( jQuery( a ).text() );
 };
@@ -138,13 +130,11 @@
 /**
  * Returns an array of the keys in a given object. Will use ES5 Object.keys() if
  * available, if not it will provide a pure javascript implementation.
- * 
+ *
  * @returns array of keys
  */
-if ( !Object.keys )
-{
-    Object.keys = function( obj )
-    {
+if ( !Object.keys ) {
+    Object.keys = function ( obj ) {
         var keys = new Array();
         for ( k in obj )
             if ( obj.hasOwnProperty( k ) )
@@ -157,10 +147,8 @@
  * Define a window.log object, and output to console.log if it exists. (this is
  * a fix for IE8 and FF 3.6).
  */
-window.log = function( str )
-{
-    if ( this.console )
-    {
+window.log = function ( str ) {
+    if ( this.console ) {
         console.log( str );
     }
 };