cancel
Showing results for 
Search instead for 
Did you mean: 

Extending people-finder.js

chrisokelly
Champ on-the-rise
Champ on-the-rise
Hi Guys,

I am trying to extend people-finder.js to include the telephone number in results. I have made a very basic change to the file as below (changes in bold) (EDIT: turns out I can't bold inside of code tag. Its the userPhoneNumber line at the bottom of the list of variables being var'ed, and the if (userPhoneNumber.length… section at the very bottom.)


         var renderCellDescription = function PeopleFinder_renderCellDescription(elCell, oRecord, oColumn, oData)
         {
            var userName = oRecord.getData("userName"),
               name = userName,
               firstName = oRecord.getData("firstName"),
               lastName = oRecord.getData("lastName"),
               userStatus = oRecord.getData("userStatus"),
               userStatusTime = oRecord.getData("userStatusTime"),
      userPhoneNumber = oRecord.getData("telephone");
            if ((firstName !== undefined) || (lastName !== undefined))
            {
               name = firstName ? firstName + " " : "";
               name += lastName ? lastName : "";
            }
           
            var title = oRecord.getData("jobtitle") || "",
               organization = oRecord.getData("organization") || "";
           
            var desc = '<h3 class="itemname">' + $userProfile(userName, name, 'class="theme-color-1" tabindex="0"') + ' <span class="lighter">(' + $html(userName) + ')</span></h3>';
            if (title.length !== 0)
            {
               if (me.options.viewMode == Alfresco.PeopleFinder.VIEW_MODE_COMPACT)
               {
                  desc += '<div class="detail">' + $html(title) + '</div>';
               }
               else
               {
                  desc += '<div class="detail"><span>' + me.msg("label.title") + ":</span> " + $html(title) + '</div>';
               }
            }
            if (organization.length !== 0)
            {
               if (me.options.viewMode == Alfresco.PeopleFinder.VIEW_MODE_COMPACT)
               {
                  desc += '<div class="detail"> (' + $html(organization) + ')</div>';
               }
               else
               {
                  desc += '<div class="detail"><span>' + me.msg("label.company") + ":</span> " + $html(organization) + '</div>';
               }
            }
            if (userStatus !== null && me.options.viewMode !== Alfresco.PeopleFinder.VIEW_MODE_COMPACT)
            {
               desc += '<div class="user-status">' + $html(userStatus) + ' <span>(' + Alfresco.util.relativeTime(Alfresco.util.fromISO8601(userStatusTime.iso8601)) + ')</span></div>';
            }
       if (userPhoneNumber.length !== 0)
            {
               desc += '<div class="detail"><span>Telephone:</span> ' + $html(userPhoneNumber) + '</div>';
            }
            elCell.innerHTML = desc;
         };

So, what seemed like a very simple change. However, having deployed it I now cannot use people-finder.

What happens is that I can search, it appears to attempt the search but returns no results. I found that if I enter less than 1 character I get the expected "minimum of 1 character(s)" message, and if I type a nonsense string to search for it tells me it received no results. If I make a search that should return results nothing changes.
There is no response in catalina.out or alfresco.log when this happens, which led me to thinking it is an issue with the client side js. Firebug tells me "userPhoneNumber is null".

So obviously there is nothing in the oRecord object called telephone. I can see in Firebug that the JSON response includes a telephone field for each user returned. I looked through people-finder.js for where the oRecord param is passed into PeopleFinder_renderCellDescription however I can't find it called with parameters anywhere.

I am guessing the main issue here is my lack of knowledge of YUI, does anyone know what I should be doing to get the telephone field from the JSON response to the oRecord param?
2 REPLIES 2

fmontinaro
Champ in-the-making
Champ in-the-making
Hi,

you can correct the following line:
if (userPhoneNumber.length !== 0){…}
in
if (userPhoneNumber){…}

if userPhoneNumber is null the control produces an error (you can see it in firebug console).

hope this will help you…

chrisokelly
Champ on-the-rise
Champ on-the-rise
Oh Wow, that was simple. I can't believe I overcomplicated things so much for myself here. Thanks very much, it works great now.