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 if (this.node.nodeName != 'tree') throw(id + ' is not a tree');
11 JSAN.use('util.error'); this.error = new util.error();
16 main.list.prototype = {
18 'init' : function (params) {
20 if (typeof params.map_row_to_column == 'function') this.map_row_to_column = params.map_row_to_column;
22 this.prebuilt = false;
23 if (typeof params.prebuilt != 'undefined') this.prebuilt = params.prebuilt;
25 if (typeof params.columns == 'undefined') throw('main.list.init: No columns');
26 this.columns = params.columns;
30 this.treechildren = this.node.lastChild;
33 var treecols = document.createElement('treecols');
34 this.node.appendChild(treecols);
36 for (var i = 0; i < this.columns.length; i++) {
37 var treecol = document.createElement('treecol');
38 for (var j in this.columns[i]) {
39 treecol.setAttribute(j,this.columns[i][j]);
41 treecols.appendChild(treecol);
42 var splitter = document.createElement('splitter');
43 splitter.setAttribute('class','tree-splitter');
44 treecols.appendChild(splitter);
47 var treechildren = document.createElement('treechildren');
48 this.node.appendChild(treechildren);
49 this.treechildren = treechildren;
53 'append' : function (params) {
55 if (typeof params.row == 'undefined') throw('main.list.append: Object must contain a row');
57 dump('main.list.append: params = ' + js2JSON(params) + '\n');
59 var treeitem = document.createElement('treeitem');
60 this.treechildren.appendChild( treeitem );
61 var treerow = document.createElement('treerow');
62 treeitem.appendChild( treerow );
64 dump('tree = ' + this.node + ' treechildren = ' + this.treechildren + '\n');
65 dump('treeitem = ' + treeitem + ' treerow = ' + treerow + '\n');
67 for (var i = 0; i < this.columns.length; i++) {
68 var treecell = document.createElement('treecell');
70 if (typeof params.map_row_to_column == 'function') {
72 label = params.map_row_to_column(params.row,this.columns[i]);
76 if (typeof this.map_row_to_column == 'function') {
78 label = this.map_row_to_column(params.row,this.columns[i]);
81 treecell.setAttribute('label',label);
82 treerow.appendChild( treecell );
83 dump('treecell = ' + treecell + ' with label = ' + label + '\n');
90 dump('exiting main/list.js\n');