From 5819b435951b83cfe5bdb5a8632f050542a72978 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 15 Jul 2013 13:49:21 -0400 Subject: [PATCH] moved index code from index.tpl to its own file --- public/src/app.js | 44 +++++++++++++++----------------- public/src/forum/admin/index.js | 25 ++++++++++++++++++ public/templates/admin/index.tpl | 28 +------------------- 3 files changed, 46 insertions(+), 51 deletions(-) create mode 100644 public/src/forum/admin/index.js diff --git a/public/src/app.js b/public/src/app.js index 16414c8ca7..177a9f4f0a 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -19,7 +19,6 @@ var socket, var reconnecting = false; var reconnectTries = 0; - socket.on('event:connect', function(data) { console.log('connected to nodebb socket: ', data); }); @@ -48,17 +47,27 @@ var socket, } }); - socket.on('disconnect', function(data){ - - }); - socket.on('reconnecting', function(data) { + function showDisconnectModal() { + $('#disconnect-modal').modal({ + backdrop:'static', + show:true + }); + + $('#reload-button').on('click',function(){ + $('#disconnect-modal').modal('hide'); + window.location.reload(); + }); + } + reconnecting = true; reconnectTries++; + if(reconnectTries > 4) { showDisconnectModal(); return; } + app.alert({ alert_id: 'connection_alert', title: 'Reconnecting', @@ -70,7 +79,8 @@ var socket, socket.on('api:user.get_online_users', function(users) { jQuery('.username-field').each(function() { - if (this.processed === true) return; + if (this.processed === true) + return; var el = jQuery(this), uid = el.parents('li').attr('data-uid'); @@ -84,27 +94,15 @@ var socket, el.processed = true; }); }); - - function showDisconnectModal() { - $('#disconnect-modal').modal({ - backdrop:'static', - show:true - }); - - $('#reload-button').on('click',function(){ - $('#disconnect-modal').modal('hide'); - window.location.reload(); - }); - } - app.enter_room('global'); + app.enter_room('global'); + + }, async: false }); } - - // takes a string like 1000 and returns 1,000 app.addCommas = function(text) { return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); @@ -237,9 +235,7 @@ var socket, jQuery('document').ready(function() { - - - + // On menu click, change "active" state var menuEl = document.querySelector('.nav'), liEls = menuEl.querySelectorAll('li'), diff --git a/public/src/forum/admin/index.js b/public/src/forum/admin/index.js new file mode 100644 index 0000000000..f8520327ca --- /dev/null +++ b/public/src/forum/admin/index.js @@ -0,0 +1,25 @@ + +(function() { + + ajaxify.register_events(['api:get_all_rooms']); + socket.on('api:get_all_rooms', function(data) { + + var active_users = document.getElementById('active_users'), + total = 0; + active_users.innerHTML = ''; + + for(var room in data) { + if (room !== '') { + var count = data[room].length; + total += count; + active_users.innerHTML = active_users.innerHTML + "
" + room + " " + count + " active user" + (count > 1 ? "s" : "") + "
"; + } + } + + document.getElementById('connections').innerHTML = total; + }); + + app.enter_room('admin'); + socket.emit('api:get_all_rooms'); + +}()); \ No newline at end of file diff --git a/public/templates/admin/index.tpl b/public/templates/admin/index.tpl index a3a4211f3e..af5b04ba12 100644 --- a/public/templates/admin/index.tpl +++ b/public/templates/admin/index.tpl @@ -19,30 +19,4 @@

- \ No newline at end of file + \ No newline at end of file