From 3137cc2f1d1e18a14c0dce9b63d34472f781dd49 Mon Sep 17 00:00:00 2001 From: Crack Date: Sat, 10 Jul 2010 00:06:50 +0200 Subject: [PATCH] add date information when importing from localStorage --- js/config.js | 32 +++++++++++++++++++++++++++++- libraries/user_preferences.inc.php | 2 +- prefs_manage.php | 9 +++++++-- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/js/config.js b/js/config.js index 5e1c3d28c..e8777545b 100644 --- a/js/config.js +++ b/js/config.js @@ -654,6 +654,9 @@ $(function() { var ls_exists = ls_supported ? (window.localStorage['config'] || false) : false; $('.localStorage-'+(ls_supported ? 'un' : '')+'supported').hide(); $('.localStorage-'+(ls_exists ? 'empty' : 'exists')).hide(); + if (ls_exists) { + updatePrefsDate(); + } $('form.prefs-form').change(function(){ var form = $(this); var disabled = false; @@ -697,7 +700,10 @@ function savePrefsToLocalStorage(form) submit_get_json: true }, success: function(response) { - window.localStorage.setItem('config', response.prefs); + window.localStorage['config'] = response.prefs; + window.localStorage['config_mtime'] = response.mtime; + window.localStorage['config_mtime_local'] = (new Date()).toUTCString(); + updatePrefsDate(); $('.localStorage-empty').hide(); $('.localStorage-exists').show(); }, @@ -707,6 +713,30 @@ function savePrefsToLocalStorage(form) }); } +/** + * Updates preferences timestamp in Import form + */ +function updatePrefsDate() +{ + var d = new Date(window.localStorage['config_mtime_local']); + var msg = PMA_messages['strSavedOn'].replace('__DATE__', formatDate(d)); + $('#opts_import_local_storage .localStorage-exists').html(msg); +} + +/** + * Returns date formatted as YYYY-MM-DD HH:II + * + * @param {Date} d + */ +function formatDate(d) +{ + return d.getFullYear() + '-' + + (d.getMonth() < 10 ? '0'+d.getMonth() : d.getMonth()) + + '-' + (d.getDay() < 10 ? '0'+d.getDay() : d.getDay()) + + ' ' + (d.getHours() < 10 ? '0'+d.getHours() : d.getHours()) + + ':' + (d.getMinutes() < 10 ? '0'+d.getMinutes() : d.getMinutes()); +} + // // END: User preferences import/export // ------------------------------------------------------------------ \ No newline at end of file diff --git a/libraries/user_preferences.inc.php b/libraries/user_preferences.inc.php index 3b3ebe798..1bdbe3a91 100644 --- a/libraries/user_preferences.inc.php +++ b/libraries/user_preferences.inc.php @@ -75,7 +75,7 @@ $msg = PMA_Message::notice('Debug: ' . $arr2); $msg->display(); // warn about using session storage for settings -$msg = __('Your preferences will be saved only for current session. Storing them permanently requires %s pmadb %s.'); +$msg = __('Your preferences will be saved only for current session. Storing them permanently requires %spmadb%s.'); $msg = PMA_sanitize(sprintf($msg, '[a@http://wiki.phpmyadmin.net/pma/pmadb@_blank]', '[/a]')); PMA_Message::notice($msg)->display(); diff --git a/prefs_manage.php b/prefs_manage.php index 0829dd83e..ebdecce49 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -31,7 +31,9 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == } else if (isset($_POST['submit_get_json'])) { $settings = PMA_load_userprefs(); header('Content-Type: application/json'); - echo json_encode(array('prefs' => json_encode($settings['config_data']))); + echo json_encode(array( + 'prefs' => json_encode($settings['config_data']), + 'mtime' => $settings['mtime'])); return; } else if (isset($_POST['submit_import'])) { // load from JSON file @@ -124,7 +126,7 @@ require_once './libraries/user_preferences.inc.php'; ?>
@@ -151,6 +153,9 @@ PMA_printJsValue("PMA_messages['strPrefsSaved']", __('Settings have been saved')