|
139 | 139 | curSearchVal: '',
|
140 | 140 |
|
141 | 141 | exportMode: false,
|
| 142 | + formatResources: {}, |
142 | 143 | update: function () {
|
143 | 144 | teams = Storage.teams;
|
144 | 145 | if (this.curTeam) {
|
| 146 | + if (this.curTeam.format && !this.formatResources[this.curTeam.format]) { |
| 147 | + this.tryLoadFormatResource(this.curTeam.format); |
| 148 | + } |
145 | 149 | if (this.curTeam.loaded === false || (this.curTeam.teamid && !this.curTeam.loaded)) {
|
146 | 150 | this.loadTeam();
|
147 | 151 | return this.updateTeamView();
|
|
175 | 179 | });
|
176 | 180 | },
|
177 | 181 |
|
| 182 | + tryLoadFormatResource: function (format) { |
| 183 | + var teambuilder = this; |
| 184 | + if (teambuilder.formatResources[format] === true) { // already loading, bypass |
| 185 | + return; |
| 186 | + } |
| 187 | + teambuilder.formatResources[format] = true; // true - loading, array - loaded |
| 188 | + $.get('https://www.smogon.com/dex/api/formats/by-ps-name/' + format, {}, function (data) { |
| 189 | + teambuilder.formatResources[format] = data; |
| 190 | + teambuilder.update(); |
| 191 | + }); |
| 192 | + }, |
| 193 | + |
178 | 194 | /*********************************************************
|
179 | 195 | * Team list view
|
180 | 196 | *********************************************************/
|
|
1223 | 1239 | if (i < this.curTeam.capacity) {
|
1224 | 1240 | buf += '<li><button name="addPokemon" class="button big"><i class="fa fa-plus"></i> Add Pokémon</button></li>';
|
1225 | 1241 | }
|
| 1242 | + buf += '<br />'; |
| 1243 | + var formatInfo = this.formatResources[this.curTeam.format]; |
| 1244 | + // data's there and loaded |
| 1245 | + if (formatInfo && formatInfo !== true) { |
| 1246 | + if (formatInfo.resources.length || formatInfo.url) { |
| 1247 | + buf += '<strong>Teambuilding resources for this tier:</strong><br />'; |
| 1248 | + for (var i = 0; i < formatInfo.resources.length; i++) { |
| 1249 | + var resource = formatInfo.resources[i]; |
| 1250 | + // these are not <li> because that adds too much padding around each entry, making the whole thing |
| 1251 | + // take up too much space |
| 1252 | + buf += '<small style="padding: 1">- <a href="' + resource.url + '">' + resource.resource_name + '</a></small><br />'; |
| 1253 | + } |
| 1254 | + } |
| 1255 | + buf += '<small>Find more helpful resources for this tier on <a href="' + formatInfo.url + '">the Smogon Dex</a>.'; |
| 1256 | + buf += '<br />'; |
| 1257 | + } |
1226 | 1258 | buf += '</ol>';
|
1227 | 1259 | buf += '<form id="pokepasteForm" style="display:inline" method="post" action="https://pokepast.es/create" target="_blank">';
|
1228 | 1260 | buf += '<input type="hidden" name="title" id="pasteTitle">';
|
|
0 commit comments