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' : _init_tree(params); break;
37 default: throw('NYI: Need ._init() for ' + this.node.nodeName); break;
41 '_init_tree' : function (params) {
44 this.treechildren = this.node.lastChild;
47 var treecols = document.createElement('treecols');
48 this.node.appendChild(treecols);
50 for (var i = 0; i < this.columns.length; i++) {
51 var treecol = document.createElement('treecol');
52 for (var j in this.columns[i]) {
53 treecol.setAttribute(j,this.columns[i][j]);
55 treecols.appendChild(treecol);
56 var splitter = document.createElement('splitter');
57 splitter.setAttribute('class','tree-splitter');
58 treecols.appendChild(splitter);
61 var treechildren = document.createElement('treechildren');
62 this.node.appendChild(treechildren);
63 this.treechildren = treechildren;
67 '_init_listbox' : function (params) {
70 var listhead = document.createElement('listhead');
71 this.node.appendChild(listhead);
73 var listcols = document.createElement('listcols');
74 this.node.appendChild(listcols);
76 for (var i = 0; i < this.columns.length; i++) {
77 var listheader = document.createElement('listheader');
78 listhead.appendChild(listheader);
79 var listcol = document.createElement('listcol');
80 listcols.appendChild(listcol);
81 for (var j in this.columns[i]) {
82 listhead.setAttribute(j,this.columns[i][j]);
83 listcol.setAttribute(j,this.columns[i][j]);
89 'append' : function (params) {
90 switch (this.node.nodeName) {
91 case 'tree' : this._append_to_tree(params); break;
92 case 'listbox' : this._append_to_listbox(params); break;
93 default: throw('NYI: Need .append() for ' + this.node.nodeName); break;
97 '_append_to_tree' : function (params) {
99 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
101 var s = ('util.list.append: params = ' + js2JSON(params) + '\n');
103 var treeitem = document.createElement('treeitem');
104 this.treechildren.appendChild( treeitem );
105 var treerow = document.createElement('treerow');
106 treeitem.appendChild( treerow );
108 s += ('tree = ' + this.node + ' treechildren = ' + this.treechildren + '\n');
109 s += ('treeitem = ' + treeitem + ' treerow = ' + treerow + '\n');
111 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
113 treerow.setAttribute('retrieve_id',params.retrieve_id);
114 //FIXME//Make async and fire when row is visible in list
116 if (typeof params.retrieve_row == 'function') {
118 row = params.retrieve_row( params );
122 if (typeof this.retrieve_row == 'function') {
124 row = this.retrieve_row( params );
129 this._map_row_to_treecell(params,treerow);
132 this._map_row_to_treecell(params,treerow);
134 this.error.sdump('D_LIST',s);
139 '_append_to_listbox' : function (params) {
141 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
143 var s = ('util.list.append: params = ' + js2JSON(params) + '\n');
145 var listitem = document.createElement('listitem');
146 this.node.appendChild( listitem );
148 s += ('listbox = ' + this.node + ' listitem = ' + listitem + '\n');
150 if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
152 listitem.setAttribute('retrieve_id',params.retrieve_id);
153 //FIXME//Make async and fire when row is visible in list
155 if (typeof params.retrieve_row == 'function') {
157 row = params.retrieve_row( params );
161 if (typeof this.retrieve_row == 'function') {
163 row = this.retrieve_row( params );
168 this._map_row_to_listcell(params,listitem);
171 this._map_row_to_listcell(params,listitem);
173 this.error.sdump('D_LIST',s);
179 '_map_row_to_treecell' : function(params,treerow) {
181 for (var i = 0; i < this.columns.length; i++) {
182 var treecell = document.createElement('treecell');
184 if (typeof params.map_row_to_column == 'function') {
186 label = params.map_row_to_column(params.row,this.columns[i]);
190 if (typeof this.map_row_to_column == 'function') {
192 label = this.map_row_to_column(params.row,this.columns[i]);
195 treecell.setAttribute('label',label);
196 treerow.appendChild( treecell );
197 s += ('treecell = ' + treecell + ' with label = ' + label + '\n');
199 this.error.sdump('D_LIST',s);
202 '_map_row_to_listcell' : function(params,listitem) {
204 for (var i = 0; i < this.columns.length; i++) {
206 if (typeof params.map_row_to_column == 'function') {
208 value = params.map_row_to_column(params.row,this.columns[i]);
212 if (typeof this.map_row_to_column == 'function') {
214 value = this.map_row_to_column(params.row,this.columns[i]);
217 if (typeof value == 'string') {
218 var listcell = document.createElement('listcell');
219 listcell.setAttribute('label',value);
220 listitem.appendChild(listcell);
221 s += ('listcell = ' + listcell + ' with label = ' + value + '\n');
223 listitem.appendChild(value);
224 s += ('listcell = ' + value + ' is really a ' + value.nodeName + '\n');
227 this.error.sdump('D_LIST',s);
231 dump('exiting util.list.js\n');