From 00a447037acefee3aea108f671a7e56f132dc2f0 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sat, 8 Mar 2014 01:37:25 -0500 Subject: [PATCH] VRFS-1287 VRFS-1340 fix issues with weird behavior of Okay and Cancel buttons in notifications --- web/app/assets/javascripts/layout.js | 49 ++++++++++++++++--------- web/app/assets/javascripts/sidebar.js | 4 +- web/app/views/clients/_sidebar.html.erb | 2 +- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/web/app/assets/javascripts/layout.js b/web/app/assets/javascripts/layout.js index 17ddd4d2e..6d05f6437 100644 --- a/web/app/assets/javascripts/layout.js +++ b/web/app/assets/javascripts/layout.js @@ -711,7 +711,7 @@ if (notifyQueue.length === 0) { firstNotification = true; - setNotificationInfo(message, descriptor); + setNotificationInfo(message, descriptor, $notify); } notifyQueue.push({message: message, descriptor: descriptor}); @@ -733,11 +733,13 @@ if (notifyDetails !== undefined) { setNotificationInfo(notifyDetails.message, notifyDetails.descriptor); } + + notifyDetails = {}; } }); }; - function setNotificationInfo(message, descriptor) { + function setNotificationInfo(message, descriptor, notificationSelector) { var $notify = $('[layout="notify"]'); $('h2', $notify).text(message.title); $('p', $notify).empty(); @@ -763,19 +765,20 @@ $('div.detail', $notify).hide(); } + $('#ok-button', $notify).unbind('click'); + $('#cancel-button', $notify).unbind('click'); + if (descriptor) { if (descriptor.ok_text) { $('#ok-button', $notify).html(descriptor.ok_text); } else { $('#ok-button', $notify).html("OKAY"); - } - - if (descriptor.ok_callback !== undefined) { - $('#ok-button', $notify).unbind('click'); - $('#ok-button', $notify).click(function () { + } + + $('#ok-button', $notify).click(function () { + if (descriptor.ok_callback !== undefined) { if (descriptor.ok_callback_args) { - logger.debug("descriptor.ok_callback_args=" + descriptor.ok_callback_args); descriptor.ok_callback(descriptor.ok_callback_args); return false; } @@ -783,8 +786,11 @@ descriptor.ok_callback(); return false; } - }); - } + } + else { + notificationSelector.hide(); + } + }); if (descriptor.cancel_text) { $('#cancel-button', $notify).html(descriptor.cancel_text); @@ -797,12 +803,10 @@ $('#cancel-button', $notify).html("CANCEL"); } } - - if (descriptor.cancel_callback !== undefined) { - $('#cancel-button', $notify).unbind('click'); - $('#cancel-button', $notify).click(function () { + + $('#cancel-button', $notify).click(function () { + if (descriptor.cancel_callback !== undefined) { if (descriptor.cancel_callback_args) { - logger.debug("descriptor.cancel_callback_args=" + descriptor.cancel_callback_args); descriptor.cancel_callback(descriptor.cancel_callback_args); return false; } @@ -810,12 +814,23 @@ descriptor.cancel_callback(); return false; } - }); - } + } + else { + notificationSelector.hide(); + } + }); } + // by default OKAY and CANCEL should just hide the notification else { $('#ok-button', $notify).html("OKAY"); + $('#ok-button', $notify).click(function () { + notificationSelector.hide(); + }); + $('#cancel-button', $notify).html("CANCEL"); + $('#cancel-button', $notify).click(function () { + notificationSelector.hide(); + }); } } diff --git a/web/app/assets/javascripts/sidebar.js b/web/app/assets/javascripts/sidebar.js index 1c2acdc16..dcf046bc8 100644 --- a/web/app/assets/javascripts/sidebar.js +++ b/web/app/assets/javascripts/sidebar.js @@ -515,8 +515,8 @@ function acceptFriendRequest(args) { rest.acceptFriendRequest({ - status : 'accept', - friend_request_id : args.friend_request_id + status: 'accept', + friend_request_id: args.friend_request_id }).done(function(response) { deleteNotification(args.notification_id); // delete notification corresponding to this friend request initializeFriendsPanel(); // refresh friends panel when request is accepted diff --git a/web/app/views/clients/_sidebar.html.erb b/web/app/views/clients/_sidebar.html.erb index 7354ddf60..5305c7cbe 100644 --- a/web/app/views/clients/_sidebar.html.erb +++ b/web/app/views/clients/_sidebar.html.erb @@ -201,7 +201,7 @@
  • - {text}   + {text}
    {date}