Getting the back button to work

This commit is contained in:
Maxime Beauchemin 2016-02-02 12:45:00 -08:00
parent 9c47415d62
commit 3b9b81f93e
2 changed files with 19 additions and 10 deletions

View File

@ -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/',

View File

@ -72,8 +72,7 @@
</div>
<div class="topsql row">
<div class="col-xs-7 fillheight">
<textarea id="sql" class="fillup">SELECT * FROM information_schema.tables;
</textarea>
<textarea id="sql" class="fillup"></textarea>
</div>
<div class="col-xs-5 fillheight">
<div class="metadata fillup bordered">