From 4ae16b85edf81785c41594ad9a4d7b09e2c1bc2e Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 14 Nov 2005 15:10:30 +0000 Subject: [PATCH] added toggle method to slimtree 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 | 14 ++-- Open-ILS/web/opac/common/js/slimtree.js | 69 +++++++++---------- Open-ILS/web/opac/common/js/utils.js | 2 +- Open-ILS/web/opac/skin/default/js/mresult.js | 8 +-- .../web/opac/skin/default/js/result_common.js | 1 + .../web/opac/skin/default/js/search_bar.js | 2 + Open-ILS/web/opac/skin/default/xml/index.xml | 1 + .../web/opac/skin/default/xml/sidebar.xml | 15 ++-- 8 files changed, 60 insertions(+), 52 deletions(-) diff --git a/Open-ILS/web/opac/common/js/opac_utils.js b/Open-ILS/web/opac/common/js/opac_utils.js index e500548c8a..8c823d0a34 100644 --- a/Open-ILS/web/opac/common/js/opac_utils.js +++ b/Open-ILS/web/opac/common/js/opac_utils.js @@ -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; } diff --git a/Open-ILS/web/opac/common/js/slimtree.js b/Open-ILS/web/opac/common/js/slimtree.js index 46d4a6b655..9228d39d59 100644 --- a/Open-ILS/web/opac/common/js/slimtree.js +++ b/Open-ILS/web/opac/common/js/slimtree.js @@ -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'); } diff --git a/Open-ILS/web/opac/common/js/utils.js b/Open-ILS/web/opac/common/js/utils.js index 9addb0077d..1dbbd60236 100644 --- a/Open-ILS/web/opac/common/js/utils.js +++ b/Open-ILS/web/opac/common/js/utils.js @@ -1,4 +1,4 @@ - +function $(id) { return getId(id); } function getId(id) { return document.getElementById(id); } diff --git a/Open-ILS/web/opac/skin/default/js/mresult.js b/Open-ILS/web/opac/skin/default/js/mresult.js index 8d18919129..9c84c1ab4e 100644 --- a/Open-ILS/web/opac/skin/default/js/mresult.js +++ b/Open-ILS/web/opac/skin/default/js/mresult.js @@ -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()]; } diff --git a/Open-ILS/web/opac/skin/default/js/result_common.js b/Open-ILS/web/opac/skin/default/js/result_common.js index 1d42024f8e..6eea11de08 100644 --- a/Open-ILS/web/opac/skin/default/js/result_common.js +++ b/Open-ILS/web/opac/skin/default/js/result_common.js @@ -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']; diff --git a/Open-ILS/web/opac/skin/default/js/search_bar.js b/Open-ILS/web/opac/skin/default/js/search_bar.js index 139573da5c..4dfd061b53 100644 --- a/Open-ILS/web/opac/skin/default/js/search_bar.js +++ b/Open-ILS/web/opac/skin/default/js/search_bar.js @@ -46,8 +46,10 @@ function searchBarInit() { } function _opacHandleLocationTagClick() { + /* orgTreeSelector.openTo( (newSearchLocation != null) ? parseInt(newSearchLocation) : getLocation(), true ); + */ swapCanvas(G.ui.common.org_container); } diff --git a/Open-ILS/web/opac/skin/default/xml/index.xml b/Open-ILS/web/opac/skin/default/xml/index.xml index ba2056aa1e..80a8e556a9 100644 --- a/Open-ILS/web/opac/skin/default/xml/index.xml +++ b/Open-ILS/web/opac/skin/default/xml/index.xml @@ -11,6 +11,7 @@ + diff --git a/Open-ILS/web/opac/skin/default/xml/sidebar.xml b/Open-ILS/web/opac/skin/default/xml/sidebar.xml index da818cfa69..2ab5947e72 100644 --- a/Open-ILS/web/opac/skin/default/xml/sidebar.xml +++ b/Open-ILS/web/opac/skin/default/xml/sidebar.xml @@ -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");'); @@ -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");'); @@ -86,9 +90,12 @@ -- 2.43.2