1 dump('entering util.list.js\n');
3 if (typeof main == 'undefined') main = {};
4 util.list = function (id) {
6 this.node = document.getElementById(id);
8 if (!this.node) throw('Could not find element ' + id);
9 switch(this.node.nodeName) {
13 throw(this.node.nodeName + ' not yet supported'); break;
14 default: throw(this.node.nodeName + ' not supported'); break;
17 JSAN.use('util.error'); this.error = new util.error();
22 util.list.prototype = {
24 'init' : function (params) {
26 if (typeof params.map_row_to_column == 'function') this.map_row_to_column = params.map_row_to_column;
27 if (typeof params.retrieve_row == 'function') this.retrieve_row = params.retrieve_row;
29 this.prebuilt = false;
30 if (typeof params.prebuilt != 'undefined') this.prebuilt = params.prebuilt;
32 if (typeof params.columns == 'undefined') throw('util.list.init: No columns');
33 this.columns = params.columns;
35 switch(this.node.nodeName) {
36 case 'tree' : this._init_tree(params); break;
37 case 'listbox' : this._init_listbox(params); break;
38 default: throw('NYI: Need ._init() for ' + this.node.nodeName); break;
42 '_init_tree' : function (params) {
45 this.treechildren = this.node.lastChild;
48 var treecols = document.createElement('treecols');
49 this.node.appendChild(treecols);
51 for (var i = 0; i < this.columns.length; i++) {
52 var treecol = document.createElement('treecol');
53 for (var j in this.columns[i]) {
54 treecol.setAttribute(j,this.columns[i][j]);
56 treecols.appendChild(treecol);
57 var splitter = document.createElement('splitter');
58 splitter.setAttribute('class','tree-splitter');
59 treecols.appendChild(splitter);
62 var treechildren = document.createElement('treechildren');
63 this.node.appendChild(treechildren);
64 this.treechildren = treechildren;
68 '_init_listbox' : function (params) {
71 var listhead = document.createElement('listhead');
72 this.node.appendChild(listhead);
74 var listcols = document.createElement('listcols');
75 this.node.appendChild(listcols);
77 for (var i = 0; i < this.columns.length; i++) {
78 var listheader = document.createElement('listheader');
79 listhead.appendChild(listheader);
80 var listcol = document.createElement('listcol');
81 listcols.appendChild(listcol);
82 for (var j in this.columns[i]) {
83 listheader.setAttribute(j,this.columns[i][j]);
84 listcol.setAttribute(j,this.columns[i][j]);
90 'append' : function (params) {
91 switch (this.node.nodeName) {
92 case 'tree' : this._append_to_tree(params); break;
93 case 'listbox' : this._append_to_listbox(params); break;
94 default: throw('NYI: Need .append() for ' + this.node.nodeName); break;
98 '_append_to_tree' : function (params) {
100 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
102 var s = ('util.list.append: params = ' + js2JSON(params) + '\n');
104 var treeitem = document.createElement('treeitem');
105 this.treechildren.appendChild( treeitem );
106 var treerow = document.createElement('treerow');
107 treeitem.appendChild( treerow );
109 s += ('tree = ' + this.node + ' treechildren = ' + this.treechildren + '\n');
110 s += ('treeitem = ' + treeitem + ' treerow = ' + treerow + '\n');
112 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
114 treerow.setAttribute('retrieve_id',params.retrieve_id);
115 //FIXME//Make async and fire when row is visible in list
117 if (typeof params.retrieve_row == 'function') {
119 row = params.retrieve_row( params );
123 if (typeof this.retrieve_row == 'function') {
125 row = this.retrieve_row( params );
130 this._map_row_to_treecell(params,treerow);
133 this._map_row_to_treecell(params,treerow);
135 this.error.sdump('D_LIST',s);
140 '_append_to_listbox' : function (params) {
142 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
144 var s = ('util.list.append: params = ' + js2JSON(params) + '\n');
146 var listitem = document.createElement('listitem');
147 this.node.appendChild( listitem );
149 s += ('listbox = ' + this.node + ' listitem = ' + listitem + '\n');
151 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
153 listitem.setAttribute('retrieve_id',params.retrieve_id);
154 //FIXME//Make async and fire when row is visible in list
156 if (typeof params.retrieve_row == 'function') {
158 row = params.retrieve_row( params );
162 if (typeof this.retrieve_row == 'function') {
164 row = this.retrieve_row( params );
169 this._map_row_to_listcell(params,listitem);
172 this._map_row_to_listcell(params,listitem);
174 this.error.sdump('D_LIST',s);
180 '_map_row_to_treecell' : function(params,treerow) {
182 for (var i = 0; i < this.columns.length; i++) {
183 var treecell = document.createElement('treecell');
185 if (typeof params.map_row_to_column == 'function') {
187 label = params.map_row_to_column(params.row,this.columns[i]);
191 if (typeof this.map_row_to_column == 'function') {
193 label = this.map_row_to_column(params.row,this.columns[i]);
196 treecell.setAttribute('label',label);
197 treerow.appendChild( treecell );
198 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
200 this.error.sdump('D_LIST',s);
203 '_map_row_to_listcell' : function(params,listitem) {
205 for (var i = 0; i < this.columns.length; i++) {
207 if (typeof params.map_row_to_column == 'function') {
209 value = params.map_row_to_column(params.row,this.columns[i]);
213 if (typeof this.map_row_to_column == 'function') {
215 value = this.map_row_to_column(params.row,this.columns[i]);
218 if (typeof value == 'string') {
219 var listcell = document.createElement('listcell');
220 listcell.setAttribute('label',value);
221 listitem.appendChild(listcell);
222 s += ('listcell = ' + listcell + ' with label = ' + value + '\n');
224 listitem.appendChild(value);
225 s += ('listcell = ' + value + ' is really a ' + value.nodeName + '\n');
228 this.error.sdump('D_LIST',s);
232 dump('exiting util.list.js\n');