Merge branch 'bug_2832' into 3.12-master
[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         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     $(".set_syspref").click(function() {
63         var s = $(this).attr('data-syspref');
64         var v = $(this).attr('data-value');
65         // populate the input with the value in data-value
66         $("#pref_"+s).val(v);
67         // pass the DOM element to trigger "modified" to enable submit button
68         mark_modified.call($("#pref_"+s)[0]);
69         return false;
70     });
71
72     window.onbeforeunload = function () {
73         if ( KOHA.Preferences.Modified ) {
74             return MSG_MADE_CHANGES;
75         }
76     }
77
78     $( '.prefs-tab .action .cancel' ).click( function () { KOHA.Preferences.Modified = false } );
79
80     $( '.prefs-tab .save-all' ).attr( 'disabled', true ).click( function () {
81         KOHA.Preferences.Save( this.form );
82         return false;
83     } );
84
85     $( '.prefs-tab .expand-textarea' ).show().click( function () {
86         $( this ).hide().nextAll( 'textarea, input[type=submit]' )
87             .animate( { height: 'show', queue: false } )
88             .animate( { opacity: 1 } );
89
90         return false;
91     } ).nextAll( 'textarea, input[type=submit]' ).hide().css( { opacity: 0 } );
92
93     $("h3").attr("class","expanded").attr("title",MSG_CLICK_TO_EXPAND);
94     var collapsible = $(".collapsed,.expanded");
95
96     $(collapsible).toggle(
97         function () {
98             $(this).addClass("collapsed").removeClass("expanded").attr("title",MSG_CLICK_TO_EXPAND);
99             $(this).next("table").hide();
100         },
101         function () {
102             $(this).addClass("expanded").removeClass("collapsed").attr("title",MSG_CLICK_TO_COLLAPSE);
103             $(this).next("table").show();
104         }
105     );
106
107     if ( to_highlight ) {
108         var words = to_highlight.split( ' ' );
109         $( '.prefs-tab table' ).find( 'td, th' ).not( '.name-cell' ).each( function ( i, td ) {
110             $.each( words, function ( i, word ) { $( td ).highlight( word ) } );
111         } ).find( 'option' ).removeHighlight();
112     }
113
114     if ( search_jumped ) {
115         document.location.hash = "jumped";
116     }
117 } );