From 57ea3074e36805d70b3a6c6ba717226fcdcd6481 Mon Sep 17 00:00:00 2001 From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Date: Mon, 21 Oct 2019 18:06:07 +0200 Subject: [PATCH] Bug 23594: Batch modification for itemtypes on suggestions page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This new enhancement adds the ability to update the item types for selected suggestions on the suggestions management page (suggestion/suggestion.pl) To achieve this goal we needed to refresh a bit the template, in order to get rid of weird code. To not recreate the previous coding awkwardness some code has been rewritten (mainly the removal of suggestiontype) Test plan: - Create some suggestions - On the suggestions management page, select some of them and a new item types. - Submit the form and confirm that the itemtype of the suggestions has been updated - Also you should confirm that the "delete" and "change status" still work as before Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> --- .../prog/en/modules/suggestion/suggestion.tt | 223 +++++++++++---------- suggestion/suggestion.pl | 17 +- 2 files changed, 124 insertions(+), 116 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 3c5d366..6c4935a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -55,7 +55,7 @@ <div id="toolbar" class="btn-toolbar"> <a class="btn btn-default" id="editsuggestion" href="suggestion.pl?op=edit&suggestionid=[% suggestionid | html %]"><i class="fa fa-pencil"></i> Edit</a> - <a class="btn btn-default deletesuggestion" href="suggestion.pl?op=delete&edit_field=[% suggestionid | html %]"><i class="fa fa-trash"></i> Delete</a> + <a class="btn btn-default deletesuggestion" href="suggestion.pl?op=delete&suggestionid=[% suggestionid | html %]"><i class="fa fa-trash"></i> Delete</a> </div> <fieldset class="rows"> @@ -439,7 +439,7 @@ <ul class="ui-tabs-nav"> [% FOREACH suggestion IN suggestions %] <li> - <a href="#[% suggestion.suggestiontype | uri %]"> + <a href="#tab_[% loop.count %]"> [% IF ( suggestion.suggestiontypelabel ) %] [% IF (suggestion.suggestiontypelabel == "Pending") %]Pending [% ELSIF (suggestion.suggestiontypelabel == "Accepted") %]Accepted @@ -463,12 +463,12 @@ [% END %] [% FOREACH suggestion IN suggestions %] -<div id="[% suggestion.suggestiontype | html %]"> -<form class="update_suggestions" name="f[% suggestion.suggestiontype | html %]" method="post" action="/cgi-bin/koha/suggestion/suggestion.pl#[% suggestion.suggestiontype | html %]"> +<div id="tab_[% loop.count %]"> +<form class="update_suggestions" name="f" method="post" action="/cgi-bin/koha/suggestion/suggestion.pl#tab_[% loop.count %]"> [% IF ( suggestion.suggestions_loop ) %] -<p><a id="CheckAll[% suggestion.suggestiontype | html %]" href="#">Check all</a> | <a id="UncheckAll[% suggestion.suggestiontype | html %]" href="#">Uncheck all</a></p> - <table id="[% suggestion.suggestiontype | html %]t" class="sorted"> +<p><a class="checkall" href="#">Check all</a> | <a name="uncheckall" href="#">Uncheck all</a></p> + <table id="table_[% loop.count %]" class="sorted"> <thead> <tr> <th class="NoSort"> </th> @@ -485,7 +485,7 @@ [% FOREACH suggestions_loo IN suggestion.suggestions_loop %] <tr> <td> - <input type="checkbox" name="edit_field" value="[% suggestions_loo.suggestionid | html %]" /> + <input type="checkbox" name="suggestionid" value="[% suggestions_loo.suggestionid | html %]" /> </td> <td> <a href="suggestion.pl?suggestionid=[% suggestions_loo.suggestionid | uri %]&op=show" title="suggestion" > @@ -534,80 +534,93 @@ </td> <td class="actions"> <a class="btn btn-xs btn-default" href="suggestion.pl?suggestionid=[% suggestions_loo.suggestionid | html %]&op=edit"><i class="fa fa-pencil"></i> Edit</a> - <a class="btn btn-default btn-xs deletesuggestion" href="suggestion.pl?op=delete&edit_field=[% suggestions_loo.suggestionid | html %]"><i class="fa fa-trash"></i> Delete</a> + <a class="btn btn-default btn-xs deletesuggestion" href="suggestion.pl?op=delete&suggestionid=[% suggestions_loo.suggestionid | html %]"><i class="fa fa-trash"></i> Delete</a> </td> </tr> [% END %]</tbody> - </table> <fieldset> - <div id="select-reason[% suggestion.suggestiontype | html %]"> - <div id="status[% suggestion.suggestiontype | html %]"> - <label for="STATUS[% suggestion.suggestiontype | html %]">Mark selected as: </label> - <select name="STATUS" id="STATUS[% suggestion.suggestiontype | html %]"> - <option value=""> -- Choose a status --</option> - - [% IF (statusselected_ASKED ) %] - <option value="ASKED" selected="selected">Pending</option> - [% ELSE %] - <option value="ASKED">Pending</option> - [% END %] - - [% IF (statusselected_ACCEPTED ) %] - <option value="ACCEPTED" selected="selected">Accepted</option> - [% ELSE %] - <option value="ACCEPTED">Accepted</option> - [% END %] - - [% IF (statusselected_CHECKED ) %] - <option value="CHECKED" selected="selected">Checked</option> - [% ELSE %] - <option value="CHECKED">Checked</option> - [% END %] - - [% IF ( statusselected_REJECTED ) %] - <option value="REJECTED" selected="selected">Rejected</option> - [% ELSE %] - <option value="REJECTED">Rejected</option> - [% END %] - - [% FOREACH s IN SuggestionStatuses %] - <option value="[% s.authorised_value | html %]">[% s.lib | html %]</option> - [% END %] - </select> - - <label for="reason[% suggestion.suggestiontype | html %]">with this reason:</label> - <select id="reason[% suggestion.suggestiontype | html %]" name="reason[% suggestion.suggestiontype | html %]"> - <option value=""> -- Choose a reason -- </option> - [% FOREACH reasonsloo IN suggestion.reasonsloop %] - <option value="[% reasonsloo.lib | html %]">[% reasonsloo.lib | html %]</option> - [% END %] - <option value="other">Others...</option> - </select> - - <span id="other_reason[% suggestion.suggestiontype | html %]"> - <input type="text" size="31" id="select-other_reason[% suggestion.suggestiontype | html %]" name="other_reason[% suggestion.suggestiontype | html %]" placeholder="please note your reason here..." /> - <a href="#back[% suggestion.suggestiontype | uri %]">Cancel</a> - </span> + </table> - <strong style="padding: 0 1em;">OR:</strong> + <div class="row"> + <h2 style="padding-left:1em;">Change selected suggestions</h3> + <div class="col-sm-4"> + <fieldset> + <div id="select-reason"> + <label for="STATUS">Mark selected as: </label> + <select name="STATUS" id="STATUS"> + <option value=""> -- Choose a status --</option> + + [% IF (statusselected_ASKED ) %] + <option value="ASKED" selected="selected">Pending</option> + [% ELSE %] + <option value="ASKED">Pending</option> + [% END %] + + [% IF (statusselected_ACCEPTED ) %] + <option value="ACCEPTED" selected="selected">Accepted</option> + [% ELSE %] + <option value="ACCEPTED">Accepted</option> + [% END %] + + [% IF (statusselected_CHECKED ) %] + <option value="CHECKED" selected="selected">Checked</option> + [% ELSE %] + <option value="CHECKED">Checked</option> + [% END %] + + [% IF ( statusselected_REJECTED ) %] + <option value="REJECTED" selected="selected">Rejected</option> + [% ELSE %] + <option value="REJECTED">Rejected</option> + [% END %] + + [% FOREACH s IN SuggestionStatuses %] + <option value="[% s.authorised_value | html %]">[% s.lib | html %]</option> + [% END %] + </select> + + <label for="reason">with this reason:</label> + <select name="reason"> + <option value=""> -- Choose a reason -- </option> + [% FOREACH reasonsloo IN suggestion.reasonsloop %] + <option value="[% reasonsloo.lib | html %]">[% reasonsloo.lib | html %]</option> + [% END %] + <option value="other">Others...</option> + </select> + + <span class="other_reason"> + <input type="text" size="31" name="other_reason" placeholder="please note your reason here..." /> + <a href="#" class="cancel_note">Cancel</a> + </span> + </div> + + <input type="hidden" name="branchcode" value="[% branchfilter | html %]" /> + <fieldset class="action"><button type="submit" class="btn btn-default btn-xs" value="update_status"/>Submit</button></fieldset> + </fieldset> + </div> + <div class="col-sm-4"> + <fieldset> + <label for="itemtype">Update item types with: </label> + [% PROCESS 'av-build-dropbox.inc' name="suggestion_itemtype", category="SUGGEST_FORMAT", size = 20 %] + <input type="hidden" name="branchcode" value="[% branchfilter | html %]" /> + <fieldset class="action"><button type="submit" class="btn btn-default btn-xs" value="update_itemtype"/>Submit</button></fieldset> + </fieldset> + </div> - <label for="[% suggestion.suggestiontype | html %]delete">Delete selected</label> - <input type="checkbox" name="op" id="[% suggestion.suggestiontype | html %]delete" /> + <div class="col-sm-4"> + <fieldset> + <label for="delete_[% loop.count %]">Delete selected</label> + <input type="hidden" name="branchcode" value="[% branchfilter | html %]" /> + <fieldset class="action"><button type="submit" class="btn btn-default btn-xs" value="delete"/>Delete</button></fieldset> + </fieldset> + </div> </div> - </div> - <input type="hidden" name="branchcode" value="[% branchfilter | html %]" /> - <input type="hidden" name="tabcode" value="[% suggestion.suggestiontype | html %]" /> - <input type="hidden" name="op" value="change" /> -</fieldset> - <fieldset class="action"> - <input type="submit" value="Submit" /></fieldset> -</form> [% ELSE %] <b>No results.</b> [% END %] +</form> </div> [% END %] - </div> [% END %] [% UNLESS ( op_save ) %] @@ -786,14 +799,6 @@ [% INCLUDE 'datatables.inc' %] [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %] <script type="text/javascript"> - /** - * displayOther. - * This function display the select or an textaera to write a reason. - */ - function displayOther(id,show,hide){ - $("#"+hide+id).hide(); - $("#"+show+id).show(); - } $(document).ready(function() { $('#suggestiontabs').tabs({ // Correct table sizing for tables hidden in tabs @@ -809,36 +814,26 @@ ], "sPaginationType": "full" })); - [% FOREACH suggestion IN suggestions %] - // functions for [% suggestion.suggestiontype | html %] interactions - $("#CheckAll[% suggestion.suggestiontype | html %]").click(function(e){ - $("#[% suggestion.suggestiontype | html %]t").checkCheckboxes(); - e.preventDefault(); + $(".checkall").click(function(e){ + $(this).parent(form).checkCheckboxes(); + return false; }); - $("#UncheckAll[% suggestion.suggestiontype | html %]").click(function(e){ - $("#[% suggestion.suggestiontype | html %]t").unCheckCheckboxes(); - e.preventDefault(); + $(".uncheckall").click(function(e){ + $(this).parent(form).unCheckCheckboxes(); + return false; }); - $("#other_reason[% suggestion.suggestiontype | html %]").hide(); - $("#reason[% suggestion.suggestiontype | html %]").change(function(){ + $(".other_reason").hide(); + $("select[name='reason']").change(function(){ if($(this).val() == "other"){ $(this).hide(); - $("#other_reason[% suggestion.suggestiontype | html %]").show(); - } - }); - $("#[% suggestion.suggestiontype | html %]delete").change(function(){ - if(this.checked){ - $("form[name='f[% suggestion.suggestiontype | html %]'] input[name=op]").attr("value","delete"); - } else { - $("form[name='f[% suggestion.suggestiontype | html %]'] input[name=op]").attr("value","change"); + $(this).siblings(".other_reason").show(); } }); - [% END %] - $("a[href*=back]").click(function(){ - var sid = $(this).attr("href").replace(/#back/,""); - $("#reason"+sid).show().find("option[value='']").attr("selected","selected"); - $("#other_reason"+sid).hide(); + $("a.cancel_note").click(function(e) { + $(this).parent().siblings("select").show().find("option[value='']").attr("selected","selected"); + $(this).siblings("input[name='other_reason']").hide(); + e.preventDefault(); }); $("h4.local_collapse a").click(function(){ $(this).parent().parent().find("ol").toggle(); @@ -885,27 +880,33 @@ } }); - $("form.update_suggestions").on("submit", function(e){ - var form = this; - var action_delete_selected = $(this).find("input[value='delete']").is(":checked"); - if ( action_delete_selected ) { - var suggestions_to_delete = $(this).find("input[name='edit_field']:checked"); - if ( suggestions_to_delete.length == 0 ) { - alert(_("Please select at least one suggestion to delete")); - e.preventDefault(); - return false; - } else if ( suggestions_to_delete.length == 1 ) { + $("button[type='submit']").on("click", function(e) { + var form = $(this).parents("form"); + var action = $(this).val(); + var selected_suggestions = $(form).find("input[name='suggestionid']:checked"); + if ( selected_suggestions.length == 0 ) { + alert(_("Please select at least one suggestion")); + e.preventDefault(); + return false; + } + if ( action == "delete" ) { + if ( selected_suggestions.length == 1 ) { if ( ! confirm(_("Are you sure you want to delete this suggestion?")) ) { e.preventDefault(); return false; } - } else if ( suggestions_to_delete.length > 1 ) { + } else if ( selected_suggestions.length > 1 ) { if ( ! confirm(_("Are you sure you want to delete these suggestions?")) ) { e.preventDefault(); return false; } } } + + $('<input />').attr('type', 'hidden') + .attr('name', "op") + .attr('value', action) + .appendTo(form); return true; }); }); diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index e1fca26..9653e69 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -84,7 +84,7 @@ my $input = CGI->new; my $redirect = $input->param('redirect'); my $suggestedbyme = (defined $input->param('suggestedbyme')? $input->param('suggestedbyme'):1); my $op = $input->param('op')||'else'; -my @editsuggestions = $input->multi_param('edit_field'); +my @editsuggestions = $input->multi_param('suggestionid'); my $suggestedby = $input->param('suggestedby'); my $returnsuggestedby = $input->param('returnsuggestedby'); my $returnsuggested = $input->param('returnsuggested'); @@ -104,7 +104,7 @@ $suggestion_only->{STATUS} = $suggestion_ref->{STATUS}; delete $$suggestion_ref{$_} foreach qw( suggestedbyme op displayby tabcode edit_field ); foreach (keys %$suggestion_ref){ - delete $$suggestion_ref{$_} if (!$$suggestion_ref{$_} && ($op eq 'else' || $op eq 'change')); + delete $$suggestion_ref{$_} if (!$$suggestion_ref{$_} && ($op eq 'else' )); } my ( $template, $borrowernumber, $cookie, $userflags ) = get_template_and_user( { @@ -188,7 +188,7 @@ elsif ($op=~/edit/) { Init($suggestion_ref); $op ='save'; } -elsif ($op eq "change" ) { +elsif ($op eq "update_status" ) { my $suggestion; # set accepted/rejected/managed informations if applicable @@ -212,9 +212,9 @@ elsif ($op eq "change" ) { $suggestion->{managedby} = C4::Context->userenv->{number}; $suggestion->{STATUS} = $STATUS; } - if ( my $reason = $input->param("reason$tabcode") ) { + if ( my $reason = $input->param("reason") ) { if ( $reason eq "other" ) { - $reason = $input->param("other_reason$tabcode"); + $reason = $input->param("other_reason"); } $suggestion->{reason} = $reason; } @@ -244,6 +244,13 @@ elsif ($op eq "change" ) { } $op = 'else'; } +elsif ( $op eq 'update_itemtype' ) { + my $new_itemtype = $input->param('suggestion_itemtype'); + foreach my $suggestionid (@editsuggestions) { + next unless $suggestionid; + &ModSuggestion({ suggestionid => $suggestionid, itemtype => $new_itemtype }); + } +} elsif ( $op eq 'show' ) { $suggestion_ref=&GetSuggestion($$suggestion_ref{'suggestionid'}); my $budget = GetBudget $$suggestion_ref{budgetid}; -- 2.1.4