Bug 36081: Use multivalue_preference
C4::Context->multivalue_preference is not used so far and split on | However the values of "multiple" sysprefs are separated by... comma! Let support both here. This patch also removes silly JS code in the template. Signed-off-by: Magnus Enger <magnus@libriotech.no> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz>
This commit is contained in:
parent
3a817ca380
commit
7b0f6f6bc1
|
|
@ -364,9 +364,11 @@ sub multivalue_preference {
|
|||
my ( $self, $preference ) = @_;
|
||||
|
||||
my $syspref = $self->preference($preference) // q{};
|
||||
my $values = [ split qr{\|}, $syspref ];
|
||||
|
||||
return $values;
|
||||
return [ split qr{\|}, $syspref ]
|
||||
if $syspref =~ qr{\|};
|
||||
|
||||
return [ split qr{,}, $syspref ]
|
||||
}
|
||||
|
||||
=head2 enable_syspref_cache
|
||||
|
|
|
|||
|
|
@ -266,10 +266,9 @@ sub store {
|
|||
if ( !$self->in_storage ) {
|
||||
$self->created_on( dt_from_string() );
|
||||
}
|
||||
my $format = $self->format;
|
||||
if ( C4::Context->preference('ArticleRequestsSupportedFormats') !~ /\b$format\b/ ) {
|
||||
Koha::Exceptions::ArticleRequest::WrongFormat->throw;
|
||||
}
|
||||
|
||||
Koha::Exceptions::ArticleRequest::WrongFormat->throw
|
||||
unless grep { $_ eq $self->format } @{ C4::Context->multivalue_preference('ArticleRequestsSupportedFormats') };
|
||||
|
||||
return $self->SUPER::store;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,11 @@ sub Preference {
|
|||
return C4::Context->preference( $pref );
|
||||
}
|
||||
|
||||
sub MultivaluePreference {
|
||||
my ( $self, $pref ) = @_;
|
||||
return C4::Context->multivalue_preference( $pref );
|
||||
}
|
||||
|
||||
=head3 CSVDelimiter
|
||||
|
||||
The delimiter option 'tabs' is stored in the DB as 'tabulation' to avoid issues
|
||||
|
|
|
|||
|
|
@ -1367,7 +1367,10 @@ Circulation:
|
|||
-
|
||||
- "The following article request formats are supported:"
|
||||
- pref: ArticleRequestsSupportedFormats
|
||||
- "(Valid choices are currently: PHOTOCOPY and SCAN. Separate the supported formats by a vertical bar. The first listed format is selected by default when you request via the OPAC.)"
|
||||
multiple_sortable:
|
||||
PHOTOCOPY: Photocopy
|
||||
SCAN: Scan
|
||||
- "The first listed format is selected by default when you request via the OPAC."
|
||||
|
||||
|
||||
Item bundles:
|
||||
|
|
|
|||
|
|
@ -155,13 +155,21 @@
|
|||
<input type="text" name="patron_notes" id="patron_notes" size="50"/>
|
||||
</li>
|
||||
|
||||
[% SET ArticleRequestsSupportedFormats = Koha.MultivaluePreference('ArticleRequestsSupportedFormats') %]
|
||||
[% IF ArticleRequestsSupportedFormats.size %]
|
||||
<li>
|
||||
<label for="format">Format:</label>
|
||||
<select name="format" id="format">
|
||||
<option value="PHOTOCOPY">Photocopy</option>
|
||||
<option value="SCAN">Digital scan</option>
|
||||
[% FOR format IN ArticleRequestsSupportedFormats %]
|
||||
[% IF format == 'PHOTOCOPY' %]
|
||||
<option value="PHOTOCOPY">Photocopy</option>
|
||||
[% ELSIF format == 'SCAN' %]
|
||||
<option value="SCAN">Digital scan</option>
|
||||
[% END %]
|
||||
[% END %]
|
||||
</select>
|
||||
</li>
|
||||
[% END %]
|
||||
|
||||
<li>
|
||||
<label for="branchcode">Pickup library:</label>
|
||||
|
|
@ -295,18 +303,6 @@ $(document).ready( function() {
|
|||
}
|
||||
});
|
||||
|
||||
// Initialize format(s)
|
||||
var supported_formats = "[% Koha.Preference('ArticleRequestsSupportedFormats') | html %]";
|
||||
if( !supported_formats.match(/PHOTOCOPY/) )
|
||||
$('#format option[value="PHOTOCOPY"]').remove();
|
||||
if( !supported_formats.match(/SCAN/) )
|
||||
$('#format option[value="SCAN"]').remove();
|
||||
|
||||
if( $('#format option').length > 1 ) {
|
||||
// Select first listed format
|
||||
var first_format = supported_formats.split('|')[0].replace(/^\s*|\s*$/g, '');
|
||||
$('#format option[value="'+first_format+'"]').attr('selected', true);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
[% END %]
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ subtest 'yaml_preference() tests' => sub {
|
|||
|
||||
subtest 'multivalue_preference() tests' => sub {
|
||||
|
||||
plan tests => 3;
|
||||
plan tests => 4;
|
||||
|
||||
t::lib::Mocks::mock_preference( 'MultiValuedSyspref', '' );
|
||||
is_deeply( C4::Context->multivalue_preference('MultiValuedSyspref'), [] );
|
||||
|
|
@ -70,6 +70,9 @@ subtest 'multivalue_preference() tests' => sub {
|
|||
|
||||
t::lib::Mocks::mock_preference( 'MultiValuedSyspref', 'some|more|values' );
|
||||
is_deeply( C4::Context->multivalue_preference('MultiValuedSyspref'), [ 'some', 'more', 'values' ] );
|
||||
|
||||
t::lib::Mocks::mock_preference( 'MultiValuedSyspref', 'some,more,values' );
|
||||
is_deeply( C4::Context->multivalue_preference('MultiValuedSyspref'), [ 'some', 'more', 'values' ] );
|
||||
};
|
||||
|
||||
subtest 'needs_install() tests' => sub {
|
||||
|
|
|
|||
Loading…
Reference in New Issue