LP#1849212 OPAC Search Course Reserves Facet user/zbanks/lp1849212-OPACE-search-course-reserves
authorZavier Banks <zbanks@catalyte.io>
Tue, 26 Nov 2019 22:10:12 +0000 (22:10 +0000)
committerZavier Banks <zbanks@catalyte.io>
Tue, 26 Nov 2019 22:33:28 +0000 (22:33 +0000)
Created a facet that will filter the course
materials against the current search. Using
the checkbox, the user can toggle the
filter on and off.

Signed-off-by: Zavier Banks <zbanks@catalyte.io>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/templates/opac/parts/advanced/search.tt2
Open-ILS/src/templates/opac/parts/result/adv_filter.tt2
Open-ILS/web/js/ui/default/opac/copyloc.js

index 43459a1..73a581e 100644 (file)
@@ -3094,7 +3094,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
             </actions>
         </permacrud>
     </class>
-    <class id="acmcm" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="asset::course_module_course_materials" oils_persist:tablename="asset.course_module_course_materials" reporter:label="Course Materials">
+    <class id="acmcm" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="asset::course_module_course_materials" oils_persist:tablename="asset.course_module_course_materials" reporter:label="Course Materials" oils_persist:field_safe="true">
         <fields oils_persist:primary="id" oils_persist:sequence="asset.course_module_course_materials_id_seq">
             <field reporter:label="ID" name="id" reporter:datatype="id" />
             <field reporter:label="Course" name="course" reporter:datatype="link" />
index 7ac166d..89de95c 100644 (file)
                                 [% l("Group Formats and Editions") %]</label>
                         </div>
                     [% END %]
-
                 [% CASE "copy_location" %]
                     <select id="adv_copy_location_selector"
                         title="[% l('Select Shelving Location') %]"
 [%
         END;
     END; %]
-
+        </div>
+        <div class="adv_filter_block" id='course_reserves_facet'>
+            <div class="adv_filter_block_item">
+                <input type='checkbox' name="coursereserves" value="filtercoursereserves"
+                    onchange="add_course_reserves_ids_to_query()"
+                    [%- CGI.param('coursereserves').grep('filtercoursereserves').size ?
+                        'checked="checked"' : '' %]
+                    id='opac.result.coursereserves' />
+                    <label for='opac.result.coursereserves'>
+                        [% l("Filter With Course Reserves") %]</label>
+                <input type='checkbox' name="query" value=""
+                    [%- CGI.param('coursereserves').grep('filtercoursereserves').size ?
+                        'checked="checked"' : '' %] id='coursereservesvalue' hidden />
+                <input type='checkbox' name="qtype" value="keyword"
+                    [%- CGI.param('coursereserves').grep('filtercoursereserves').size ?
+                        'checked="checked"' : '' %] id='coursereservesqtype' hidden />
+                <input type='checkbox' name="contains" value="contains"
+                    [%- CGI.param('coursereserves').grep('filtercoursereserves').size ?
+                        'checked="checked"' : '' %] id='coursereservescontains' hidden />
+            </div>
         </div>
     </div>
 </div>
index 35b2c77..5b8cf68 100644 (file)
@@ -83,3 +83,14 @@ FOR filter IN ctx.query_struct.filters;
 
 [%- END; # IF pubdate_filters -%]
 [%- END; # FOR -%]
+
+[%IF CGI.param('coursereserves').grep('filtercoursereserves').size >0 %]
+    <div class="adv_filter_results_group_wrapper">
+        <div class="adv_filter_results_group">
+                <h4 class="title">[% l('Course Reserves') %]</h4>
+                <a class="button remove_filter"
+                title="[% l('Remove course reserves filter') %]"
+                href="[% mkurl('', {}, ['coursereserves']) %]" rel="nofollow" vocab=""> &times;</a>
+        </div>
+    </div>
+[%- END %]
index 08023d6..d416143 100644 (file)
@@ -1,10 +1,68 @@
 dojo.require("DojoSRF");
 dojo.require("openils.CGI");
 
+var course_list_query=[];
+course_reserves = dojo.byId("opac.result.coursereserves");
+value = dojo.byId("coursereservesvalue");
+qtype = dojo.byId("coursereservesqtype");
+contains = dojo.byId("coursereservescontains");
+
+/**
+ * Query the database for the course reserves materials.
+ */
+function get_course_reserves(display_orgs) {
+    var params = [{
+        cache : 1, 
+        fields : ['item'],
+        query : {course : display_orgs}
+    }];
+    new OpenSRF.ClientSession('open-ils.fielder').request({
+        method: 'open-ils.fielder.acmcm.atomic',
+        params: params,
+        async: true,
+        oncomplete: function(r) {
+            var resp = r.recv();
+            if (resp) {
+                var list = resp.content();
+                //List out all the items, and add them to a list.
+                dojo.forEach(list, function(item, index) {
+                    if(index == 0){ //If this is the first entry, create the string.
+                        course_list_query = "((id:"+item.item+")";
+                    } else{ course_list_query += "||(id:"+item.item+")";}
+                })
+                course_list_query += ")";
+                filter_reserves();
+            }
+        }
+    }).send(); 
+}
+
+/**
+ * Add the query to the filterwithreserves checkbox
+ */
+function filter_reserves() {
+    value.setAttribute('value', course_list_query)
+}
+
+window.add_course_reserves_ids_to_query = add_course_reserves_ids_to_query;
+function add_course_reserves_ids_to_query() {
+    //Resets the Course Reserves Facet, if unchecked.
+    if(!course_reserves.getAttribute("checked") || course_reserves.getAttribute("checked") == "") {
+        course_reserves.setAttribute("checked", 'checked')
+        value.setAttribute("checked", 'checked')
+        qtype.setAttribute("checked", 'checked')
+        contains.setAttribute("checked", 'checked')
+    }else {
+        dojo.removeAttr(course_reserves, 'checked');
+        dojo.removeAttr(value, 'checked');
+        dojo.removeAttr(qtype, 'checked');
+        dojo.removeAttr(contains, 'checked');
+    }
+}
+
 // called on initial page load and when the advance search org unit
 // selector is changed.
 function apply_adv_copy_locations() {
-
     // patron selected org
     var sel = dojo.byId('adv_org_selector');
     var selected_id = sel.options[sel.selectedIndex].getAttribute('value');
@@ -32,6 +90,7 @@ function apply_adv_copy_locations() {
     display_orgs.push(org_unit.id);
     collect_parent_orgs(org_unit.parent_ou);
     fetch_adv_copy_locations(display_orgs);
+    get_course_reserves(display_orgs)
 }
 
 function fetch_adv_copy_locations(org_ids) {
@@ -58,7 +117,7 @@ function fetch_adv_copy_locations(org_ids) {
             } else {
                 dojo.addClass('adv_chunk_copy_location', 'hidden');
             }
-        }                                                              
+        }
     }).send(); 
 }
 
@@ -72,9 +131,8 @@ function render_adv_copy_locations(locations) {
         if (!dojo.isArray(url_selected)) 
             url_selected = [url_selected];
     }
-
     dojo.removeClass('adv_chunk_copy_location', 'hidden');
-    
+
     // sort by name
     locations = locations.sort(
         function(a, b) {return a.name < b.name ? -1 : 1}