Bug 25553: Make date columns sortable on the edit items table
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 22 May 2020 09:02:39 +0000 (11:02 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 24 Jun 2020 12:23:23 +0000 (14:23 +0200)
When editing items, the table at the top contain several columns that
have date values, but they cannot be sorted by dates correctly.

Test plan:
Have several items with different dates in columns that contain dates,
like items.dateaccessioned, items.datelastseen)
Sort the column and confirm that with this patch the lines are sorted
correctly

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

cataloguing/additem.pl
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt

index b0ce8b5..130ff0a 100755 (executable)
@@ -872,7 +872,7 @@ for my $row ( @big_array ) {
         {
             my ( undef, $subfield ) = GetMarcFromKohaField($kohafield);
             next unless $key eq $subfield;
-            $item_field->{field} = output_pref( { str => $row->{$key}, dateonly => 1 } );
+            $item_field->{datatype} = 'date';
         }
 
         push @item_fields, $item_field;
index 463edf4..f8fff0d 100644 (file)
@@ -1,6 +1,7 @@
 [% USE raw %]
 [% USE Asset %]
 [% USE Koha %]
+[% USE KohaDates %]
 [% USE ColumnsSettings %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Cataloging &rsaquo; [% title | html %] [% IF ( author ) %] by [% author | html %][% END %] (Record #[% biblionumber | html %]) &rsaquo; Items</title>
@@ -45,6 +46,7 @@
 
 <div id="cataloguing_additem_itemlist">
     [% IF ( item_loop ) %]
+        [% SET date_fields = [ 'dateaccessioned', 'onloan', 'datelastseen', 'datelastborrowed', 'replacementpricedate' ] %]
         <div>
         <table id="itemst">
           <thead>
                 <th>&nbsp;</th>
                 [% FOREACH item_header IN item_header_loop %]
                     [% IF item_header.column_name %]
-                        <th data-colname="[% item_header.column_name | html %]">
+                        [% IF date_fields.grep(item_header.column_name).size %]
+                            <th class="title-string" data-colname="[% item_header.column_name | html %]">
+                        [% ELSE %]
+                            <th data-colname="[% item_header.column_name | html %]">
+                        [% END %]
                     [% ELSE %]
                         <th>
                     [% END %]
                       </td>
                     [% END %]
                 [% FOREACH item_valu IN item_loo.item_value %]
-                    <td>[% item_valu.field | html %]</td>
+                    [% IF item_valu.datatype == 'date' %]
+                        <td><span title="[% item_valu.field | html %]">[% item_valu.field | $KohaDates %]</span></td>
+                    [% ELSE %]
+                        <td>[% item_valu.field | html %]</td>
+                    [% END %]
                 [% END %]
                 </tr>
                 [% END %]