dojo.provide("acf.games.Archive"); dojo.require("acf._ACF"); dojo.require("acf.data.CustomQueryStore"); dojo.require("acf.games.CheckerBoard"); dojo.require("kfc.base._GridBase"); dojo.require("dijit.Tree"); dojo.require("dijit.layout.BorderContainer"); dojo.require("dijit.layout.ContentPane"); dojo.require("dojox.grid.DataGrid"); dojo.declare("acf.games.Archive", [kfc.base._GridBase], { templateString: dojo.cache("acf.games","templates/Archive.html") ,widgetsInTemplate: true ,constructor: function() { this.xDomain = false; this.callbackName = 'acf_callback'; } /* Local Attributes */ ,archiveTreeFile: 'server/archiveTree.php' ,gamesFile: 'server/findGame.php' ,loadFile: 'server/findGame.php' ,defaultOrder: 'CSYE' ,searchObj: {} /* End Local Attributes */ ,_getGridStructure: function() { var struct = [ { name: " ", field: "", formatter: function () { return " "; }, editable: false, width: "1em" } //,{ name: "Id", field: "P_ID", width: "4em" } ,{ name: "Style", field: "P_STYLE", width: "6em" } ,{ name: "Category", field: "P_CATEGORY", width: "12em" } ,{ name: "Year", field: "P_YEAR", width: "4em" } ,{ name: "Event", field: "P_EVENT", width: "20em" } //,{ name: "Date", field: "P_DATE", width: "8em" } ,{ name: "Red", field: "P_BLACK_PLAYER", width: "12em" } ,{ name: "White", field: "P_WHITE_PLAYER", width: "12em" } ,{ name: "Result", field: "P_RESULT_TEXT", width: "8em" } ]; return struct; } ,getSearchObj: function() { return this.searchObj; } ,setNodeParams: function(item,q) { // Start with empty object var i = item; // QueryReadStore format if(item['i']) { i = item['i']; } var q = dojo.clone(i); q['P_ORDER'] = this.getOrder(); /* // i has everything we need q["P_CURRENT"] = i['P_CURRENT']; q["P_STYLE_ID"] = i['P_STYLE_ID']; q["P_CATEGORY_ID"] = i['P_CATEGORY_ID']; q["P_YEAR"] = i['P_YEAR']; */ return q; } ,getOrder: function() { return this.defaultOrder; } ,listGames: function(a,b,c) { this.searchObj = a['i']; this.getData(); } ,createStore: function() { this.archiveStore = new acf.data.CustomQueryStore({ url: this.archiveTreeFile ,requestMethod: "post" ,getServerQuery: dojo.hitch(this,'setNodeParams') }); } ,createModel: function() { var o = this.getOrder(); this.archiveModel = new dijit.tree.ForestStoreModel({ store: this.archiveStore ,deferItemLoadingUntilExpand: true ,query: { "P_CURRENT": o.charAt(0) ,"P_ORDER": o } ,rootId: "root" ,rootLabel: "Archive" ,childrenAttrs: ["children"] ,newItemIdAttr: 'P_ID' }); } ,createTree: function() { this.archiveTree = new dijit.Tree({ model: this.archiveModel ,openOnClick: true ,persist: false ,onClick: dojo.hitch(this,'listGames') },this.tree_ph); } ,initTree: function() { // Force these to go in order var cs = dojo.connect(this,'createStore',this,'createModel'); var cm = dojo.connect(this,'createModel',this,'createTree'); var ct = dojo.connect(this,'createTree',this,function() { dojo.disconnect(cs); dojo.disconnect(cm); dojo.disconnect(ct); }); this.createStore(); } ,loadGame: function(i,j) { var s = this.f_grid.selection.getSelected(); var r = s[0]; this.board.gameId = r.P_ID[0]; this.board._loadMode(); } ,createBoard: function() { this.board = new acf.games.CheckerBoard({ rows: 8 ,playable: 'd' ,showNumbers: 'off' ,sqSize: 30 ,mode: 'GAME' },this.board_ph); this.board.startup(); } ,postCreate: function() { // Break then resize after border container loads setTimeout(dojo.hitch(this,'createBoard'),1000); this.initTree(); dojo.connect(this.f_grid,'onDblClick',this,'loadGame'); this.inherited(arguments); } });