basic import/export for localStorage, needs to be polished

This commit is contained in:
Crack
2010-07-09 19:37:49 +02:00
parent 104ac11c1d
commit 5717683ef1
3 changed files with 59 additions and 6 deletions

View File

@@ -3,4 +3,6 @@ make CSS for darkblue_orange
check input escaping, $cfg is no longer safe to use check input escaping, $cfg is no longer safe to use
preference: preference:
- synchronize language, theme ThemeDefault - synchronize language, theme ThemeDefault
allow to import ThemeDefault

View File

@@ -664,9 +664,49 @@ $(function() {
disabled = true; disabled = true;
} }
form.find('input[type=submit]').attr('disabled', disabled); 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 // END: User preferences import/export
// ------------------------------------------------------------------ // ------------------------------------------------------------------

View File

@@ -28,6 +28,11 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') ==
$settings = PMA_load_userprefs(); $settings = PMA_load_userprefs();
echo json_encode($settings['config_data']); echo json_encode($settings['config_data']);
return; 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'])) { } else if (isset($_POST['submit_import'])) {
// load from JSON file // load from JSON file
$json = ''; $json = '';
@@ -117,15 +122,21 @@ $GLOBALS['js_include'][] = 'config.js';
require_once './libraries/header.inc.php'; require_once './libraries/header.inc.php';
require_once './libraries/user_preferences.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="maincontainer">
<div id="main_pane_left"> <div id="main_pane_left">
<div class="group"> <div class="group">
<h2><?php echo __('Import') ?></h2> <h2><?php echo __('Import') ?></h2>
<form class="group-cnt prefs-form" name="prefs_import" action="prefs_manage.php" method="post" enctype="multipart/form-data"> <form class="group-cnt prefs-form" name="prefs_import" action="prefs_manage.php" method="post" enctype="multipart/form-data">
<?php <?php
echo PMA_generateHiddenMaxFileSize($max_upload_size) . "\n"; echo PMA_generateHiddenMaxFileSize($max_upload_size) . "\n";
echo PMA_generate_common_hidden_inputs() . "\n"; echo PMA_generate_common_hidden_inputs() . "\n";
?> ?>
<input type="hidden" name="json" value="" />
<div style="padding-bottom:0.5em"> <div style="padding-bottom:0.5em">
<input type="radio" id="import_text_file" name="import_type" value="text_file" checked="checked" /> <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> <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>
<div class="group"> <div class="group">
<h2><?php echo __('Reset') ?></h2> <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 PMA_generate_common_hidden_inputs() . "\n" ?>
<?php echo __('You can reset all your settings and restore them to default values') ?> <?php echo __('You can reset all your settings and restore them to default values') ?>
<br /><br /> <br /><br />