diff --git a/.gsoc/todo.txt b/.gsoc/todo.txt index 961215a7b..579ab144b 100644 --- a/.gsoc/todo.txt +++ b/.gsoc/todo.txt @@ -3,4 +3,6 @@ make CSS for darkblue_orange check input escaping, $cfg is no longer safe to use preference: -- synchronize language, theme ThemeDefault \ No newline at end of file +- synchronize language, theme ThemeDefault + +allow to import ThemeDefault diff --git a/js/config.js b/js/config.js index 2b07f0a7a..5e1c3d28c 100644 --- a/js/config.js +++ b/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 // ------------------------------------------------------------------ \ No newline at end of file diff --git a/prefs_manage.php b/prefs_manage.php index 663ed0ea8..0829dd83e 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -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,15 +122,21 @@ $GLOBALS['js_include'][] = 'config.js'; require_once './libraries/header.inc.php'; require_once './libraries/user_preferences.inc.php'; ?> +

- + +
@@ -184,7 +195,7 @@ require_once './libraries/user_preferences.inc.php';

- +