Bug 9043: Syspref improvement: add new type "multiple"
This patch adds a new type "multiple" for syspref. This new type allows to select several values for one syspref. Signed-off-by: Koha Team Lyon 3 <koha@univ-lyon3.fr> Signed-off-by: Jacek Ablewicz <abl@biblos.pk.edu.pl> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
parent
b17297434c
commit
28ebfafc9b
4 changed files with 41 additions and 4 deletions
|
@ -17,8 +17,7 @@
|
|||
# with Koha; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Modern::Perl;
|
||||
|
||||
use CGI;
|
||||
use Encode;
|
||||
|
@ -106,6 +105,21 @@ sub _get_chunk {
|
|||
map { { text => $options{'choices'}->{$_}, value => $_, selected => ( $_ eq $value || ( $_ eq '' && ( $value eq '0' || !$value ) ) ) } }
|
||||
keys %{ $options{'choices'} }
|
||||
];
|
||||
} elsif ( $options{'multiple'} ) {
|
||||
my @values = split /\|/, $value;
|
||||
$chunk->{type} = 'multiple';
|
||||
$chunk->{CHOICES} = [
|
||||
sort { $a->{'text'} cmp $b->{'text'} }
|
||||
map {
|
||||
my $option_value = $_;
|
||||
{
|
||||
text => $options{multiple}->{$option_value},
|
||||
value => $option_value,
|
||||
selected => grep /^$option_value$/, @values,
|
||||
}
|
||||
}
|
||||
keys %{ $options{multiple} }
|
||||
];
|
||||
}
|
||||
|
||||
$chunk->{ 'type_' . $chunk->{'type'} } = 1;
|
||||
|
|
|
@ -3,7 +3,18 @@
|
|||
KOHA.Preferences = {
|
||||
Save: function ( form ) {
|
||||
modified_prefs = $( form ).find( '.modified' );
|
||||
// $.serialize removes empty value, we need to keep them.
|
||||
// If a multiple select has all its entries unselected
|
||||
var unserialized = new Array();
|
||||
$(modified_prefs).each(function(){
|
||||
if ( $(this).attr('multiple') && $(this).val() == null ) {
|
||||
unserialized.push($(this));
|
||||
}
|
||||
});
|
||||
data = modified_prefs.serialize();
|
||||
$(unserialized).each(function(){
|
||||
data += '&' + $(this).attr('name') + '=';
|
||||
});
|
||||
if ( !data ) {
|
||||
humanMsg.displayAlert( MSG_NOTHING_TO_SAVE );
|
||||
return;
|
||||
|
@ -46,7 +57,7 @@ $( document ).ready( function () {
|
|||
$( this.form ).find( '.save-all' ).removeAttr( 'disabled' );
|
||||
$( this ).addClass( 'modified' );
|
||||
var name_cell = $( this ).parents( '.name-row' ).find( '.name-cell' );
|
||||
if ( !name_cell.find( '.modified-warning' ).length )
|
||||
if ( !name_cell.find( '.modified-warning' ).length )
|
||||
name_cell.append( '<em class="modified-warning">('+MSG_MODIFIED+')</em>' );
|
||||
KOHA.Preferences.Modified = true;
|
||||
}
|
||||
|
|
|
@ -116,6 +116,18 @@
|
|||
</option>
|
||||
[% END %]
|
||||
</select>
|
||||
[% ELSIF ( CHUNK.type_multiple ) %]
|
||||
<select name="pref_[% CHUNK.name %]" id="pref_[% CHUNK.name %]" class="preference preference-[% CHUNK.class or "choice" %]" multiple="multiple">
|
||||
[% FOREACH CHOICE IN CHUNK.CHOICES %]
|
||||
[% IF ( CHOICE.selected ) %]
|
||||
<option value="[% CHOICE.value %]" selected="selected">
|
||||
[% ELSE %]
|
||||
<option value="[% CHOICE.value %]">
|
||||
[% END %]
|
||||
[% CHOICE.text %]
|
||||
</option>
|
||||
[% END %]
|
||||
</select>
|
||||
[% ELSIF ( CHUNK.type_textarea ) %]
|
||||
<a class="expand-textarea" style="display: none" href="#">Click to Edit</a>
|
||||
<textarea name="pref_[% CHUNK.name %]" id="pref_[% CHUNK.name %]" class="preference preference-[% CHUNK.class or "short" %]" rows="10" cols="40">[% CHUNK.value %]</textarea>
|
||||
|
|
|
@ -95,7 +95,7 @@ sub set_preferences {
|
|||
|
||||
next if ( !defined( $pref ) );
|
||||
|
||||
my $value = join( ',', $query->param( $param ) );
|
||||
my $value = join( '|', $query->param( $param ) );
|
||||
|
||||
C4::Context->set_preference( $pref, $value );
|
||||
logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $pref . " | " . $value );
|
||||
|
|
Loading…
Reference in a new issue