+document.addEventListener("DOMContentLoaded", function() {
+
+ //console.log('LOADED');
+ NodeList.prototype.forEach = Array.prototype.forEach;
+ var ext = ( window._dbq['param.format'] ? '.'+window._dbq['param.format'] : '');
+ if ( ext == '.'+window._dbq['default.format'] ) ext='';
+
+ /* Clean when submit */
+ document.querySelectorAll("form").forEach(function(e) {
+ e.onsubmit = function() {
+ if (this.elements['limit']) {
+ var limit = this.elements['limit'];
+ if (window._dbq['default_limit'] != 'undefined' && limit.value == window._dbq['default_limit']) limit.removeAttribute("value");
+ }
+ return form_submit_clean(this);
+ };
+ });
+
+ /*
+ Menu
+ */
+ document.querySelectorAll("form.menu").forEach(function(form) {
+ form.setAttribute('action',window.location.toString().replace(/\?.*$/,''));
+
+ /* Format */
+ form.querySelectorAll("form.menu select.format").forEach(function(e) {
+ e.removeAttribute('name');
+ e.onchange = function() {
+ this.form.setAttribute('action',window._dbq['table.base']+'.'+this.value);
+ return this.form.onsubmit();
+ }
+ });
+
+ /* Table */
+ form.querySelectorAll("form.menu select.tables").forEach(function(e) {
+ e.removeAttribute('name');
+ e.onchange = function() {
+ this.form.setAttribute('action',window._dbq['db.base']+'/'+this.value+ext);
+ /*
+ window.location = this.form.getAttribute('action')+'?table='+e.value;
+ return false;
+ */
+ form_clean(this.form);
+ return this.form.onsubmit();
+ }
+ });
+
+ /* Limit */
+
+ /* Auto submit */
+ form.querySelectorAll("form.menu select.limit").forEach(function(e) {
+ e.onchange = function() {
+ return this.form.onsubmit();
+ };
+ });
+
+ });
+
+ if (document.querySelector(".nav.bottom") && document.querySelector("table.rows")) {
+ document.querySelector("table.rows").insertAdjacentHTML("beforebegin",""
+ +"<div class=\"nav top\">"+document.querySelector(".nav.bottom").innerHTML+"</div>"
+ );
+ }
+
+ // No more than 100% width
+ document.querySelectorAll("table").forEach(function(e) {
+ if (parseInt(e.offsetWidth) > parseInt(window.innerWidth)) {
+ e.className = e.className.replace(/(^| +)fixed($| )/,'') + ' fixed'
+ e.className = e.className.trim();
+ //console.log(e.offsetWidth +'>'+ window.innerWidth+' '+e.className);
+ }
+ });
+
+ if ( window._dbq['perm'] < window._dbq['perms']['write']) {
+ document.querySelectorAll("form.edit").forEach(function(e) {
+ e.setAttribute('onsubmit','return false');
+ });
+ document.querySelectorAll("form.edit input[type=submit],form.edit input[type=reset]").forEach(function(e) {
+ e.setAttribute('style','display:none');
+ });
+ }
+
+ document.querySelectorAll("form.menu input[type=submit]").forEach(function(e) {
+ e.insertAdjacentHTML("afterend",''
+ +' <input type="button" class="clear '+e.className+'" onclick="form_clean(this.form)"'
+ +' value="'+window._dbq['text.clear']+'"'
+ +' />'
+ +( window._dbq['perm'] >= window._dbq['perms']['write']
+ ? ' <input type="button" class="add '+e.className+'"'
+ +' onclick="window.location=\''+window._dbq['table.base']+'/add/\'"'
+ +' value="'+window._dbq['text.add']+'"/>'
+ : ''
+ )
+ );
+ });
+
+ if (document.querySelector("th.delete")) {
+
+ var a = document.createElement('a');
+ a.setAttribute('href','#');
+ a.innerHTML = document.querySelector("th.delete").innerHTML;// + ' All';
+ document.querySelector("th.delete").innerHTML = '';
+
+ a.onclick = function() {
+ var forms = document.querySelectorAll("form.rm");
+ var elem = document.querySelector(".rows") ? document.querySelector(".rows") : '';
+ elem.className = 'loader';
+
+ for (j = 0; j < forms.length; ++j) {
+
+ var f = forms[j];
+ var url = f.getAttribute('action');
+ var params = [];
+ var items = f.getElementsByTagName('input');
+ for (i = 0; i < items.length; ++i) {
+ var e = items[i];
+ params.push(e.name+'='+encodeURI(e.value));
+ }
+
+ var xhttp = new XMLHttpRequest();
+ xhttp.open("POST", url, true);
+ xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ xhttp.onload = function (e) { if (xhttp.readyState === 4) {
+ if ( j != forms.length ) return;
+ location.reload();
+ } }
+ xhttp.send(params.join('&'));
+ //console.log(params.join('&'));
+
+ }//);
+ return false;
+ };
+ document.querySelector("th.delete").appendChild(a);
+ }
+
+ document.querySelectorAll("body > h1 a.db, body > h1 a.table").forEach(function(e) {
+ var item = document.getElementById(e.className);
+ if (!item) return;
+ var id = item.getAttribute('id');
+ var sel = document.createElement('select');
+ sel.id = 'nav-'+id;
+ sel.innerHTML = item.innerHTML;
+ sel.onchange = function() {
+ var id = this.id.replace(/^[^-]+-/,'');
+ var e = document.getElementById(id);
+ console.log(id+' '+this.value);
+ e.value = this.value;
+ e.onchange();
+ };
+ item.parentElement.style.display = 'none';
+ e.parentNode.replaceChild(sel, e);
+ return false;
+ });
+
+});
+
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") {
- e.value = "";
- } else if (e.type.match(/^select/) && (0
- || e.name == 'limit'
- || e.name == 'format'
- )) {
- e.selectedIndex = 0;
- /*
- */
- }
- }
+ var e;
+ for(i=0;i<form.length;i++) {
+ e = form.elements[i];
+ if (e.style.display == "none") continue;
+
+ if (e.type == "text") {
+ e.value = "";
+ } else if (e.type.match(/^select/) && (0
+ || e.name == 'limit'
+ || e.name == 'format'
+ )) {
+ e.selectedIndex = 0;
+ /*
+ */
+ }
+ }
}
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;
-
- f.reset();
- window.location = url;
- return false;
+ 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;
+
+ f.reset();
+ window.location = url;
+ return false;
}
-document.addEventListener("DOMContentLoaded", function() {
-
- //console.log('LOADED');
- NodeList.prototype.forEach = Array.prototype.forEach;
- var ext = ( window._dbq['param.format'] ? '.'+window._dbq['param.format'] : '');
- if ( ext == '.'+window._dbq['default.format'] ) ext='';
-
- /* Clean when submit */
- document.querySelectorAll("form").forEach(function(e) {
- e.onsubmit = function() {
- if (this.elements['limit']) {
- var limit = this.elements['limit'];
- if (window._dbq['default_limit'] != 'undefined' && limit.value == window._dbq['default_limit']) limit.removeAttribute("value");
- }
- return form_submit_clean(this);
- };
- });
-
- /*
- Menu
- */
- document.querySelectorAll("form.menu").forEach(function(form) {
- form.setAttribute('action',window.location.toString().replace(/\?.*$/,''));
-
- /* Format */
- form.querySelectorAll("form.menu select.format").forEach(function(e) {
- e.removeAttribute('name');
- e.onchange = function() {
- this.form.setAttribute('action',window._dbq['table.base']+'.'+this.value);
- return this.form.onsubmit();
- }
- });
-
- /* Table */
- form.querySelectorAll("form.menu select.tables").forEach(function(e) {
- e.removeAttribute('name');
- e.onchange = function() {
- this.form.setAttribute('action',window._dbq['db.base']+'/'+this.value+ext);
- /*
- window.location = this.form.getAttribute('action')+'?table='+e.value;
- return false;
- */
- form_clean(this.form);
- return this.form.onsubmit();
- }
- });
-
- /* Limit */
-
- /* Auto submit */
- form.querySelectorAll("form.menu select.limit").forEach(function(e) {
- e.onchange = function() {
- return this.form.onsubmit();
- };
- });
-
- });
-
- if (document.querySelector(".nav.bottom") && document.querySelector("table.rows")) {
- document.querySelector("table.rows").insertAdjacentHTML("beforebegin",""
- +"<div class=\"nav top\">"+document.querySelector(".nav.bottom").innerHTML+"</div>"
- );
- }
-
- // No more than 100% width
- document.querySelectorAll("table").forEach(function(e) {
- if (parseInt(e.offsetWidth) > parseInt(window.innerWidth)) {
- e.className = e.className.replace(/(^| +)fixed($| )/,'') + ' fixed'
- e.className = e.className.trim();
- //console.log(e.offsetWidth +'>'+ window.innerWidth+' '+e.className);
- }
- });
-
- if ( window._dbq['perm'] < window._dbq['perms']['write']) {
- document.querySelectorAll("form.edit").forEach(function(e) {
- e.setAttribute('onsubmit','return false');
- });
- document.querySelectorAll("form.edit input[type=submit],form.edit input[type=reset]").forEach(function(e) {
- e.setAttribute('style','display:none');
- });
- }
-
- document.querySelectorAll("form.menu input[type=submit]").forEach(function(e) {
- e.insertAdjacentHTML("afterend",''
- +' <input type="button" class="clear '+e.className+'" onclick="form_clean(this.form)"'
- +' value="'+window._dbq['text.clear']+'"'
- +' />'
- +( window._dbq['perm'] >= window._dbq['perms']['write']
- ? ' <input type="button" class="add '+e.className+'"'
- +' onclick="window.location=\''+window._dbq['table.base']+'/add/\'"'
- +' value="'+window._dbq['text.add']+'"/>'
- : ''
- )
- );
- });
-
- if (document.querySelector("th.delete")) {
- var a = document.createElement('a');
- a.setAttribute('href','#');
- a.innerHTML = document.querySelector("th.delete").innerHTML;// + ' All';
- document.querySelector("th.delete").innerHTML = '';
- a.onclick = function() {
- var forms = document.querySelectorAll("form.rm");
- var elem = document.querySelector(".rows") ? document.querySelector(".rows") : '';
- //if (elem) elem.innerHTML = 0;
- elem.className = 'loader';
- for (j = 0; j < forms.length; ++j) {
- //if (elem) elem.innerHTML = parseInt(elem.innerHTML) + 1;
- var f = forms[j];
- var url = f.getAttribute('action');
- var params = [];
- var items = f.getElementsByTagName('input');
- for (i = 0; i < items.length; ++i) {
- var e = items[i];
- params.push(e.name+'='+encodeURI(e.value));
- }
- var xhttp = new XMLHttpRequest();
- xhttp.open("POST", url, true);
- xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- xhttp.onload = function (e) { if (xhttp.readyState === 4) {
- if ( j != forms.length ) return;
- location.reload();
- } }
- xhttp.send(params.join('&'));
- //console.log(params.join('&'));
- }//);
- return false;
- };
- document.querySelector("th.delete").appendChild(a);
- }
-
-});
+function url2select(url) {
+ var xhttp = new XMLHttpRequest();
+ xhttp.open("GET", url, true);
+ xhttp.onload = function (e) { if (xhttp.readyState === 4) {
+ console.log(xhttp.responseText);
+ //var row = JSON.parse(xhttp.responseText);
+ //console.log(row);
+ } }
+ xhttp.send();
+}