Lp# 1849212 OPAC Search Course Reserves Facet
authorZavier Banks <zbanks@catalyte.io>
Thu, 21 Nov 2019 21:20:52 +0000 (21:20 +0000)
committerZavier Banks <zbanks@catalyte.io>
Thu, 21 Nov 2019 21:20:52 +0000 (21:20 +0000)
I'm currently in the process of adding a new component
that will filter the course reserves materials against
the queried records. I've added both the html and database
querying. All that left is to sort out a few bugs.

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/web/js/ui/default/opac/copyloc.js

index e5b9f19..f2e9dc7 100644 (file)
@@ -3093,7 +3093,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..b193c25 100644 (file)
@@ -2,6 +2,7 @@
     PROCESS "opac/parts/misc_util.tt2";
     PROCESS get_library;
 %]
+
 <form action="[% ctx.opac_root %]/results" method="get">
 <div id='adv_global_search' class='data_grid data_grid_center'>
     <div id='adv_search_rows'>
                         </div>
                     [% END %]
 
+                <div class="adv_course_materials_filter" id='course_reserves_facet'>
+                    <input type='checkbox' name="coursereserves" value="filtercoursereserves"
+                        onclick="add_course_reserves_ids_to_query()"
+                        [%- CGI.param('coursereserves').grep(filtercoursereserves).size ?
+                            'checked="checked"' : '' %]
+                        id='opac.result.filterwithreserves' />
+                        <label for='opac.result.filterwithreserves'>
+                            [% 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>
+
                 [% CASE "copy_location" %]
                     <select id="adv_copy_location_selector"
                         title="[% l('Select Shelving Location') %]"
index 08023d6..5b3ee03 100644 (file)
@@ -1,6 +1,66 @@
 dojo.require("DojoSRF");
 dojo.require("openils.CGI");
 
+
+var course_list_query=[];
+
+/**
+ * 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+") ";}
+                })
+                filter_reserves();
+            }
+        }
+    }).send(); 
+}
+
+
+/**
+ * Add the query to the filterwithreserves checkbox
+ */
+function filter_reserves() {
+    dojo.byId("coursereservesvalue").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() {
+    course_reserves = dojo.byId("opac.result.filterwithreserves");
+    
+    if(!course_reserves.getAttribute("checked") || course_reserves.getAttribute("checked")=="") {
+        console.log("Checked", course_reserves.getAttribute("checked") )
+        course_reserves.setAttribute("checked", 'checked')
+        dojo.byId("coursereservesvalue").setAttribute("checked", 'checked')
+        dojo.byId("coursereservesqtype").setAttribute("checked", 'checked')
+        dojo.byId("coursereservescontains").setAttribute("checked", 'checked')
+    }else {
+        console.log("Unchecked", course_reserves.getAttribute("checked") )
+        course_reserves.setAttribute("checked", '')
+        dojo.byId("coursereservesvalue").setAttribute("checked", '')
+        dojo.byId("coursereservesqtype").setAttribute("checked", '')
+        dojo.byId("coursereservescontains").setAttribute("checked", '')
+    } 
+}
+
 // called on initial page load and when the advance search org unit
 // selector is changed.
 function apply_adv_copy_locations() {
@@ -32,6 +92,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 +119,7 @@ function fetch_adv_copy_locations(org_ids) {
             } else {
                 dojo.addClass('adv_chunk_copy_location', 'hidden');
             }
-        }                                                              
+        }
     }).send(); 
 }
 
@@ -72,9 +133,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}