var photostatus = photostatus || {};
/**
* @param data
*/
photostatus.receivePhotoStatusData = function(data) {
var viewer = data.get('viewer').getData();
var owner = data.get('owner').getData();
var ownerData = data.get('owner_data').getData()[owner.getId()];
//var ownerName = owner.getDisplayName();
var ownerImage = ownerData['image'];
var ownerStatus = ownerData['text'];
//var html = ['', ownerName, ' is ', ownerStatus];
var html = ['
', ownerStatus];
if (viewer.getId() === owner.getId()) {
html = photostatus.addSetStatusInputs(html, ownerImage, ownerStatus);
}
document.getElementById('profile').innerHTML = html.join('');
};
/**
* Asks for the photo status image and text for the profile owner. Also
* requests viewer data to see if the owner and viewer are the same.
*/
photostatus.requestPhotoStatusData = function() {
var fields = ['image', 'text'];
var req = opensocial.newDataRequest();
// Not needed to fetch data, but to get the viewer's ID number
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');
// Not needed to fetch data, but to get the owner's ID number
req.add(req.newFetchPersonRequest('OWNER'), 'owner');
// Get the photo status data for the owner.
req.add(req.newFetchPersonAppDataRequest('OWNER', fields), 'owner_data');
req.send(photostatus.receivePhotoStatusData);
};
/**
* If the viewer of the page is the owner, this function is called to add the
* HTML elements which allow the user to change the photo and status text.
* @param htmlParts {Array} The HTML elements which will be added to the page.
* @param imageUrl {String} The URL of the image the user is currently using
* for their status.
* @param status {String} Current status text for the user.
* @return The htmlParts array with new elements appended.
*/
photostatus.addSetStatusInputs = function(htmlParts, imageUrl, status) {
htmlParts.push('
Status: ');
htmlParts.push('Image URL: ');
htmlParts.push('
');
htmlParts.push('