diff --git a/js/client-teambuilder.js b/js/client-teambuilder.js
index e03e6102f..9335b2b8d 100644
--- a/js/client-teambuilder.js
+++ b/js/client-teambuilder.js
@@ -19,7 +19,9 @@
},
events: {
// teambuilder events
- 'keydown .chartinput': 'chartKeydown'
+ 'keydown .chartinput': 'chartKeydown',
+ 'focus .chartinput': 'chartFocus',
+ 'change .chartinput': 'chartChange'
},
dispatchClick: function(e) {
e.preventDefault();
@@ -323,7 +325,7 @@
this.curSet = newPokemon;
this.curSetLoc = this.curTeam.team.length-1;
this.update();
- // selfR.teamBuilderElem.find('.setcell-pokemon input').select();
+ this.$('input[name=pokemon]').select();
},
/*********************************************************
@@ -368,6 +370,170 @@
buf += '
';
this.$el.html(buf);
+ this.$chart = this.$('.teambuilder-results');
+ },
+ curChartType: '',
+ curChartName: '',
+ updateChart: function() {
+ var type = this.curChartType;
+ if (type === 'stats') {
+ this.updateStatForm();
+ return;
+ }
+ if (type === 'details') {
+ this.updateDetailsForm();
+ return;
+ }
+ this.$chart.html('Loading '+this.curChartType+'...');
+ },
+ setStatFormGuesses: function() {
+ this.updateStatForm(true);
+ },
+ updateStatForm: function(setGuessed) {
+ var buf = '';
+ var set = this.curSet;
+ buf += 'EVs
';
+ buf += '';
+ this.$chart.html(buf);
+ },
+ updateDetailsForm: function() {
+ var buf = '';
+ var set = this.curSet;
+ var template = Tools.getTemplate(set.species);
+ if (!set) return;
+ buf += 'Details
';
+ buf += '';
+ this.$chart.html(buf);
},
arrangeCallback: {
@@ -431,14 +597,108 @@
}
},
stats: function(i, button) {
- this.selectPokemon($(button).closest('li').val());
+ if (!this.curSet) this.selectPokemon($(button).closest('li').val());
+ this.curChartType = 'stats';
+ this.updateStatForm();
},
details: function(i, button) {
- this.selectPokemon($(button).closest('li').val());
+ if (!this.curSet) this.selectPokemon($(button).closest('li').val());
+ this.curChartType = 'details';
+ this.updateDetailsForm();
+ },
+ chartTypes: {
+ pokemon: 'pokemon',
+ item: 'item',
+ ability: 'ability',
+ move1: 'move',
+ move2: 'move',
+ move3: 'move',
+ move4: 'move',
+ stats: 'stats',
+ details: 'details'
},
chartKeydown: function() {
//
},
+ chartFocus: function(e) {
+ var $target = $(e.currentTarget);
+ var name = e.currentTarget.name;
+ var type = this.chartTypes[name];
+
+ if (!this.curSet) {
+ var i = +$target.closest('li').prop('value');
+ this.curSet = this.curTeam.team[i];
+ this.curSetLoc = i;
+ this.update();
+ if (type === 'stats' || type === 'details') {
+ this.$('button[name='+name+']').click();
+ } else {
+ this.$('input[name='+name+']').select();
+ }
+ return;
+ }
+
+ this.curChartName = name;
+ this.curChartType = type;
+ this.updateChart();
+ },
+ chartChange: function(e) {
+ var name = e.currentTarget.name;
+ var type = this.chartTypes[name];
+ var val = Chart.firstResult;
+ var id = toId(e.currentTarget.value);
+ if (toId(val) !== id) {
+ $(e.currentTarget).addClass('incomplete');
+ return;
+ }
+ e.currentTarget.value = val;
+ switch (name) {
+ case 'pokemon':
+ // selfR.formChangePokemon(val);
+ break;
+ case 'item':
+ if (val || e.currentTarget.value === '') {
+ this.curSet.item = val;
+ // selfR.updatePokemonSprite();
+ }
+ break;
+ case 'ability':
+ if (val) {
+ this.curSet.ability = val;
+ }
+ break;
+ case 'move1':
+ if (val || e.currentTarget.value === '') {
+ this.curSet.moves[0] = val;
+ // selfR.formChooseMove(val);
+ }
+ break;
+ case 'move2':
+ if (!this.curSet.moves[0]) this.curSet.moves[0] = '';
+ if (val || e.currentTarget.value === '') {
+ this.curSet.moves[1] = val;
+ // selfR.formChooseMove(val);
+ }
+ break;
+ case 'move3':
+ if (!this.curSet.moves[0]) this.curSet.moves[0] = '';
+ if (!this.curSet.moves[1]) this.curSet.moves[1] = '';
+ if (val || e.currentTarget.value === '') {
+ this.curSet.moves[2] = val;
+ // selfR.formChooseMove(val);
+ }
+ break;
+ case 'move4':
+ if (!this.curSet.moves[0]) this.curSet.moves[0] = '';
+ if (!this.curSet.moves[1]) this.curSet.moves[1] = '';
+ if (!this.curSet.moves[2]) this.curSet.moves[2] = '';
+ if (val || e.currentTarget.value === '') {
+ this.curSet.moves[3] = val;
+ // selfR.formChooseMove(val);
+ }
+ break;
+ }
+ },
/*********************************************************
* Utility functions