From adeb2f9e8402b2e3a6f91aaca49e14e2ce657bcd Mon Sep 17 00:00:00 2001 From: Dave Page Date: Wed, 11 Feb 2015 12:50:45 +0000 Subject: [PATCH] Allow multiple settings to be stored at once to avoid multiple requests. --- .../browser/templates/browser/body.html | 31 ++++++++++--------- web/pgadmin/settings/views.py | 14 ++++++--- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/web/pgadmin/browser/templates/browser/body.html b/web/pgadmin/browser/templates/browser/body.html index f1bb0a1ba..8c7a9246a 100644 --- a/web/pgadmin/browser/templates/browser/body.html +++ b/web/pgadmin/browser/templates/browser/body.html @@ -34,12 +34,19 @@ function storeLayout(pane, $pane, paneState, paneOptions) { state = layout.readState(); - $.post("{{ url_for('settings.store') }}", { setting: "Browser/SQL-Pane/Size", value: state.center.children.layout1.south.size }); - $.post("{{ url_for('settings.store') }}", { setting: "Browser/SQL-Pane/Hidden", value: state.center.children.layout1.south.initHidden }); - $.post("{{ url_for('settings.store') }}", { setting: "Browser/SQL-Pane/Closed", value: state.center.children.layout1.south.initClosed }); - $.post("{{ url_for('settings.store') }}", { setting: "Browser/Browser-Pane/Size", value: state.west.size }); - $.post("{{ url_for('settings.store') }}", { setting: "Browser/Browser-Pane/Hidden", value: state.west.initHidden }); - $.post("{{ url_for('settings.store') }}", { setting: "Browser/Browser-Pane/Closed", value: state.west.initClosed }); + settings = { setting1: "Browser/SQLPane/Size", + value1: state.center.children.layout1.south.size, + setting2: "Browser/SQLPane/Closed", + value2: state.center.children.layout1.south.initClosed, + setting3: "Browser/BrowserPane/Size", + value3: state.west.size, + setting4: "Browser/BrowserPane/Closed", + value4: state.west.initClosed, + count: 4 + } + + $.post("{{ url_for('settings.store') }}", settings); + return true } @@ -62,12 +69,10 @@ function getSetting(setting, defval) { } // Get the previous settings -var sqlPaneSize = getSetting("Browser/SQL-Pane/Size", "250") -var sqlPaneHidden = (getSetting("Browser/SQL-Pane/Hidden", "false") == "true" ? true : false) -var sqlPaneClosed = (getSetting("Browser/SQL-Pane/Closed", "false") == "true" ? true : false) -var browserPaneSize = getSetting("Browser/Browser-Pane/Size", "250") -var browserPaneHidden = (getSetting("Browser/Browser-Pane/Hidden", "false") == "true" ? true : false) -var browserPaneClosed = (getSetting("Browser/Browser-Pane/Closed", "false") == "true" ? true : false) +var sqlPaneSize = getSetting("Browser/SQLPane/Size", "250") +var sqlPaneClosed = (getSetting("Browser/SQLPane/Closed", "false") == "true" ? true : false) +var browserPaneSize = getSetting("Browser/BrowserPane/Size", "250") +var browserPaneClosed = (getSetting("Browser/BrowserPane/Closed", "false") == "true" ? true : false) var layout var layoutDefault = { @@ -80,7 +85,6 @@ var layoutDefault = { center__onresize: "storeLayout", south__maskContents: true, south__size: sqlPaneSize, - south__initHidden: sqlPaneHidden, south__initClosed: sqlPaneClosed, south__spacing_closed: 22, south__togglerLength_closed: 140, @@ -92,7 +96,6 @@ var layoutDefault = { }], west__maskContents: true, west__size: browserPaneSize, - west__initHidden: browserPaneHidden, west__initClosed: browserPaneClosed, west__spacing_closed: 22, west__togglerLength_closed: 140, diff --git a/web/pgadmin/settings/views.py b/web/pgadmin/settings/views.py index f7709be06..97e465e36 100644 --- a/web/pgadmin/settings/views.py +++ b/web/pgadmin/settings/views.py @@ -23,12 +23,16 @@ blueprint = Blueprint(MODULE_NAME, __name__, url_prefix='/' + MODULE_NAME) @blueprint.route("/store//", methods=['GET']) @login_required def store(setting=None, value=None): - """Store a configuration setting.""" + """Store a configuration setting, or if this is a POST request and a + count value is present, store multiple settings at once.""" if request.method == 'POST': - setting = request.form['setting'] - value = request.form['value'] - - store_setting(setting, value) + if 'count' in request.form: + for x in range(int(request.form['count'])): + store_setting(request.form['setting%d' % (x+1)], request.form['value%d' % (x+1)]) + else: + store_setting(request.form['setting'], request.form['value']) + else: + store_setting(setting, value) return ''