Bug 9444 [Revised] Use DataTables in system preferences editor
[koha_fer] / koha-tmpl / intranet-tmpl / prog / en / js / pages / preferences.js
index cbf98b8..96e9e99 100644 (file)
@@ -1,20 +1,14 @@
-$(document).ready(function() {
-    $("table.preferences").tablesorter({
-        sortList: [[0,0]],
-        headers: { 1: { sorter:false}}
-    });
-});
-
 // We can assume 'KOHA' exists, as we depend on KOHA.AJAX
 
 KOHA.Preferences = {
     Save: function ( form ) {
-        data = $( form ).find( '.modified' ).serialize();
+        modified_prefs = $( form ).find( '.modified' );
+        data = modified_prefs.serialize();
         if ( !data ) {
-            humanMsg.displayAlert( 'Nothing to save' );
+            humanMsg.displayAlert( MSG_NOTHING_TO_SAVE );
             return;
         }
-        KOHA.AJAX.MarkRunning( $( form ).find( '.save-all' ), _( 'Saving...' ) );
+        KOHA.AJAX.MarkRunning( $( form ).find( '.save-all' ), _( MSG_SAVING ) );
         KOHA.AJAX.Submit( {
             data: data,
             url: '/cgi-bin/koha/svc/config/systempreferences/',
@@ -23,7 +17,13 @@ KOHA.Preferences = {
         } );
     },
     Success: function ( form ) {
-        humanMsg.displayAlert( 'Saved' );
+        var msg = "";
+        modified_prefs.each(function(){
+            var modified_pref = $(this).attr("id");
+            modified_pref = modified_pref.replace("pref_","");
+            msg += '<strong>Saved preference '+modified_pref+'</strong>\n';
+        });
+        humanMsg.displayAlert(msg);
 
         $( form )
             .find( '.modified-warning' ).remove().end()
@@ -33,12 +33,21 @@ KOHA.Preferences = {
 };
 
 $( document ).ready( function () {
+
+    $("table.preferences").dataTable($.extend(true, {}, dataTablesDefaults, {
+        "sDom": 't',
+        "aoColumnDefs": [
+            { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false }
+        ],
+        "bPaginate": false
+    }));
+
     function mark_modified() {
         $( this.form ).find( '.save-all' ).removeAttr( 'disabled' );
         $( this ).addClass( 'modified' );
         var name_cell = $( this ).parents( '.name-row' ).find( '.name-cell' );
                if ( !name_cell.find( '.modified-warning' ).length )
-            name_cell.append( '<em class="modified-warning">(modified)</em>' );
+            name_cell.append( '<em class="modified-warning">('+MSG_MODIFIED+')</em>' );
         KOHA.Preferences.Modified = true;
     }
 
@@ -52,9 +61,19 @@ $( document ).ready( function () {
         mark_modified.call(this);
     } );
 
+    $(".set_syspref").click(function() {
+        var s = $(this).attr('data-syspref');
+        var v = $(this).attr('data-value');
+        // populate the input with the value in data-value
+        $("#pref_"+s).val(v);
+        // pass the DOM element to trigger "modified" to enable submit button
+        mark_modified.call($("#pref_"+s)[0]);
+        return false;
+    });
+
     window.onbeforeunload = function () {
         if ( KOHA.Preferences.Modified ) {
-            return _( "You have made changes to system preferences." );
+            return MSG_MADE_CHANGES;
         }
     }
 
@@ -73,17 +92,17 @@ $( document ).ready( function () {
         return false;
     } ).nextAll( 'textarea, input[type=submit]' ).hide().css( { opacity: 0 } );
 
-    $("h3").attr("class","expanded").attr("title",_("Click to expand this section"));
+    $("h3").attr("class","expanded").attr("title",MSG_CLICK_TO_EXPAND);
     var collapsible = $(".collapsed,.expanded");
 
     $(collapsible).toggle(
         function () {
-            $(this).addClass("collapsed").removeClass("expanded").attr("title",_("Click to expand this section"));
-            $(this).next("table").hide();
+            $(this).addClass("collapsed").removeClass("expanded").attr("title",MSG_CLICK_TO_EXPAND);
+            $(this).next("div").hide();
         },
         function () {
-            $(this).addClass("expanded").removeClass("collapsed").attr("title",_("Click to collapse this section"));
-            $(this).next("table").show();
+            $(this).addClass("expanded").removeClass("collapsed").attr("title",MSG_CLICK_TO_COLLAPSE);
+            $(this).next("div").show();
         }
     );
 
@@ -91,7 +110,7 @@ $( document ).ready( function () {
         var words = to_highlight.split( ' ' );
         $( '.prefs-tab table' ).find( 'td, th' ).not( '.name-cell' ).each( function ( i, td ) {
             $.each( words, function ( i, word ) { $( td ).highlight( word ) } );
-        } ).find( 'option' ).removeHighlight();
+        } ).find( 'option, textarea' ).removeHighlight();
     }
 
     if ( search_jumped ) {