Bug 42553: preferences.pl: Allow 'multiple_sortable' to use 'authval' source
The 'choices' renderer in admin/preferences.pl already supports a
dynamic 'authval' source: the YAML can say
choices: authval
source: SOMECATEGORY
and the choices are populated from the named authorised value category
at render time.
The 'multiple_sortable' renderer (the SortableJS-backed drag-and-drop
multi-select used by OPACAuthorIdentifiersAndInformation and
ArticleRequestsSupportedFormats) had no equivalent — choices had to be
hardcoded in the .pref YAML.
This patch adds the same dispatcher to 'multiple_sortable' so prefs
needing an ordered, picker-driven multi-select of authorised values
can declare:
multiple_sortable: authval
source: PAYMENT_TYPE
Behaviour for existing prefs (which pass a hash directly to
'multiple_sortable') is unchanged — the new branch only fires when the
value is a scalar.
Test plan:
1. Create a temporary system preference using the new pattern, e.g. by
adding to admin/preferences/accounting.pref:
- pref: TestSortableAV
multiple_sortable: authval
source: PAYMENT_TYPE
and seeding INSERT INTO systempreferences with type='Free'.
2. Visit Administration > System preferences and find the pref.
3. Verify the widget renders as a sortable list of every value in the
PAYMENT_TYPE authorised value category, with checkboxes and drag
handles, matching the look of OPACAuthorIdentifiersAndInformation.
4. Pick two or three, reorder them, save.
5. Reload the page and verify the order and selection are preserved.
6. With 'source' omitted or 'multiple_sortable' set to a string other
than 'authval', verify the page raises a clear error.
7. Existing prefs (OPACAuthorIdentifiersAndInformation,
ArticleRequestsSupportedFormats) continue to render unchanged.
Sponsored-by: OpenFifth <https://openfifth.co.uk/>
Signed-off-by: Jackie Usher <jackie.usher@westsussex.gov.uk>
Signed-off-by: Debbie McCarthy <debbie.mccarthy@westsussex.gov.uk>
Signed-off-by: Hannah Dunne-Howrie <hdunne-howrie@westminster.gov.uk>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
812ac7155d
commit
eb93c2b2e7
|
|
@ -28,6 +28,7 @@ use C4::ClassSource qw( GetClassSources GetClassSource );
|
|||
use C4::Output qw( output_html_with_http_headers output_and_exit_if_error );
|
||||
use C4::Templates;
|
||||
use Koha::Acquisition::Currencies;
|
||||
use Koha::AuthorisedValues;
|
||||
use Koha::Database::Columns;
|
||||
use Koha::ILL::Request::Config;
|
||||
use IO::File;
|
||||
|
|
@ -201,6 +202,16 @@ sub _get_chunk {
|
|||
keys %{ $options{multiple} }
|
||||
];
|
||||
} elsif ( $options{'multiple_sortable'} ) {
|
||||
if ( ref( $options{'multiple_sortable'} ) eq '' ) {
|
||||
if ( $options{'multiple_sortable'} eq 'authval' && $options{'source'} ) {
|
||||
$options{'multiple_sortable'} = {
|
||||
map { $_->authorised_value => $_->lib }
|
||||
Koha::AuthorisedValues->search( { category => $options{'source'} } )->as_list
|
||||
};
|
||||
} else {
|
||||
die 'Unrecognized source for multiple_sortable: ' . $options{'multiple_sortable'};
|
||||
}
|
||||
}
|
||||
my @values;
|
||||
@values = split /,/, $value if defined($value);
|
||||
$chunk->{type} = 'multiple_sortable';
|
||||
|
|
|
|||
Loading…
Reference in New Issue