]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/common/js/slimtree.js
6efc32814a025ea560bc47a64d3186fe448aae1a
[Evergreen.git] / Open-ILS / web / opac / common / js / slimtree.js
1 var stpicopen   = '../../../images/slimtree/folder.gif';
2 var stpicclose = '../../../images/slimtree/folderopen.gif';
3 var stpicblank = '../../../images/slimtree/page.gif';
4 var stpicline   = '../../../images/slimtree/line.gif';
5 var stpicjoin   = '../../../images/slimtree/join.gif';
6 var stpicjoinb = '../../../images/slimtree/joinbottom.gif';
7
8 var stimgopen   = elem('img',{src:stpicopen,border:0});
9 var stimgclose  = elem('img',{src:stpicclose,border:0});
10 var stimgblank  = elem('img',{src:stpicblank,border:0});
11 var stimgline   = elem('img',{src:stpicline,border:0});
12 var stimgjoin   = elem('img',{src:stpicjoin,border:0, style:'display:inline;'});
13
14 function SlimTree(context) { this.context = context; }
15
16 SlimTree.prototype.addNode = function( id, pid, name, action ) {
17
18         var div                 = elem('div',{id:id});
19         var topdiv              = elem('div',{style:'vertical-align:middle'});
20         var link                        = elem('a', {id:'stlink_' + id}); 
21         var actionref   = elem('a',{href:action}, name);
22         var contdiv             = elem('div',{id:'stcont_' + id});
23
24         topdiv.appendChild(link);
25         topdiv.appendChild(actionref);
26         div.appendChild(topdiv);
27         div.appendChild(contdiv);
28
29         if( pid == -1 ) { 
30                 this.rootid = id;
31                 this.context.appendChild(div);
32                 link.appendChild(stimgblank.cloneNode(true));
33         } else {
34                 if(pid == this.rootid) stOpen(pid);
35                 else stClose(pid);
36                 getId(pid).setAttribute('haschild','1');
37                 link.appendChild(stimgblank.cloneNode(true));
38                 div.style.paddingLeft = '18px';
39                 div.style.backgroundImage = 'url('+stpicjoinb+')';
40                 div.style.backgroundRepeat = 'no-repeat';
41                 getId('stcont_' + pid).appendChild(div);
42                 if (div.previousSibling) {
43                         div.previousSibling.firstChild.appendChild(stimgjoin.cloneNode(true));
44                         div.previousSibling.firstChild.appendChild(div.previousSibling.firstChild.firstChild);
45                         div.previousSibling.firstChild.appendChild(div.previousSibling.firstChild.firstChild);
46                         div.previousSibling.firstChild.firstChild.style.marginLeft = '-18px';
47
48                         div.previousSibling.style.backgroundImage = 'url('+stpicline+')';
49                         div.previousSibling.style.backgroundRepeat = 'repeat-y';
50                 }
51         }
52 }
53
54 SlimTree.prototype.expandAll = function() { stFlex(this.rootid, 'open'); }
55 SlimTree.prototype.closeAll = function() { stFlex(this.rootid,'close', this.rootid); }
56 function stFlex(id, type, root) {
57         if(type=='open') stOpen(id);
58         else { if (id != root) stClose(id); }
59         var n = getId('stcont_' + id);
60         for( var c = 0; c != n.childNodes.length; c++ ) {
61                 var ch = n.childNodes[c];
62                 if(ch.nodeName.toLowerCase() == 'div') {
63                         if(getId(ch.id).getAttribute('haschild') == '1') 
64                                 stFlex(ch.id, type);
65                 }
66         }
67 }
68
69 function stOpen( id ) {
70         var link = getId('stlink_' + id);
71         removeChildren(link);
72         link.appendChild(stimgclose.cloneNode(true));
73         link.setAttribute('href','javascript:stClose("'+id+'");');
74         unHideMe(getId('stcont_' + id));
75 }
76
77 function stClose( id ) {
78         var link = getId('stlink_' + id);
79         removeChildren(link);
80         link.appendChild(stimgopen.cloneNode(true));
81         link.setAttribute('href','javascript:stOpen("'+id+'");');
82         hideMe(getId('stcont_' + id));
83 }
84