dojo.provide("acf.games.GameSearchForm"); dojo.require("kfc.base._FormBase"); dojo.require("dijit.form.TextBox"); dojo.require("dijit.form.CheckBox"); dojo.require("dijit.form.FilteringSelect"); dojo.require("acf.games.GameListGrid"); dojo.require("dojo.io.script"); dojo.declare("acf.games.GameSearchForm", [kfc.base._FormBase], { templateString: dojo.cache("acf.games","templates/GameSearchForm.html") ,widgetsInTemplate: true ,constructor: function() { this.xDomain = true; this.callbackName = 'acf_callback'; } /* Local Attributes */ ,categoryFile: 'http://games.usacheckers.com/getCategories.php' ,styleFile: 'http://games.usacheckers.com/getStyles.php' ,resultFile: 'http://games.usacheckers.com/getResults.php' ,playerFile: 'http://games.usacheckers.com/getPlayers.php' ,yearFile: 'http://games.usacheckers.com/getYearRange.php' /* End Local Attributes */ /* Stub to be overridden */ ,loadGame: function(i) { } ,getCheckBoxParams: function(c) { var p_c = new Array(); var use_c = false; for(var v in c) { if(c[v][0] != undefined) { p_c.push(c[v][0]); } else { use_c = true; } } // Check if empty, if so no results, so alert the user and stop return (use_c) ? p_c : false; } /* Called by _StoreBase */ ,_getSearchObj: function() { // Call public function return this.getSearchObj(); } /* Public function to allow for connections */ ,getSearchObj: function() { var o = {}; var c = this.getCheckBoxParams(this.f_category.attr('value')); if(c && c.length) { o['P_CATEGORIES'] = c; } var s = this.getCheckBoxParams(this.f_style.attr('value')); if(s && s.length) { o['P_STYLES'] = s; } var r = this.getCheckBoxParams(this.f_result.attr('value')); if(r && r.length) { o['P_RESULTS'] = r; } var p = this.f_player.attr('value'); if(p) { dojo.mixin(o,p); } var y = this.f_year.attr('value'); if(y) { dojo.mixin(o,y); } return o; } ,doCall: function(p_file,p_callback) { if(p_file && p_callback) { dojo.io.script.get({ url: p_file ,content: { 'P_CALLBACK': 'acf_callback' } ,callbackParamName: 'acf_callback' ,handleAs: "json" ,load: dojo.hitch(this,p_callback) ,error: function(error) { //console.log(error); } }); } } ,buildCategoryList: function(p_data) { this.buildCheckBoxList(p_data,'P_CATEGORY','P_ID',this.category_ph); } ,buildResultList: function(p_data) { this.buildCheckBoxList(p_data,'P_RESULT_TEXT','P_RESULT',this.result_ph); } ,buildStyleList: function(p_data) { this.buildCheckBoxList(p_data,'P_STYLE','P_ID',this.style_ph); } ,setYearRange: function(p_data) { var i = p_data.items[0]; this.i_min_year.attr('value',i.P_MIN_YEAR); this.i_max_year.attr('value',i.P_MAX_YEAR); } ,setPlayerList: function(p_data) { var s = new dojo.data.ItemFileReadStore({ data: p_data }); var _this = this; s.fetch({ onComplete: function() { _this.i_player.attr('store',s); _this.i_player.attr('queryExpr',"*${0}*"); } }); } ,buildCheckBoxList: function(p_data,p_label,p_value,p_ph) { var i = p_data.items; for(var j = 0; j < i.length; j++) { var d = dojo.create('div',{'style': 'border-style:solid; border-width: 1px; display: inline; padding: 3px;'}); var l = dojo.create('label',{'innerHTML':i[j][p_label]}); var cb = new dijit.form.CheckBox({name: "c_"+i[j][p_value] ,value: i[j][p_value] ,checked: true }); dojo.place(cb.domNode,d); dojo.place(l,d); dojo.place(d,p_ph); } } ,getCategories: function() { this.doCall(this.categoryFile,'buildCategoryList'); } ,getResults: function() { this.doCall(this.resultFile,'buildResultList'); } ,getStyles: function() { this.doCall(this.styleFile,'buildStyleList'); } ,getYearRange: function() { this.doCall(this.yearFile,'setYearRange'); } ,getPlayerList: function() { this.doCall(this.playerFile,'setPlayerList'); } ,initSearchForm: function() { this.getCategories(); this.getResults(); this.getStyles(); this.getYearRange(); this.getPlayerList(); } ,postCreate: function() { // Have to do this here because constructor doesn't read html yet this.inherited(arguments); this.results_grid.loadGame = dojo.hitch(this,'loadGame'); dojo.connect(this,'setStore',this.results_grid,'setStore'); this.initSearchForm(); //this.results_grid._createStore(); } });