From 2617427e4f3a1b5f65c110c75b8313ee224881fd Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Wed, 13 Nov 2019 16:34:56 +0100
Subject: [PATCH] Bug 22784: Add the ability to archive/unarchive a purchase
 suggestions

There are performance issues when searching suggestions if there are
thousands of suggestions.
To prevent that we are going to add the ability to archive purchase
suggestions, in order to remove them from the search list (by default).

Test plan:
0. Apply all the patches, execute the updatedatabase.pl script, restart
all
1. Create some suggestions
2. Search for them
3. Use the "Archive" action button for one of them
4. Restart the search
=> The archived suggestion does no longer appear in the list
5. Use the filter "Included archived" in the "Suggestion information"
filter box
=> The archived suggestion is now displayed
6. Use other filters
=> The "archived" filter is kept from one search to another
7. Use one of the action at the bottom of the suggestion list (change
the status for instance)
=> The "archived" filter is still kept

Sponsored-by: BULAC - http://www.bulac.fr/
---
 .../prog/en/modules/suggestion/suggestion.tt              | 15 +++++++++++++--
 suggestion/suggestion.pl                                  | 10 ++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt
index 3e6ed544b3..cb45d0b3b1 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt
@@ -603,8 +603,19 @@
                     [% END %]
                 </td>
                 <td class="actions">
-                    <a class="btn btn-xs btn-default" href="suggestion.pl?suggestionid=[% suggestions_loo.suggestionid | html %]&amp;op=edit"><i class="fa fa-pencil"></i> Edit</a>
-                    <a class="btn btn-default btn-xs deletesuggestion" href="suggestion.pl?op=delete&amp;suggestionid=[% suggestions_loo.suggestionid | html %]"><i class="fa fa-trash"></i> Delete</a>
+                    <div class="dropup">
+                    <div class="btn-group">
+                        <a class="btn btn-default btn-xs" role="button" href="suggestion.pl?suggestionid=[% suggestions_loo.suggestionid | html %]&amp;op=edit"><i class="fa fa-pencil"></i> Edit</a><a class="btn btn-default btn-xs dropdown-toggle" id="more_actions_[% suggestions_loo.suggestionid | html %]" role="button" data-toggle="dropdown" href="#"><b class="caret"></b></a>
+                        <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="more_actions_[% suggestions_loo.suggestionid | html %]">
+                            <li><a class="deletesuggestion" href="suggestion.pl?op=delete&amp;suggestionid=[% suggestions_loo.suggestionid | html %]"><i class="fa fa-trash"></i> Delete</a></li>
+                            [% UNLESS suggestions_loo.archived %]
+                                <li><a class="archivesuggestion" href="suggestion.pl?op=archive&amp;suggestionid=[% suggestions_loo.suggestionid | html %]"><i class="fa fa-archive"></i> Archive</a></li>
+                            [% ELSE %]
+                                <li><a class="unarchivesuggestion" href="suggestion.pl?op=unarchive&amp;suggestionid=[% suggestions_loo.suggestionid | html %]"><i class="fa fa-archive"></i> Unarchive</a></li>
+                            [% END %]
+                        </ul>
+                    </div>
+                    </div>
                 </td>
         </tr>
         [% END %]</tbody>
diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl
index ff39b3daf9..1364c61b50 100755
--- a/suggestion/suggestion.pl
+++ b/suggestion/suggestion.pl
@@ -290,6 +290,16 @@ elsif ($op eq "update_status" ) {
     }
     redirect_with_params($input);
 }
+elsif ($op eq "archive" ) {
+    Koha::Suggestions->find($_)->update({ archived => 1 }) for @editsuggestions;
+
+    redirect_with_params($input);
+}
+elsif ($op eq "unarchive" ) {
+    Koha::Suggestions->find($_)->update({ archived => 0 }) for @editsuggestions;
+
+    redirect_with_params($input);
+}
 elsif ( $op eq 'update_itemtype' ) {
     my $new_itemtype = $input->param('suggestion_itemtype');
     foreach my $suggestionid (@editsuggestions) {
-- 
2.11.0