basic import/export for localStorage, needs to be polished
This commit is contained in:
@@ -4,3 +4,5 @@ check input escaping, $cfg is no longer safe to use
|
||||
|
||||
preference:
|
||||
- synchronize language, theme ThemeDefault
|
||||
|
||||
allow to import ThemeDefault
|
||||
|
40
js/config.js
40
js/config.js
@@ -664,9 +664,49 @@ $(function() {
|
||||
disabled = true;
|
||||
}
|
||||
form.find('input[type=submit]').attr('disabled', disabled);
|
||||
}).submit(function(e) {
|
||||
var form = $(this);
|
||||
if (form.attr('name') == 'prefs_export' && $('#export_local_storage')[0].checked) {
|
||||
e.preventDefault();
|
||||
// use AJAX to read JSON settings and save them
|
||||
savePrefsToLocalStorage(form);
|
||||
} else if (form.attr('name') == 'prefs_import' && $('#import_local_storage')[0].checked) {
|
||||
// set 'json' input and submit form
|
||||
form.find('input[name=json]').val(window.localStorage['config']);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Saves user preferences to localStorage
|
||||
*
|
||||
* @param {Element} form
|
||||
*/
|
||||
function savePrefsToLocalStorage(form)
|
||||
{
|
||||
form = $(form);
|
||||
var submit = form.find('input[type=submit]');
|
||||
//PMA_messages['strPrefsSaved']
|
||||
submit.attr('disabled', true);
|
||||
$.ajax({
|
||||
url: 'prefs_manage.php',
|
||||
cache: false,
|
||||
type: 'POST',
|
||||
data: {
|
||||
token: form.find('input[name=token]').val(),
|
||||
submit_get_json: true
|
||||
},
|
||||
success: function(response) {
|
||||
window.localStorage.setItem('config', response.prefs);
|
||||
$('.localStorage-empty').hide();
|
||||
$('.localStorage-exists').show();
|
||||
},
|
||||
complete: function() {
|
||||
submit.attr('disabled', false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
// END: User preferences import/export
|
||||
// ------------------------------------------------------------------
|
@@ -28,6 +28,11 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') ==
|
||||
$settings = PMA_load_userprefs();
|
||||
echo json_encode($settings['config_data']);
|
||||
return;
|
||||
} 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'])));
|
||||
return;
|
||||
} else if (isset($_POST['submit_import'])) {
|
||||
// load from JSON file
|
||||
$json = '';
|
||||
@@ -117,6 +122,11 @@ $GLOBALS['js_include'][] = 'config.js';
|
||||
require_once './libraries/header.inc.php';
|
||||
require_once './libraries/user_preferences.inc.php';
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<?php
|
||||
PMA_printJsValue("PMA_messages['strPrefsSaved']", __('Settings have been saved'));
|
||||
?>
|
||||
</script>
|
||||
<div id="maincontainer">
|
||||
<div id="main_pane_left">
|
||||
<div class="group">
|
||||
@@ -126,6 +136,7 @@ require_once './libraries/user_preferences.inc.php';
|
||||
echo PMA_generateHiddenMaxFileSize($max_upload_size) . "\n";
|
||||
echo PMA_generate_common_hidden_inputs() . "\n";
|
||||
?>
|
||||
<input type="hidden" name="json" value="" />
|
||||
<div style="padding-bottom:0.5em">
|
||||
<input type="radio" id="import_text_file" name="import_type" value="text_file" checked="checked" />
|
||||
<label for="import_text_file"><?php echo __('Import from text file') ?></label>
|
||||
@@ -184,7 +195,7 @@ require_once './libraries/user_preferences.inc.php';
|
||||
</div>
|
||||
<div class="group">
|
||||
<h2><?php echo __('Reset') ?></h2>
|
||||
<form class="group-cnt prefs-form" name="prefs_export" action="prefs_manage.php" method="post">
|
||||
<form class="group-cnt prefs-form" name="prefs_reset" action="prefs_manage.php" method="post">
|
||||
<?php echo PMA_generate_common_hidden_inputs() . "\n" ?>
|
||||
<?php echo __('You can reset all your settings and restore them to default values') ?>
|
||||
<br /><br />
|
||||
|
Reference in New Issue
Block a user