Bug 5917 : Converted templates
[koha.git] / koha-tt / 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         modified_prefs = $( form ).find( '.modified' );
13         data = modified_prefs.serialize();
14         if ( !data ) {
15             humanMsg.displayAlert( MSG_NOTHING_TO_SAVE );
16             return;
17         }
18         KOHA.AJAX.MarkRunning( $( form ).find( '.save-all' ), _( MSG_SAVING ) );
19         KOHA.AJAX.Submit( {
20             data: data,
21             url: '/cgi-bin/koha/svc/config/systempreferences/',
22             success: function ( data ) { KOHA.Preferences.Success( form ) },
23             complete: function () { KOHA.AJAX.MarkDone( $( form ).find( '.save-all' ) ) }
24         } );
25     },
26     Success: function ( form ) {
27         var msg = "";
28         modified_prefs.each(function(){
29             var modified_pref = $(this).attr("id");
30             modified_pref = modified_pref.replace("pref_","");
31             msg += '<strong>Saved preference '+modified_pref+'</strong>\n';
32         });
33         humanMsg.displayAlert(msg);
34
35         $( form )
36             .find( '.modified-warning' ).remove().end()
37             .find( '.modified' ).removeClass('modified');
38         KOHA.Preferences.Modified = false;
39     }
40 };
41
42 $( document ).ready( function () {
43     function mark_modified() {
44         $( this.form ).find( '.save-all' ).removeAttr( 'disabled' );
45         $( this ).addClass( 'modified' );
46         var name_cell = $( this ).parents( '.name-row' ).find( '.name-cell' );
47                 if ( !name_cell.find( '.modified-warning' ).length )
48             name_cell.append( '<em class="modified-warning">('+MSG_MODIFIED+')</em>' );
49         KOHA.Preferences.Modified = true;
50     }
51
52     $( '.prefs-tab' )
53         .find( 'input.preference, textarea.preference' ).keyup( function () {
54             if ( this.defaultValue === undefined || this.value != this.defaultValue ) mark_modified.call( this );
55         } ).end()
56         .find( 'select.preference' ).change( mark_modified );
57     $('.preference-checkbox').change( function () {
58         $('.preference-checkbox').addClass('modified');
59         mark_modified.call(this);
60     } );
61
62     window.onbeforeunload = function () {
63         if ( KOHA.Preferences.Modified ) {
64             return MSG_MADE_CHANGES;
65         }
66     }
67
68     $( '.prefs-tab .action .cancel' ).click( function () { KOHA.Preferences.Modified = false } );
69
70     $( '.prefs-tab .save-all' ).attr( 'disabled', true ).click( function () {
71         KOHA.Preferences.Save( this.form );
72         return false;
73     } );
74
75     $( '.prefs-tab .expand-textarea' ).show().click( function () {
76         $( this ).hide().nextAll( 'textarea, input[type=submit]' )
77             .animate( { height: 'show', queue: false } )
78             .animate( { opacity: 1 } );
79
80         return false;
81     } ).nextAll( 'textarea, input[type=submit]' ).hide().css( { opacity: 0 } );
82
83     $("h3").attr("class","expanded").attr("title",MSG_CLICK_TO_EXPAND);
84     var collapsible = $(".collapsed,.expanded");
85
86     $(collapsible).toggle(
87         function () {
88             $(this).addClass("collapsed").removeClass("expanded").attr("title",MSG_CLICK_TO_EXPAND);
89             $(this).next("table").hide();
90         },
91         function () {
92             $(this).addClass("expanded").removeClass("collapsed").attr("title",MSG_CLICK_TO_COLLAPSE);
93             $(this).next("table").show();
94         }
95     );
96
97     if ( to_highlight ) {
98         var words = to_highlight.split( ' ' );
99         $( '.prefs-tab table' ).find( 'td, th' ).not( '.name-cell' ).each( function ( i, td ) {
100             $.each( words, function ( i, word ) { $( td ).highlight( word ) } );
101         } ).find( 'option' ).removeHighlight();
102     }
103
104     if ( search_jumped ) {
105         document.location.hash = "jumped";
106     }
107 } );