VRFS-287 add support for deleting notifications from sidebar

This commit is contained in:
Brian Smith 2013-04-06 21:41:43 -04:00
parent c593551efd
commit 09c36788c2
2 changed files with 39 additions and 19 deletions

View File

@ -116,11 +116,31 @@
});
$('#sidebar-notification-list').append(notificationHtml);
$('li[notification-id=' + val.id + ']').find('#img-delete-notification').click(deleteNotification);
});
}
function deleteNotification(evt) {
decrementNotificationCount();
evt.stopPropagation();
var notificationId = $(this).attr('notification-id');
alert(notificationId);
var url = "/api/users/" + context.JK.currentUserId + "/notifications/" + notificationId;
$.ajax({
type: "DELETE",
dataType: "json",
contentType: 'application/json',
url: url,
processData: false,
success: function(response) {
delete notifications[notificationId];
$('li[notification-id=' + notificationId + ']').hide();
decrementNotificationCount();
},
error: app.ajaxError
});
}
function initializeChatPanel() {
@ -243,9 +263,7 @@
$('#sidebar-notification-count').html(count - 1);
}
// TODO
// (1) optimize so we're not hitting server on each keyup once > 2 characters are entered
// (2) hide any expanded panels once search starts
// TODO: optimize so we're not hitting server on each keyup once > 2 characters are entered
function events() {
$('#search-input').keyup(function(evt) {
// ENTER KEY
@ -304,9 +322,6 @@
"created_at": payload.created_at
};
logger.debug("Added notification " + notifications[payload.notification_id].id + " to array");
logger.debug("Notification size = " + notifications.length);
incrementNotificationCount();
var template = $("#template-notification-panel").html();

View File

@ -104,6 +104,19 @@
</div>
</div>
<!-- Search result template -->
<script type="text/template" id="template-sidebar-search-result">
<div user-id="{userId}" class="sidebar-search-result">
<a href="#" class="avatar-small"><img src="{avatar_url}" /></a>
<div class="result-name">{userName}<br />
<span class="result-location">{location}</span>
</div><br />
<a id="btn-connect-friend" class="button-orange smallbutton right">CONNECT</a>
<br clear="all" />
</div>
</script>
<!-- Friend panel template -->
<script type="text/template" id="template-friend-panel">
<li class="{cssClass}">
<div class="avatar-small"><img src="{avatar_url}" /></div>
@ -118,17 +131,7 @@
</li>
</script>
<script type="text/template" id="template-sidebar-search-result">
<div user-id="{userId}" class="sidebar-search-result">
<a href="#" class="avatar-small"><img src="{avatar_url}" /></a>
<div class="result-name">{userName}<br />
<span class="result-location">{location}</span>
</div><br />
<a id="btn-connect-friend" class="button-orange smallbutton right">CONNECT</a>
<br clear="all" />
</div>
</script>
<!-- Friend request confirmation template -->
<script type="text/template" id="template-sidebar-invitation-sent">
<div user-id="{userId}" class="sidebar-search-connected">
<div style="margin-top:10px;">
@ -141,6 +144,7 @@
</div>
</script>
<!-- Notification panel template -->
<script type="text/template" id="template-notification-panel">
<li notification-id="{notificationId}">
<div class="avatar-small"><img src="{avatar_url}" /></div>
@ -149,7 +153,7 @@
<em>({date})</em>
<div class="note-delete">
<a href="#">
<%= image_tag "shared/icon_delete_sm.png", :width=>13, :height=>13 %>
<img id="img-delete-notification" notification-id="{notificationId}" src="/assets/shared/icon_delete_sm.png" width="13" height="13" />
</a>
</div>
</div>
@ -157,6 +161,7 @@
</li>
</script>
<!-- Chat panel template -->
<script type="text/template" id="template-chat-panel">
<li>
<div class="avatar-small"><img src="{avatar_url}" /></div>