← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5659: (mobil) removed support for changing localeDb in settings (nobody really uses this), added suppor...

 

------------------------------------------------------------
revno: 5659
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-01-04 12:36:32 +0100
message:
  (mobil) removed support for changing localeDb in settings (nobody really uses this), added support for changing firstName, surname, phoneNumber and email (in preparation for messaging support)
modified:
  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/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/settings.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
=== modified 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	2011-10-14 10:44:57 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings/action/GetSettingsAction.java	2012-01-04 11:36:32 +0000
@@ -27,17 +27,14 @@
 
 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 com.opensymphony.xwork2.Action;
 import org.hisp.dhis.i18n.I18nService;
 import org.hisp.dhis.i18n.locale.LocaleManager;
 import org.hisp.dhis.i18n.resourcebundle.ResourceBundleManager;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
 
-import com.opensymphony.xwork2.Action;
+import java.util.*;
 
 /**
  * @author mortenoh
@@ -70,6 +67,13 @@
         this.i18nService = i18nService;
     }
 
+    private CurrentUserService currentUserService;
+
+    public void setCurrentUserService( CurrentUserService currentUserService )
+    {
+        this.currentUserService = currentUserService;
+    }
+
     // -------------------------------------------------------------------------
     // Input & Output
     // -------------------------------------------------------------------------
@@ -88,18 +92,52 @@
         return currentLocale;
     }
 
-    private List<Locale> availableLocalesDb;
-
-    public List<Locale> getAvailableLocalesDb()
-    {
-        return availableLocalesDb;
-    }
-
-    private Locale currentLocaleDb;
-
-    public Locale getCurrentLocaleDb()
-    {
-        return currentLocaleDb;
+    private String firstName;
+
+    public String getFirstName()
+    {
+        return firstName;
+    }
+
+    public void setFirstName( String firstName )
+    {
+        this.firstName = firstName;
+    }
+
+    private String surname;
+
+    public String getSurname()
+    {
+        return surname;
+    }
+
+    public void setSurname( String surname )
+    {
+        this.surname = surname;
+    }
+
+    private String phoneNumber;
+
+    public String getPhoneNumber()
+    {
+        return phoneNumber;
+    }
+
+    public void setPhoneNumber( String phoneNumber )
+    {
+        this.phoneNumber = phoneNumber;
+    }
+
+    private String email;
+
+    public String getEmail()
+    {
+        return email;
+    }
+
+    public void setEmail( String email )
+    {
+        this.email = email;
     }
 
     // -------------------------------------------------------------------------
@@ -127,25 +165,15 @@
         currentLocale = localeManager.getCurrentLocale();
 
         // ---------------------------------------------------------------------
-        // Get available locales in db
+        // Get settings for current user
         // ---------------------------------------------------------------------
 
-        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();
+        User user = currentUserService.getCurrentUser();
+
+        firstName = user.getFirstName();
+        surname = user.getSurname();
+        phoneNumber = user.getPhoneNumber();
+        email = user.getEmail();
 
         return SUCCESS;
     }

=== modified 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	2011-10-14 10:44:57 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/action/settings/action/SaveSettingsFormAction.java	2012-01-04 11:36:32 +0000
@@ -27,12 +27,17 @@
 
 package org.hisp.dhis.light.action.settings.action;
 
+import com.opensymphony.xwork2.Action;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.Validate;
+import org.apache.commons.validator.EmailValidator;
+import org.hisp.dhis.i18n.locale.LocaleManager;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserService;
+
 import java.util.Locale;
 
-import org.hisp.dhis.i18n.locale.LocaleManager;
-
-import com.opensymphony.xwork2.Action;
-
 public class SaveSettingsFormAction
     implements Action
 {
@@ -54,6 +59,20 @@
         this.localeManagerDB = localeManagerDB;
     }
 
+    private CurrentUserService currentUserService;
+
+    public void setCurrentUserService( CurrentUserService currentUserService )
+    {
+        this.currentUserService = currentUserService;
+    }
+
+    private UserService userService;
+
+    public void setUserService( UserService userService )
+    {
+        this.userService = userService;
+    }
+
     // -------------------------------------------------------------------------
     // Input & Output
     // -------------------------------------------------------------------------
@@ -72,6 +91,54 @@
         this.currentLocaleDb = currentLocaleDb;
     }
 
+    private String firstName;
+
+    public String getFirstName()
+    {
+        return firstName;
+    }
+
+    public void setFirstName( String firstName )
+    {
+        this.firstName = firstName;
+    }
+
+    private String surname;
+
+    public String getSurname()
+    {
+        return surname;
+    }
+
+    public void setSurname( String surname )
+    {
+        this.surname = surname;
+    }
+
+    private String phoneNumber;
+
+    public String getPhoneNumber()
+    {
+        return phoneNumber;
+    }
+
+    public void setPhoneNumber( String phoneNumber )
+    {
+        this.phoneNumber = phoneNumber;
+    }
+
+    private String email;
+
+    public String getEmail()
+    {
+        return email;
+    }
+
+    public void setEmail( String email )
+    {
+        this.email = email;
+    }
+
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
@@ -79,10 +146,36 @@
     @Override
     public String execute()
     {
+        Validate.notEmpty( currentLocale );
+        Validate.notEmpty( firstName );
+        Validate.notEmpty( surname );
+
+        // ---------------------------------------------------------------------
+        // Update user account settings
+        // ---------------------------------------------------------------------
+
+        User user = currentUserService.getCurrentUser();
+
+        user.setFirstName( firstName );
+        user.setSurname( surname );
+        user.setPhoneNumber( phoneNumber );
+
+        if ( StringUtils.isNotBlank( email ) )
+        {
+            if ( EmailValidator.getInstance().isValid( email ) )
+            {
+                user.setEmail( email );
+            }
+        }
+
+        userService.updateUser( user );
+
+        // ---------------------------------------------------------------------
+        // Update locale settings (ui)
+        // ---------------------------------------------------------------------
+
         localeManagerInterface.setCurrentLocale( getRespectiveLocale( currentLocale ) );
 
-        localeManagerDB.setCurrentLocale( getRespectiveLocale( currentLocaleDb ) );
-
         return SUCCESS;
     }
 
@@ -97,19 +190,19 @@
 
         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:
+            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-12-27 11:13:41 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml	2012-01-04 11:36:32 +0000
@@ -100,12 +100,15 @@
     <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" />
+    <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
   </bean>
 
   <bean id="org.hisp.dhis.light.action.settings.action.SaveSettingsFormAction" class="org.hisp.dhis.light.action.settings.action.SaveSettingsFormAction"
     scope="prototype">
     <property name="localeManagerInterface" ref="org.hisp.dhis.i18n.locale.LocaleManager" />
     <property name="localeManagerDB" ref="org.hisp.dhis.i18n.locale.LocaleManagerDb" />
+    <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
+    <property name="userService" ref="org.hisp.dhis.user.UserService" />
   </bean>
   
 </beans>

=== modified 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	2011-10-14 10:44:57 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/settings.vm	2012-01-04 11:36:32 +0000
@@ -4,6 +4,23 @@
 <form action="saveSettingsForm.action" method="POST">
 
 <div class="header-box" align="center">
+    <h3 style="text-align: left;">$i18n.getString( "update_user" )</h3>
+    <p style="text-align: left;">
+        $i18n.getString("first_name") *<br/>
+        <input type="text" id="firstName" name="firstName" value="$!firstName" /> <br />
+
+        $i18n.getString("surname") *<br />
+        <input type="text" id="surname" name="surname" value="$!surname" /> <br />
+
+        $i18n.getString("phone_number") <br />
+        <input type="text" id="phoneNumber" name="phoneNumber" value="$!phoneNumber" />
+
+        $i18n.getString("email") <br />
+        <input type="text" id="email" name="email" value="$!email" />
+    </p>
+</div>
+
+<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%;">
@@ -15,20 +32,7 @@
 </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>
+	<p> <input type="submit" style="width: 100%;" value="$i18n.getString("save")" /> </p>
 </div>
 
 </form>