=== 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 availableLocalesDb; - - public List 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( i18nService.getAvailableLocales() ); - - if ( !availableLocales.contains( localeManager.getFallbackLocale() ) ) - { - availableLocales.add( localeManager.getFallbackLocale() ); - } - - Collections.sort( availableLocales, new Comparator() - { - 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 @@ + + + === 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 @@
+

$i18n.getString( "update_user" )

+

+ $i18n.getString("first_name") *
+
+ + $i18n.getString("surname") *
+
+ + $i18n.getString("phone_number")
+ + + $i18n.getString("email")
+ +

+
+ +

$i18n.getString( "language" )

- #foreach( $locale in $availableLocalesDb ) - - #end - -

-
- -
-

- -

+