diff --git a/js/client-mainmenu.js b/js/client-mainmenu.js
index f5be55824..f2ce2c5cc 100644
--- a/js/client-mainmenu.js
+++ b/js/client-mainmenu.js
@@ -561,10 +561,9 @@
var self = this;
this.$('button[name=team]').each(function (i, el) {
- var val = el.value;
- if (val === 'random') return;
+ if (el.value === 'random') return;
var format = $(el).closest('form').find('button[name=format]').val();
- $(el).replaceWith(self.renderTeams(format, val));
+ $(el).replaceWith(self.renderTeams(format));
});
},
updateRightMenu: function () {
@@ -690,7 +689,7 @@
return '';
},
curTeamFormat: '',
- curTeamIndex: -1,
+ curTeamIndex: 0,
renderTeams: function (formatid, teamIndex) {
if (!Storage.teams || !window.BattleFormats) {
return '';
@@ -896,8 +895,12 @@
var formatid = this.sourceEl.closest('form').find('button[name=format]').val();
i = +i;
this.sourceEl.val(i).html(TeamPopup.renderTeam(i));
- app.rooms[''].curTeamIndex = i;
- app.rooms[''].curTeamFormat = formatid;
+ if (this.sourceEl[0].offsetParent.className === 'mainmenuwrapper') {
+ app.rooms[''].curTeamIndex = i;
+ app.rooms[''].curTeamFormat = formatid;
+ } else if (this.sourceEl[0].offsetParent.className === 'tournament-box active') {
+ app.curSideRoom.tournamentBox.curTeamIndex = i;
+ }
this.close();
}
}, {
diff --git a/js/client-teambuilder.js b/js/client-teambuilder.js
index db6df55c8..99f939273 100644
--- a/js/client-teambuilder.js
+++ b/js/client-teambuilder.js
@@ -237,6 +237,16 @@
i = +i;
this.deletedTeamLoc = i;
this.deletedTeam = teams.splice(i, 1)[0];
+ for (var room in app.rooms) {
+ var selection = app.rooms[room].$('button.teamselect').val();
+ if (!selection || selection === 'random') continue;
+ var obj = app.rooms[room].id === "" ? app.rooms[room] : app.rooms[room].tournamentBox;
+ if (i < obj.curTeamIndex) {
+ obj.curTeamIndex--;
+ } else if (i === obj.curTeamIndex) {
+ obj.curTeamIndex = -1;
+ }
+ }
Storage.deleteTeam(this.deletedTeam);
app.user.trigger('saveteams');
this.update();
@@ -244,6 +254,16 @@
undoDelete: function () {
if (this.deletedTeamLoc >= 0) {
teams.splice(this.deletedTeamLoc, 0, this.deletedTeam);
+ for (var room in app.rooms) {
+ var selection = app.rooms[room].$('button.teamselect').val();
+ if (!selection || selection === 'random') continue;
+ var obj = app.rooms[room].id === "" ? app.rooms[room] : app.rooms[room].tournamentBox;
+ if (this.deletedTeamLoc < obj.curTeamIndex + 1) {
+ obj.curTeamIndex++;
+ } else if (obj.curTeamIndex === -1) {
+ obj.curTeamIndex = this.deletedTeamLoc;
+ }
+ }
var undeletedTeam = this.deletedTeam;
this.deletedTeam = null;
this.deletedTeamLoc = -1;
@@ -256,6 +276,12 @@
Storage.importTeam(this.$('.teamedit textarea').val(), true);
teams = Storage.teams;
Storage.saveAllTeams();
+ for (var room in app.rooms) {
+ var selection = app.rooms[room].$('button.teamselect').val();
+ if (!selection || selection === 'random') continue;
+ var obj = app.rooms[room].id === "" ? app.rooms[room] : app.rooms[room].tournamentBox;
+ obj.curTeamIndex = 0;
+ }
this.back();
},
"new": function () {
@@ -276,6 +302,12 @@
iconCache: ''
};
teams.unshift(newTeam);
+ for (var room in app.rooms) {
+ var selection = app.rooms[room].$('button.teamselect').val();
+ if (!selection || selection === 'random') continue;
+ var obj = app.rooms[room].id === "" ? app.rooms[room] : app.rooms[room].tournamentBox;
+ obj.curTeamIndex++;
+ }
this.edit(0);
},
"import": function () {
@@ -355,6 +387,18 @@
var team = Storage.teams[originalLoc];
Storage.teams.splice(originalLoc, 1);
Storage.teams.splice(newLoc, 0, team);
+ for (var room in app.rooms) {
+ var selection = app.rooms[room].$('button.teamselect').val();
+ if (!selection || selection === 'random') continue;
+ var obj = app.rooms[room].id === "" ? app.rooms[room] : app.rooms[room].tournamentBox;
+ if (originalLoc === obj.curTeamIndex) {
+ obj.curTeamIndex = newLoc;
+ } else if (originalLoc > obj.curTeamIndex && newLoc <= obj.curTeamIndex) {
+ obj.curTeamIndex++;
+ } else if (originalLoc < obj.curTeamIndex && newLoc >= obj.curTeamIndex) {
+ obj.curTeamIndex--;
+ }
+ }
Storage.saveTeams();
app.user.trigger('saveteams');
}