Author: doll
Date: Mon Feb 11 18:16:02 2008
New Revision: 620688

URL: http://svn.apache.org/viewvc?rev=620688&view=rev
Log:
The samplecontainer now parses and dumps the name field properly. It currently 
only supports the unstructured name field and should be extended at a later 
point. 

Also made some small changes to the displayName handling in person.js. If the 
name object does not exist, it tries the nickname field. Also, put the name 
fields in an array because they were being screwed up by caja. 
 


Modified:
    incubator/shindig/trunk/features/opensocial-reference/person.js
    
incubator/shindig/trunk/features/opensocial-samplecontainer/statefileparser.js

Modified: incubator/shindig/trunk/features/opensocial-reference/person.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-reference/person.js?rev=620688&r1=620687&r2=620688&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-reference/person.js (original)
+++ incubator/shindig/trunk/features/opensocial-reference/person.js Mon Feb 11 
18:16:02 2008
@@ -480,6 +480,13 @@
 };
 
 
+var ORDERED_NAME_FIELDS_ = [
+    opensocial.Name.Field.HONORIFIC_PREFIX,
+    opensocial.Name.Field.GIVEN_NAME,
+    opensocial.Name.Field.FAMILY_NAME,
+    opensocial.Name.Field.HONORIFIC_SUFFIX,
+    opensocial.Name.Field.ADDITIONAL_NAME];
+
 /**
  * Gets a text display name for this person; guaranteed to return
  * a useful string.
@@ -487,27 +494,27 @@
  * @return {String} The display name
  */
 opensocial.Person.prototype.getDisplayName = function() {
-  var name = '';
-  var s = '';
-
   var name = this.getField(opensocial.Person.Field.NAME);
-  // Try unstructed field first
-  s = name.getField(opensocial.Name.Field.UNSTRUCTURED);
+  if (name) {
+    // Try unstructured field first
+    var unstructured = name.getField(opensocial.Name.Field.UNSTRUCTURED);
+    if (unstructured) {
+      return unstructured;
+    }
 
-  if (s) return(s);
-
-  // Next try to construct the name from the individual components
-  s = '';
-  for (var field in [name.getField(opensocial.Name.Field.HONORIFIC_PREFIX),
-                     name.getField(opensocial.Name.Field.GIVEN_NAME),
-                     name.getField(opensocial.Name.Field.FAMILY_NAME),
-                     name.getField(opensocial.Name.Field.HONORIFIC_SUFFIX),
-                     name.getField(opensocial.Name.Field.ADDITIONAL_NAME)]) {
-      if (name.getField(field)) {
-          s += name.getField(field) + ' ';
+    // Next try to construct the name from the individual components
+    var fullName = '';
+    for (var i = 0; i < ORDERED_NAME_FIELDS_.length; i++) {
+      var nameValue = name.getField(ORDERED_NAME_FIELDS_[i]);
+      if (nameValue) {
+        fullName += nameValue + ' ';
       }
+    }
+    return fullName.replace(/^\s+|\s+$/g, '') ;
   }
-  return s.replace(/^\s+|\s+$/g, '') ;
+
+  // Finally, try the nickname field
+  return this.getField(opensocial.Person.Field.NICKNAME);
 };
 
 

Modified: 
incubator/shindig/trunk/features/opensocial-samplecontainer/statefileparser.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-samplecontainer/statefileparser.js?rev=620688&r1=620687&r2=620688&view=diff
==============================================================================
--- 
incubator/shindig/trunk/features/opensocial-samplecontainer/statefileparser.js 
(original)
+++ 
incubator/shindig/trunk/features/opensocial-samplecontainer/statefileparser.js 
Mon Feb 11 18:16:02 2008
@@ -193,7 +193,8 @@
 StateFileParser.loadPerson = function(container, xmlNode, isOwner, isViewer) {
   var fields = {
     'id' : $(xmlNode).attr(opensocial.Person.Field.ID),
-    'name' : $(xmlNode).attr(opensocial.Person.Field.NAME),
+    'name' : new opensocial.Name(
+        {'unstructured' : $(xmlNode).attr(opensocial.Person.Field.NAME)}),
     'thumbnailUrl' : $(xmlNode).attr(opensocial.Person.Field.THUMBNAIL_URL),
     'profileUrl' : $(xmlNode).attr(opensocial.Person.Field.PROFILE_URL)};
   return container.newPerson(fields, isOwner, isViewer);
@@ -328,11 +329,19 @@
   xmlText += StateFileParser.dumpPersonField(personObj,
       opensocial.Person.Field.ID);
   xmlText += StateFileParser.dumpPersonField(personObj,
-      opensocial.Person.Field.NAME);
-  xmlText += StateFileParser.dumpPersonField(personObj,
       opensocial.Person.Field.THUMBNAIL_URL);
   xmlText += StateFileParser.dumpPersonField(personObj,
       opensocial.Person.Field.PROFILE_URL);
+
+  // TODO: Change the sample container to understand all of the name fields
+  var name = personObj.getField(opensocial.Person.Field.NAME);
+  if (name) {
+    var unstructured = name.getField(opensocial.Name.Field.UNSTRUCTURED);
+    if (unstructured) {
+      xmlText += ' name="' + unstructured + '"';
+    }
+  }
+
   xmlText += '></person>\n';
   return xmlText;
 };


Reply via email to