]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/common/js/slimtree.js
added params for filtering pubdate before/after/between/during. added functional...
[Evergreen.git] / Open-ILS / web / opac / common / js / slimtree.js
1 /*
2 var stpicopen   = '../../../../images/slimtree/folder.gif';
3 var stpicclose = '../../../../images/slimtree/folderopen.gif';
4 */
5 var stpicopen   = '../../../../images/slimtree/folder2.gif';
6 var stpicclose = '../../../../images/slimtree/folderopen2.gif';
7 var stpicblank = '../../../../images/slimtree/page.gif';
8 var stpicline   = '../../../../images/slimtree/line.gif';
9 var stpicjoin   = '../../../../images/slimtree/join.gif';
10 var stpicjoinb = '../../../../images/slimtree/joinbottom.gif';
11
12 var stimgopen;
13 var stimgclose;
14 var stimgblank;
15 var stimgline;
16 var stimgjoin;
17
18 function _apc(root,node) { root.appendChild(node); }
19
20 function SlimTree(context, handle, rootimg) { 
21         
22         if(!stimgopen) {
23                 stimgopen       = elem('img',{src:stpicopen,border:0});
24                 stimgclose      = elem('img',{src:stpicclose,border:0});
25                 stimgblank      = elem('img',{src:stpicblank,border:0});
26                 stimgline       = elem('img',{src:stpicline,border:0});
27                 stimgjoin       = elem('img',{src:stpicjoin,border:0, style:'display:inline;'});
28         }
29
30         this.context    = context; 
31         this.handle             = handle;
32         this.cache              = new Object();
33         if(rootimg) 
34                 this.rootimg = elem('img', 
35                         {src:rootimg,border:0,style:'padding-right: 4px;'});
36 }
37
38 SlimTree.prototype.addCachedChildren = function(pid) {
39         var child;
40         while( child = this.cache[pid].shift() ) 
41                 this.addNode( child.id, child.pid, 
42                         child.name, child.action, child.title );
43         this.cache[pid] = null;
44 }
45
46 SlimTree.prototype.addNode = function( id, pid, name, action, title, cls ) {
47
48         if( pid != -1 && !$(pid)) {
49                 if(!this.cache[pid]) this.cache[pid] = new Array();
50                 this.cache[pid].push(
51                         {id:id,pid:pid,name:name,action:action,title:title });
52                 return;
53         }
54
55         if(!action)
56                 action='javascript:'+this.handle+'.toggle("'+id+'");';
57
58         var actionref;
59         if( typeof action == 'string' )
60                 actionref = elem('a',{href:action}, name);
61         else {
62                 actionref = elem('a',{href:'javascript:void(0);'}, name);
63                 actionref.onclick = action;
64         }
65
66         var div                 = elem('div',{id:id});
67         var topdiv              = elem('div',{style:'vertical-align:middle'});
68         var link                        = elem('a', {id:'stlink_' + id}); 
69         var contdiv             = elem('div',{id:'stcont_' + id});
70
71         if(cls) addCSSClass(actionref, cls);
72
73         //actionref.setAttribute('href',action);
74         if(title) actionref.setAttribute('title',title);
75         else actionref.setAttribute('title',name);
76
77         _apc(topdiv,link);
78         _apc(topdiv,actionref);
79         _apc(div,topdiv);
80         _apc(div,contdiv);
81
82         if( pid == -1 ) { 
83
84                 this.rootid = id;
85                 _apc(this.context,div);
86                 if(this.rootimg) _apc(link,this.rootimg.cloneNode(true));
87                 else _apc(link,stimgblank.cloneNode(true));
88
89         } else {
90
91                 if(pid == this.rootid) this.open(pid);
92                 else this.close(pid);
93                 $(pid).setAttribute('haschild','1');
94                 _apc(link,stimgblank.cloneNode(true));
95                 div.style.paddingLeft = '18px';
96                 div.style.backgroundImage = 'url('+stpicjoinb+')';
97                 div.style.backgroundRepeat = 'no-repeat';
98                 _apc($('stcont_' + pid), div);
99                 if (div.previousSibling) stMakePaths(div);
100         }
101         if(this.cache[id]) this.addCachedChildren(id);
102 }
103
104 function stMakePaths(div) {
105         _apc(div.previousSibling.firstChild,stimgjoin.cloneNode(true));
106         _apc(div.previousSibling.firstChild,div.previousSibling.firstChild.firstChild);
107         _apc(div.previousSibling.firstChild,div.previousSibling.firstChild.firstChild);
108         div.previousSibling.firstChild.firstChild.style.marginLeft = '-18px';
109         div.previousSibling.style.backgroundImage = 'url('+stpicline+')';
110         div.previousSibling.style.backgroundRepeat = 'repeat-y';
111 }
112
113 SlimTree.prototype.expandAll = function() { this.flex(this.rootid, 'open'); }
114 SlimTree.prototype.closeAll = function() { this.flex(this.rootid,'close'); }
115 SlimTree.prototype.flex = function(id, type) {
116         if(type=='open') this.open(id);
117         else { if (id != this.rootid) this.close(id); }
118         var n = $('stcont_' + id);
119         for( var c = 0; c != n.childNodes.length; c++ ) {
120                 var ch = n.childNodes[c];
121                 if(ch.nodeName.toLowerCase() == 'div') {
122                         if($(ch.id).getAttribute('haschild') == '1') 
123                                 this.flex(ch.id, type);
124                 }
125         }
126 }
127
128 SlimTree.prototype.toggle = function(id) {
129         if($(id).getAttribute('ostate') == '1') this.open(id);
130         else if($(id).getAttribute('ostate') == '2') this.close(id);
131 }
132
133 SlimTree.prototype.open = function(id) {
134         if($(id).getAttribute('ostate') == '2') return;
135         var link = $('stlink_' + id);
136         if(!link) return;
137         if(id != this.rootid || !this.rootimg) {
138                 removeChildren(link);
139                 _apc(link,stimgclose.cloneNode(true));
140         }
141         link.setAttribute('href','javascript:' + this.handle + '.close("'+id+'");');
142         unHideMe($('stcont_' + id));
143         $(id).setAttribute('ostate','2');
144 }
145
146 SlimTree.prototype.close = function(id) {
147         var link = $('stlink_' + id);
148         if(!link) return;
149         if(id != this.rootid || !this.rootimg) {
150                 removeChildren(link);
151                 _apc(link,stimgopen.cloneNode(true));
152         }
153         link.setAttribute('href','javascript:' + this.handle + '.open("'+id+'");');
154         hideMe($('stcont_' + id));
155         $(id).setAttribute('ostate','1');
156 }
157