From 7411fe90c37869d00cf7e6f49a6e2d2e62350d01 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 19 Feb 2013 14:48:04 +0100 Subject: [PATCH] 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. http://bugs.koha-community.org/show_bug.cgi?id=9456 --- admin/preferences.pl | 11 +++++++++-- koha-tmpl/intranet-tmpl/prog/en/js/pages/preferences.js | 5 ++++- .../intranet-tmpl/prog/en/modules/admin/preferences.tt | 12 ++++++++++++ svc/config/systempreferences | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/admin/preferences.pl b/admin/preferences.pl index db91e76..fc27657 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -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 C4::Auth; @@ -104,6 +103,14 @@ 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 { { text => $options{multiple}->{$_}, value => $_, selected => ( $_ ~~ @values ) } } + keys %{ $options{multiple} } + ]; } $chunk->{ 'type_' . $chunk->{'type'} } = 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/pages/preferences.js b/koha-tmpl/intranet-tmpl/prog/en/js/pages/preferences.js index 4d793a1..dec4037 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/pages/preferences.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/pages/preferences.js @@ -11,6 +11,9 @@ KOHA.Preferences = { Save: function ( form ) { modified_prefs = $( form ).find( '.modified' ); data = modified_prefs.serialize(); + if ( data.length == 0 && $(modified_prefs).attr('multiple') ) { + data = $(modified_prefs).attr('name') + "="; + } if ( !data ) { humanMsg.displayAlert( MSG_NOTHING_TO_SAVE ); return; @@ -44,7 +47,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( '('+MSG_MODIFIED+')' ); KOHA.Preferences.Modified = true; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt index 5b20399..778b685 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt @@ -105,6 +105,18 @@ [% END %] + [% ELSIF ( CHUNK.type_multiple ) %] + [% ELSIF ( CHUNK.type_textarea ) %] diff --git a/svc/config/systempreferences b/svc/config/systempreferences index 8622f6a..831a646 100755 --- a/svc/config/systempreferences +++ b/svc/config/systempreferences @@ -96,7 +96,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 ); -- 1.7.10.4