diff --git a/js/client-mainmenu.js b/js/client-mainmenu.js
index 6a6670634..cefb0dde3 100644
--- a/js/client-mainmenu.js
+++ b/js/client-mainmenu.js
@@ -607,19 +607,46 @@
var BattleListPopup = this.BattleListPopup = Popup.extend({
type: 'semimodal',
initialize: function() {
+ var buf = '
';
+
+ buf += '
';
+ buf += '
';
+ buf += '
';
+ this.$el.html(buf);
+ this.$list = this.$('.list');
+
app.on('response:roomlist', this.update, this);
app.send('/cmd roomlist');
this.update();
},
events: {
- 'click .ilink': 'clickLink'
+ 'click .ilink': 'clickLink',
+ 'change select': 'changeFormat'
+ },
+ format: '',
+ changeFormat: function(e) {
+ this.format = e.currentTarget.value;
+ this.update();
},
update: function(data) {
- if (!data) {
- this.$el.html('Loading...
');
+ if (!data && !this.data) {
+ this.$list.html('Loading...
');
return;
}
+ if (!data) {
+ data = this.data;
+ } else {
+ this.data = data;
+ }
var buf = '';
+
var i = 0;
for (var id in data.rooms) {
var roomData = data.rooms[id];
@@ -627,25 +654,27 @@
if (!matches) {
continue; // bogus room ID could be used to inject JavaScript
}
- var format = (matches ? '[' + matches[1] + ']
' : '');
- var roomDesc = format + '' + Tools.escapeHTML(roomData.p1) + ' vs. ' + Tools.escapeHTML(roomData.p2) + '';
+ var format = (matches[1]||'');
+ if (this.format && format !== this.format) continue;
+ var formatBuf = (format ? '[' + Tools.escapeFormat(format) + ']
' : '');
+ var roomDesc = formatBuf + '' + Tools.escapeHTML(roomData.p1) + ' vs. ' + Tools.escapeHTML(roomData.p2) + '';
if (!roomData.p1) {
matches = id.match(/[^0-9]([0-9]*)$/);
- roomDesc = format + 'empty room ' + matches[1];
+ roomDesc = formatBuf + 'empty room ' + matches[1];
} else if (!roomData.p2) {
- roomDesc = format + '' + Tools.escapeHTML(roomData.p1) + '';
+ roomDesc = formatBuf + '' + Tools.escapeHTML(roomData.p1) + '';
}
buf += '';
i++;
}
if (!i) {
- buf = 'No battles are going on right now.
';
+ buf = 'No '+Tools.escapeFormat(this.format)+' battles are going on right now.
';
} else {
- buf = '
'+i+' battles
'+buf+'
';
+ buf = ''+i+' '+Tools.escapeFormat(this.format)+' battles
' + buf;
}
- this.$el.html(buf);
+ this.$list.html(buf);
},
clickLink: function(e) {
if (e.cmdKey || e.metaKey || e.ctrlKey) return;