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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt (-1 / +2 lines)
Lines 211-217 Link Here
211
        var MSG_LOADING = _( "Loading..." );
211
        var MSG_LOADING = _( "Loading..." );
212
        var MSG_ALL_VALUE_WARN = _("Note: _ALL_ value will override all other values");
212
        var MSG_ALL_VALUE_WARN = _("Note: _ALL_ value will override all other values");
213
        var MSG_UPD_LOC_FORMAT_WARN = _("The following values are not formatted correctly:");
213
        var MSG_UPD_LOC_FORMAT_WARN = _("The following values are not formatted correctly:");
214
        var MSG_INVALID = _( "Error: presence of invalid data prevent saving. Please make the corrections and try again." );
214
        var MSG_INVALID = _( "Error: presence of invalid data prevents saving. Please make the corrections and try again." );
215
        var MSG_INVALID_SYNTAX = _( "Error: Preference '%s' has invalid syntax" );
215
    </script>
216
    </script>
216
    [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
217
    [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
217
    [% Asset.js("js/ajax.js") | $raw %]
218
    [% Asset.js("js/ajax.js") | $raw %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js (-1 / +21 lines)
Lines 30-36 KOHA.Preferences = { Link Here
30
            data: data,
30
            data: data,
31
            url: '/cgi-bin/koha/svc/config/systempreferences/',
31
            url: '/cgi-bin/koha/svc/config/systempreferences/',
32
            success: function ( data ) { KOHA.Preferences.Success( form ) },
32
            success: function ( data ) { KOHA.Preferences.Success( form ) },
33
            complete: function () { KOHA.AJAX.MarkDone( $( form ).find( '.save-all' ) ) }
33
            complete: function () { KOHA.AJAX.MarkDone( $( form ).find( '.save-all' ) ) },
34
            error: function( data ) { KOHA.Preferences.Error( data ) }
34
        } );
35
        } );
35
    },
36
    },
36
    Success: function ( form ) {
37
    Success: function ( form ) {
Lines 46-51 KOHA.Preferences = { Link Here
46
            .find( '.modified-warning' ).remove().end()
47
            .find( '.modified-warning' ).remove().end()
47
            .find( '.modified' ).removeClass('modified');
48
            .find( '.modified' ).removeClass('modified');
48
        KOHA.Preferences.Modified = false;
49
        KOHA.Preferences.Modified = false;
50
    },
51
    Error: function ( form ) {
52
        msg = "<strong>"+ MSG_DATA_NOT_SAVED + "</strong>\n";
53
        modified_prefs.each(function(){
54
            var modified_pref = $(this).attr("id");
55
            modified_pref = modified_pref.replace("pref_","");
56
            if (modified_pref in form.sysprefs) {
57
                if (form.sysprefs[modified_pref].error === 'Koha::Exceptions::Config::InvalidSyntax') {
58
                    msg += "<strong>"+ MSG_INVALID_SYNTAX.format(modified_pref) + "</strong>\n";
59
                } else {
60
                    msg += "<strong>"+ form.type + "</strong>\n";
61
                }
62
            } else {
63
                msg += "<strong>"+ MSG_SAVED_PREFERENCE.format(modified_pref) + "</strong>\n";
64
            }
65
        });
66
        humanMsg.displayAlert(msg);
67
68
        KOHA.Preferences.Modified = true;
49
    }
69
    }
50
};
70
};
51
71
(-)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 95-100 pref_virtualshelves=0 Link Here
95
=cut
102
=cut
96
103
97
sub set_preferences {
104
sub set_preferences {
105
    my $errors;
98
    unless ( C4::Context->config( 'demo' ) ) {
106
    unless ( C4::Context->config( 'demo' ) ) {
99
        foreach my $param ( $query->param() ) {
107
        foreach my $param ( $query->param() ) {
100
            my ( $pref ) = ( $param =~ /pref_(.*)/ );
108
            my ( $pref ) = ( $param =~ /pref_(.*)/ );
Lines 102-113 sub set_preferences { Link Here
102
            next if ( !defined( $pref ) );
110
            next if ( !defined( $pref ) );
103
111
104
            my $value = join( ',', $query->multi_param( $param ) );
112
            my $value = join( ',', $query->multi_param( $param ) );
105
113
            try {
106
            C4::Context->set_preference( $pref, $value );
114
                C4::Context->set_preference( $pref, $value );
115
            } catch {
116
                unless (blessed $_ && $_->can('rethrow')) {
117
                    $logger->error( "Error saving system preference $pref, $_" );
118
                    $errors->{$pref} = { error => $_ };
119
                } else {
120
                    $logger->error( "Error saving system preference $pref (" .
121
                        ref($_) . ')' );
122
                    $errors->{$pref} = { error => ref($_) };
123
                }
124
            };
107
        }
125
        }
108
    }
126
    }
109
127
110
    C4::Service->return_success( $response );
128
    if ($errors) {
129
        return C4::Service->return_error( 'input', undef, sysprefs => $errors );
130
    }
131
132
    C4::Service->return_success( $response )
111
}
133
}
112
134
113
C4::Service->dispatch(
135
C4::Service->dispatch(
114
- 

Return to bug 20930