class Tournament{ id: string name: string full_name: string status: string logo: Object organization: string description: string size: number teams: Team[] = [] isLoading: boolean constructor(data: Object) { for (let key in data){ this[key] = data[key]; } } async fetchTeams(){ this.isLoading = true; this.teams = []; let list = []; for (let i = 0, size = Infinity; i < size; i += 50){ let range = i + '-' + (i + 49); try { let result = await APICall( 'viewer/v2/tournaments/' + this.id + '/participants', {sort: 'alphabetic'}, {Range: 'participants=' + range} ); size = result['real_size']; list = list.concat(result['items']); } catch (e){ console.info('Failed to fetch teams ' + range + ':', e); } } for (let item of list){ this.teams.push(new Team(item)); } this.isLoading = false; } buildMainHtml(){ let teamsList = $('#teams-list'); teamsList.html(''); $('#team').html(''); let name = this.full_name; name = !name ? this.name : name; $('#tournament-teams > h2').text(name); for (let team of this.teams){ teamsList.append(team.teaserHtml); } } get teaserHtml(){ let html = $('
'); html.attr('class', 'tournament-teaser'); html.on('click', () => !this.isLoading ? openTournament(this) : null); html.data('id', this.id); let logo = $('') logo.attr('src', this.logo ? this.logo['logo_small'] : ""); logo.on('load', () => html.show()); let name = $(''); name.text(this.name); if (logo.attr('src')) html.hide(); html.append(logo, name); return html; } }