1 // We can assume 'KOHA' exists, as we depend on KOHA.AJAX
4 Save: function ( form ) {
5 modified_prefs = $( form ).find( '.modified' );
6 // $.serialize removes empty value, we need to keep them.
7 // If a multiple select has all its entries unselected
8 var unserialized = new Array();
9 $(modified_prefs).each(function(){
10 if ( $(this).attr('multiple') && $(this).val() == null ) {
11 unserialized.push($(this));
14 data = modified_prefs.serialize();
15 $(unserialized).each(function(){
16 data += '&' + $(this).attr('name') + '=';
19 humanMsg.displayAlert( MSG_NOTHING_TO_SAVE );
22 KOHA.AJAX.MarkRunning( $( form ).find( '.save-all' ), MSG_SAVING );
25 url: '/cgi-bin/koha/svc/config/systempreferences/',
26 success: function ( data ) { KOHA.Preferences.Success( form ) },
27 complete: function () { KOHA.AJAX.MarkDone( $( form ).find( '.save-all' ) ) }
30 Success: function ( form ) {
32 modified_prefs.each(function(){
33 var modified_pref = $(this).attr("id");
34 modified_pref = modified_pref.replace("pref_","");
35 msg += "<strong>"+ MSG_SAVED_PREFERENCE.format(modified_pref) + "</strong>\n";
37 humanMsg.displayAlert(msg);
40 .find( '.modified-warning' ).remove().end()
41 .find( '.modified' ).removeClass('modified');
42 KOHA.Preferences.Modified = false;
46 $( document ).ready( function () {
48 $("table.preferences").dataTable($.extend(true, {}, dataTablesDefaults, {
51 { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false }
56 function mark_modified() {
57 $( this.form ).find( '.save-all' ).removeAttr( 'disabled' );
58 $( this ).addClass( 'modified' );
59 var name_cell = $( this ).parents( '.name-row' ).find( '.name-cell' );
60 if ( !name_cell.find( '.modified-warning' ).length )
61 name_cell.append( '<em class="modified-warning">('+MSG_MODIFIED+')</em>' );
62 KOHA.Preferences.Modified = true;
66 .find( 'input.preference, textarea.preference' ).on('input', function () {
67 if ( this.defaultValue === undefined || this.value != this.defaultValue ) mark_modified.call( this );
69 .find( 'select.preference' ).change( mark_modified );
70 $('.preference-checkbox').change( function () {
71 $('.preference-checkbox').addClass('modified');
72 mark_modified.call(this);
75 $(".set_syspref").click(function() {
76 var s = $(this).attr('data-syspref');
77 var v = $(this).attr('data-value');
78 // populate the input with the value in data-value
80 // pass the DOM element to trigger "modified" to enable submit button
81 mark_modified.call($("#pref_"+s)[0]);
85 window.onbeforeunload = function () {
86 if ( KOHA.Preferences.Modified ) {
87 return MSG_MADE_CHANGES;
91 $( '.prefs-tab .action .cancel' ).click( function () { KOHA.Preferences.Modified = false } );
93 $( '.prefs-tab .save-all' ).attr( 'disabled', true ).click( function () {
94 KOHA.Preferences.Save( this.form );
98 $( '.prefs-tab .expand-textarea' ).show().click( function () {
99 $( this ).hide().nextAll( 'textarea, input[type=submit], a' )
100 .animate( { height: 'show', queue: false } )
101 .animate( { opacity: 1 } );
104 } ).nextAll( 'textarea, input[type=submit]' ).hide().css( { opacity: 0 } );
106 $( '.prefs-tab .collapse-textarea' ).hide().click( function () {
107 $( this ).show().prevAll( 'textarea, input[type=submit]' )
108 .animate( { height: 'hide', queue: false } )
109 .animate( { opacity: 0 } );
111 $( this ).hide().prevAll( 'a' ).show();
116 $("h3").attr("class","expanded").attr("title",MSG_CLICK_TO_EXPAND);
117 var collapsible = $(".collapsed,.expanded");
119 $(collapsible).on("click",function(){
120 var panel = $(this).next("div");
121 if(panel.is(":visible")){
122 $(this).addClass("collapsed").removeClass("expanded").attr("title",MSG_CLICK_TO_EXPAND);
125 $(this).addClass("expanded").removeClass("collapsed").attr("title",MSG_CLICK_TO_COLLAPSE);
130 if ( to_highlight ) {
131 var words = to_highlight.split( ' ' );
132 $( '.prefs-tab table' ).find( 'td, th' ).not( '.name-cell' ).each( function ( i, td ) {
133 $.each( words, function ( i, word ) { $( td ).highlight( word ) } );
134 } ).find( 'option, textarea' ).removeHighlight();
137 if ( search_jumped ) {
138 document.location.hash = "jumped";