Bug 18394: Remove useless code from item search
authorJulian Maurice <julian.maurice@biblibre.com>
Thu, 6 Apr 2017 12:26:08 +0000 (14:26 +0200)
committerKyle M Hall <kyle@bywatersolutions.com>
Thu, 13 Apr 2017 12:52:50 +0000 (08:52 -0400)
The item search was originally designed to work even with JS disabled.
Since bug 15111, the staff interface does not work at all without JS, so some
parts of this code are useless and should be removed

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

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

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

catalogue/itemsearch.pl
koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.inc [deleted file]
koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_items.inc [deleted file]
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt

index fa6b357..66a9cf7 100755 (executable)
@@ -36,10 +36,10 @@ my $cgi = new CGI;
 my %params = $cgi->Vars;
 
 my $format = $cgi->param('format');
-my ($template_name, $content_type);
+my $template_name = 'catalogue/itemsearch.tt';
+
 if (defined $format and $format eq 'json') {
     $template_name = 'catalogue/itemsearch_json.tt';
-    $content_type = 'json';
 
     # Map DataTables parameters with 'regular' parameters
     $cgi->param('rows', scalar $cgi->param('iDisplayLength'));
@@ -75,10 +75,8 @@ if (defined $format and $format eq 'json') {
 
     # Retrieve all results
     $cgi->param('rows', 0);
-} else {
-    $format = 'html';
-    $template_name = 'catalogue/itemsearch.tt';
-    $content_type = 'html';
+} elsif (defined $format) {
+    die "Unsupported format $format";
 }
 
 my ($template, $borrowernumber, $cookie) = get_template_and_user({
@@ -226,93 +224,78 @@ if (scalar keys %params > 0) {
         search_params => $search_params,
         results => $results,
         total_rows => $total_rows,
-        search_done => 1,
     );
 
-    if ($format eq 'html') {
-        # Build pagination bar
-        my $url = '/cgi-bin/koha/catalogue/itemsearch.pl';
-        my @params;
-        foreach my $p (keys %params) {
-            my @v = $cgi->multi_param($p);
-            push @params, map { "$p=" . $_ } @v;
-        }
-        $url .= '?' . join ('&', @params);
-        my $nb_pages = 1 + int($total_rows / $search_params->{rows});
-        my $current_page = $search_params->{page};
-        my $pagination_bar = pagination_bar($url, $nb_pages, $current_page, 'page');
+    if ($format eq 'csv') {
+        print $cgi->header({
+            type => 'text/csv',
+            attachment => 'items.csv',
+        });
 
-        $template->param(pagination_bar => $pagination_bar);
+        for my $line ( split '\n', $template->output ) {
+            print "$line\n" unless $line =~ m|^\s*$|;
+        }
+    } elsif ($format eq 'json') {
+        output_with_http_headers $cgi, $cookie, $template->output, 'json';
     }
-}
 
-if ($format eq 'html') {
-    # Retrieve data required for the form.
-
-    my @branches = map { value => $_->branchcode, label => $_->branchname }, Koha::Libraries->search( {}, { order_by => 'branchname' } );
-    my @locations;
-    foreach my $location (@$location_values) {
-        push @locations, {
-            value => $location->{authorised_value},
-            label => $location->{lib} // $location->{authorised_value},
-        };
-    }
-    my @itemtypes;
-    foreach my $itemtype ( Koha::ItemTypes->search ) {
-        push @itemtypes, {
-            value => $itemtype->itemtype,
-            label => $itemtype->translated_description,
-        };
-    }
+    exit;
+}
 
-    my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.ccode', authorised_value => { not => undef } });
-    my $ccode_avcode = $mss->count ? $mss->next->authorised_value : 'CCODE';
-    my $ccodes = GetAuthorisedValues($ccode_avcode);
-    my @ccodes;
-    foreach my $ccode (@$ccodes) {
-        push @ccodes, {
-            value => $ccode->{authorised_value},
-            label => $ccode->{lib},
-        };
-    }
+# Display the search form
 
-    my @notforloans;
-    foreach my $value (@$notforloan_values) {
-        push @notforloans, {
-            value => $value->{authorised_value},
-            label => $value->{lib},
-        };
-    }
-
-    my @items_search_fields = GetItemSearchFields();
+my @branches = map { value => $_->branchcode, label => $_->branchname }, Koha::Libraries->search( {}, { order_by => 'branchname' } );
+my @locations;
+foreach my $location (@$location_values) {
+    push @locations, {
+        value => $location->{authorised_value},
+        label => $location->{lib} // $location->{authorised_value},
+    };
+}
+my @itemtypes;
+foreach my $itemtype ( Koha::ItemTypes->search ) {
+    push @itemtypes, {
+        value => $itemtype->itemtype,
+        label => $itemtype->translated_description,
+    };
+}
 
-    my $authorised_values = {};
-    foreach my $field (@items_search_fields) {
-        if (my $category = ($field->{authorised_values_category})) {
-            $authorised_values->{$category} = GetAuthorisedValues($category);
-        }
-    }
+$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.ccode', authorised_value => { not => undef } });
+my $ccode_avcode = $mss->count ? $mss->next->authorised_value : 'CCODE';
+my $ccodes = GetAuthorisedValues($ccode_avcode);
+my @ccodes;
+foreach my $ccode (@$ccodes) {
+    push @ccodes, {
+        value => $ccode->{authorised_value},
+        label => $ccode->{lib},
+    };
+}
 
-    $template->param(
-        branches => \@branches,
-        locations => \@locations,
-        itemtypes => \@itemtypes,
-        ccodes => \@ccodes,
-        notforloans => \@notforloans,
-        items_search_fields => \@items_search_fields,
-        authorised_values_json => to_json($authorised_values),
-    );
+my @notforloans;
+foreach my $value (@$notforloan_values) {
+    push @notforloans, {
+        value => $value->{authorised_value},
+        label => $value->{lib},
+    };
 }
 
-if ($format eq 'csv') {
-    print $cgi->header({
-        type => 'text/csv',
-        attachment => 'items.csv',
-    });
+my @items_search_fields = GetItemSearchFields();
 
-    for my $line ( split '\n', $template->output ) {
-        print "$line\n" unless $line =~ m|^\s*$|;
+my $authorised_values = {};
+foreach my $field (@items_search_fields) {
+    if (my $category = ($field->{authorised_values_category})) {
+        $authorised_values->{$category} = GetAuthorisedValues($category);
     }
-} else {
-    output_with_http_headers $cgi, $cookie, $template->output, $content_type;
 }
+
+$template->param(
+    branches => \@branches,
+    locations => \@locations,
+    itemtypes => \@itemtypes,
+    ccodes => \@ccodes,
+    notforloans => \@notforloans,
+    items_search_fields => \@items_search_fields,
+    authorised_values_json => to_json($authorised_values),
+);
+
+output_html_with_http_headers $cgi, $cookie, $template->output;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.inc
deleted file mode 100644 (file)
index 8f65913..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-[%- USE Branches -%]
-[%- USE Koha -%]
-[% biblio = item.biblio %]
-[% biblioitem = item.biblioitem %]
-<tr>
-  <td>
-    <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio.biblionumber %]" title="Go to record detail page">[% biblio.title %]</a>
-    [% IF ( Koha.Preference( 'marcflavour' ) == 'UNIMARC' && biblio.author ) %] by[% END %] [% biblio.author |html %]
-  </td>
-  <td>[% biblioitem.publicationyear || biblio.copyrightdate %]</td>
-  <td>[% biblioitem.publishercode %]</td>
-  <td>[% biblioitem.collectiontitle %]</td>
-  <td>
-    <a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% biblio.biblionumber %]#item[% item.itemnumber %]" title="Go to item details">[% item.barcode %]</a>
-  </td>
-  <td>[% item.itemcallnumber %]</td>
-  <td>[% Branches.GetName(item.homebranch) %]</td>
-  <td>[% Branches.GetName(item.holdingbranch) %]</td>
-  <td>[% item.location %]</td>
-  <td>[% item.stocknumber %]</td>
-  <td>[% item.status %]</td>
-  <td>[% item.issues || 0 %]</td>
-  <td><a href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&amp;biblionumber=[% item.biblionumber %]&amp;itemnumber=[% item.itemnumber %]">Edit</a></td>
-</tr>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_items.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_items.inc
deleted file mode 100644 (file)
index 33aa9de..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-[% names = CGI.param() %]
-[% params = [] %]
-[% FOREACH name IN names %]
-  [% IF name != 'sortby' AND name != 'sortorder' %]
-    [% params.push(name _ "=" _ CGI.param(name)) %]
-  [% END %]
-[% END %]
-[% base_url = "/cgi-bin/koha/catalogue/itemsearch.pl?" _ params.join('&') %]
-
-[% BLOCK itemsearch_header %]
-  [% sortorder = 'asc' %]
-  [% classes = [] %]
-  [% IF CGI.param('sortby') == name %]
-    [% classes.push('active') %]
-    [% classes.push('sort-' _ CGI.param('sortorder')) %]
-    [% IF CGI.param('sortorder') == 'asc' %]
-      [% sortorder = 'desc' %]
-    [% END %]
-  [% END %]
-  [% url = base_url _ '&sortby=' _ name _ '&sortorder=' _ sortorder %]
-  <th class="[% classes.join(' ') %]">
-    <a href="[% url %]" title="Sort on [% label %] ([% sortorder %])">[% text %]</a>
-  </th>
-[% END %]
-
-<table>
-  <thead>
-    <tr>
-      [% INCLUDE itemsearch_header name='title' label='title' text='Title' %]
-      [% INCLUDE itemsearch_header name='publicationyear' label='publication date' text='Publication date' %]
-      [% INCLUDE itemsearch_header name='publishercode' label='publisher' text='Publisher' %]
-      [% INCLUDE itemsearch_header name='collectiontitle' label='collection' text='Collection' %]
-      [% INCLUDE itemsearch_header name='barcode' label='barcode' text='Barcode' %]
-      [% INCLUDE itemsearch_header name='itemcallnumber' label='callnumber' text='Call number' %]
-      [% INCLUDE itemsearch_header name='homebranch' label='home branch' text='Home library' %]
-      [% INCLUDE itemsearch_header name='holdingbranch' label='holding branch' text='Current location' %]
-      [% INCLUDE itemsearch_header name='location' label='location' text='Shelving location' %]
-      [% INCLUDE itemsearch_header name='stocknumber' label='inventory number' text='Inventory number' %]
-      [% INCLUDE itemsearch_header name='notforloan' label='status' text='Status' %]
-      [% INCLUDE itemsearch_header name='issues' label='issues' text='Checkouts' %]
-      <th></th>
-    </tr>
-  </thead>
-  <tbody>
-    [% FOREACH item IN items %]
-      [% INCLUDE 'catalogue/itemsearch_item.inc' item = item %]
-    [% END %]
-  </tbody>
-</table>
index e88d774..a904146 100644 (file)
     </div>
   </div>
   <div id="doc3" class="yui-t7">
-      <div id="results-wrapper">
-        [% IF search_done %]
-          [% IF total_rows > 0 %]
-            <p>Found [% total_rows %] results.</p>
-          [% ELSE %]
-            <p>No results found.</p>
-          [% END %]
-
-          [% IF results %]
-            [% INCLUDE 'catalogue/itemsearch_items.inc' items = results %]
-          [% END %]
-
-          <div class="pages">
-            [% pagination_bar %]
-          </div>
-
-        [% END %]
-      </div>
+      <div id="results-wrapper"></div>
 
     [% INCLUDE 'intranet-bottom.inc' %]