Bug 35604: New 'ill-backends' syspref type

UI rendering of sortable ILL backends

Sponsored-by: NHS England
Sponsored-by: PTFS Europe Ltd
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Pedro Amorim 2023-12-18 16:42:15 -01:00 committed by Katrin Fischer
parent a74be1de72
commit e10e0c8f05
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 54 additions and 0 deletions

View File

@ -29,6 +29,7 @@ use C4::Output qw( output_html_with_http_headers output_and_exit_if_error )
use C4::Templates;
use Koha::Acquisition::Currencies;
use Koha::Database::Columns;
use Koha::ILL::Backends;
use IO::File;
use YAML::XS;
use Encode;
@ -80,6 +81,29 @@ sub _get_chunk {
$chunk->{'input_type'} = 'email';
} elsif ( $options{'class'} && $options{'class'} eq 'date' ) {
$chunk->{'dateinput'} = 1;
} elsif ( $options{'type'} && $options{'type'} eq 'ill-backends' ) {
my @priority_enabled_backends = split ",", C4::Context->preference('AutoILLBackendPriority');
my @sys_pref_backends = map( { name => $_, enabled => 1 }, @priority_enabled_backends );
my $installed_backends = Koha::ILL::Backends->installed_backends;
foreach my $installed_backend ( @{$installed_backends} ) {
if ( not grep { $installed_backend eq $_->{name} } @sys_pref_backends ) {
my $backend = Koha::ILL::Request->new->load_backend($installed_backend);
push(
@sys_pref_backends,
{
name => $installed_backend,
enabled => 0,
!$backend->_backend_capability('provides_backend_availability_check')
? ( unable => 1 )
: ()
}
);
}
}
$chunk->{'ill_backends'} = \@sys_pref_backends;
$chunk->{'type'} = 'ill_backends';
} elsif ( $options{'type'} && ( $options{'type'} eq 'opac-languages' || $options{'type'} eq 'staff-languages' ) ) {
my $current_languages = { map { +$_, 1 } split( /\s*,\s*/, $value ) };

View File

@ -164,6 +164,28 @@
<textarea style="display:none" name="pref_[% CHUNK.name | html %]" id="pref_[% CHUNK.name | html %]" class="preference preference-[% CHUNK.class or "short" | html %] codemirror" rows="10" cols="40">[% CHUNK.value | html %]</textarea>
<a class="collapse-textarea" id="collapse_[% CHUNK.name | html %]" data-target="[% CHUNK.name | html %]" data-syntax="[% CHUNK.syntax | html %]" style="display:none" href="#">Collapse</br></a>
[% END %]
[% ELSIF ( CHUNK.type_ill_backends ) %]
[% IF ( !CHUNK.ill_backends.empty ) %]
<ul class="sortable">
[% FOREACH ill_backend IN CHUNK.ill_backends %]
<li>
<i class="fa-solid fa-fw fa-grip-vertical" aria-hidden="true" style="color:#B7B7B7"></i>
[% IF ( ill_backend.enabled ) %]
<label for="pref_[% CHUNK.name | html %]_[% ill_backend.name | html %]">[% loop.index()+1 | html %]. [% ill_backend.name | html %]</label>
<input value="[% ill_backend.name | html %]" name="pref_[% CHUNK.name | html %]" id="pref_[% CHUNK.name | html %]_[% ill_backend.name | html %]" type="checkbox" class="preference preference-checkbox" checked="checked" />
[% ELSIF (ill_backend.unable) %]
<label style="color:red" for="pref_[% CHUNK.name | html %]_[% ill_backend.name | html %]">[% loop.index()+1 | html %]. [% ill_backend.name | html %] (Unable to provide availability)</label>
<input value="[% ill_backend.name | html %]" name="pref_[% CHUNK.name | html %]" id="pref_[% CHUNK.name | html %]_[% ill_backend.name | html %]" type="checkbox" class="preference preference-checkbox" disabled />
[% ELSE %]
<label for="pref_[% CHUNK.name | html %]_[% ill_backend.name | html %]">[% ill_backend.name | html %]</label>
<input value="[% ill_backend.name | html %]" name="pref_[% CHUNK.name | html %]" id="pref_[% CHUNK.name | html %]_[% ill_backend.name | html %]" type="checkbox" class="preference preference-checkbox" />
[% END %]
</li>
[% END # FOREACH ill_backend %]
</ul> <!-- / ul.sortable -->
[% ELSE %]
<p><strong>No available backends</strong></p>
[% END # IF ( CHUNK.ill_backends ) %]
[% ELSIF ( CHUNK.type_languages ) %]
<ul class="sortable">
[% FOREACH language IN CHUNK.languages %]

View File

@ -242,6 +242,14 @@ $(".sortable").each((i, e) => {
Sortable.create(e, {
animation: 150,
onUpdate: function (e) {
$(e.target)
.find("li label")
.each(function (i) {
let newText = $(this)
.text()
.replace(/\d+\./, i + 1 + ".");
$(this).text(newText);
});
$(e.target).find("input:first").change();
},
});