From: miker Date: Sun, 26 Sep 2010 15:31:41 +0000 (+0000) Subject: allow more complex facet ordering X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a93c992931a205f0160dc6fa161021801fc80519;p=evergreen%2Fbjwebb.git allow more complex facet ordering git-svn-id: svn://svn.open-ils.org/ILS/trunk@18007 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/web/js/dojo/openils/widget/FacetSidebar.js b/Open-ILS/web/js/dojo/openils/widget/FacetSidebar.js index 3ac08e7a4..76c668462 100644 --- a/Open-ILS/web/js/dojo/openils/widget/FacetSidebar.js +++ b/Open-ILS/web/js/dojo/openils/widget/FacetSidebar.js @@ -14,6 +14,40 @@ * --------------------------------------------------------------------------- */ +/* Example markup: + +
+ + + +
+ +
+
+ + */ + + if(!dojo._hasResource["openils.widget.FacetSidebar"]) { dojo._hasResource["openils.widget.FacetSidebar"] = true; @@ -31,7 +65,7 @@ if(!dojo._hasResource["openils.widget.FacetSidebar"]) { facetData : {}, facetCacheKey : '', searchBox : '', - classOrder : null, + classOrder : null, // Array of cmc.name values, OR array of objects with name and facetOrder properties searchSubmit : '', facetLimit : 10, maxValuesPerFacet : 100, @@ -75,7 +109,10 @@ if(!dojo._hasResource["openils.widget.FacetSidebar"]) { classes = []; dojo.forEach( this.classOrder, - function(x) { classes.push({name:x}); } + function(x) { + if (dojo.isObject(x)) classes.push(x); + else classes.push({name:x}); + } ); } @@ -83,13 +120,26 @@ if(!dojo._hasResource["openils.widget.FacetSidebar"]) { dojo.forEach( classes, function (x) { - var possible_facets = dojo.filter( - openils.widget.Searcher._cache.arr.cmf, - function (y) { - if (y.field_class == x.name && facetData[y.id]) return 1; - return 0; - } - ); + var possible_facets = []; + if (x.facetOrder) { + dojo.forEach(x.facetOrder, function(fname) { + possible_facets.push(dojo.filter( + openils.widget.Searcher._cache.arr.cmf, + function (y) { + if (y.field_class == x.name && y.name == fname) return 1; + return 0; + } + )[0]); + }); + } else { + possible_facets = dojo.filter( + openils.widget.Searcher._cache.arr.cmf, + function (y) { + if (y.field_class == x.name && facetData[y.id]) return 1; + return 0; + } + ); + } if (possible_facets.length > 0) me.addClass( x.name, possible_facets ); } );