From cd0fa24e7d5a3e905bc1c0a0d6c61ba24c80b3ef Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Mon, 4 Nov 2013 18:54:43 +0100 Subject: [PATCH] MT#4287 Use Statesave Feature This saves every configuration for datatables locally And clear every localStorage setting on login/logout --- share/layout/body.tt | 5 ----- share/templates/helpers/datatables.tt | 17 ++++++++++++----- share/templates/login/login.tt | 1 + 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/share/layout/body.tt b/share/layout/body.tt index 3a2954be74..f45e4027f2 100644 --- a/share/layout/body.tt +++ b/share/layout/body.tt @@ -180,11 +180,6 @@ $(function () { } }); } - - var my_pathname = window.location.pathname; - $('.dataTables_length > label > select').on('change', function (e) { - localStorage.setItem('ngcp_dt_entries'+my_pathname, $(this).find(":selected").text()); - }); }); diff --git a/share/templates/helpers/datatables.tt b/share/templates/helpers/datatables.tt index b472968efa..cd650dffad 100644 --- a/share/templates/helpers/datatables.tt +++ b/share/templates/helpers/datatables.tt @@ -25,10 +25,6 @@ $.extend( $.fn.dataTableExt.oStdClasses, { } ); $(document).ready(function() { - var my_pathname = window.location.pathname; - var show_rows_storage = localStorage.getItem('ngcp_dt_entries'+my_pathname); - if (! show_rows_storage ) - show_rows_storage = 5; var [% helper.id_from_name %]_table = $('#[% helper.id_from_name %]_table') .dataTable( { "sDom": "<'row-fluid ngcp_dt_top_elements'lf>t<'row-fluid'<'pull-left'i><'pull-right'p>>", @@ -36,6 +32,17 @@ $(document).ready(function() { "bServerSide": true, "bPaginate": [% helper.paginate || 'true' %], "bFilter": [% helper.filter || 'true' %], + "bStateSave": true, + "fnStateSave": function (oSettings, oData) { + localStorage.setItem( + 'ngcp_dt_[% helper.id_from_name %]_table', + JSON.stringify(oData) + ); + }, + "fnStateLoad": function (oSettings) { + return JSON.parse( localStorage.getItem('ngcp_dt_[% helper.id_from_name %]_table') ); + }, + "sPaginationType": "bootstrap", [% IF helper.length_change %] "bLengthChange": true, @@ -45,7 +52,7 @@ $(document).ready(function() { [% END %] "bSort": true, "bInfo": true, - "iDisplayLength": show_rows_storage, + "iDisplayLength": 5, 'iShowPages': 5, "sAjaxSource": "[% helper.ajax_uri %]", [% IF helper.column_sort -%] diff --git a/share/templates/login/login.tt b/share/templates/login/login.tt index 8c2ba3895d..0f3919f11d 100644 --- a/share/templates/login/login.tt +++ b/share/templates/login/login.tt @@ -40,6 +40,7 @@