Bug 16759: Make OPAC holdings table configurable
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 28 Jul 2017 19:28:08 +0000 (16:28 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 25 Oct 2017 15:14:40 +0000 (12:14 -0300)
This patch makes the holdings table in the OPAC biblio detail page
configurable using the Columns configuration tools.

This patch:
- Moves the holdingst table from plain DataTable to KohaTable
- Creates a sample yml colvis configuration for this table
  containing all the currently available columns

To test:
- Visit some record's detail page in the OPAC
- Apply this patch
- Reload
=> SUCCESS: The page shows the same information
- On the staff interface, go to:
  Home > Administration > Columns settings
=> SUCCESS: There's a new OPAC section containing the configuration for
   holdingst.
- Choose to hide some fields (both currently displayed and currently hidden).
- Reload the OPAC detail page
=> SUCCESS:
   - Required fields are hidden
   - It doesn't explode because of trying to hide stuff that is not there to start with
- Sign off :-D

Sponsored-by: DOVER
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Followed test plan, patch worked as described. Also passed QA test tool

Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
admin/columns_settings.yml
koha-tmpl/intranet-tmpl/prog/en/modules/admin/columns_settings.tt
koha-tmpl/opac-tmpl/bootstrap/en/includes/columns_settings.inc [new file with mode: 0644]
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt

index 5198c0d..ab23de9 100644 (file)
@@ -255,6 +255,40 @@ modules:
           cannot_be_toggled: 1
           cannot_be_modified: 1
 
+  opac:
+    biblio-detail:
+      holdingst:
+        -
+          columnname: item_itemtype
+        -
+          columnname: item_current_location
+        -
+          columnname: item_home_location
+        -
+          columnname: item_ccode
+        -
+          columnname: item_callnumber
+        -
+          columnname: item_enumchron
+        -
+          columnname: item_url
+        -
+          columnname: item_copy
+        -
+          columnname: item_status
+        -
+          columnname: item_notes
+        -
+          columnname: item_datedue
+        -
+          columnname: item_barcode
+        -
+          columnname: item_holds
+        -
+          columnname: item_priority
+        -
+          columnname: item_coursereserves
+
   reports:
     lostitems:
       lostitems-table:
index 4bdaf07..884cc77 100644 (file)
             [% PROCESS pagelist module=modules.members modulename="members" %]
           </div>
 
+          <h3><a href="#opac">OPAC</a></h3>
+          <div id="opac">
+            <h4>OPAC tables</h4>
+            [% PROCESS pagelist module=modules.opac modulename="opac" %]
+          </div>
+
           <h3><a href="#reports">Reports</a></h3>
           <div id="reports">
             <h4>Reports tables</h4>
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/columns_settings.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/columns_settings.inc
new file mode 100644 (file)
index 0000000..b065a35
--- /dev/null
@@ -0,0 +1,37 @@
+[% USE ColumnsSettings %]
+
+<script type="text/javascript">
+function KohaTable(selector, dt_parameters, columns_settings) {
+    var id = 0;
+    var hidden_ids = [];
+    var included_ids = [];
+    $(columns_settings).each( function() {
+        var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( 'th' );
+        var used_id = dt_parameters.bKohaColumnsUseNames ? named_id : id;
+        if ( used_id == -1 ) return;
+
+        if ( this['is_hidden'] == "1" ) {
+            hidden_ids.push( used_id );
+        }
+        if ( this['cannot_be_toggled'] == "0" ) {
+            included_ids.push( used_id );
+        }
+        id++;
+    });
+    dt_parameters[ "buttons" ] = [
+        {
+            extend: 'colvis',
+            columns: included_ids,
+            text: _("Column visibility"),
+        }
+    ];
+    var table = $(selector).dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
+
+    $(hidden_ids).each(function(index, value) {
+        table.fnSetColumnVis( value, false );
+    });
+
+    return table;
+}
+
+</script>
index 8d0fae1..528d7d2 100644 (file)
@@ -2,6 +2,7 @@
 [% USE Koha %]
 [% USE KohaDates %]
 [% USE Branches %]
+[% USE ColumnsSettings %]
 [% USE AuthorisedValues %]
 [% SET TagsShowEnabled = ( ( Koha.Preference( 'TagsEnabled' ) == 1 ) && TagsShowOnDetail ) %]
 [% SET TagsInputEnabled = ( ( Koha.Preference( 'opacuserlogin' ) == 1 ) && ( Koha.Preference( 'TagsEnabled' ) == 1 ) && TagsInputOnDetail ) %]
     <table class="holdingst table table-bordered table-striped">
         <thead>
             <tr>
-                [% IF ( item_level_itypes ) %]<th id="item_itemtype" class="itype">Item type</th>[% END %]
-                [% IF ( OpacLocationBranchToDisplay == 'holding' || OpacLocationBranchToDisplay == 'both' ) %]
-                    <th id="item_current_location" class="item_location">Current location</th>
-                [% END %]
-                [% IF ( OpacLocationBranchToDisplay == 'home' || OpacLocationBranchToDisplay == 'both' ) %]
-                    <th id="item_home_location" class="item_location">Home library</th>
-                [% END %]
-                [% IF ( itemdata_ccode ) %]<th id="item_ccode" class="collection">Collection</th>[% END %]
-                <th id="item_callnumber" class="call_no">Call number</th>
-                [% IF ( itemdata_enumchron ) %]<th id="item_enumchron" class="vol_info">Vol info</th>[% END %]
-                [% IF ( itemdata_uri ) %]<th id="item_url" class="url">URL</th>[% END %]
-                [% IF ( itemdata_copynumber ) %]<th id="item_copy" class="copynumber">Copy number</th>[% END %]
-                <th id="item_status" class="status">Status</th>
-                [% IF ( itemdata_itemnotes ) %]<th id="item_notes" class="notes">Notes</th>[% END %]
-                <th id="item_datedue" class="date_due">Date due</th>
-                [% IF ( OPACShowBarcode ) %]<th id="item_barcode" class="barcode">Barcode</th>[% END %]
-                [% IF holds_count.defined %]
-                    <th id="item_holds">Item holds</th>
-                [% ELSIF show_priority %]
-                    <th id="item_priority">Item hold queue priority</th>
-                [% END %]
-                [% IF ( ShowCourseReservesHeader ) %]<th id="item_coursereserves">Course reserves</th>[% END %]
+        [% IF ( item_level_itypes ) %]
+                <th id="item_itemtype" data-colname="item_itemtype" class="itype">Item type</th>[% END %]
+        [% IF ( OpacLocationBranchToDisplay == 'holding' || OpacLocationBranchToDisplay == 'both' ) %]
+                <th id="item_current_location" data-colname="item_current_location" class="item_location">Current location</th>[% END %]
+        [% IF ( OpacLocationBranchToDisplay == 'home' || OpacLocationBranchToDisplay == 'both' ) %]
+                <th id="item_home_location" data-colname="item_home_location" class="item_location">Home library</th>[% END %]
+        [% IF ( itemdata_ccode ) %]
+                <th id="item_ccode" data-colname="item_ccode" class="collection">Collection</th>[% END %]
+                <th id="item_callnumber" data-colname="item_callnumber" class="call_no">Call number</th>
+        [% IF ( itemdata_enumchron ) %]
+                <th id="item_enumchron" data-colname="item_enumchron" class="vol_info">Vol info</th>[% END %]
+        [% IF ( itemdata_uri ) %]
+                <th id="item_url" data-colname="item_url" class="url">URL</th>[% END %]
+        [% IF ( itemdata_copynumber ) %]
+                <th id="item_copy" data-colname="item_copy" class="copynumber">Copy number</th>[% END %]
+                <th id="item_status" data-colname="item_status" class="status">Status</th>
+        [% IF ( itemdata_itemnotes ) %]
+                <th id="item_notes" data-colname="item_notes" class="notes">Notes</th>[% END %]
+                <th id="item_datedue" data-colname="item_datedue" class="date_due">Date due</th>
+        [% IF ( OPACShowBarcode ) %]
+                <th id="item_barcode" data-colname="item_barcode" class="barcode">Barcode</th>[% END %]
+        [% IF holds_count.defined %]
+                <th id="item_holds" data-colname="item_holds">Item holds</th>
+        [% ELSIF show_priority %]
+                <th id="item_priority" data-colname="item_priority">Item hold queue priority</th>
+        [% END %]
+        [% IF ( ShowCourseReservesHeader ) %]
+                <th id="item_coursereserves" data-colname="item_coursereserves">Course reserves</th>[% END %]
             </tr>
         </thead>
         <tbody>
 
 [% BLOCK jsinclude %]
 [% INCLUDE 'datatables.inc' %]
+[% INCLUDE 'columns_settings.inc' %]
 [% IF ( SocialNetworks ) %]
     <script type="text/javascript" src="https://apis.google.com/js/plusone.js">
     //<![CDATA[
                 return element.html();
             }
         });
+
+        var columns_settings = [% ColumnsSettings.GetColumns( 'opac', 'biblio-detail', 'holdingst', 'json' ) %];
+        KohaTable(".holdingst", {
+            dom: 'B<"clearfix">t',
+            "columnDefs": [
+                { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
+                { "sType": "title-string", "aTargets" : [ "title-string" ] }
+                ],
+            "bKohaColumnsUseNames": true
+        }, columns_settings);
+
 [% IF ( TagsInputEnabled && loggedinusername ) %]
         $(".tag_add").click(function(){
             var thisid = $(this).attr("id");
         [% ELSE %]
             var default_order_index = 0;
         [% END %]
-        $(".holdingst").dataTable($.extend(true, {}, dataTablesDefaults, {
-            "aoColumns": [
-                [% IF ( item_level_itypes ) %]null,[% END %]
-                [% IF ( OpacLocationBranchToDisplay == 'holding' || OpacLocationBranchToDisplay == 'both' ) %]null,[% END %]
-                [% IF ( OpacLocationBranchToDisplay == 'home' || OpacLocationBranchToDisplay == 'both' ) %]null,[% END %]
-                [% IF ( itemdata_ccode ) %]null,[% END %]
-                null,
-                [% IF ( itemdata_enumchron ) %]null,[% END %]
-                [% IF ( itemdata_uri ) %]null,[% END %]
-                [% IF ( itemdata_copynumber ) %]null,[% END %]
-                null,
-                [% IF ( itemdata_itemnotes ) %]null,[% END %]
-                { "sType": "title-string" },
-                [% IF ( OPACShowBarcode ) %]null,[% END %]
-                [% IF holds_count.defined %]
-                    null,
-                [% ELSIF show_priority %]
-                    null,
-                [% END %]
-                [% IF ( ShowCourseReservesHeader ) %]null,[% END %]
-            ],
-            "aaSorting": [[ default_order_index, 'asc' ]]
-        }));
 
         [% IF ( query_desc ) %][% IF ( OpacHighlightedWords ) %]var query_desc = "[% query_desc |replace("'", "\'") |replace('\n', '\\n') |replace('\r', '\\r') |html %]";
             q_array = query_desc.split(" ");