]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/util/list.js
rename main.list to util.list
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / evergreen / util / list.js
1 dump('entering util.list.js\n');
2
3 if (typeof main == 'undefined') main = {};
4 util.list = function (id) {
5
6         this.node = document.getElementById(id);
7
8         if (!this.node) throw('Could not find element ' + id);
9         switch(this.node.nodeName) {
10                 case 'tree' : break;
11                 case 'richlistbox' :
12                 case 'listbox' : 
13                         throw(this.node.nodeName + ' not yet supported'); break;
14                 default: throw(this.node.nodeName + ' not supported'); break;
15         }
16
17         JSAN.use('util.error'); this.error = new util.error();
18
19         return this;
20 };
21
22 util.list.prototype = {
23
24         'init' : function (params) {
25
26                 if (typeof params.map_row_to_column == 'function') this.map_row_to_column = params.map_row_to_column;
27
28                 this.prebuilt = false;
29                 if (typeof params.prebuilt != 'undefined') this.prebuilt = params.prebuilt;
30
31                 if (typeof params.columns == 'undefined') throw('util.list.init: No columns');
32                 this.columns = params.columns;
33
34                 if (this.prebuilt) {
35                 
36                         this.treechildren = this.node.lastChild;        
37                 
38                 } else {
39                         var treecols = document.createElement('treecols');
40                         this.node.appendChild(treecols);
41
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]);
46                                 }
47                                 treecols.appendChild(treecol);
48                                 var splitter = document.createElement('splitter');
49                                 splitter.setAttribute('class','tree-splitter');
50                                 treecols.appendChild(splitter);
51                         }
52
53                         var treechildren = document.createElement('treechildren');
54                         this.node.appendChild(treechildren);
55                         this.treechildren = treechildren;
56                 }
57         },
58
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;
63                 }
64         },
65
66         'append_to_tree' : function (params) {
67
68                 if (typeof params.row == 'undefined') throw('util.list.append: Object must contain a row');
69
70                 dump('util.list.append: params = ' + js2JSON(params) + '\n');
71
72                 var treeitem = document.createElement('treeitem');
73                 this.treechildren.appendChild( treeitem );
74                 var treerow = document.createElement('treerow');
75                 treeitem.appendChild( treerow );
76
77                 dump('tree = ' + this.node + '  treechildren = ' + this.treechildren + '\n');
78                 dump('treeitem = ' + treeitem + '  treerow = ' + treerow + '\n');
79
80                 for (var i = 0; i < this.columns.length; i++) {
81                         var treecell = document.createElement('treecell');
82                         var label = '';
83                         if (typeof params.map_row_to_column == 'function')  {
84
85                                 label = params.map_row_to_column(params.row,this.columns[i]);
86
87                         } else {
88
89                                 if (typeof this.map_row_to_column == 'function') {
90
91                                         label = this.map_row_to_column(params.row,this.columns[i]);
92                                 }
93                         }
94                         treecell.setAttribute('label',label);
95                         treerow.appendChild( treecell );
96                         dump('treecell = ' + treecell + ' with label = ' + label + '\n');
97                 }
98
99                 return treeitem;
100         }
101
102 }
103 dump('exiting util.list.js\n');