← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4945: (mobile) implemented settings for locale / localeDb

 

------------------------------------------------------------
revno: 4945
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-10-14 12:44:57 +0200
message:
  (mobile) implemented settings for locale / localeDb
added:
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings/
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings/action/
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings/action/GetSettingsAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings/action/SaveSettingsFormAction.java
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/settings.vm
modified:
  dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties
  dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/menu.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
=== added directory 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings'
=== added directory 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings/action'
=== added file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings/action/GetSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings/action/GetSettingsAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings/action/GetSettingsAction.java	2011-10-14 10:44:57 +0000
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2004-2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.light.action.settings.action;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Locale;
+
+import org.hisp.dhis.i18n.I18nService;
+import org.hisp.dhis.i18n.locale.LocaleManager;
+import org.hisp.dhis.i18n.resourcebundle.ResourceBundleManager;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author mortenoh
+ */
+public class GetSettingsAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private ResourceBundleManager resourceBundleManager;
+
+    public void setResourceBundleManager( ResourceBundleManager resourceBundleManager )
+    {
+        this.resourceBundleManager = resourceBundleManager;
+    }
+
+    private LocaleManager localeManager;
+
+    public void setLocaleManager( LocaleManager localeManager )
+    {
+        this.localeManager = localeManager;
+    }
+
+    private I18nService i18nService;
+
+    public void setI18nService( I18nService i18nService )
+    {
+        this.i18nService = i18nService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input & Output
+    // -------------------------------------------------------------------------
+
+    private List<Locale> availableLocales;
+
+    public List<Locale> getAvailableLocales()
+    {
+        return availableLocales;
+    }
+
+    private Locale currentLocale;
+
+    public Locale getCurrentLocale()
+    {
+        return currentLocale;
+    }
+
+    private List<Locale> availableLocalesDb;
+
+    public List<Locale> getAvailableLocalesDb()
+    {
+        return availableLocalesDb;
+    }
+
+    private Locale currentLocaleDb;
+
+    public Locale getCurrentLocaleDb()
+    {
+        return currentLocaleDb;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action Implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        // ---------------------------------------------------------------------
+        // Get available locales
+        // ---------------------------------------------------------------------
+
+        availableLocales = new ArrayList<Locale>( resourceBundleManager.getAvailableLocales() );
+
+        Collections.sort( availableLocales, new Comparator<Locale>()
+        {
+            public int compare( Locale locale0, Locale locale1 )
+            {
+                return locale0.getDisplayName().compareTo( locale1.getDisplayName() );
+            }
+        } );
+
+        currentLocale = localeManager.getCurrentLocale();
+
+        // ---------------------------------------------------------------------
+        // Get available locales in db
+        // ---------------------------------------------------------------------
+
+        availableLocalesDb = new ArrayList<Locale>( i18nService.getAvailableLocales() );
+
+        if ( !availableLocales.contains( localeManager.getFallbackLocale() ) )
+        {
+            availableLocales.add( localeManager.getFallbackLocale() );
+        }
+
+        Collections.sort( availableLocales, new Comparator<Locale>()
+        {
+            public int compare( Locale locale0, Locale locale1 )
+            {
+                return locale0.getDisplayName().compareTo( locale1.getDisplayName() );
+            }
+        } );
+
+        currentLocaleDb = localeManager.getCurrentLocale();
+
+        return SUCCESS;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings/action/SaveSettingsFormAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings/action/SaveSettingsFormAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings/action/SaveSettingsFormAction.java	2011-10-14 10:44:57 +0000
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2004-2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.light.action.settings.action;
+
+import java.util.Locale;
+
+import org.hisp.dhis.i18n.locale.LocaleManager;
+
+import com.opensymphony.xwork2.Action;
+
+public class SaveSettingsFormAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private LocaleManager localeManagerInterface;
+
+    public void setLocaleManagerInterface( LocaleManager localeManagerInterface )
+    {
+        this.localeManagerInterface = localeManagerInterface;
+    }
+
+    private LocaleManager localeManagerDB;
+
+    public void setLocaleManagerDB( LocaleManager localeManagerDB )
+    {
+        this.localeManagerDB = localeManagerDB;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input & Output
+    // -------------------------------------------------------------------------
+
+    private String currentLocale;
+
+    public void setCurrentLocale( String locale )
+    {
+        this.currentLocale = locale;
+    }
+
+    private String currentLocaleDb;
+
+    public void setCurrentLocaleDb( String currentLocaleDb )
+    {
+        this.currentLocaleDb = currentLocaleDb;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action Implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String execute()
+    {
+        localeManagerInterface.setCurrentLocale( getRespectiveLocale( currentLocale ) );
+
+        localeManagerDB.setCurrentLocale( getRespectiveLocale( currentLocaleDb ) );
+
+        return SUCCESS;
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    private Locale getRespectiveLocale( String locale )
+    {
+        String[] tokens = locale.split( "_" );
+        Locale newLocale = null;
+
+        switch ( tokens.length )
+        {
+        case 1:
+            newLocale = new Locale( tokens[0] );
+            break;
+
+        case 2:
+            newLocale = new Locale( tokens[0], tokens[1] );
+            break;
+
+        case 3:
+            newLocale = new Locale( tokens[0], tokens[1], tokens[2] );
+            break;
+
+        default:
+        }
+
+        return newLocale;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml	2011-10-12 17:49:13 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml	2011-10-14 10:44:57 +0000
@@ -78,4 +78,17 @@
     <property name="selectionTreeManager" ref="org.hisp.dhis.oust.manager.SelectionTreeManager" />
   </bean>
 
+  <!-- Settings -->
+
+  <bean id="org.hisp.dhis.light.action.settings.action.GetSettingsAction" class="org.hisp.dhis.light.action.settings.action.GetSettingsAction">
+    <property name="resourceBundleManager" ref="org.hisp.dhis.i18n.resourcebundle.ResourceBundleManager" />
+    <property name="localeManager" ref="org.hisp.dhis.i18n.locale.LocaleManager" />
+    <property name="i18nService" ref="org.hisp.dhis.i18n.I18nService" />
+  </bean>
+
+  <bean id="org.hisp.dhis.light.action.settings.action.SaveSettingsFormAction" class="org.hisp.dhis.light.action.settings.action.SaveSettingsFormAction">
+    <property name="localeManagerInterface" ref="org.hisp.dhis.i18n.locale.LocaleManager" />
+    <property name="localeManagerDB" ref="org.hisp.dhis.i18n.locale.LocaleManagerDb" />
+  </bean>
+
 </beans>

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties	2011-10-13 14:29:49 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/org/hisp/dhis/light/i18n_module.properties	2011-10-14 10:44:57 +0000
@@ -19,4 +19,7 @@
 available_datasets = Available data sets
 available_organisation_units = Available organisation units
 available_periods = Available periods
-dataset_is_complete = DataSet is complete
\ No newline at end of file
+dataset_is_complete = DataSet is complete
+settings = Settings
+language = Interface Language
+db_language = Database Language

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml	2011-10-13 14:29:49 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/struts.xml	2011-10-14 10:44:57 +0000
@@ -42,7 +42,7 @@
     </action>
 
     <!-- Reports -->
-    
+
     <action name="reports" class="org.hisp.dhis.light.dashboard.action.ProvideContentAction">
       <result name="success" type="velocity">/dhis-web-light/main.vm</result>
       <param name="page">/dhis-web-light/reports.vm</param>
@@ -80,5 +80,16 @@
       </result>
     </action>
 
+    <!-- Settings -->
+
+    <action name="settings" class="org.hisp.dhis.light.action.settings.action.GetSettingsAction">
+      <result name="success" type="velocity">/dhis-web-light/main.vm</result>
+      <param name="page">/dhis-web-light/settings.vm</param>
+    </action>
+
+    <action name="saveSettingsForm" class="org.hisp.dhis.light.action.settings.action.SaveSettingsFormAction">
+      <result name="success" type="redirect">/mobile/index.action</result>
+    </action>
+
   </package>
 </struts>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/menu.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/menu.vm	2011-10-13 14:29:49 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/menu.vm	2011-10-14 10:44:57 +0000
@@ -4,6 +4,7 @@
 <ul>
     <li><a href="selectOrganisationUnit.action">$i18n.getString( "data_entry" )</a></li>
     <li><a href="reports.action">$i18n.getString( "reports" )</a></li>
+    <li><a href="settings.action">$i18n.getString( "settings" )</a></li>
 </ul>
 </p>
 

=== added file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/settings.vm'
--- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/settings.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/settings.vm	2011-10-14 10:44:57 +0000
@@ -0,0 +1,40 @@
+
+<h2>$i18n.getString( "settings" )</h2>
+
+<form action="saveSettingsForm.action" method="POST">
+
+<div class="header-box" align="center">
+	<h3 style="text-align: left;">$i18n.getString( "language" )</h3>
+	<p style="text-align: left;">
+		<select id="currentLocale" name="currentLocale" style="width: 100%;">
+		#foreach( $locale in $availableLocales )
+			<option value="$locale.toString()" #if( $locale == $currentLocale )selected="selected"#end>$locale.getDisplayName()</option>
+		#end
+		</select>
+	</p>
+</div>
+
+<div class="header-box" align="center">
+	<h3 style="text-align: left;">$i18n.getString( "db_language" )</h3>
+	<p style="text-align: left;">
+		<select id="currentLocaleDb" name="currentLocaleDb" style="width: 100%;">
+		#foreach( $locale in $availableLocalesDb )
+			<option value="$locale.toString()" #if( $locale == $currentLocaleDb )selected="selected"#end>$locale.getDisplayName()</option>
+		#end
+		</select>
+	</p>
+</div>
+
+<div class="header-box" align="center">
+	<p>
+		<input type="submit" style="width: 100%;" value="$i18n.getString("save")" />
+	</p>
+</div>
+
+</form>
+
+<div id="footer">
+<h2>$i18n.getString( "navigate_to" )</h2>
+<ul>
+	<li><a href="index.action">$i18n.getString("home")</a></li>
+</ul>