Created
September 5, 2012 20:36
-
-
Save sbob-sfdc/3644332 to your computer and use it in GitHub Desktop.
Workshop 303, Tutorial 3, Step 4.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function refreshChatter(response) { | |
forcetkClient.chatterFeed($j("#detailpage").attr("data-id"), updateChatterList, onErrorSfdc); | |
} | |
function updateChatterList(response) { | |
// output debug information to the log | |
SFHybridApp.logToConsole("Got Chatter"); | |
SFHybridApp.logToConsole(response.items.length); | |
// clear div_chatter_list HTML | |
$j("#div_chatter_list").html(""); | |
// loop through all items and display UI | |
$j.each(response.items, function(i, chatter) { | |
// open a new div | |
var newItemDiv = $j("<div class='ui-body ui-body-b'>"); | |
// append the item author name | |
newItemDiv.append($j("<h5>" + chatter.actor.name + " said ...</h5>")); | |
// append the item text | |
newItemDiv.append($j("<p>" + chatter.body.text + "</p>")); | |
// display item comments | |
var newCommentDiv; | |
$j.each(chatter.comments.comments, function(i, comment) { | |
// reset newCommentDiv to open the div | |
newCommentDiv = $j("<div class='ui-body ui-body-c'>"); | |
// append the item author name | |
newCommentDiv.append($j("<h5>" + comment.user.name + " commented ...</h5>")); | |
// append the item text | |
newCommentDiv.append($j("<p>" + comment.body.text + "</p>")); | |
// append the closing inner div tag | |
newCommentDiv.append($j("</div>")); | |
// append newCommentDiv to newItemDiv | |
newItemDiv.append(newCommentDiv); | |
}); | |
// append a comment button to the item | |
newItemDiv.append($j("<a href='#' data-role='button' data-min='true' class='comment' data-theme='b' data-inline='true' data-icon='plus' data-id='" + chatter.id + "'>Your Comment</a>")); | |
// append the closing outer div tag | |
newItemDiv.append($j("</div>")); | |
// add the final item output to the div | |
$j("#div_chatter_list").append(newItemDiv); | |
}); | |
var newPostButtonDiv = $j("<a href='#' data-role='button' data-min='true' class='post' data-theme='b' data-icon='plus' data-inline='true' class='post'>New Post</a>") | |
$j("#div_chatter_list").append(newPostButtonDiv); | |
// set up listeners for chatterButton clicks | |
$j("a.comment").click(function() { | |
SFHybridApp.logToConsole("Commenting"); | |
var id = $j(this).attr('data-id'); | |
var post = prompt('Enter New Comment'); | |
if (post != null) { | |
forcetkClient.postChatterComment(id, post, refreshChatter, onErrorSfdc); | |
} | |
}); | |
// set up listeners for chatterButton clicks | |
$j("a.post").click(function() { | |
SFHybridApp.logToConsole("Posting"); | |
var id = $j("#detailpage").attr("data-id"); | |
SFHybridApp.logToConsole('detailpage id.'); | |
SFHybridApp.logToConsole(id); | |
var post = prompt('Enter New Post'); | |
if (post != null) { | |
forcetkClient.postChatterItem(id, post, refreshChatter, onErrorSfdc); | |
} | |
}); | |
// render the final chatter list | |
$j("#div_chatter_list").trigger("create"); | |
// log debug information | |
SFHybridApp.logToConsole('Item output div.'); | |
SFHybridApp.logToConsole($j("#div_chatter_list").html()); | |
// change the view to the detailpage, tracking the location change | |
$j.mobile.changePage('#chatterpage', { | |
changeHash: true | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment