View | Details | Raw Unified | Return to bug 20930
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt (+1 lines)
Lines 189-194 Link Here
189
        var MSG_SESSION_TIMED_OUT = _( "You need to log in again, your session has timed out" );
189
        var MSG_SESSION_TIMED_OUT = _( "You need to log in again, your session has timed out" );
190
        var MSG_DATA_NOT_SAVED = _( "Error; your data might not have been saved" );
190
        var MSG_DATA_NOT_SAVED = _( "Error; your data might not have been saved" );
191
        var MSG_LOADING = _( "Loading..." );
191
        var MSG_LOADING = _( "Loading..." );
192
        var MSG_INVALID_SYNTAX = _( "Error; Preference %s has invalid syntax" );
192
    </script>
193
    </script>
193
    <script src="[% interface %]/lib/jquery/plugins/humanmsg.js" type="text/javascript"></script>
194
    <script src="[% interface %]/lib/jquery/plugins/humanmsg.js" type="text/javascript"></script>
194
    <script src="[% interface %]/[% theme %]/js/ajax.js" type="text/javascript"></script>
195
    <script src="[% interface %]/[% theme %]/js/ajax.js" type="text/javascript"></script>
(-)a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js (-1 / +21 lines)
Lines 24-30 KOHA.Preferences = { Link Here
24
            data: data,
24
            data: data,
25
            url: '/cgi-bin/koha/svc/config/systempreferences/',
25
            url: '/cgi-bin/koha/svc/config/systempreferences/',
26
            success: function ( data ) { KOHA.Preferences.Success( form ) },
26
            success: function ( data ) { KOHA.Preferences.Success( form ) },
27
            complete: function () { KOHA.AJAX.MarkDone( $( form ).find( '.save-all' ) ) }
27
            complete: function () { KOHA.AJAX.MarkDone( $( form ).find( '.save-all' ) ) },
28
            error: function( data ) { KOHA.Preferences.Error( data ) }
28
        } );
29
        } );
29
    },
30
    },
30
    Success: function ( form ) {
31
    Success: function ( form ) {
Lines 40-45 KOHA.Preferences = { Link Here
40
            .find( '.modified-warning' ).remove().end()
41
            .find( '.modified-warning' ).remove().end()
41
            .find( '.modified' ).removeClass('modified');
42
            .find( '.modified' ).removeClass('modified');
42
        KOHA.Preferences.Modified = false;
43
        KOHA.Preferences.Modified = false;
44
    },
45
    Error: function ( form ) {
46
        msg = "<strong>"+ MSG_DATA_NOT_SAVED + "</strong>\n";
47
        modified_prefs.each(function(){
48
            var modified_pref = $(this).attr("id");
49
            modified_pref = modified_pref.replace("pref_","");
50
            if (modified_pref in form.sysprefs) {
51
                if (form.sysprefs[modified_pref].error === 'Koha::Exceptions::Config::InvalidSyntax') {
52
                    msg += "<strong>"+ MSG_INVALID_SYNTAX.format(modified_pref) + "</strong>\n";
53
                } else {
54
                    msg += "<strong>"+ form.type + "</strong>\n";
55
                }
56
            } else {
57
                msg += "<strong>"+ MSG_SAVED_PREFERENCE.format(modified_pref) + "</strong>\n";
58
            }
59
        });
60
        humanMsg.displayAlert(msg);
61
62
        KOHA.Preferences.Modified = true;
43
    }
63
    }
44
};
64
};
45
65
(-)a/svc/config/systempreferences (-4 / +25 lines)
Lines 24-29 use C4::Context; Link Here
24
use C4::Service;
24
use C4::Service;
25
use C4::Log;
25
use C4::Log;
26
26
27
use Koha::Logger;
28
29
use Scalar::Util qw( blessed );
30
use Try::Tiny;
31
32
our $logger = Koha::Logger->get({ interface => 'intranet' });
33
27
=head1 NAME
34
=head1 NAME
28
35
29
svc/config/systempreferences - Web service for setting system preferences
36
svc/config/systempreferences - Web service for setting system preferences
Lines 87-92 pref_virtualshelves=0 Link Here
87
=cut
94
=cut
88
95
89
sub set_preferences {
96
sub set_preferences {
97
    my $errors;
90
    unless ( C4::Context->config( 'demo' ) ) {
98
    unless ( C4::Context->config( 'demo' ) ) {
91
        foreach my $param ( $query->param() ) {
99
        foreach my $param ( $query->param() ) {
92
            my ( $pref ) = ( $param =~ /pref_(.*)/ );
100
            my ( $pref ) = ( $param =~ /pref_(.*)/ );
Lines 94-105 sub set_preferences { Link Here
94
            next if ( !defined( $pref ) );
102
            next if ( !defined( $pref ) );
95
103
96
            my $value = join( ',', $query->multi_param( $param ) );
104
            my $value = join( ',', $query->multi_param( $param ) );
97
105
            try {
98
            C4::Context->set_preference( $pref, $value );
106
                C4::Context->set_preference( $pref, $value );
107
            } catch {
108
                unless (blessed $_ && $_->can('rethrow')) {
109
                    $logger->error( "Error saving system preference $pref, $_" );
110
                    $errors->{$pref} = { error => $_ };
111
                } else {
112
                    $logger->error( "Error saving system preference $pref (" .
113
                        ref($_) . ')' );
114
                    $errors->{$pref} = { error => ref($_) };
115
                }
116
            };
99
        }
117
        }
100
    }
118
    }
101
119
102
    C4::Service->return_success( $response );
120
    if ($errors) {
121
        return C4::Service->return_error( 'input', undef, sysprefs => $errors );
122
    }
123
124
    C4::Service->return_success( $response )
103
}
125
}
104
126
105
C4::Service->dispatch(
127
C4::Service->dispatch(
106
- 

Return to bug 20930