Support allowRename in RoomGames

Now, if you're in a roomgame that doesn't allow renames, the client will
warn you about that.
This commit is contained in:
Guangcong Luo 2016-01-14 21:31:13 -05:00
parent 7fd31032a3
commit e2ecab4884
2 changed files with 31 additions and 1 deletions

View File

@ -507,7 +507,9 @@
var buf = '<form class="battleform"><p><label class="label">Games:</label></p>';
buf += '<div class="roomlist">';
for (var roomid in this.games) {
buf += '<div><a href="/' + toRoomid(roomid) + '" class="ilink" style="text-align: center">' + Tools.escapeHTML(this.games[roomid]) + '</a></div>';
var name = this.games[roomid];
if (name.slice(-1) === '*') name = name.slice(0, -1);
buf += '<div><a href="/' + toRoomid(roomid) + '" class="ilink" style="text-align: center">' + Tools.escapeHTML(name) + '</a></div>';
}
buf += '</div>';
if (!$searchGroup.is(':visible')) buf += '<p class="buttonbar"><button name="showSearchGroup">Add game</button></p>';

View File

@ -2450,6 +2450,25 @@
}
} else if (data.reason) {
buf += '<p>' + Tools.parseMessage(data.reason) + '</p>';
} else if (!data.force) {
var noRenameGames = '';
if (app.rooms[''].games) {
for (var roomid in app.rooms[''].games) {
var title = app.rooms[''].games[roomid];
if (title.slice(-1) === '*') {
noRenameGames += '<li>' + Tools.escapeHTML(title.slice(0, -1)) + '</li>';
}
}
}
if (noRenameGames) {
buf += '<p>You can\'t change name in the middle of these games:</p>';
buf += '<ul>' + noRenameGames + '</ul>';
buf += '<p class="buttonbar"><button name="force"><small style="color:red">Forfeit and change name</small></button></p>';
buf += '<p class="buttonbar"><button type="submit" autofocus><strong>Cancel</strong></button></p>';
buf += '</form>';
this.$el.html(buf);
return;
}
}
var name = (data.name || '');
@ -2469,6 +2488,15 @@
var css = hashColor(toUserid(name)).slice(6, -1);
preview.css('color', css);
},
force: function () {
var sourceEl = this.sourceEl;
this.close();
app.addPopup(LoginPopup, {
force: true,
sourceEl: sourceEl,
sourcePopup: app.popups[app.popups.length - 1]
});
},
submit: function (data) {
this.close();
if (!$.trim(data.username)) return;