1 dump('entering main/list.js\n');
3 if (typeof main == 'undefined') main = {};
4 main.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 main.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;
28 this.prebuilt = false;
29 if (typeof params.prebuilt != 'undefined') this.prebuilt = params.prebuilt;
31 if (typeof params.columns == 'undefined') throw('main.list.init: No columns');
32 this.columns = params.columns;
36 this.treechildren = this.node.lastChild;
39 var treecols = document.createElement('treecols');
40 this.node.appendChild(treecols);
42 for (var i = 0; i < this.columns.length; i++) {
43 var treecol = document.createElement('treecol');
44 for (var j in this.columns[i]) {
45 treecol.setAttribute(j,this.columns[i][j]);
47 treecols.appendChild(treecol);
48 var splitter = document.createElement('splitter');
49 splitter.setAttribute('class','tree-splitter');
50 treecols.appendChild(splitter);
53 var treechildren = document.createElement('treechildren');
54 this.node.appendChild(treechildren);
55 this.treechildren = treechildren;
59 'append' : function (params) {
60 switch (this.node.nodeName) {
61 case 'tree' : this.append_to_tree(params); break;
62 default: throw('NYI: Need .append() for ' + this.node.nodeName); break;
66 'append_to_tree' : function (params) {
68 if (typeof params.row == 'undefined') throw('main.list.append: Object must contain a row');
70 dump('main.list.append: params = ' + js2JSON(params) + '\n');
72 var treeitem = document.createElement('treeitem');
73 this.treechildren.appendChild( treeitem );
74 var treerow = document.createElement('treerow');
75 treeitem.appendChild( treerow );
77 dump('tree = ' + this.node + ' treechildren = ' + this.treechildren + '\n');
78 dump('treeitem = ' + treeitem + ' treerow = ' + treerow + '\n');
80 for (var i = 0; i < this.columns.length; i++) {
81 var treecell = document.createElement('treecell');
83 if (typeof params.map_row_to_column == 'function') {
85 label = params.map_row_to_column(params.row,this.columns[i]);
89 if (typeof this.map_row_to_column == 'function') {
91 label = this.map_row_to_column(params.row,this.columns[i]);
94 treecell.setAttribute('label',label);
95 treerow.appendChild( treecell );
96 dump('treecell = ' + treecell + ' with label = ' + label + '\n');
103 dump('exiting main/list.js\n');