Bug 34478: Add 'op' to tags/review

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2024-02-07 16:19:19 +01:00
parent 6ed291c842
commit 23ebad24b6
Signed by: jonathan.druart
GPG key ID: A085E712BEF0E0F0
3 changed files with 23 additions and 22 deletions

View file

@ -81,8 +81,8 @@ tr > td input,td input[type="submit"] { font-size: 85%; padding: 1px; }
[% IF ( op_count ) %]
<div class="dialog message" id="main_status">
[% IF ( op == 'approve' ) %] <span>Approved</span>
[% ELSIF ( op == 'reject' ) %] <span>Rejected</span>
[% IF ( op == 'cud-approve' ) %] <span>Approved</span>
[% ELSIF ( op == 'cud-reject' ) %] <span>Rejected</span>
[% ELSIF ( op == 'test' ) %] <span>Tested</span>
[% ELSE %]<span>Unknown operation ([% op | html %]) on</span>
[% END %]
@ -184,8 +184,8 @@ tr > td input,td input[type="submit"] { font-size: 85%; padding: 1px; }
</div> <!-- /.page-section -->
[% END %]
[% IF ( tagloop ) %]<fieldset class="action">
<button type="submit" value="Approve" class="btn btn-default" id="approve_button" name="op-approve"><i class="fa fa-check"></i> Approve</button>
<button type="submit" value="Reject" class="btn btn-default" id="reject_button" name="op-reject"><i class="fa fa-times"></i> Reject</button>
<button type="submit" value="cud-approve" class="btn btn-default" id="approve_button" name="op"><i class="fa fa-check"></i> Approve</button>
<button type="submit" value="cud-reject" class="btn btn-default" id="reject_button" name="op"><i class="fa fa-times"></i> Reject</button>
</fieldset>[% END %]
</form>
</div>

View file

@ -1,6 +1,5 @@
review_ajax_params = {
url: "/cgi-bin/koha/tags/review.pl",
type: "POST",
dataType: "script"
};
@ -102,9 +101,10 @@ $(document).ready(function() {
var gettitle;
// window.alert(__("Click detected on ") + event.target + ": " + $(event.target).html);
if ($(event.target).is('.ok')) {
$.ajax(Object.assign({}, review_ajax_params, {
$.ajax(Object.assign({}, {...review_ajax_params, type: "POST"}, {
data: {
ok: $(event.target).attr("title")
tag: $(event.target).attr("title"),
op: 'cud-approve',
},
success: count_approve // success_approve
}));
@ -123,9 +123,10 @@ $(document).ready(function() {
}
}
if ($(event.target).is('.rej')) {
$.ajax(Object.assign({}, review_ajax_params, {
$.ajax(Object.assign({}, {...review_ajax_params, type: "POST"}, {
data: {
rej: $(event.target).attr("title")
tag: $(event.target).attr("title"),
op: 'cud-reject',
},
success: count_reject // success_reject
}));
@ -146,9 +147,10 @@ $(document).ready(function() {
}
if ($(event.target).is('#test_button')) {
$(event.target).text( __("Testing...") ).prop('disabled', true);
$.ajax(Object.assign({}, review_ajax_params, {
$.ajax(Object.assign({}, {...review_ajax_params, type: "GET"}, {
data: {
test: $('#test').val()
tag: $('#test').val(),
op: 'test',
},
success: success_test_call // success_reject
}));

View file

@ -56,15 +56,17 @@ sub ajax_auth_cgi { # returns CGI object
if (is_ajax()) {
my $input = &ajax_auth_cgi($needed_flags);
my $operator = C4::Context->userenv->{'number'}; # must occur AFTER auth
my ($tag, $js_reply);
if ($tag = $input->param('test')) {
my $js_reply;
my $op = $input->param('op') || q{};
my $tag = $input->param('tag');
if ($op eq 'test') {
my $check = is_approved($tag);
$js_reply = ( $check >= 1 ? 'success' : $check <= -1 ? 'failure' : 'indeterminate' ) . "_test('".uri_escape_utf8($tag)."');\n";
}
if ($tag = $input->param('ok')) {
elsif ($op eq 'cud-approve') {
$js_reply = ( whitelist($operator,$tag) ? 'success' : 'failure') . "_approve('".uri_escape_utf8($tag)."');\n";
}
if ($tag = $input->param('rej')) {
elsif ($op eq 'cud-reject') {
$js_reply = ( blacklist($operator,$tag) ? 'success' : 'failure') . "_reject('".uri_escape_utf8($tag)."');\n";
}
output_with_http_headers $input, undef, $js_reply, 'js';
@ -83,20 +85,17 @@ my ($template, $borrowernumber, $cookie) = get_template_and_user(
}
);
my ($op, @errors, @tags);
my (@errors, @tags);
foreach (qw( approve reject test )) {
$op = $_ if ( $input->param("op-$_") );
}
$op ||= 'none';
my $op = $input->param('op') || q{};
@tags = $input->multi_param('tags');
if ($op eq 'approve') {
if ($op eq 'cud-approve') {
foreach (@tags) {
whitelist($borrowernumber,$_) or push @errors, {failed_ok=>$_};
}
} elsif ($op eq 'reject' ) {
} elsif ($op eq 'cud-reject' ) {
foreach (@tags) {
blacklist($borrowernumber,$_) or push @errors, {failed_rej=>$_};
}