1 /* global KOHA MSG_MADE_CHANGES CodeMirror MSG_CLICK_TO_EXPAND MSG_CLICK_TO_COLLAPSE to_highlight search_jumped humanMsg MSG_NOTHING_TO_SAVE MSG_MODIFIED MSG_SAVING MSG_SAVED_PREFERENCE dataTablesDefaults */
2 // We can assume 'KOHA' exists, as we depend on KOHA.AJAX
5 Save: function ( form ) {
6 modified_prefs = $( form ).find( '.modified' );
7 // $.serialize removes empty value, we need to keep them.
8 // If a multiple select has all its entries unselected
9 var unserialized = new Array();
10 $(modified_prefs).each(function(){
11 if ( $(this).attr('multiple') && $(this).val() == null ) {
12 unserialized.push($(this));
15 data = modified_prefs.serialize();
16 $(unserialized).each(function(){
17 data += '&' + $(this).attr('name') + '=';
20 humanMsg.displayAlert( MSG_NOTHING_TO_SAVE );
23 KOHA.AJAX.MarkRunning( $( form ).find( '.save-all' ), MSG_SAVING );
26 url: '/cgi-bin/koha/svc/config/systempreferences/',
27 success: function ( data ) { KOHA.Preferences.Success( form ) },
28 complete: function () { KOHA.AJAX.MarkDone( $( form ).find( '.save-all' ) ) }
31 Success: function ( form ) {
33 modified_prefs.each(function(){
34 var modified_pref = $(this).attr("id");
35 modified_pref = modified_pref.replace("pref_","");
36 msg += "<strong>"+ MSG_SAVED_PREFERENCE.format(modified_pref) + "</strong>\n";
38 humanMsg.displayAlert(msg);
41 .find( '.modified-warning' ).remove().end()
42 .find( '.modified' ).removeClass('modified');
43 KOHA.Preferences.Modified = false;
47 $( document ).ready( function () {
49 $("table.preferences").dataTable($.extend(true, {}, dataTablesDefaults, {
52 { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false }
57 function mark_modified() {
58 $( this.form ).find( '.save-all' ).prop('disabled', false);
59 $( this ).addClass( 'modified' );
60 var name_cell = $( this ).parents( '.name-row' ).find( '.name-cell' );
61 if ( !name_cell.find( '.modified-warning' ).length )
62 name_cell.append( '<em class="modified-warning">('+MSG_MODIFIED+')</em>' );
63 KOHA.Preferences.Modified = true;
67 .find( 'input.preference, textarea.preference' ).on('input', function () {
68 if ( this.defaultValue === undefined || this.value != this.defaultValue ) mark_modified.call( this );
70 .find( 'select.preference' ).change( mark_modified );
71 $('.preference-checkbox').change( function () {
72 $('.preference-checkbox').addClass('modified');
73 mark_modified.call(this);
76 $(".set_syspref").click(function() {
77 var s = $(this).attr('data-syspref');
78 var v = $(this).attr('data-value');
79 // populate the input with the value in data-value
81 // pass the DOM element to trigger "modified" to enable submit button
82 mark_modified.call($("#pref_"+s)[0]);
86 $(".sortable").sortable();
87 $(".sortable").on( "sortchange", function( event, ui ) {
88 // This is not exact but we just need to trigger a change
89 $(ui.item.find('input:first')).change();
92 window.onbeforeunload = function () {
93 if ( KOHA.Preferences.Modified ) {
94 return MSG_MADE_CHANGES;
98 $( '.prefs-tab .action .cancel' ).click( function () { KOHA.Preferences.Modified = false } );
100 $( '.prefs-tab .save-all' ).prop('disabled', true).click( function () {
101 KOHA.Preferences.Save( this.form );
105 $( ".expand-textarea" ).on("click", function(e){
108 var target = $(this).data("target");
109 var syntax = $(this).data("syntax");
110 $("#collapse_" + target ).show();
112 var editor = CodeMirror.fromTextArea( document.getElementById( "pref_" + target ), {
117 editor.on("change", function(){
118 mark_modified.call( $("#pref_" + target )[0]);
120 editor.on("blur", function(){
124 $("#pref_" + target ).show();
128 $( ".collapse-textarea" ).on("click", function(e){
131 var target = $(this).data("target");
132 var syntax = $(this).data("syntax");
133 $("#expand_" + target ).show();
135 var editor = $("#pref_" + target ).next(".CodeMirror")[0].CodeMirror;
138 $("#pref_" + target ).hide();
141 $("h3").attr("class","expanded").attr("title",MSG_CLICK_TO_EXPAND);
142 var collapsible = $(".collapsed,.expanded");
144 $(collapsible).on("click",function(){
145 var panel = $(this).next("div");
146 if(panel.is(":visible")){
147 $(this).addClass("collapsed").removeClass("expanded").attr("title",MSG_CLICK_TO_EXPAND);
150 $(this).addClass("expanded").removeClass("collapsed").attr("title",MSG_CLICK_TO_COLLAPSE);
155 if ( to_highlight ) {
156 var words = to_highlight.split( ' ' );
157 $( '.prefs-tab table' ).find( 'td, th' ).not( '.name-cell' ).each( function ( i, td ) {
158 $.each( words, function ( i, word ) { $( td ).highlight( word ) } );
159 } ).find( 'option, textarea' ).removeHighlight();
162 if ( search_jumped ) {
163 document.location.hash = "jumped";
166 $("#pref_UpdateItemLocationOnCheckin").change(function(){
167 var the_text = $(this).val();
169 if ( the_text.indexOf('_ALL_:') != -1 ) alert_text = MSG_ALL_VALUE_WARN + '\n';
170 var split_text =the_text.split("\n");
171 var alert_issues = '';
173 var reg_check = /.*:\s.*/;
174 for (var i=0; i < split_text.length; i++){
175 if ( !split_text[i].match(reg_check) && split_text[i].length ) {
176 alert_issues+=split_text[i]+"\n";
180 if (issue_count) alert_text += "\n"+ MSG_UPD_LOC_FORMAT_WARN +"\n"+alert_issues;
181 if ( alert_text.length ) alert(alert_text);