From 3b9b81f93e22e1e62dfb11b286e7daaaba30ebfb Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Tue, 2 Feb 2016 12:45:00 -0800 Subject: [PATCH] Getting the back button to work --- panoramix/static/panoramix.js | 26 ++++++++++++++++++-------- panoramix/templates/panoramix/sql.html | 3 +-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/panoramix/static/panoramix.js b/panoramix/static/panoramix.js index 679ea47c83784..b42654da48ff8 100644 --- a/panoramix/static/panoramix.js +++ b/panoramix/static/panoramix.js @@ -49,6 +49,12 @@ var px = (function() { var visualizations = {}; var dashboard = undefined; + function getParam(name) { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), + results = regex.exec(location.search); + return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); + } function UTC(dttm){ return v = new Date(dttm.getUTCFullYear(), dttm.getUTCMonth(), dttm.getUTCDate(), dttm.getUTCHours(), dttm.getUTCMinutes(), dttm.getUTCSeconds()); @@ -333,12 +339,6 @@ var px = (function() { for(var i=0; i < collapsed_fieldsets.length; i++){ toggle_fieldset($('legend:contains("' + collapsed_fieldsets[i] + '")'), false); } - function getParam(name) { - name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); - var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), - results = regex.exec(location.search); - return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); - } $(".select2").select2({dropdownAutoWidth : true}); $(".select2Sortable").select2({dropdownAutoWidth : true}); @@ -445,6 +445,8 @@ var px = (function() { function initSqlEditorView() { var editor = ace.edit("sql"); + editor.$blockScrolling = Infinity + var textarea = $('#sql').hide(); editor.setTheme("ace/theme/crimson_editor"); editor.setOptions({ @@ -453,7 +455,6 @@ var px = (function() { }); editor.getSession().setMode("ace/mode/sql"); editor.focus(); - $("select").select2({dropdownAutoWidth : true}); function showTableMetadata() { $(".metadata").load('/panoramix/table/' + $("#dbtable").val() + '/'); @@ -468,10 +469,19 @@ var px = (function() { editor.setValue(msg); }); }); - $("#select_star").click(); + editor.setValue(getParam('sql')); + $(window).bind("popstate", function(event) { + // Browser back button + var returnLocation = history.location || document.location; + // Could do something more lightweight here, but we're not optimizing + // for the use of the back button anyways + editor.setValue(getParam('sql')); + $("#run").click(); + }); $("#run").click(function() { $('#results').hide(0); $('#loading').show(0); + history.pushState({}, document.title, '?sql=' + encodeURIComponent(editor.getValue())); $.ajax({ type: "POST", url: '/panoramix/runsql/', diff --git a/panoramix/templates/panoramix/sql.html b/panoramix/templates/panoramix/sql.html index 3cde931755fd2..84c38e73ed464 100644 --- a/panoramix/templates/panoramix/sql.html +++ b/panoramix/templates/panoramix/sql.html @@ -72,8 +72,7 @@

db: [{{ db }}]

- +