Skip to content

Commit

Permalink
Merge branch 'adminui_fixes' into adminui_testing
Browse files Browse the repository at this point in the history
Conflicts:
	fnordmetric-webui/fnordmetric-webui-util.js
  • Loading branch information
lauraschlimmer committed Nov 19, 2014
2 parents ecb6229 + 8145021 commit af5de99
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 66 deletions.
18 changes: 11 additions & 7 deletions fnordmetric-webui/fnordmetric-webui-queryeditor.js
Expand Up @@ -126,6 +126,12 @@ FnordMetric.views.QueryPlayground = function() {
}
}

function beforeUnloadEvent(e) {
e.returnValue =
"You may loose your query when leaving the page.";
}


function render(viewport, url, query_params) {
direction = "horizontal";
viewport = viewport;
Expand Down Expand Up @@ -169,13 +175,10 @@ FnordMetric.views.QueryPlayground = function() {


/* set eventListeners */
window.onbeforeunload = function(e) {
return "You may loose your query when leaving the page.";
}
window.addEventListener(
'beforeunload', beforeUnloadEvent, false);

window.addEventListener('resize', function() {
updateLayout()
});
window.addEventListener('resize', updateLayout);

editor_pane.addEventListener('keydown', function(e) {
if ((e.ctrlKey || e.metaKey) && e.keyCode == 13) {
Expand Down Expand Up @@ -268,7 +271,8 @@ FnordMetric.views.QueryPlayground = function() {
}

function destroy() {

window.removeEventListener('beforeunload', beforeUnloadEvent, false);
window.removeEventListener('resize', updateLayout);
}

return {
Expand Down
69 changes: 10 additions & 59 deletions fnordmetric-webui/fnordmetric-webui-util.js
Expand Up @@ -26,9 +26,8 @@ FnordMetric.util.parseQueryString = function(qstr) {
var query_params = {};

if (qstr.indexOf("?") >= 0) {
path = (qstr.substr(0, qstr.indexOf("?")) != "undefined")?
qstr.substr(0, qstr.indexOf("?")) : "";

path = qstr.substr(0, qstr.indexOf("?"));
path = path.replace("#", "");

var params_str = qstr.substr(qstr.indexOf("?") + 1);
var raw_params = params_str.split('&');
Expand Down Expand Up @@ -92,6 +91,7 @@ FnordMetric.util.setURLQueryString = function(hash, query_params, encode, push_s
}

if (push_state) {
console.log("push state");
window.history.pushState({url:path}, "#", path);
}
window.location.hash = path;
Expand Down Expand Up @@ -520,7 +520,6 @@ FnordMetric.util.generateSQLQueryFromParams = function(params) {
query =
draw_stm + select_expr + from_expr +
where_expr + group_expr + ";";

return query;
}

Expand All @@ -545,7 +544,7 @@ FnordMetric.util.getMonthStr = function(index) {

FnordMetric.util.isNumKey = function(keycode) {
return (
(keycode >= 48 && keycode <= 57) || (keycode >= 96 && keycode <= 105));
(keycode >= 48 && keycode <= 57));
}

/* tab, arrow-left, arrow-right, deletekeys */
Expand All @@ -558,62 +557,14 @@ FnordMetric.util.isNavKey = function(keycode) {
keycode == 46);
}


FnordMetric.util.validatedTimeInput = function (time_input, type, callback) {
var input = time_input.value;

time_input.addEventListener('keydown', function(e) {
if (e.keyCode == 13) {
callback();
return;
}
if (FnordMetric.util.isNumKey(e.keyCode)) {
var n = String.fromCharCode(e.keyCode);
input = time_input.value;

if (type == "hour") {
if (input.length == 0) {
if (n >= 0 && n <= 2) {
input = n;
time_input.value = n;
} else{
e.preventDefault();
}
} else if (input.length == 1) {
if (input < 2 || (input == 2 && n < 4)) {
input = input * 10 + n;
time_input.value += n;
} else {
e.preventDefault();
}
} else {
e.preventDefault();
}

} else if (type == "minute") {
if (input.length == 0) {
if (n >= 0 && n <= 5) {
input = n;
time_input.value = n;
} else {
e.preventDefault();
}
} else if (input.length == 1) {
input = input * 10 + n;
time_input.value += n;
} else {
e.preventDefault();
}
} else {
e.preventDefault();
}
}

if (!FnordMetric.util.isNavKey(e.keyCode)) {
FnordMetric.util.validatedTimeInput = function(time_input) {
time_input.maxLength = "2";
time_input.addEventListener('keypress', function(e) {
if (!FnordMetric.util.isNavKey(e.keyCode) &&
!FnordMetric.util.isNumKey(e.keyCode)) {
e.preventDefault();
}
}, false);

},false);
}

FnordMetric.util.appendLeadingZero = function (num) {
Expand Down

0 comments on commit af5de99

Please sign in to comment.