added toggle method to slimtree
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 14 Nov 2005 15:10:30 +0000 (15:10 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 14 Nov 2005 15:10:30 +0000 (15:10 +0000)
used toggle method to allow open/close on root node of sidebar trees

made parent-less child caching simpler and hopefully faster in slimtree

moved to the org tree over to slim tree to test

git-svn-id: svn://svn.open-ils.org/ILS/trunk@2018 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/opac/common/js/opac_utils.js
Open-ILS/web/opac/common/js/slimtree.js
Open-ILS/web/opac/common/js/utils.js
Open-ILS/web/opac/skin/default/js/mresult.js
Open-ILS/web/opac/skin/default/js/result_common.js
Open-ILS/web/opac/skin/default/js/search_bar.js
Open-ILS/web/opac/skin/default/xml/index.xml
Open-ILS/web/opac/skin/default/xml/sidebar.xml

index e500548..8c823d0 100644 (file)
@@ -415,26 +415,26 @@ function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
 /* build the org tree */
 /* ----------------------------------------------------------------------- */
 function drawOrgTree() {
-       G.ui.common.org_tree.innerHTML = buildOrgSelector().toString();
-       //buildOrgSelector(G.ui.common.org_tree);
+       //G.ui.common.org_tree.innerHTML = buildOrgSelector().toString();
+       buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);
 }
        
 var orgTreeSelector;
 function buildOrgSelector(node) {
-       var tree = new dTree("orgTreeSelector"); 
-       //var tree = new SlimTree(node);
+       //var tree = new dTree("orgTreeSelector"); 
+       var tree = new SlimTree(node,'orgTreeSelector');
+       orgTreeSelector = tree;
        for( var i in orgArraySearcher ) { 
                var node = orgArraySearcher[i];
                if( node == null ) continue;
                if(node.parent_ou() == null)
-                       tree.add(node.id(), -1, node.name(), 
+                       tree.addNode(node.id(), -1, node.name(), 
                                "javascript:orgSelect(" + node.id() + ");", node.name());
                else {
-                       tree.add(node.id(), findOrgUnit(node.parent_ou()).id(), node.name(), 
+                       tree.addNode(node.id(), findOrgUnit(node.parent_ou()).id(), node.name(), 
                                "javascript:orgSelect(" + node.id() + ");", node.name());
                }
        }
-       orgTreeSelector = tree;
        return tree;
 }
 
index 46d4a6b..9228d39 100644 (file)
@@ -18,39 +18,25 @@ function SlimTree(context, handle, rootimg) {
        this.handle             = handle;
        this.cache              = new Object();
        if(rootimg) 
-               this.rootimg = elem('img', {src:rootimg,border:0,style:'padding-right: 4px;'});
+               this.rootimg = elem('img', 
+                       {src:rootimg,border:0,style:'padding-right: 4px;'});
 }
 
-SlimTree.prototype.cacheMe = function( id, pid, name, action, title ) {
-       if(this.cache[id]) return;
-       this.cache[id]                          = {};
-       this.cache[id].pid              = pid
-       this.cache[id].name             = name
-       this.cache[id].action   = action
-       this.cache[id].title            = title
-}
-
-SlimTree.prototype.flushCache = function() {
-       for( var c in this.cache ) {
-               var obj = this.cache[c];
-               if(obj && getId(obj.pid)) {
-                       this.cache[c] = null;
-                       this.addNode(c,obj.pid, obj.name, obj.action,obj.title);
-               }
-       }
+SlimTree.prototype.addCachedChildren = function(pid) {
+       var child;
+       while( child = this.cache[pid].shift() ) 
+               this.addNode( child.id, child.pid, 
+                       child.name, child.action, child.title );
+       this.cache[pid] = null;
 }
 
 SlimTree.prototype.addNode = function( id, pid, name, action, title ) {
 
-       if( pid != -1 && !getId(pid)) {
-               if(this.cache[pid]) {
-                       var obj = this.cache[pid];
-                       this.addNode(pid, obj.pid,obj.name, obj.action,obj.title );
-                       this.cache[pid] = null;
-               } else {
-                       this.cacheMe(id, pid, name, action, title);
-                       return;
-               }
+       if( pid != -1 && !$(pid)) {
+               if(!this.cache[pid]) this.cache[pid] = new Array();
+               this.cache[pid].push(
+                       {id:id,pid:pid,name:name,action:action,title:title });
+               return;
        }
 
        var div                 = elem('div',{id:id});
@@ -68,22 +54,25 @@ SlimTree.prototype.addNode = function( id, pid, name, action, title ) {
        _apc(div,contdiv);
 
        if( pid == -1 ) { 
+
                this.rootid = id;
                _apc(this.context,div);
                if(this.rootimg) _apc(link,this.rootimg.cloneNode(true));
                else _apc(link,stimgblank.cloneNode(true));
+
        } else {
+
                if(pid == this.rootid) this.open(pid);
                else this.close(pid);
-               getId(pid).setAttribute('haschild','1');
+               $(pid).setAttribute('haschild','1');
                _apc(link,stimgblank.cloneNode(true));
                div.style.paddingLeft = '18px';
                div.style.backgroundImage = 'url('+stpicjoinb+')';
                div.style.backgroundRepeat = 'no-repeat';
-               _apc(getId('stcont_' + pid), div);
+               _apc($('stcont_' + pid), div);
                if (div.previousSibling) stMakePaths(div);
        }
-       this.flushCache();
+       if(this.cache[id]) this.addCachedChildren(id);
 }
 
 function stMakePaths(div) {
@@ -100,33 +89,41 @@ SlimTree.prototype.closeAll = function() { this.flex(this.rootid,'close'); }
 SlimTree.prototype.flex = function(id, type) {
        if(type=='open') this.open(id);
        else { if (id != this.rootid) this.close(id); }
-       var n = getId('stcont_' + id);
+       var n = $('stcont_' + id);
        for( var c = 0; c != n.childNodes.length; c++ ) {
                var ch = n.childNodes[c];
                if(ch.nodeName.toLowerCase() == 'div') {
-                       if(getId(ch.id).getAttribute('haschild') == '1') 
+                       if($(ch.id).getAttribute('haschild') == '1') 
                                this.flex(ch.id, type);
                }
        }
 }
 
+SlimTree.prototype.toggle = function(id) {
+       if($(id).getAttribute('ostate') == '1') this.open(id);
+       else if($(id).getAttribute('ostate') == '2') this.close(id);
+}
+
 SlimTree.prototype.open = function(id) {
-       var link = getId('stlink_' + id);
+       if($(id).getAttribute('ostate') == '2') return;
+       var link = $('stlink_' + id);
        if(id != this.rootid || !this.rootimg) {
                removeChildren(link);
                _apc(link,stimgclose.cloneNode(true));
        }
        link.setAttribute('href','javascript:' + this.handle + '.close("'+id+'");');
-       unHideMe(getId('stcont_' + id));
+       unHideMe($('stcont_' + id));
+       $(id).setAttribute('ostate','2');
 }
 
 SlimTree.prototype.close = function(id) {
-       var link = getId('stlink_' + id);
+       var link = $('stlink_' + id);
        if(id != this.rootid || !this.rootimg) {
                removeChildren(link);
                _apc(link,stimgopen.cloneNode(true));
        }
        link.setAttribute('href','javascript:' + this.handle + '.open("'+id+'");');
-       hideMe(getId('stcont_' + id));
+       hideMe($('stcont_' + id));
+       $(id).setAttribute('ostate','1');
 }
 
index 9addb00..1dbbd60 100644 (file)
@@ -1,4 +1,4 @@
-
+function $(id) { return getId(id); }
 function getId(id) {
        return document.getElementById(id);
 }
index 8d18919..9c84c1a 100644 (file)
@@ -46,8 +46,8 @@ function mresultHandleCount(r) {
 function mresultCollectIds(method) {
 
        if(getOffset() == 0) {
-               idsCookie.put(COOKIE_IDS,"");
-               idsCookie.write();
+               //idsCookie.put(COOKIE_IDS,"");
+               //idsCookie.write();
 
        } else {
                var c = JSON2js(idsCookie.get(COOKIE_IDS));
@@ -89,8 +89,8 @@ function mresultSetRecords(idstruct) {
                ranks[x] = parseFloat(idstruct[x - o][1]);
                onlyrecord[x] = parseInt(idstruct[x - o][2]);
        }
-       idsCookie.put(COOKIE_IDS, js2JSON({ recs: records, ranks : ranks }) );
-       idsCookie.write();
+       //idsCookie.put(COOKIE_IDS, js2JSON({ recs: records, ranks : ranks }) );
+       //idsCookie.write();
        TOPRANK = ranks[getOffset()];
 }
 
index 1d42024..6eea11d 100644 (file)
@@ -416,6 +416,7 @@ function resultAppendCrossRef(r) {
        var item                = r._item
        var stype       = r._stype;
        var result      = r.getResultObject();
+       if(!result) return;
        var froms       = result['from'];
        var alsos       = result['also'];
 
index 139573d..4dfd061 100644 (file)
@@ -46,8 +46,10 @@ function searchBarInit() {
 }
 
 function _opacHandleLocationTagClick() {
+       /*
        orgTreeSelector.openTo(  
                (newSearchLocation != null) ? parseInt(newSearchLocation) : getLocation(), true );
+               */
        swapCanvas(G.ui.common.org_container);
 }
 
index ba2056a..80a8e55 100644 (file)
@@ -11,6 +11,7 @@
                <script language='javascript' src='../../../common/js/CGI.js'> </script>
                <script language='javascript' src='../../../common/js/Cookie.js'> </script>
 
+               <script language='javascript' src='../../../common/js/slimtree.js'> </script>
                <script language='javascript' src='../../../common/js/dtree.js'> </script>
                <script language='javascript' src='../../../common/js/JSON.js'> </script>
                <script language='javascript' src='../../../common/js/fmcore.js'> </script>
index da818cf..2ab5947 100644 (file)
@@ -64,7 +64,9 @@
                                document.getElementById('subject_sidebar_tree_div'),
                                'subjectSidebarTree', '../../../images/slimtree/related.jpg');
                        subjectSidebarTree.addNode( 'subjectSidebarTreeRoot', -1, 
-                               "&sidebar.relevantSubjects.headerLabel;", null);
+                               "&sidebar.relevantSubjects.headerLabel;", 
+                               'javascript:subjectSidebarTree.toggle(' +
+                                       '"subjectSidebarTreeRoot");');
                </script>
        </div>
 
@@ -76,7 +78,9 @@
                                document.getElementById('author_sidebar_tree_div'),
                                'authorSidebarTree','../../../images/slimtree/people.jpg');
                        authorSidebarTree.addNode( 'authorSidebarTreeRoot', -1, 
-                               "&sidebar.relevantAuthors.headerLabel;", null);
+                               "&sidebar.relevantAuthors.headerLabel;", 
+                               'javascript:authorSidebarTree.toggle(' +
+                                       '"authorSidebarTreeRoot");');
                </script>
        </div>
 
                <script language='javascript'>
                        var seriesSidebarTree = new SlimTree(
                                document.getElementById('series_sidebar_tree_div'),
-                               'seriesSidebarTree','../../../images/slimtree/houses.jpg');
+                               'seriesSidebarTree',
+                               '../../../images/slimtree/houses.jpg');
                        seriesSidebarTree.addNode( 'seriesSidebarTreeRoot', -1, 
-                               "&sidebar.relevantSeries.headerLabel;", null);
+                               "&sidebar.relevantSeries.headerLabel;", 
+                               'javascript:seriesSidebarTree.toggle(' +
+                                       '"seriesSidebarTreeRoot");');
                </script>
        </div>