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 if ( ! $(form).valid() ) {
7 humanMsg.displayAlert( MSG_INVALID );
11 modified_prefs = $( form ).find( '.modified' );
12 // $.serialize removes empty value, we need to keep them.
13 // If a multiple select has all its entries unselected
14 var unserialized = new Array();
15 $(modified_prefs).each(function(){
16 if ( $(this).attr('multiple') && $(this).val() == null ) {
17 unserialized.push($(this));
20 data = modified_prefs.serialize();
21 $(unserialized).each(function(){
22 data += '&' + $(this).attr('name') + '=';
25 humanMsg.displayAlert( MSG_NOTHING_TO_SAVE );
28 KOHA.AJAX.MarkRunning( $( form ).find( '.save-all' ), MSG_SAVING );
31 url: '/cgi-bin/koha/svc/config/systempreferences/',
32 success: function ( data ) { KOHA.Preferences.Success( form ) },
33 complete: function () { KOHA.AJAX.MarkDone( $( form ).find( '.save-all' ) ) }
36 Success: function ( form ) {
38 modified_prefs.each(function(){
39 var modified_pref = $(this).attr("id");
40 modified_pref = modified_pref.replace("pref_","");
41 msg += "<strong>"+ MSG_SAVED_PREFERENCE.format(modified_pref) + "</strong>\n";
43 humanMsg.displayAlert(msg);
46 .find( '.modified-warning' ).remove().end()
47 .find( '.modified' ).removeClass('modified');
48 KOHA.Preferences.Modified = false;
52 function mark_modified() {
53 $( this.form ).find( '.save-all' ).prop('disabled', false);
54 $( this ).addClass( 'modified' );
55 var name_cell = $( this ).parents( '.name-row' ).find( '.name-cell' );
56 if ( !name_cell.find( '.modified-warning' ).length )
57 name_cell.append( '<em class="modified-warning">('+MSG_MODIFIED+')</em>' );
58 KOHA.Preferences.Modified = true;
61 window.onbeforeunload = function () {
62 if ( KOHA.Preferences.Modified ) {
63 return MSG_MADE_CHANGES;
67 $( document ).ready( function () {
69 $("table.preferences").dataTable($.extend(true, {}, dataTablesDefaults, {
72 { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false }
78 .find( 'input.preference, textarea.preference' ).on('input', function () {
79 if ( this.defaultValue === undefined || this.value != this.defaultValue ) mark_modified.call( this );
81 .find( 'select.preference' ).change( mark_modified );
82 $('.preference-checkbox').change( function () {
83 $('.preference-checkbox').addClass('modified');
84 mark_modified.call(this);
87 $(".set_syspref").click(function() {
88 var s = $(this).attr('data-syspref');
89 var v = $(this).attr('data-value');
90 // populate the input with the value in data-value
92 // pass the DOM element to trigger "modified" to enable submit button
93 mark_modified.call($("#pref_"+s)[0]);
97 $(".sortable").sortable();
98 $(".sortable").on( "sortchange", function( event, ui ) {
99 // This is not exact but we just need to trigger a change
100 $(ui.item.find('input:first')).change();
103 $( '.prefs-tab .action .cancel' ).click( function () { KOHA.Preferences.Modified = false } );
105 $( '.prefs-tab .save-all' ).prop('disabled', true).click( function () {
106 KOHA.Preferences.Save( this.form );
110 $( ".expand-textarea" ).on("click", function(e){
113 var target = $(this).data("target");
114 var syntax = $(this).data("syntax");
115 $("#collapse_" + target ).show();
117 var editor = CodeMirror.fromTextArea( document.getElementById( "pref_" + target ), {
121 viewportMargin: Infinity,
122 gutters: ["CodeMirror-lint-markers"],
125 editor.on("change", function(){
126 mark_modified.call( $("#pref_" + target )[0]);
128 editor.on("blur", function(){
132 $("#pref_" + target ).show();
136 $( ".collapse-textarea" ).on("click", function(e){
139 var target = $(this).data("target");
140 var syntax = $(this).data("syntax");
141 $("#expand_" + target ).show();
143 var editor = $("#pref_" + target ).next(".CodeMirror")[0].CodeMirror;
146 $("#pref_" + target ).hide();
149 $("h3").attr("class","expanded").attr("title",MSG_CLICK_TO_EXPAND);
150 var collapsible = $(".collapsed,.expanded");
152 $(collapsible).on("click",function(){
153 var h3Id = $(this).attr("id");
154 var panel = $("#collapse_" + h3Id);
155 if(panel.is(":visible")){
156 $(this).addClass("collapsed").removeClass("expanded").attr("title",MSG_CLICK_TO_EXPAND);
159 $(this).addClass("expanded").removeClass("collapsed").attr("title",MSG_CLICK_TO_COLLAPSE);
164 $(".pref_sublink").on("click", function(){
165 /* If the user clicks a sub-menu link in the sidebar,
166 check to see if it is collapsed. If so, expand it */
167 var href = $(this).attr("href");
168 href = href.replace("#","");
169 var panel = $("#collapse_" + href );
170 if( panel.is(":hidden") ){
171 $("#" + href ).addClass("expanded").removeClass("collapsed").attr("title",MSG_CLICK_TO_COLLAPSE);
176 if ( to_highlight ) {
177 var words = to_highlight.split( ' ' );
178 $( '.prefs-tab table' ).find( 'td, th' ).not( '.name-cell' ).each( function ( i, td ) {
179 $.each( words, function ( i, word ) { $( td ).highlight( word ) } );
180 } ).find( 'option, textarea' ).removeHighlight();
183 if ( search_jumped ) {
184 document.location.hash = "jumped";
187 $("#pref_UpdateItemLocationOnCheckin").change(function(){
188 var the_text = $(this).val();
190 if ( the_text.indexOf('_ALL_:') != -1 ) alert_text = MSG_ALL_VALUE_WARN + '\n';
191 var split_text =the_text.split("\n");
192 var alert_issues = '';
194 var reg_check = /.*:\s.*/;
195 for (var i=0; i < split_text.length; i++){
196 if ( !split_text[i].match(reg_check) && split_text[i].length ) {
197 alert_issues+=split_text[i]+"\n";
201 if (issue_count) alert_text += "\n"+ MSG_UPD_LOC_FORMAT_WARN +"\n"+alert_issues;
202 if ( alert_text.length ) alert(alert_text);
205 $(".prefs-tab form").each(function () {
208 errorPlacement: function(error, element) {
209 var placement = $(element).parent();
211 $(placement).append(error)
213 error.insertAfter(element);
219 $(".preference-email").each(function() {
220 $(this).rules("add", {