]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/main/list.js
f8abba5e164157e45310fea3f9d7c6f16ec13626
[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                                 var splitter = document.createElement('splitter');
43                                 splitter.setAttribute('class','tree-splitter');
44                                 treecols.appendChild(splitter);
45                         }
46
47                         var treechildren = document.createElement('treechildren');
48                         this.node.appendChild(treechildren);
49                         this.treechildren = treechildren;
50                 }
51         },
52
53         'append' : function (params) {
54
55                 if (typeof params.row == 'undefined') throw('main.list.append: Object must contain a row');
56
57                 dump('main.list.append: params = ' + js2JSON(params) + '\n');
58
59                 var treeitem = document.createElement('treeitem');
60                 this.treechildren.appendChild( treeitem );
61                 var treerow = document.createElement('treerow');
62                 treeitem.appendChild( treerow );
63
64                 dump('tree = ' + this.node + '  treechildren = ' + this.treechildren + '\n');
65                 dump('treeitem = ' + treeitem + '  treerow = ' + treerow + '\n');
66
67                 for (var i = 0; i < this.columns.length; i++) {
68                         var treecell = document.createElement('treecell');
69                         var label = '';
70                         if (typeof params.map_row_to_column == 'function')  {
71
72                                 label = params.map_row_to_column(params.row,this.columns[i]);
73
74                         } else {
75
76                                 if (typeof this.map_row_to_column == 'function') {
77
78                                         label = this.map_row_to_column(params.row,this.columns[i]);
79                                 }
80                         }
81                         treecell.setAttribute('label',label);
82                         treerow.appendChild( treecell );
83                         dump('treecell = ' + treecell + ' with label = ' + label + '\n');
84                 }
85
86                 return treeitem;
87         }
88
89 }
90 dump('exiting main/list.js\n');