From 5cbe139ac9e673c2a0e53cc327cfcf3fc5b9ba46 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 13 Jan 2016 12:55:15 +0530 Subject: [PATCH] show number of pending requests --- static/js/peersButton.js | 41 +++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/static/js/peersButton.js b/static/js/peersButton.js index 0a22af5..8185c6c 100644 --- a/static/js/peersButton.js +++ b/static/js/peersButton.js @@ -9,10 +9,10 @@ oml.ui.peersButton = function() { marginRight: '6px' }) .bindEvent({ - click: function() { - // ... - } - }); + click: open + }), + count, + requests = 0; Ox.Button({ style: 'symbol', @@ -23,18 +23,45 @@ oml.ui.peersButton = function() { float: 'left', borderRadius: 0 }) + .bindEvent({ + click: open + }) .appendTo(that); - Ox.Element() + count = Ox.Element() .addClass('OxLight') .css({ float: 'left', - marginTop: '2px', + marginTop: '3px', fontSize: '9px' }) .html('0') .appendTo(that); + oml.bindEvent({ + 'peering.request': update, + 'peering.accept': update, + 'peering.reject': update + }); + update(); + + function open() { + oml.UI.set({page: 'users'}); + } + function update() { + oml.api.getUsers(function(result) { + requests = result.data.users.filter(function(user) { + return user.pending=="received"; + }).length; + count.html(requests); + that.options({ + tooltip: Ox._(requests + ? Ox.formatCount(requests, 'peering request') + : 'No peering requests') + }); + }); + } + return that; -}; \ No newline at end of file +};