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' ).prop('disabled', false);
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 $("dl.sortable").sortable();
86 $("dl.sortable").on( "sortchange", function( event, ui ) {
87 // This is not exact but we just need to trigger a change
88 $(ui.item.find('input:first')).change();
91 window.onbeforeunload = function () {
92 if ( KOHA.Preferences.Modified ) {
93 return MSG_MADE_CHANGES;
97 $( '.prefs-tab .action .cancel' ).click( function () { KOHA.Preferences.Modified = false } );
99 $( '.prefs-tab .save-all' ).prop('disabled', true).click( function () {
100 KOHA.Preferences.Save( this.form );
104 $( '.prefs-tab .expand-textarea' ).show().click( function () {
105 $( this ).hide().nextAll( 'textarea, input[type=submit], a' )
106 .animate( { height: 'show', queue: false } )
107 .animate( { opacity: 1 } );
110 } ).nextAll( 'textarea, input[type=submit]' ).hide().css( { opacity: 0 } );
112 $( '.prefs-tab .collapse-textarea' ).hide().click( function () {
113 $( this ).show().prevAll( 'textarea, input[type=submit]' )
114 .animate( { height: 'hide', queue: false } )
115 .animate( { opacity: 0 } );
117 $( this ).hide().prevAll( 'a' ).show();
122 $("h3").attr("class","expanded").attr("title",MSG_CLICK_TO_EXPAND);
123 var collapsible = $(".collapsed,.expanded");
125 $(collapsible).on("click",function(){
126 var panel = $(this).next("div");
127 if(panel.is(":visible")){
128 $(this).addClass("collapsed").removeClass("expanded").attr("title",MSG_CLICK_TO_EXPAND);
131 $(this).addClass("expanded").removeClass("collapsed").attr("title",MSG_CLICK_TO_COLLAPSE);
136 if ( to_highlight ) {
137 var words = to_highlight.split( ' ' );
138 $( '.prefs-tab table' ).find( 'td, th' ).not( '.name-cell' ).each( function ( i, td ) {
139 $.each( words, function ( i, word ) { $( td ).highlight( word ) } );
140 } ).find( 'option, textarea' ).removeHighlight();
143 if ( search_jumped ) {
144 document.location.hash = "jumped";