← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8991: wip, user profile in jquery mobile

 

------------------------------------------------------------
revno: 8991
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-11-13 13:14:21 +0100
message:
  wip, user profile in jquery mobile
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/UserAccount.java
  dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/base.vm
  dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/user-account.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-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java	2012-11-05 10:43:15 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java	2012-11-13 12:14:21 +0000
@@ -158,34 +158,27 @@
         }
 
         UserAccount userAccount = new UserAccount();
+
+        // user account
         userAccount.setFirstName( currentUser.getFirstName() );
         userAccount.setSurname( currentUser.getSurname() );
         userAccount.setEmail( currentUser.getEmail() );
         userAccount.setPhoneNumber( currentUser.getPhoneNumber() );
 
+        // profile
+        userAccount.setIntroduction( currentUser.getIntroduction() );
+        userAccount.setJobTitle( currentUser.getJobTitle() );
+        userAccount.setGender( currentUser.getGender() );
+        // currentUser.setBirthday( currentUser.getBirthday() );
+        userAccount.setNationality( currentUser.getNationality() );
+        userAccount.setEmployer( currentUser.getEmployer() );
+        userAccount.setEducation( currentUser.getEducation() );
+        userAccount.setInterests( currentUser.getInterests() );
+        userAccount.setLanguages( currentUser.getLanguages() );
+
         JacksonUtils.toJson( response.getOutputStream(), userAccount );
     }
 
-    @RequestMapping( value = "/user-account", method = RequestMethod.POST, consumes = "application/xml" )
-    public void postUserAccountXml( HttpServletResponse response, HttpServletRequest request ) throws Exception
-    {
-        UserAccount userAccount = JacksonUtils.fromXml( request.getInputStream(), UserAccount.class );
-        User currentUser = currentUserService.getCurrentUser();
-
-        if ( currentUser == null )
-        {
-            ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
-            return;
-        }
-
-        currentUser.setFirstName( userAccount.getFirstName() );
-        currentUser.setSurname( userAccount.getSurname() );
-        currentUser.setEmail( userAccount.getEmail() );
-        currentUser.setPhoneNumber( userAccount.getPhoneNumber() );
-
-        userService.updateUser( currentUser );
-    }
-
     @RequestMapping( value = "/user-account", method = RequestMethod.POST, consumes = "application/json" )
     public void postUserAccountJson( HttpServletResponse response, HttpServletRequest request ) throws Exception
     {
@@ -198,11 +191,23 @@
             return;
         }
 
+        // basic user account
         currentUser.setFirstName( userAccount.getFirstName() );
         currentUser.setSurname( userAccount.getSurname() );
         currentUser.setEmail( userAccount.getEmail() );
         currentUser.setPhoneNumber( userAccount.getPhoneNumber() );
 
+        // profile
+        currentUser.setIntroduction( userAccount.getIntroduction() );
+        currentUser.setJobTitle( userAccount.getJobTitle() );
+        currentUser.setGender( userAccount.getGender() );
+        // currentUser.setBirthday( userAccount.getBirthday() );
+        currentUser.setNationality( userAccount.getNationality() );
+        currentUser.setEmployer( userAccount.getEmployer() );
+        currentUser.setEducation( userAccount.getEducation() );
+        currentUser.setInterests( userAccount.getInterests() );
+        currentUser.setLanguages( userAccount.getLanguages() );
+
         userService.updateUser( currentUser );
     }
 
@@ -244,7 +249,7 @@
         Forms forms = new Forms();
 
         Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
-        Set<DataSet> userDataSets = null;
+        Set<DataSet> userDataSets;
         Set<OrganisationUnit> userOrganisationUnits = new HashSet<OrganisationUnit>( currentUser.getOrganisationUnits() );
 
         if ( currentUser.getUserCredentials().getAllAuthorities().contains( "ALL" ) )

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/UserAccount.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/UserAccount.java	2012-10-30 11:56:01 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/UserAccount.java	2012-11-13 12:14:21 +0000
@@ -27,18 +27,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.hisp.dhis.common.Dxf2Namespace;
-
 import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
-@JacksonXmlRootElement( localName = "settings", namespace = Dxf2Namespace.NAMESPACE )
 public class UserAccount
 {
+    // user account
     private String firstName;
 
     private String surname;
@@ -47,12 +43,30 @@
 
     private String phoneNumber;
 
+    // profile
+    private String introduction;
+
+    private String jobTitle;
+
+    private String gender;
+
+    private String birthday;
+
+    private String nationality;
+
+    private String employer;
+
+    private String education;
+
+    private String interests;
+
+    private String languages;
+
     public UserAccount()
     {
     }
 
-    @JsonProperty(required = true)
-    @JacksonXmlProperty(namespace = Dxf2Namespace.NAMESPACE)
+    @JsonProperty( required = true )
     public String getFirstName()
     {
         return firstName;
@@ -63,8 +77,7 @@
         this.firstName = firstName;
     }
 
-    @JsonProperty(required = true)
-    @JacksonXmlProperty(namespace = Dxf2Namespace.NAMESPACE)
+    @JsonProperty( required = true )
     public String getSurname()
     {
         return surname;
@@ -76,7 +89,6 @@
     }
 
     @JsonProperty
-    @JacksonXmlProperty(namespace = Dxf2Namespace.NAMESPACE)
     public String getEmail()
     {
         return email;
@@ -88,7 +100,6 @@
     }
 
     @JsonProperty
-    @JacksonXmlProperty(namespace = Dxf2Namespace.NAMESPACE)
     public String getPhoneNumber()
     {
         return phoneNumber;
@@ -98,4 +109,103 @@
     {
         this.phoneNumber = phoneNumber;
     }
+
+    @JsonProperty
+    public String getIntroduction()
+    {
+        return introduction;
+    }
+
+    public void setIntroduction( String introduction )
+    {
+        this.introduction = introduction;
+    }
+
+    @JsonProperty
+    public String getJobTitle()
+    {
+        return jobTitle;
+    }
+
+    public void setJobTitle( String jobTitle )
+    {
+        this.jobTitle = jobTitle;
+    }
+
+    @JsonProperty
+    public String getGender()
+    {
+        return gender;
+    }
+
+    public void setGender( String gender )
+    {
+        this.gender = gender;
+    }
+
+    @JsonProperty
+    public String getBirthday()
+    {
+        return birthday;
+    }
+
+    public void setBirthday( String birthday )
+    {
+        this.birthday = birthday;
+    }
+
+    @JsonProperty
+    public String getNationality()
+    {
+        return nationality;
+    }
+
+    public void setNationality( String nationality )
+    {
+        this.nationality = nationality;
+    }
+
+    @JsonProperty
+    public String getEmployer()
+    {
+        return employer;
+    }
+
+    public void setEmployer( String employer )
+    {
+        this.employer = employer;
+    }
+
+    @JsonProperty
+    public String getEducation()
+    {
+        return education;
+    }
+
+    public void setEducation( String education )
+    {
+        this.education = education;
+    }
+
+    @JsonProperty
+    public String getInterests()
+    {
+        return interests;
+    }
+
+    public void setInterests( String interests )
+    {
+        this.interests = interests;
+    }
+
+    @JsonProperty
+    public String getLanguages()
+    {
+        return languages;
+    }
+
+    public void setLanguages( String languages )
+    {
+        this.languages = languages;
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/base.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/base.vm	2012-10-30 15:57:06 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/base.vm	2012-11-13 12:14:21 +0000
@@ -1,6 +1,6 @@
 <!DOCTYPE html>
-<html manifest="app-cache">
-<!-- <html> -->
+<!-- <html manifest="app-cache"> -->
+<html>
 
 <head>
 	<title>DHIS2</title>

=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/user-account.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/user-account.vm	2012-10-30 14:02:06 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/user-account.vm	2012-11-13 12:14:21 +0000
@@ -4,13 +4,31 @@
         $.mobile.loading( 'show' );
 
         $.ajax({
-            url: '../api/currentUser',
+            url: '../api/currentUser/user-account',
             dataType: 'json'
         }).success(function(data) {
+            // user account
             $('#firstNameInput').val(data.firstName);
             $('#surnameInput').val(data.surname);
             $('#emailInput').val(data.email);
             $('#phoneNumberInput').val(data.phoneNumber);
+
+            // profile
+            $('#introductionInput').val(data.introduction);
+            $('#jobTitleInput').val(data.jobTitle);
+
+            $('#genderInput').children().each(function ( idx, item ) {
+                item.selected = item.value == data.gender;
+            });
+
+            $('#genderInput').selectmenu('refresh')
+
+            // $('#birthdayInput').val(data.birthday);
+            $('#nationalityInput').val(data.nationality);
+            $('#employerInput').val(data.employer);
+            $('#educationInput').val(data.education);
+            $('#interestsInput').val(data.interests);
+            $('#languagesInput').val(data.languages);
         }).complete(function() {
             $.mobile.loading( 'hide' );
         });
@@ -26,7 +44,7 @@
             $.mobile.loading( 'show' );
 
             $.ajax({
-                url: '../api/currentUser/user-account.json',
+                url: '../api/currentUser/user-account',
                 contentType: 'application/json',
                 data: JSON.stringify( settings ),
                 type: 'POST'
@@ -48,21 +66,59 @@
 	</header>
 
     <section data-role="content">
-       <form id="settings-form" method="POST">
-           <label for="firstNameInput">First Name:</label>
-           <input id="firstNameInput" name="firstName" type="text" placeholder="Enter first name.." />
-
-           <label for="surnameInput">Surname:</label>
-           <input id="surnameInput" name="surname" type="text" placeholder="Enter surname.." />
-
-           <label for="emailInput">E-mail:</label>
-           <input id="emailInput" name="email" type="text" placeholder="Enter e-mail.." />
-
-           <label for="phoneNumberInput">Phone Number:</label>
-           <input id="phoneNumberInput" name="phoneNumber" type="text" placeholder="Enter phone number.." />
-
-           <input type="submit" value="Save" />
-       </form>
+        <form id="settings-form" method="POST">
+        <ul data-role="listview" data-inset="true">
+            <li data-role="list-divider">User Account</li>
+            <li>
+                   <label for="firstNameInput">First Name:</label>
+                   <input id="firstNameInput" name="firstName" type="text" placeholder="First name.." />
+
+                   <label for="surnameInput">Surname:</label>
+                   <input id="surnameInput" name="surname" type="text" placeholder="Surname.." />
+
+                   <label for="emailInput">E-mail:</label>
+                   <input id="emailInput" name="email" type="text" placeholder="E-mail.." />
+
+                   <label for="phoneNumberInput">Phone Number:</label>
+                   <input id="phoneNumberInput" name="phoneNumber" type="text" placeholder="Phone number.." />
+            </li>
+            <li data-role="list-divider">Profile</li>
+            <li>
+                <label for="introductionInput">Introduction</label>
+                <textarea id="introductionInput" name="introduction"></textarea>
+
+                <label for="jobTitleInput">Job Title:</label>
+                <input id="jobTitleInput" name="jobTitle" type="text" placeholder="Job Title.." />
+
+                <label for="genderInput">Gender:</label>
+                <select id="genderInput" name="gender">
+                    <option value="gender_male">Male</option>
+                    <option value="gender_female">Female</option>
+                    <option value="gender_other">Other</option>
+                </select>
+
+                <label for="birthdayInput">Birthday:</label>
+                <input id="birthdayInput" name="birthday" type="text" placeholder="yyyy-mm-dd (e.g. 1980-04-02)" />
+
+                <label for="nationalityInput">Nationality:</label>
+                <input id="nationalityInput" name="nationality" type="text" placeholder="Nationality.." />
+
+                <label for="employerInput">Employer:</label>
+                <input id="employerInput" name="employer" type="text" placeholder="Employer.." />
+
+                <label for="educationInput">Education:</label>
+                <textarea id="educationInput" name="education"></textarea>
+
+                <label for="interestsInput">Interests:</label>
+                <textarea id="interestsInput" name="interests"></textarea>
+
+                <label for="languagesInput">Languages:</label>
+                <textarea id="languagesInput" name="languages"></textarea>
+
+                <input type="submit" value="Save" />
+            </li>
+        </ul>
+        </form>
    	</section>
 
     <footer data-role="footer" data-theme="b">