<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs
    title="Thought Bowl"
    description="Warning: This is still Work In Progress and incomplete.
                 It's the 'thought bowl'. Put your thoughts in it and share with friends.
                 Want to watch a movie, may one your friend also wants to or may he/she has already watched and can give your feedback. 
                 Similarly for books, places, devices, schools, restaurants....
                 Relate yourself to any URI using any word. Find out what your friend likes, wants, hates...and how it all changed in a time line...
                 generate a biography...Enter your friend's mind while controlling who can see what parts of your brain."    
    title_url="http://geocities.com/srinidhi_vishwa"
    scrolling="true"
    author="Srinidhi Viswanatha"
    author_email="srinvis+pensieve@gmail.com">
    <Require feature="opensocial-0.5"/>
</ModulePrefs>
<Content type="html">
    <![CDATA[
    <script type="text/javascript">

    function checkDataError(dataResponse, id)
    {
        if(dataResponse.get(id).hadError())
        {
            throw dataResponse.get(id).getError();
        }
    }
    
    function getData()
    {
        document.getElementById('pensieve_main').innerHTML = 'Requesting data from server...please wait';
        var req = opensocial.newDataRequest();
        req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');
        req.add(req.newFetchPersonRequest('OWNER'), 'owner');
        var projection = {"MAX": 2, 
                          "PROFILE_DETAILS": "FULL"};
        req.add(req.newFetchPeopleRequest ('OWNER_FRIENDS', projection), 'ownerFriends'); 
        req.add(req.newFetchPeopleRequest ('VIEWER_FRIENDS'), 'viewerFriends'); 
        req.send(onResponse);
    }
        
    function onResponse(dataResponse)
    {
        var html = "";

        try
        {
            //**********************************1. Get Viewer
            checkDataError(dataResponse, 'viewer'); var viewer = dataResponse.get('viewer').getData();
            html += 'Hello <b>' + viewer.getDisplayName() + '</b>.' 

            //**********************************2. Get Owner
            checkDataError(dataResponse, 'owner'); var owner = dataResponse.get('owner').getData();
            if(owner. isViewer())
            {
            html += "<br><br>Pensieve uses google notebook underneath, please goto <a href='http://www.google.com/notebook'>Google Notebook</a>"
                  + "<br>You can share Google Notebook with your friends, see <a href='http://www.google.com/googlenotebook/faq.html'>Help</a>."
                  + "<br><br>Use Google notebook like a collaborative diary that your selected friends can view and search."
                  + "<br><br>It's the 'thought bowl'. Put your thoughts in it and share with friends. Want to watch a movie, may one your friend "
                  + "also wants to or may he/she has already watched and can give your feedback. Similarly for books, places, devices, schools," 
                  + " restaurants....Relate yourself to any URI using any word. Find out what your friend likes, wants, hates...and how it all "
                  + "changed in a time line...generate a biography...Enter your friend's mind while controlling who can see what parts of your brain.";
            } 
            else
            {
                html += "Sorry, Currently you will need to get <b>"+ owner.getDisplayName() +"</b>'s google notebook address by email/IM to visit it.";
            }

            //**********************************3. Get Owner's Friends who have Pensieve
            checkDataError(dataResponse, 'ownerFriends'); var ownerFriends = dataResponse.get('ownerFriends').getData();
            html += "<br><br>Visit the thought profile of..."
            ownerFriends.each(function(friend)
            {
            html += '<li>' + friend.getDisplayName(); //+ friend.getField(opensocial.Person.Field.THUMBNAIL_URL) + friend.getField(opensocial.Person.Field.PROFILE_URL');
            });
            html += '</ul>'; 

            //**********************************4. Get Owner's Friends who don't have 'Pensieve'
            checkDataError(dataResponse, 'viewerFriends'); var viewerFriends = dataResponse.get('viewerFriends').getData();
            html += "<br><br>Invite a friend to install Pensieve application..."
            viewerFriends.each(function(friend)
            {
                html += '<li>' + friend.getDisplayName();
            });
            html += '</ul>'; 
        }
        catch(error)
        {
            html += "<br> Error fetching data...Bad Bad orkut server...no dought for you...<br>";
            html += error;
        }
        document.getElementById('pensieve_main').innerHTML = html;
    }
            
    _IG_RegisterOnloadHandler(getData);
    </script>
    <div id='pensieve_main'></div>
    ]]>
</Content>
</Module>

