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);
44 var treechildren = document.createElement('treechildren');
45 this.node.appendChild(treechildren);
46 this.treechildren = treechildren;
50 'append' : function (params) {
52 if (typeof params.row == 'undefined') throw('main.list.append: Object must contain a row');
54 var treeitem = document.createElement('treeitem');
55 this.treechildren.appendChild( treeitem );
56 var treerow = document.createElement('treerow');
57 treeitem.appendChild( treerow );
59 for (var i = 0; i < this.columns.length; i++) {
60 var treecell = document.createElement('treecell');
62 if (typeof params.map_row_to_col == 'function') {
64 label = params.map_row_to_col(params.row,this.columns[i]);
68 if (typeof this.map_row_to_col == 'function') {
70 label = this.map_row_to_col(params.row,this.columns[i]);
73 treecell.setAttribute('label',label);
74 treerow.appendChild( treecell );
81 dump('exiting main/list.js\n');