allow more complex facet ordering
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 26 Sep 2010 15:31:41 +0000 (15:31 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 26 Sep 2010 15:31:41 +0000 (15:31 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@18007 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/widget/FacetSidebar.js

index 3ac08e7..76c6684 100644 (file)
  * ---------------------------------------------------------------------------
  */
 
+/*  Example markup:
+
+<div id='facetSidebarContainer' class='hide_me'>
+
+    <div class="side_bar_item" style="margin-top: 10px; font-weight: bold;">
+        <span>&navigate.facetRefine;</span>
+    </div>
+
+    <div
+        dojoType='openils.widget.FacetSidebar'
+        searchBox='facet_box'
+        searchSubmit='search_submit'
+        facetLimit='5'
+        maxValuesPerFacet='10'
+        classOrder='[{"name":"author","facetOrder":["personal","corporate"]},{"name":"subject","facetOrder":["topic"]},"series",{"name":"subject","facetOrder":["name","geographic"]}]'
+    >
+        <script type='dojo/method' event='populate'><![CDATA[
+            var f_sidebar = this;
+            attachEvt("result", "allRecordsReceived", function () {
+                if(!resultFacetKey) return;
+                if (f_sidebar.facetCacheKey) return; // already rendered it
+
+                dojo.removeClass('facetSidebarContainer','hide_me');
+
+                f_sidebar.facetCacheKey = resultFacetKey;
+                f_sidebar.render();
+            });
+        ]]></script>
+    </div>
+</div>
+
+ */
+
+
 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 );
                     }
                 );