Bug 34478: Add 'op' to opac-tags

There are way more to do in this controller!...

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2024-01-31 12:11:10 +01:00
parent 797586b908
commit 36e5555144
Signed by: jonathan.druart
GPG key ID: A085E712BEF0E0F0
3 changed files with 47 additions and 41 deletions

View file

@ -251,6 +251,7 @@
</p>
</div> <!-- /.col-6 -->
<div class="col-auto">
<input type="hidden" name="op" value="cud-add" />
<input name="tagbutton" class="btn btn-sm btn-primary tagbutton" title="[% biblio.biblionumber | html %]" type="submit" value="Add" />
<a class="cancel_tag_add" id="cancel[% biblio.biblionumber | html %]" href="#">(done)</a>
<span id="newtag[% biblio.biblionumber | html %]_status" class="tagstatus" style="display:none;">

View file

@ -178,6 +178,7 @@
[% END %]
</tbody>
</table>
<input type="hidden" name="op" value="cud-del" />
<input type="submit" value="Delete selected tags" class="btn btn-danger btn-sm delete">
</form>
[% END # /MY_TAGS %]

View file

@ -129,48 +129,52 @@ if ($add_op) {
}
}
my $scrubber;
my @newtags_keys = (keys %newtags);
if (scalar @newtags_keys) {
$scrubber = C4::Scrubber->new();
foreach my $biblionumber (@newtags_keys) {
my $bibResults = {adds=>0, errors=>[]};
my @values = split /[;,]/, $newtags{$biblionumber};
foreach (@values) {
s/^\s*(.+)\s*$/$1/;
my $clean_tag = $scrubber->scrub($_);
unless ($clean_tag eq $_) {
if ($clean_tag =~ /\S/) {
push @errors, {scrubbed=>$clean_tag};
push @{$bibResults->{errors}}, {scrubbed=>$clean_tag};
} else {
push @errors, {scrubbed_all_bad=>1};
push @{$bibResults->{errors}}, {scrubbed_all_bad=>1};
next; # we don't add it if there's nothing left!
}
}
my $result = ($openadds) ?
add_tag($biblionumber,$clean_tag,$loggedinuser,$loggedinuser) : # pre-approved
add_tag($biblionumber,$clean_tag,$loggedinuser) ;
if ($result) {
$counts{$biblionumber}++;
$bibResults->{adds}++;
} else {
push @errors, {failed_add_tag=>$clean_tag};
push @{$bibResults->{errors}}, {failed_add_tag=>$clean_tag};
Koha::Logger->get->warn("add_tag($biblionumber,$clean_tag,$loggedinuser...) returned bad result (" . (defined $result ? $result : 'UNDEF') .")");
}
}
$perBibResults->{$biblionumber} = $bibResults;
}
}
my $op = $query->param('op') || q{};
my $dels = 0;
foreach (@deltags) {
if (remove_tag($_,$loggedinuser)) {
$dels++;
} else {
push @errors, {failed_delete=>$_};
}
if ( $op eq 'cud-add' ) {
my $scrubber;
my @newtags_keys = (keys %newtags);
if (scalar @newtags_keys) {
$scrubber = C4::Scrubber->new();
foreach my $biblionumber (@newtags_keys) {
my $bibResults = {adds=>0, errors=>[]};
my @values = split /[;,]/, $newtags{$biblionumber};
foreach (@values) {
s/^\s*(.+)\s*$/$1/;
my $clean_tag = $scrubber->scrub($_);
unless ($clean_tag eq $_) {
if ($clean_tag =~ /\S/) {
push @errors, {scrubbed=>$clean_tag};
push @{$bibResults->{errors}}, {scrubbed=>$clean_tag};
} else {
push @errors, {scrubbed_all_bad=>1};
push @{$bibResults->{errors}}, {scrubbed_all_bad=>1};
next; # we don't add it if there's nothing left!
}
}
my $result = ($openadds) ?
add_tag($biblionumber,$clean_tag,$loggedinuser,$loggedinuser) : # pre-approved
add_tag($biblionumber,$clean_tag,$loggedinuser) ;
if ($result) {
$counts{$biblionumber}++;
$bibResults->{adds}++;
} else {
push @errors, {failed_add_tag=>$clean_tag};
push @{$bibResults->{errors}}, {failed_add_tag=>$clean_tag};
Koha::Logger->get->warn("add_tag($biblionumber,$clean_tag,$loggedinuser...) returned bad result (" . (defined $result ? $result : 'UNDEF') .")");
}
}
$perBibResults->{$biblionumber} = $bibResults;
}
}
} elsif ( $op eq 'cud-del' ) {
foreach (@deltags) {
if (remove_tag($_,$loggedinuser)) {
$dels++;
} else {
push @errors, {failed_delete=>$_};
}
}
}
if ($is_ajax) {