]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/main/list.js
main.list
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / evergreen / main / list.js
1 dump('entering main/list.js\n');
2
3 if (typeof main == 'undefined') main = {};
4 main.list = function (id) {
5
6         this.node = document.getElementById(id);
7
8         if (!this.node) throw('Could not find element ' + id);
9         if (this.node.nodeName != 'tree') throw(id + ' is not a tree');
10
11         JSAN.use('util.error'); this.error = new util.error();
12
13         return this;
14 };
15
16 main.list.prototype = {
17
18         'init' : function (params) {
19
20                 if (typeof params.map_row_to_column == 'function') this.map_row_to_column = params.map_row_to_column;
21
22                 this.prebuilt = false;
23                 if (typeof params.prebuilt != 'undefined') this.prebuilt = params.prebuilt;
24
25                 if (typeof params.columns == 'undefined') throw('main.list.init: No columns');
26                 this.columns = params.columns;
27
28                 if (this.prebuilt) {
29                 
30                         this.treechildren = this.node.lastChild;        
31                 
32                 } else {
33                         var treecols = document.createElement('treecols');
34                         this.node.appendChild(treecols);
35
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]);
40                                 }
41                                 treecols.appendChild(treecol);
42                         }
43
44                         var treechildren = document.createElement('treechildren');
45                         this.node.appendChild(treechildren);
46                         this.treechildren = treechildren;
47                 }
48         },
49
50         'append' : function (params) {
51
52                 if (typeof params.row == 'undefined') throw('main.list.append: Object must contain a row');
53
54                 var treeitem = document.createElement('treeitem');
55                 this.treechildren.appendChild( treeitem );
56                 var treerow = document.createElement('treerow');
57                 treeitem.appendChild( treerow );
58
59                 for (var i = 0; i < this.columns.length; i++) {
60                         var treecell = document.createElement('treecell');
61                         var label = '';
62                         if (typeof params.map_row_to_col == 'function')  {
63
64                                 label = params.map_row_to_col(params.row,this.columns[i]);
65
66                         } else {
67
68                                 if (typeof this.map_row_to_col == 'function') {
69
70                                         label = this.map_row_to_col(params.row,this.columns[i]);
71                                 }
72                         }
73                         treecell.setAttribute('label',label);
74                         treerow.appendChild( treecell );
75                 }
76
77                 return treeitem;
78         }
79
80 }
81 dump('exiting main/list.js\n');