← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4769: I18n functionality - Changed Request to jQuery.

 

------------------------------------------------------------
revno: 4769
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-09-30 10:49:43 +0700
message:
  I18n functionality - Changed Request to jQuery.
removed:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/responseTranslationInput.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/responseTranslationSuccess.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/responseTranslations.vm
added:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/jsonTranslations.vm
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/i18n.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/translate.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.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/i18n/i18n.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/i18n.js	2010-06-09 06:37:34 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/i18n.js	2011-09-30 03:49:43 +0000
@@ -1,106 +1,61 @@
-//----------------------------------------------------------
-// Regular Expression using for checking shortname' value
-//----------------------------------------------------------
-
-regexShortName = /^[\w][\w\d]+$/;
-
-//----------------------------------------------------------
-
-
-function updateTranslation()
-{
-    var id = document.getElementById("objectId").value;
-
-    var className = document.getElementById("className").value;
-
-    var box = document.getElementById("loc");
-    var loc = box.options[box.selectedIndex].value;
-
-    var url = "getTranslations.action?id=" + id + "&className=" + className + "&loc=" + loc ;
-
-    var request = new Request();
-
-    request.setResponseTypeXML('translation');
-
-    request.setCallbackSuccess(updateTranslationReceived);
-
-    /* Clear fields */
-    for ( var i = 0; i < propNames.length; i++ )
-    {
-        document.getElementById(propNames[i]).value = "";
-    }
-
-    if ( loc != "heading" )
-    {
-        request.send(url);
-    }
-}
-
-function updateTranslationReceived( xmlObject )
-{
-    var translations = xmlObject.getElementsByTagName("translation");
-
-    for ( var i = 0; i < translations.length; i++ )
-    {
-        var key = translations[ i ].getElementsByTagName("key")[0].firstChild.nodeValue;
-
-        var value = translations[ i ].getElementsByTagName("value")[0].firstChild.nodeValue;
-
-        var field = document.getElementById(key);
-
-        if ( field != null )
-        {
-            field.value = value;
-        }
-    }
-}
-
-function updateReference()
-{
-    var id = document.getElementById("objectId").value;
-
-    var className = document.getElementById("className").value;
-
-    var box = document.getElementById("referenceLoc");
-    var loc = box.options[box.selectedIndex].value;
-
-    var url = "getTranslations.action?id=" + id + "&className=" + className + "&loc=" + loc ;
-
-    var request = new Request();
-
-    request.setResponseTypeXML('translation');
-
-    request.setCallbackSuccess(updateReferenceReceived);
-
-    /* Clear fields */
-    for ( var i = 0; i < propNames.length; i++ )
-    {
-        document.getElementById(propNames[i] + " Ref").innerHTML = "";
-    }
-
-    if ( loc != "heading" )
-    {
-        request.send(url);
-    }
-}
-
-function updateReferenceReceived( xmlObject )
-{
-    var translations = xmlObject.getElementsByTagName("translation");
-
-    for ( var i = 0; i < translations.length; i++ )
-    {
-        var key = translations[ i ].getElementsByTagName("key")[0].firstChild.nodeValue;
-
-        var value = translations[ i ].getElementsByTagName("value")[0].firstChild.nodeValue;
-
-        var field = document.getElementById(key + " Ref");
-
-        if ( field != null )
-        {
-            field.innerHTML = value;
-        }
-    }
+function getTranslation()
+{
+	/* Clear fields */
+	for ( var i = 0; i < propNames.length; i++ )
+	{
+		byId( propNames[i] ).value = "";
+	}
+
+    var loc = getFieldValue( 'loc' );
+	
+	if ( loc != "heading" )
+	{
+		jQuery.postJSON( 'getTranslations.action', {
+			id: getFieldValue( 'objectId' ),
+			className: getFieldValue( 'className' ),
+			loc: loc
+		}, function ( json ) {
+			
+			var translations = json.translations;
+
+			for ( var i = 0; i < translations.length; i++ )
+			{
+				var field = byId( translations[i].key );
+
+				if ( field != null ) field.value = translations[i].value;
+			}
+		});
+	}
+}
+
+function getReference()
+{
+    /* Clear fields */
+    for ( var i = 0; i < propNames.length; i++ )
+    {
+        byId( propNames[i] + " Ref" ).innerHTML = "";
+    }
+
+    var loc = getFieldValue( 'referenceLoc' );
+
+    if ( loc != "heading" )
+    {
+		jQuery.postJSON( 'getTranslations.action', {
+			id: getFieldValue ( 'objectId' ),
+			className: getFieldValue ( 'className' ),
+			loc: loc
+		}, function ( json )
+		{
+			var translations = json.translations;
+
+			for ( var i = 0; i < translations.length; i++ )
+			{
+				var field = document.getElementById( translations[i].key + ' Ref' );
+
+				if ( field != null ) field.innerHTML = translations[i].value;
+			}
+		});
+	}
 }
 
 function addLocale()

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/jsonTranslations.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/jsonTranslations.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/jsonTranslations.vm	2011-09-30 03:49:43 +0000
@@ -0,0 +1,10 @@
+#set( $size = $!{translations.keySet().size()} )
+{ "translations": [
+  #foreach( $key in $translations.keySet() )
+  {
+    "key": "$!{key}",
+	"value": "$!encoder.jsonEncode( ${translations.get( $!{key} )} )"
+  }#if( $velocityCount < $size ),#end
+  #end
+  ]
+}
\ No newline at end of file

=== removed file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/responseTranslationInput.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/responseTranslationInput.vm	2010-03-31 09:54:25 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/responseTranslationInput.vm	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<message type="input">$encoder.xmlEncode( $message )</message>
\ No newline at end of file

=== removed file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/responseTranslationSuccess.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/responseTranslationSuccess.vm	2010-03-31 09:54:25 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/responseTranslationSuccess.vm	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<message type="success">$encoder.xmlEncode( $message )</message>
\ No newline at end of file

=== removed file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/responseTranslations.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/responseTranslations.vm	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/responseTranslations.vm	1970-01-01 00:00:00 +0000
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<translations>
-#foreach( $key in $translations.keySet() )
-	<translation>
-	    <key>$key</key>
-	    <value>$encoder.xmlEncode( $translations.get( $key ) )</value>
-	</translation>
-#end
-</translations>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/translate.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/translate.vm	2010-10-19 10:12:54 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/translate.vm	2011-09-30 03:49:43 +0000
@@ -28,7 +28,7 @@
 	<tr>
 	<td style="width:12em"></td>
 	<td style="width:20em">
-        <select id="loc" name="loc" onchange="updateTranslation()" style="min-width:20em">
+        <select id="loc" name="loc" onchange="getTranslation()" style="min-width:20em">
             <option value="heading">$i18n.getString( "translation_select_locale" )</option>
 			#foreach ($locale in $availableLocales )
 				<option value="$locale" #if( $currentLocale == $locale ) selected="selected" #end>$locale.displayName</option>
@@ -36,7 +36,7 @@
 		</select>
     </td>
     <td style="width:20em">
-        <select id="referenceLoc" name="referenceLocal" onchange="updateReference()" style="min-width:20em">
+        <select id="referenceLoc" name="referenceLocal" onchange="getReference()" style="min-width:20em">
             <option value="heading">$i18n.getString( "translation_select_ref" )</option>
 			#foreach ($locale in $availableLocales )
 			    <option value="$locale" #if( $currentRefLocale == $locale ) selected="selected" #end>$locale.displayName</option>

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2011-09-27 07:36:07 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2011-09-30 03:49:43 +0000
@@ -300,17 +300,16 @@
     </action>
 
     <action name="validateAddDuplicatedTranslation" class="org.hisp.dhis.i18n.action.ValidateAddDuplicatedTranslationAction">
-      <result name="success" type="velocity-xml">/dhis-web-commons/i18n/responseTranslationSuccess.vm
-      </result>
-      <result name="input" type="velocity-xml">/dhis-web-commons/i18n/responseTranslationInput.vm
-      </result>
+      <result name="success" type="velocity-json">
+		/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+      <result name="input" type="velocity-json">
+		/dhis-web-commons/ajax/jsonResponseInput.vm</result>
       <param name="onExceptionReturn">plainTextError</param>
     </action>
 
     <action name="getTranslations" class="org.hisp.dhis.i18n.action.GetTranslationsAction">
-      <result name="success" type="velocity">
-        /dhis-web-commons/i18n/responseTranslations.vm
-      </result>
+      <result name="success" type="velocity-json">
+        /dhis-web-commons/i18n/jsonTranslations.vm</result>
       <param name="onExceptionReturn">plainTextError</param>
     </action>