From 69cb27b596fd7831dbfe6f0120baf024f0c2c8ea Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Wed, 16 Dec 2015 01:09:48 -0500 Subject: [PATCH] Keep newly opened format folders visible Normally, when navigating away from an empty format folder, it'll disappear from the folder list. This keeps the folder visible if you just opened it from a team selector or the 'New format folder' button, so you can drag teams from other folders to that folder. --- js/client-mainmenu.js | 7 +++---- js/client-teambuilder.js | 44 +++++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/js/client-mainmenu.js b/js/client-mainmenu.js index 27cdceab7..326e0cdb6 100644 --- a/js/client-mainmenu.js +++ b/js/client-mainmenu.js @@ -827,8 +827,8 @@ initialize: function (data) { var curFormat = data.format; this.onselect = data.onselect; - var selectType = (this.sourceEl.closest('form').data('search') ? 'search' : 'challenge'); - if (this.sourceEl.hasClass('teambuilderformatselect')) selectType = 'teambuilder'; + var selectType = data.selectType; + if (!selectType) selectType = (this.sourceEl.closest('form').data('search') ? 'search' : 'challenge'); var bufs = []; var curBuf = 0; var curSection = ''; @@ -972,8 +972,7 @@ app.joinRoom('teambuilder'); var teambuilder = app.rooms['teambuilder']; if (!teambuilder.exportMode && !teambuilder.curTeam && teamFormat) { - teambuilder.curFormat = teamFormat; - teambuilder.update(); + teambuilder.selectFolder(teamFormat); } }, selectTeam: function (i) { diff --git a/js/client-teambuilder.js b/js/client-teambuilder.js index ac78eab3f..a06208e53 100644 --- a/js/client-teambuilder.js +++ b/js/client-teambuilder.js @@ -29,6 +29,7 @@ this.saveFlag = false; app.user.trigger('saveteams'); } + this.curFormatKeep = ''; }, events: { // team changes @@ -171,20 +172,22 @@ buf += '
' : '">') + '
(all)
' + (!this.curFormat ? '
' : ''); var folderTable = {}; var folders = []; - if (Storage.teams) for (var i = -1; i < Storage.teams.length; i++) { + if (Storage.teams) for (var i = -2; i < Storage.teams.length; i++) { var format; - if (i >= 0) { - format = Storage.teams[i].format; - } else { + if (i === -2) { + format = this.curFormatKeep; + } else if (i === -1) { format = this.curFormat; + } else { + format = Storage.teams[i].format; + if (!format || format === 'gen6') { + if ('gen6' in folderTable) continue; + folderTable['gen6'] = 1; + folders.push('A~'); + continue; + } } - if (!format || format === 'gen6') { - if (i < 0 && format) continue; - if ('gen6' in folderTable) continue; - folderTable['gen6'] = 1; - folders.push('A~'); - continue; - } + if (!format) continue; if (format in folderTable) continue; folderTable[format] = 1; switch (format.slice(0, 4)) { @@ -321,10 +324,15 @@ format = $(e.currentTarget).data('value'); e.preventDefault(); if (format === '+') { - this.format('', e.currentTarget); e.stopImmediatePropagation(); + var self = this; + app.addPopup(FormatPopup, {format: '', sourceEl: e.currentTarget, selectType: 'teambuilder', onselect: function (newFormat) { + self.changeFormat(newFormat); + }}); return; } + } else { + this.curFormatKeep = format; } this.curFormat = (format === 'all' ? '' : format); this.updateFolderList(); @@ -892,15 +900,9 @@ return; } var self = this; - if (this.curTeam) { - app.addPopup(FormatPopup, {format: format, sourceEl: button, onselect: function (newFormat) { - self.changeFormat(newFormat); - }}); - } else { - app.addPopup(FormatPopup, {format: format, sourceEl: button, onselect: function (newFormat) { - self.selectFolder(newFormat); - }}); - } + app.addPopup(FormatPopup, {format: format, sourceEl: button, selectType: 'teambuilder', onselect: function (newFormat) { + self.changeFormat(newFormat); + }}); }, changeFormat: function (format) { this.curTeam.format = format;