diff --git a/js/client-chat.js b/js/client-chat.js index 54bb332df..5f0a6cdad 100644 --- a/js/client-chat.js +++ b/js/client-chat.js @@ -531,7 +531,7 @@ name2 = row[3]; silent = (row[0] === 'B'); - var matches = this.parseBattleID(id); + var matches = ChatRoom.parseBattleID(id); if (!matches) { return; // bogus room ID could be used to inject JavaScript } @@ -751,13 +751,7 @@ if (message.substr(0,2) === '//') message = message.substr(1); this.$chat.append(chatDiv + timestamp + '' + clickableName + ': ' + messageSanitize(message) + ''); } - }, - parseBattleID: function(id) { - if (id.lastIndexOf('-') > 6) { - return id.match(/^battle\-([a-z0-9]*)\-?[0-9]*$/); - } - return id.match(/^battle\-([a-z0-9]*[a-z])[0-9]*$/); - }, + } }, { getTimestamp: function(section) { var pref = Tools.prefs('timestamps') || {}; @@ -771,6 +765,12 @@ return '[' + components.map( function(x) { return (x < 10) ? '0' + x : x; } ).join(':') + '] '; + }, + parseBattleID: function(id) { + if (id.lastIndexOf('-') > 6) { + return id.match(/^battle\-([a-z0-9]*)\-?[0-9]*$/); + } + return id.match(/^battle\-([a-z0-9]*[a-z])[0-9]*$/); } }); diff --git a/js/client-mainmenu.js b/js/client-mainmenu.js index 8d2da5660..6a6670634 100644 --- a/js/client-mainmenu.js +++ b/js/client-mainmenu.js @@ -25,6 +25,9 @@ buf += '
'+this.renderFormats()+'
'; buf += ''+this.renderTeams()+'
'; buf += ''; + + buf += ''; + buf += ''; // right menu @@ -475,6 +478,9 @@ }, joinRoom: function(room) { app.joinRoom(room); + }, + roomlist: function() { + app.addPopup('roomlist', BattleListPopup); } }); @@ -598,4 +604,61 @@ } }); + var BattleListPopup = this.BattleListPopup = Popup.extend({ + type: 'semimodal', + initialize: function() { + app.on('response:roomlist', this.update, this); + app.send('/cmd roomlist'); + this.update(); + }, + events: { + 'click .ilink': 'clickLink' + }, + update: function(data) { + if (!data) { + this.$el.html('Loading...
'); + return; + } + var buf = ''; + var i = 0; + for (var id in data.rooms) { + var roomData = data.rooms[id]; + var matches = ChatRoom.parseBattleID(id); + if (!matches) { + continue; // bogus room ID could be used to inject JavaScript + } + var format = (matches ? '[' + matches[1] + ']No battles are going on right now.
'; + } else { + buf = '
'+i+' battles
'+buf+'