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