]> git.nbdom.net Git - nb.git/commitdiff
dbq
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 23 Dec 2016 09:59:44 +0000 (09:59 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 23 Dec 2016 09:59:44 +0000 (09:59 +0000)
www/dbq/html/default.js [new file with mode: 0644]

diff --git a/www/dbq/html/default.js b/www/dbq/html/default.js
new file mode 100644 (file)
index 0000000..7b46542
--- /dev/null
@@ -0,0 +1,67 @@
+function form_submit_clean(form) {
+  form_clean(form);
+  form.submit();
+}
+
+function form_clean(form) {
+    var e;
+    for(i=0;i<form.length;i++) {
+      e = form.elements[i];
+      if (e.style.display == "none") continue;
+      if (e.type != "text") continue;
+      e.value = ""
+    }
+}
+
+function form_submit_clean(f) {
+  var i = 0;
+  var url = "";
+  var action = f.getAttribute("action");
+  var method = f.getAttribute("method");
+  if (method != "get") return true;
+
+  for(i=0;i<f.length;i++) {
+    var p = f[i];
+    if (!p.name) continue;
+    if (p.value=="") continue;
+    if (p.value=="undefined") continue;
+    url += (url ? "&" : "?") + encodeURI(p.name) + "=" + encodeURI(p.value);
+  }
+
+  url = (action == "?" ? "" : action) + url;
+
+  window.location = url;
+  return false;
+}
+
+document.addEventListener("DOMContentLoaded", function() {
+
+  for (var e of document.querySelectorAll("form")) {
+    e.onsubmit = function() {
+      return form_submit_clean(this);
+    };
+  }
+  document.getElementById("table").removeAttribute("name");
+  document.getElementById("format").removeAttribute("name");
+
+  for (var e of document.querySelectorAll(".menu select.tables, .menu select.format, .menu select.limit")) {
+    e.onchange = function() {
+      var format = document.getElementById("format").value;
+      if (format == window._dbq["HTML_FORMAT"]) format = "html";
+      window.location =  "./" + document.getElementById("table").value + "." + format;
+      return false;
+    };
+  }
+
+  for (var e of document.querySelectorAll(".menu select.limit")) {
+    e.onchange = function() {
+      this.form.submit();
+      return false;
+    };
+  }
+
+  if (document.querySelector(".nav.bottom")) {
+    document.querySelector("table.rows").insertAdjacentHTML("beforebegin","<div class=\"nav top\">"+document.querySelector(".nav.bottom").innerHTML+"</div>");
+  }
+
+});