ff9d93204a01a5a172dd53e216b0ca647d33b27d
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / js / pages / preferences.js
1 // We can assume 'KOHA' exists, as we depend on KOHA.AJAX
2
3 KOHA.Preferences = {
4     Save: function ( form ) {
5         data = $( form ).find( '.modified' ).serialize();
6         if ( !data ) {
7             humanMsg.displayAlert( 'Nothing to save' );
8             return;
9         }
10         KOHA.AJAX.MarkRunning( $( form ).find( '.save-all' ), _( 'Saving...' ) );
11         KOHA.AJAX.Submit( {
12             data: data,
13             url: '/cgi-bin/koha/svc/config/systempreferences/',
14             success: function ( data ) { KOHA.Preferences.Success( form ) },
15             complete: function () { KOHA.AJAX.MarkDone( $( form ).find( '.save-all' ) ) }
16         } );
17     },
18     Success: function ( form ) {
19         humanMsg.displayAlert( 'Saved' );
20
21         $( form )
22             .find( '.modified-warning' ).remove().end()
23             .find( '.modified' ).removeClass('modified');
24         KOHA.Preferences.Modified = false;
25     }
26 };
27
28 $( document ).ready( function () {
29     function mark_modified() {
30         $( this.form ).find( '.save-all' ).removeAttr( 'disabled' );
31         $( this ).addClass( 'modified' );
32         var name_cell = $( this ).parent().parent().find( '.name-cell' );
33
34                 if ( !name_cell.find( '.modified-warning' ).length ) name_cell.append( '<em class="modified-warning">(modified)</em>' );
35         KOHA.Preferences.Modified = true;
36     }
37
38     $( '.prefs-tab' )
39         .find( 'input.preference, textarea.preference' ).keyup( function () {
40             if ( this.defaultValue === undefined || this.value != this.defaultValue ) mark_modified.call( this );
41         } ).end()
42         .find( 'select.preference' ).change( mark_modified );
43
44     window.onbeforeunload = function () {
45         if ( KOHA.Preferences.Modified ) {
46             return _( "You have made changes to system preferences." );
47         }
48     }
49
50     $( '.prefs-tab .action .cancel' ).click( function () { KOHA.Preferences.Modified = false } );
51
52     $( '.prefs-tab .save-all' ).attr( 'disabled', true ).click( function () {
53         KOHA.Preferences.Save( this.form );
54         return false;
55     } );
56
57     $( '.prefs-tab .expand-textarea' ).show().click( function () {
58         $( this ).hide().nextAll( 'textarea, input[type=submit]' )
59             .animate( { height: 'show', queue: false } )
60             .animate( { opacity: 1 } );
61
62         return false;
63     } ).nextAll( 'textarea, input[type=submit]' ).hide().css( { opacity: 0 } );
64
65     $("h3").attr("class","expanded").attr("title",_("Click to expand this section"));
66     var collapsible = $(".collapsed,.expanded");
67
68     $(collapsible).toggle(
69         function () {
70             $(this).addClass("collapsed").removeClass("expanded").attr("title",_("Click to expand this section"));
71             $(this).next("table").hide();
72         },
73         function () {
74             $(this).addClass("expanded").removeClass("collapsed").attr("title",_("Click to collapse this section"));
75             $(this).next("table").show();
76         }
77     );
78
79     if ( to_highlight ) {
80         var words = to_highlight.split( ' ' );
81         $( '.prefs-tab table' ).find( 'td, th' ).not( '.name-cell' ).each( function ( i, td ) {
82             $.each( words, function ( i, word ) { $( td ).highlight( word ) } );
83         } ).find( 'option' ).removeHighlight();
84     }
85
86     if ( search_jumped ) {
87         document.location.hash = "jumped";
88     }
89 } );