add date information when importing from localStorage

This commit is contained in:
Crack
2010-07-10 00:06:50 +02:00
parent bcaecbf10a
commit 3137cc2f1d
3 changed files with 39 additions and 4 deletions

View File

@@ -654,6 +654,9 @@ $(function() {
var ls_exists = ls_supported ? (window.localStorage['config'] || false) : false; var ls_exists = ls_supported ? (window.localStorage['config'] || false) : false;
$('.localStorage-'+(ls_supported ? 'un' : '')+'supported').hide(); $('.localStorage-'+(ls_supported ? 'un' : '')+'supported').hide();
$('.localStorage-'+(ls_exists ? 'empty' : 'exists')).hide(); $('.localStorage-'+(ls_exists ? 'empty' : 'exists')).hide();
if (ls_exists) {
updatePrefsDate();
}
$('form.prefs-form').change(function(){ $('form.prefs-form').change(function(){
var form = $(this); var form = $(this);
var disabled = false; var disabled = false;
@@ -697,7 +700,10 @@ function savePrefsToLocalStorage(form)
submit_get_json: true submit_get_json: true
}, },
success: function(response) { 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-empty').hide();
$('.localStorage-exists').show(); $('.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 // END: User preferences import/export
// ------------------------------------------------------------------ // ------------------------------------------------------------------

View File

@@ -31,7 +31,9 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') ==
} else if (isset($_POST['submit_get_json'])) { } else if (isset($_POST['submit_get_json'])) {
$settings = PMA_load_userprefs(); $settings = PMA_load_userprefs();
header('Content-Type: application/json'); 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; return;
} else if (isset($_POST['submit_import'])) { } else if (isset($_POST['submit_import'])) {
// load from JSON file // load from JSON file
@@ -124,7 +126,7 @@ require_once './libraries/user_preferences.inc.php';
?> ?>
<script type="text/javascript"> <script type="text/javascript">
<?php <?php
PMA_printJsValue("PMA_messages['strPrefsSaved']", __('Settings have been saved')); PMA_printJsValue("PMA_messages['strSavedOn']", __('Saved on: __DATE__'));
?> ?>
</script> </script>
<div id="maincontainer"> <div id="maincontainer">
@@ -151,6 +153,9 @@ PMA_printJsValue("PMA_messages['strPrefsSaved']", __('Settings have been saved')
<div id="opts_import_local_storage" style="display:none"> <div id="opts_import_local_storage" style="display:none">
<span class="localStorage-supported"> <span class="localStorage-supported">
<?php echo __('Settings will be imported from your browser\'s local storage.') ?> <?php echo __('Settings will be imported from your browser\'s local storage.') ?>
<span class="localStorage-exists">
<?php echo __('Saved on: __DATE__') ?>
</span>
<span class="localStorage-empty"> <span class="localStorage-empty">
<?php PMA_Message::notice(__('You have no saved settings!'))->display() ?> <?php PMA_Message::notice(__('You have no saved settings!'))->display() ?>
</span> </span>