JBAS-1932 New headings UI mattype filter
authorBill Erickson <berickxx@gmail.com>
Thu, 30 Nov 2017 17:15:22 +0000 (12:15 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Adds a new mattype (format) exclusion filter for the New Headings Report
interface.

Also adds a new 'Format' field to the headings list display.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/cat/authority/new_headings.tt2
Open-ILS/web/js/ui/default/cat/authority/new_headings.js

index 9060e45..0ec57cf 100644 (file)
@@ -6,7 +6,7 @@
 
 <style type="text/css">
 
-  .date-input { width: 6em; }
+  .date-input { width: 7em; }
 
   #headings-table th {
     font-weight: bold;
     background-color: white;
   }
 
+  #mattype-select-container {
+    font-size: 120%;
+    position:fixed;
+    top: 0px;
+    right: 50px;
+    text-align:right;
+    padding: 4px 8px 4px 8px;
+    background-color: white;
+    border-radius: 0px 0px 8px 8px;
+    border: 2px solid #9ee7fa;
+    border-top: none;
+    border-right-radius: 0px;
+  }
+
+
   #navigation-div {
     background-color: #9ee7fa;
     border-bottom: solid grey 1px;
     padding: 3px;
   }
 
+  #mattype-select-container option {
+    padding: 2px;
+  }
+
 </style>
 
 <div id='navigation-div-container'>
         class='date-input' dojoType='dijit.form.DateTextBox'/></span>
       <span>End Date: <input type='text' jsId='endDate'
         class='date-input' dojoType='dijit.form.DateTextBox'/></span>
-      <span><button id='apply-dates-btn'>Apply Dates</button></span>
+      <span><button id='apply-dates-btn'>Apply</button></span>
     </div>
     <div style='padding-left: 20px; padding-right: 20px; float:left'>|</div>
     <div style='float:left'>
   <div id='navigation-div-pad'></div>
 </div>
 
+<div id='mattype-select-container'>
+  <div style='padding-bottom: 7px'>
+    <b>Excluded These Formats</b>
+  </div>
+  <div id='mattype-filter-template'>
+    <span name='mattype-name'></span> 
+    <input name='mattype-checkbox' type='checkbox'/>
+  </div>
+</div>
+
 <div id='below-nav-div'>
 
   <div id='loading-indicator' class="hidden">
               <td>From 245:</td>
               <td><span name='bib_marc_245'></span></td>
             </tr>
+            <tr>
+              <td>Format:</td>
+              <td><span name='mattype_label'></span></td>
           </table>
         </td>
       </tr>
index 751fd93..47ce3c7 100644 (file)
@@ -20,6 +20,9 @@ var headings_tbody;
 var template_row;
 var cached_headings
 var all_fetched;
+var mattypes = [];
+var mattype_container;
+var mattype_template;
 
 // Force a minimum start date for new headings to avoid reporting on
 // (practically) all headings, which occurs when the start date preceeds
@@ -68,6 +71,14 @@ function load() {
             dojo.byId('headings-row-template'));
     } 
 
+    if (!mattype_container) {
+        mattype_container = dojo.byId('mattype-select-container');
+        mattype_template = mattype_container.removeChild(
+            dojo.byId('mattype-filter-template'));
+    }
+
+    fetch_mattypes();
+
     setup_paging();
 
     dojo.byId('apply-dates-btn').onclick = function() {
@@ -82,6 +93,27 @@ function load() {
     endDate.attr('value', initDate);
 }
 
+function fetch_mattypes() {
+
+    pcrud.search('ccvm', {ctype : 'mattype'}, {
+        order_by : {ccvm : ['value']},
+        async : true,
+        oncomplete : function(r) { 
+            mattypes = openils.Util.readResponse(r);
+            dojo.forEach(mattypes, function(type) {
+                var row = mattype_template.cloneNode(true);
+                var namebox = openils.Util.getNodeByName('mattype-name', row);
+                var chkbox = openils.Util.getNodeByName('mattype-checkbox', row);
+                chkbox.setAttribute('code', type.code());
+                namebox.innerHTML = type.value();
+                // also modify checkbox by clicking on label
+                namebox.onclick = function() {chkbox.checked = !chkbox.checked}
+                mattype_container.appendChild(row);
+            });
+        }
+    });
+}
+
 // Fetch headings.
 // Limiting each pcrud query by browse_axis significantly speeds up
 // the DB query, so fetch in order of display: author -> subject -> series.
@@ -117,7 +149,7 @@ function load_headings(is_new, new_page) {
     /* cache 4 pages, plus 1 heading at a time */
     var fetch_count = page_size * 4 + 1;
 
-    pcrud.search('rcbe', compile_date_filter(), {
+    pcrud.search('rcbe', compile_query_filter(), {
         offset : page_offset,
         limit : fetch_count, 
         async : true,
@@ -134,7 +166,7 @@ function load_headings(is_new, new_page) {
     });
 }
 
-function compile_date_filter() {
+function compile_query_filter() {
     start_date = startDate.attr('value');
     end_date = endDate.attr('value');
 
@@ -158,21 +190,29 @@ function compile_date_filter() {
         end_date = openils.Util.getYMD(end_date);
     }
 
-    var date_filter = {}
+    var query_filter = {}
 
     if (start_date && end_date) {
         // use -and instead of BETWEEN so that end_date is not inclusive.
-        date_filter['-and'] = [
+        query_filter['-and'] = [
             {heading_date : {'>=' : start_date}},
             {heading_date : {'<' : end_date}}
         ];
     } else if (start_date) {
-        date_filter.heading_date = {'>=' : start_date};
+        query_filter.heading_date = {'>=' : start_date};
     } else {
-        date_filter.heading_date = {'<' : end_date};
+        query_filter.heading_date = {'<' : end_date};
     }
 
-    return date_filter;
+    dojo.query('[name=mattype-checkbox]').forEach(function(chkbox) {
+        if (chkbox.checked) {
+            if (!query_filter.mattype)
+                query_filter.mattype = {'not in' : []};
+            query_filter.mattype['not in'].push(chkbox.getAttribute('code'));
+        }
+    });
+
+    return query_filter;
 }
 
 function page_number() {
@@ -286,6 +326,10 @@ function draw() {
                 }
             }
         });
+
+        openils.Util.getNodeByName('mattype_label', row).innerHTML = 
+            mattypes.filter(function(m) {
+                return m.code() == heading.mattype() })[0].value();
     });
 }