Skip to content

Commit

Permalink
basic import/export for localStorage, needs to be polished
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrp committed Jul 9, 2010
1 parent 104ac11 commit 5717683
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gsoc/todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ make CSS for darkblue_orange
check input escaping, $cfg is no longer safe to use

preference:
- synchronize language, theme ThemeDefault
- synchronize language, theme ThemeDefault

allow to import ThemeDefault
40 changes: 40 additions & 0 deletions js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ------------------------------------------------------------------
21 changes: 16 additions & 5 deletions prefs_manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
$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 = '';
Expand Down Expand Up @@ -117,15 +122,21 @@
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">
<h2><?php echo __('Import') ?></h2>
<form class="group-cnt prefs-form" name="prefs_import" action="prefs_manage.php" method="post" enctype="multipart/form-data">
<?php
echo PMA_generateHiddenMaxFileSize($max_upload_size) . "\n";
echo PMA_generate_common_hidden_inputs() . "\n";
?>
<?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>
Expand Down Expand Up @@ -184,7 +195,7 @@
</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 />
Expand Down

0 comments on commit 5717683

Please sign in to comment.