Bug 23594: Batch modification for itemtypes on suggestions page

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

Sponsored-by: BULAC - http://www.bulac.fr/
Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2019-10-21 18:06:07 +02:00 committed by Martin Renvoize
parent 251bbb2eb9
commit 4494e8ba6c
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
2 changed files with 119 additions and 110 deletions

View File

@ -56,7 +56,7 @@
<div id="toolbar" class="btn-toolbar">
<a class="btn btn-default" id="editsuggestion" href="suggestion.pl?op=edit&amp;suggestionid=[% suggestionid | html %]"><i class="fa fa-pencil"></i> Edit</a>
<a class="btn btn-default deletesuggestion" href="suggestion.pl?op=delete&amp;edit_field=[% suggestionid | html %]"><i class="fa fa-trash"></i> Delete</a>
<a class="btn btn-default deletesuggestion" href="suggestion.pl?op=delete&amp;suggestionid=[% suggestionid | html %]"><i class="fa fa-trash"></i> Delete</a>
</div>
<fieldset class="rows">
@ -470,7 +470,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
@ -494,12 +494,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 noExport">&nbsp;</th>
@ -518,7 +518,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 %]&amp;op=show" title="suggestion" >
@ -571,80 +571,93 @@
</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;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&amp;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>
</table>
[% IF (statusselected_ASKED ) %]
<option value="ASKED" selected="selected">Pending</option>
[% ELSE %]
<option value="ASKED">Pending</option>
[% END %]
<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_ACCEPTED ) %]
<option value="ACCEPTED" selected="selected">Accepted</option>
[% ELSE %]
<option value="ACCEPTED">Accepted</option>
[% END %]
[% IF (statusselected_ASKED ) %]
<option value="ASKED" selected="selected">Pending</option>
[% ELSE %]
<option value="ASKED">Pending</option>
[% END %]
[% IF (statusselected_CHECKED ) %]
<option value="CHECKED" selected="selected">Checked</option>
[% ELSE %]
<option value="CHECKED">Checked</option>
[% END %]
[% IF (statusselected_ACCEPTED ) %]
<option value="ACCEPTED" selected="selected">Accepted</option>
[% ELSE %]
<option value="ACCEPTED">Accepted</option>
[% END %]
[% IF ( statusselected_REJECTED ) %]
<option value="REJECTED" selected="selected">Rejected</option>
[% ELSE %]
<option value="REJECTED">Rejected</option>
[% END %]
[% IF (statusselected_CHECKED ) %]
<option value="CHECKED" selected="selected">Checked</option>
[% ELSE %]
<option value="CHECKED">Checked</option>
[% END %]
[% FOREACH s IN SuggestionStatuses %]
<option value="[% s.authorised_value | html %]">[% s.lib | html %]</option>
[% END %]
</select>
[% IF ( statusselected_REJECTED ) %]
<option value="REJECTED" selected="selected">Rejected</option>
[% ELSE %]
<option value="REJECTED">Rejected</option>
[% END %]
<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>
[% FOREACH s IN SuggestionStatuses %]
<option value="[% s.authorised_value | html %]">[% s.lib | html %]</option>
[% END %]
</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>
<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>
<strong style="padding: 0 1em;">OR:</strong>
<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>
<label for="[% suggestion.suggestiontype | html %]delete">Delete selected</label>
<input type="checkbox" name="op" id="[% suggestion.suggestiontype | html %]delete" />
<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>
<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 ) %]
@ -823,15 +836,8 @@
[% INCLUDE 'datatables.inc' %]
[% INCLUDE 'columns_settings.inc' %]
[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
<script>
/**
* displayOther.
* This function display the select or an textaera to write a reason.
*/
function displayOther(id,show,hide){
$("#"+hide+id).hide();
$("#"+show+id).show();
}
<script type="text/javascript">
$(document).ready(function() {
$('#suggestiontabs').tabs();
@ -849,36 +855,26 @@
[% END %]
[% END %]
[% 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();
@ -925,27 +921,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;
});
});

View File

@ -83,7 +83,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');
@ -105,7 +105,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(
{
@ -210,7 +210,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
@ -234,9 +234,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;
}
@ -266,6 +266,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};