From a86a0e91a5acb5ea894a3d066f9adf3b1ef305ae Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 1 May 2009 08:00:37 -0700 Subject: [PATCH] add favor, reply, delete buttons for cometed notices --- plugins/Comet/CometPlugin.php | 16 ++++++- plugins/Comet/updatetimeline.js | 74 +++++++++++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/plugins/Comet/CometPlugin.php b/plugins/Comet/CometPlugin.php index 2e0bb40a46..48ac9dcad6 100644 --- a/plugins/Comet/CometPlugin.php +++ b/plugins/Comet/CometPlugin.php @@ -82,8 +82,22 @@ class CometPlugin extends Plugin ' '); } + $user = common_current_user(); + + if (!empty($user->id)) { + $user_id = $user->id; + } else { + $user_id = 0; + } + + $replyurl = common_local_url('newnotice'); + $favorurl = common_local_url('favor'); + // FIXME: need to find a better way to pass this pattern in + $deleteurl = common_local_url('deletenotice', + array('notice' => '0000000000')); + $action->elementStart('script', array('type' => 'text/javascript')); - $action->raw("$(document).ready(function() { updater.init(\"$this->server\", \"$timeline\");});"); + $action->raw("$(document).ready(function() { updater.init(\"$this->server\", \"$timeline\", $user_id, \"$replyurl\", \"$favorurl\", \"$deleteurl\"); });"); $action->elementEnd('script'); return true; diff --git a/plugins/Comet/updatetimeline.js b/plugins/Comet/updatetimeline.js index de750baba3..e89b3bddf7 100644 --- a/plugins/Comet/updatetimeline.js +++ b/plugins/Comet/updatetimeline.js @@ -3,14 +3,26 @@ var updater = function() { + var _server; + var _timeline; + var _userid; + var _replyurl; + var _favorurl; + var _deleteurl; var _cometd; return { - init: function(server, timeline) + init: function(server, timeline, userid, replyurl, favorurl, deleteurl) { _cometd = $.cometd; // Uses the default Comet object _cometd.setLogLevel('debug'); _cometd.init(server); + _server = server; + _timeline = timeline; + _userid = userid; + _favorurl = favorurl; + _replyurl = replyurl; + _deleteurl = deleteurl; _cometd.subscribe(timeline, receive); $(window).unload(leave); } @@ -34,7 +46,7 @@ var updater = function() var noticeItem = makeNoticeItem(message.data); $("#notices_primary .notices").prepend(noticeItem, true); $("#notices_primary .notice:first").css({display:"none"}); - $("#notices_primary .notice:first").fadeIn(2500); + $("#notices_primary .notice:first").fadeIn(1000); NoticeHover(); NoticeReply(); } @@ -68,10 +80,64 @@ var updater = function() "
"+data['source']+"
"+ ""+ ""+ - "
"+ - "
"+ + "
"; + + if (_userid != 0) { + var input = $("form#form_notice fieldset input#token"); + var session_key = input.val(); + ni = ni+makeFavoriteForm(data['id'], session_key); + ni = ni+makeReplyLink(data['id'], data['user']['screen_name']); + if (_userid == data['user']['id']) { + ni = ni+makeDeleteLink(data['id']); + } + } + + ni = ni+"
"+ ""; return ni; } + + function makeFavoriteForm(id, session_key) + { + var ff; + + ff = "
"+ + "
"+ + "Favor this notice"+ // XXX: i18n + ""+ + ""+ + ""+ + "
"+ + "
"; + return ff; + } + + function makeReplyLink(id, nickname) + { + var rl; + rl = "
"+ + "
Reply to this notice
"+ + "
"+ + "Reply "+id+""+ + ""+ + "
"+ + "
"; + return rl; + } + + function makeDeleteLink(id) + { + var dl, delurl; + delurl = _deleteurl.replace("0000000000", id); + + dl = "
"+ + "
Delete this notice
"+ + "
"+ + "Delete"+ + "
"+ + "
"; + + return dl; + } }(); -- 2.39.5