- (function() {
- $(document).ready(function() {
- var page_id, post_result;
- page_id = $('#posts-container').data('page-id');
- $('.facebook-message').live('mouseover', function() {
- return $(this).find('.message-tool-box-extras').show();
- });
- $('.facebook-message').live('mouseout', function() {
- return $(this).find('.message-tool-box-extras').hide();
- });
- $('#search-container').find(':submit').click(function() {
- var params;
- $("#posts-results").empty();
- params = {
- q: $('#search_q').val(),
- page_id: page_id
- };
- return $.read('/posts/search', params, post_result);
- });
- post_result = function(response) {
- var qtip_params, qtip_show, tmpl;
- $('.feed-more img').hide();
- _.each(response, function(wall_post) {
- var event_regex, post;
- post = wall_post.post;
- if (post.message !== null) {
- post.message = post.message.replace(/\n/, '</br>');
- }
- if ((post.properties.actions != null) && post.properties.actions.length > 0) {
- _.each(post.properties.actions, function(item) {
- return post.properties["" + (item.name.toLowerCase()) + "_link"] = encodeURIComponent(item.link);
- });
- }
- event_regex = /event.php/;
- if ((post.properties.link != null) && post.properties.link.match(event_regex)) {
- return post.properties['is_event'] = true;
- }
- });
- tmpl = $("#post_template").tmpl(response).appendTo("#posts-results");
- $(tmpl).find(".post-time").localTimeFromUTC('MM/dd/yyyy hh:mm a');
- $(tmpl).find(".post-time").each(function() {
- var time;
- time = $(this).html();
- return $(this).html($.timeago(time));
- });
- qtip_show = function(event, api) {
- var fb_user_id, request_params;
- fb_user_id = $(event.originalEvent.currentTarget).data('fb-user-id');
- request_params = {
- page_id: page_id,
- user_id: fb_user_id
- };
- return $.read('/fb_users/{user_id}/user-details', request_params, function(response) {
- var user_actions_view;
- user_actions_view = $("#user_actions_template").tmpl(response);
- api.set('content.text', user_actions_view);
- user_actions_view = $(api.elements.content);
- user_actions_view.find('.submit-keyword').click(function(e) {
- var keyword;
- keyword = {
- label: 'todo',
- monitorable_id: page_id,
- monitorable_type: 'Page',
- data: fb_user_id,
- entity_type: 'person',
- action: [user_actions_view.find("select").val()]
- };
- return $.create('/keywords', {
- keyword: keyword
- }, function(response) {
- return alert('tag added');
- });
- });
- return user_actions_view.find('.tag-user').click(function(event) {
- return user_actions_view.find(":hidden").show();
- });
- });
- };
- qtip_params = {
- content: 'Loading...',
- hide: {
- fixed: true,
- delay: 500,
- event: 'mouseleave'
- },
- events: {
- show: qtip_show
- }
- };
- return $('.user-avatar').qtip(qtip_params);
- };
- $.read('/pages/{page_id}/posts', {
- page_id: page_id
- }, post_result);
- $('.commentCount').live('click', function(event) {
- var is_post_deleted, post_id;
- if ($(this).parent().parent().find('.comments-container').length) {
- $(this).parent().parent().find('.comments-container').remove();
- return false;
- }
- post_id = $(this).data("post-id");
- is_post_deleted = $(this).data("post-deleted");
- $.read('/posts/{post_id}/comments', {
- post_id: post_id
- }, function(response) {
- var template_params;
- template_params = {
- comments: response,
- post_id: post_id,
- is_post_deleted: is_post_deleted
- };
- $("#comment_list_template").tmpl(template_params).appendTo("#post-" + post_id);
- $(".flag-post-comment").live("click", function(event) {
- var comment_id, mood, request_params;
- comment_id = $(this).data("post-comment-id");
- mood = $(this).data("mood");
- request_params = {
- post_id: post_id,
- comment_id: comment_id,
- comment: {
- mood: mood
- }
- };
- return $.update("/posts/{post_id}/comments/{comment_id}", request_params, function(response) {
- return $("#comment-" + comment_id + "-flag").children().replaceWith($("#toggle_flag_template").tmpl({
- data: response.comment,
- type: 'post-comment'
- }));
- });
- });
- $(".submit-comment").click(function(event) {
- var request_params;
- request_params = {
- post_id: $(this).data("post-id"),
- post_as: $(this).parent().parent().find(":checked").val(),
- comment: {
- post_id: post_id,
- message: $(this).parent().parent().find("textarea").val()
- }
- };
- return $.create('/posts/{post_id}/comments', request_params, function(response) {
- var comment_link, comments_count;
- $("#comment_template").tmpl({
- comment: response.comment,
- is_post_deleted: false,
- post_id: post_id
- }).appendTo("#post-" + post_id + "-comments-list");
- $("#comment-entry-" + post_id).val("");
- comment_link = $("#post-" + post_id).find(".commentCount");
- comments_count = parseInt(comment_link.data('comment-count')) + 1;
- comment_link.attr("data-comment-count", comments_count);
- return $("#post-" + post_id).find(".commentCount").html(comments_count + " Comments");
- });
- });
- return $(".delete-post-comment").live("click", function() {
- var comment_id;
- if (confirm('Are you sure?')) {
- comment_id = $(this).data("comment-id");
- $.destroy("/comments/{comment_id}", {
- comment_id: comment_id
- }, function(response) {
- return $("#comment-" + comment_id).replaceWith($("#comment_template").tmpl(response));
- });
- }
- return false;
- });
- });
- return false;
- });
- $(".delete-post").live('click', function() {
- var post_id;
- if (confirm('Are you sure?')) {
- post_id = $(this).data('postid');
- $.destroy('/posts/{post_id}', {
- post_id: post_id
- }, function(response) {
- $("#post-" + post_id).replaceWith($("#post_template").tmpl(response));
- return $("#post-" + post_id).find(".post-time").localTimeFromUTC('MM/dd/yyyy hh:mm a');
- });
- }
- return false;
- });
- $("#keywords-link").click(function() {
- return $.read("/pages/{page_id}/keywords", {
- page_id: page_id
- }, function(response) {
- var dialog, target;
- dialog = $("#keywords_dialog_template").tmpl({
- keywords: response,
- page: {
- id: page_id
- }
- }).appendTo("body");
- dialog.dialog({
- modal: true
- });
- target = $('.keyword-link-container').find('a');
- dialog.dialog("option", {
- position: {
- my: 'left top',
- at: 'right top',
- of: target
- },
- resizable: false
- });
- return $("#page-" + page_id + "-keywords").find("form").bind("ajax:success", function(xhr, data, status) {
- $("#keyword_errors").html("");
- $("#keyword_errors").hide();
- $("#keywords_template").tmpl($.parseJSON(data)).appendTo(dialog.find(".keyword-list"));
- dialog.find(".keywords-entry").find(":text").val("");
- return dialog.dialog("close");
- }, $(".ui-widget-overlay").live("click", function() {
- return dialog.dialog("close");
- }));
- });
- });
- $(".flag-post").live('click', function() {
- var mood, post_id;
- post_id = $(this).data('post-id');
- mood = $(this).data("mood");
- return $.update('/posts/{post_id}', {
- post_id: post_id,
- post: {
- mood: mood
- }
- }, function(response) {
- console.log(response);
- return $("#flag_" + post_id).replaceWith($("#toggle_flag_template").tmpl({
- data: response.post,
- type: 'post'
- }));
- });
- });
- return $('.feed-more a').click(function() {
- var page;
- $('.feed-more img').show();
- page = $(this).data('current-page') + 1;
- $(this).data('current-page', page);
- $.read('/pages/{page_id}/posts', {
- page_id: page_id,
- page: page
- }, post_result);
- return false;
- });
- });
- }).call(this);