]> git.nbdom.net Git - nb.git/commitdiff
www/dbq/html/default.js
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 16 Jan 2018 06:45:20 +0000 (06:45 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 16 Jan 2018 06:45:20 +0000 (06:45 +0000)
www/dbq/html/default.js
www/dbq/html/default.min.css
www/dbq/html/default.min.js

index d4f327325d3698134eea0f6258b496d5f8692c1a..b38f456ea71480514420d8a26b347f539d798e53 100644 (file)
@@ -195,11 +195,28 @@ function form_submit_clean(f) {
        return false;
 }
 
-function url2select(url) {
+function dbqGet(url,callback) {
        var xhttp = new XMLHttpRequest();
+       delete window._dbq['dbqGet'];
        xhttp.open("GET", url, true);
        xhttp.onload = function (e) { if (xhttp.readyState === 4) {
-               console.log(xhttp.responseText);
+               var obj = {
+                       'rows': JSON.parse(xhttp.responseText),
+                       'debug': function(obj) {
+                               console.log(obj.rows);
+                       },
+                       'select': function(obj) {
+                               var el = document.createElement('select');
+                               console.log(el);
+                       },
+               };
+               if (!callback) return (window._dbq['dbqGet'] = obj);
+               if (typeof callback == "function") return callback(obj);
+               if (typeof callback == "string" && callback in obj) {
+                       if (typeof obj[callback] == "function") return obj[callback](obj);
+                       return obj[callback];
+               }
+               //console.log(xhttp.responseText);
                //var row = JSON.parse(xhttp.responseText);
                //console.log(row);
        } }
index 7bf7755ee1b00c4526ead1193fbeb6e760b4e9b8..90b00e518f46d115d8123280a963db5de2d2645f 100644 (file)
@@ -1 +1 @@
-html{font:90% 'Trebuchet MS',sans-serif;background-color:#eee}body{display:table;margin-left:auto;margin-right:auto;padding-left:1em;padding-right:1em;color:#444}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}.loader{border:16px solid #fff;border-radius:50%;border-top:16px solid #000;padding:0;margin:0 auto 0 auto;width:8em;height:8em;animation:spin 2s linear infinite;display:block}body.loader{margin-top:8em}.loader *{display:none!important}h1{margin:0 0 .2em 0;font-size:180%;padding-bottom:.3em;margin-bottom:.5em;border-bottom:dashed 1px #444}a{color:inherit}div>a,li a,p a,td a{color:#3572b0}a,a:visited{text-decoration:none}.button:hover,a:hover{opacity:.8}ul{padding:0;margin:0}li{list-style:none;padding:0 0 0 .3em}table{border-collapse:collapse}td,th{padding:.2em .7em}th a.sort{float:left;margin-right:.1em}input:not([type]),input[type=''],input[type=date],input[type=email],input[type=password],input[type=text],input[type=url],select,textarea{border-radius:3px;border:solid 1px #ddd;padding:.3em .4em;box-shadow:0 1px 1px #eee}input[size]{max-width:70%}div.row div label:after,form label:after{content:':'}form input,form label,form select{vertical-align:middle;margin:.2em .4em .2em 0}.rows{padding:0}.rows form{display:inline-block}.block,.menu,div.row,form.edit,iframe,pre,table.rows,ul.row{border-radius:4px;border-spacing:0;padding:.5em .2em;margin-bottom:.5em;border:solid 1px #ddd;background-color:#fafafa;box-shadow:0 1px 2px #eee}table.rows{border-style:hidden;border-collapse:collapse;box-shadow:0 0 0 1px #ddd;table-layout:fixed}table.rows tr:nth-child(even) td{background-color:#fefefe}div.row div,table.rows td,table.rows th,ul.row li{border-bottom:solid 1px #ddd}div.row div,table.rows tr:last-child td,ul.row li{border-bottom:none}table.rows td,table.rows th{border-right:dashed 1px #ddd}.rows .count{text-align:right}table.rows th{text-align:left}table.rows td{padding:.3em .3em}table.rows.fixed{width:100%}div.row div label,table.rows.fixed td,table.rows.fixed th{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}table.rows.fixed th{white-space:normal}table.rows td.delete,table.rows td.view{width:1%;white-space:nowrap}table.rows.fixed th.view{width:2em}table.rows.fixed th.delete{width:2.7em}div.rows{clear:both}div.row{float:left;margin-right:4px;min-width:24%}.nofloat{float:none}div.row div{margin:0;padding:.1em .2em;border-bottom:solid 1px #fff}div.row div.view .button{margin-bottom:5px}div.row div.delete .button{margin-top:5px}div.row div:last-child{border-bottom:none;padding-bottom:0}div.row div.delete label,div.row div.view label{display:none}div.row div.delete,div.row div.view{text-align:center}div.row div label,ul.row li label{padding:.1em .5em .1em 0;min-width:20%;display:inline-block}.button{font:inherit;display:inline-block;text-decoration:none;line-height:1.6em;cursor:pointer;white-space:nowrap;box-sizing:border-box;margin:0 .1em 0 0;padding:0 .3em;border-radius:4px;border:none;color:#3572b0;background-color:#eee;background:linear-gradient(to bottom right,#eee,#ddd);box-shadow:0 1px 1px #bbb}.bottom,.center,.menu,.nav,.rows{clear:both;display:table}.bottom,.buttons,.center,.menu,.nav,.rows,td.button{margin-left:auto;margin-right:auto}div.buttons{text-align:center;margin-top:.5em}form.menu{padding:.5em;background-color:#fafafa;max-width:1024px}form.menu .button.add{float:right;margin-top:.2em}form.menu .criterias{border-top:dashed 1px #ddd;margin-top:.3em;padding-top:.3em;clear:both}form.menu .criterias span.label{border-right:solid 1px #fff;border-radius:3px;margin:0 .2em;white-space:nowrap;float:left}form.menu .criterias span.label:last-child{border-right:none}form.menu select:focus{max-width:auto}form.menu select{max-width:20%}form.menu .criterias input[type=text]{width:4em}div.row label,form.edit .fields label{width:25%;text-align:right;display:inline-block;margin-right:1em;vertical-align:top}div.row .label span,form.edit .fields .label span{width:54%;display:inline-block;text-align:left;vertical-align:middle;margin-top:.2em}form.edit .fields input[size],form.edit .fields select,form.edit .fields textarea{width:65%}
+html{font:90% 'Trebuchet MS',sans-serif;background-color:#eee}body{display:table;margin-left:auto;margin-right:auto;padding-left:1em;padding-right:1em;color:#444}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}.loader{border:16px solid #fff;border-radius:50%;border-top:16px solid #000;padding:0;margin:0 auto 0 auto;width:8em;height:8em;animation:spin 2s linear infinite;display:block}body.loader{margin-top:8em}.loader *{display:none!important}h1{margin:0 0 .2em 0;font-size:180%;padding-bottom:.3em;margin-bottom:.5em;border-bottom:dashed 1px #444}h1 select{padding:0;border:none;background:inherit;font:inherit}a{color:inherit}div>a,li a,p a,td a{color:#3572b0}a,a:visited{text-decoration:none}.button:hover,a:hover{opacity:.8}ul{padding:0;margin:0}li{list-style:none;padding:0 0 0 .3em}table{border-collapse:collapse}td,th{padding:.2em .7em}th a.sort{float:left;margin-right:.1em}input:not([type]),input[type=''],input[type=date],input[type=email],input[type=password],input[type=text],input[type=url],select,textarea{border-radius:3px;border:solid 1px #ddd;padding:.3em .4em;box-shadow:0 1px 1px #eee}input[size]{max-width:70%}div.row div label:after,form label:after{content:':'}form input,form label,form select{vertical-align:middle;margin:.2em .4em .2em 0}.rows{padding:0}.rows form{display:inline-block}.block,.menu,div.row,form.edit,iframe,pre,table.rows,ul.row{border-radius:4px;border-spacing:0;padding:.5em .2em;margin-bottom:.5em;border:solid 1px #ddd;background-color:#fafafa;box-shadow:0 1px 2px #eee}table.rows{border-style:hidden;border-collapse:collapse;box-shadow:0 0 0 1px #ddd;table-layout:fixed}table.rows tr:nth-child(even) td{background-color:#fefefe}div.row div,table.rows td,table.rows th,ul.row li{border-bottom:solid 1px #ddd}div.row div,table.rows tr:last-child td,ul.row li{border-bottom:none}table.rows td,table.rows th{border-right:dashed 1px #ddd}.rows .count{text-align:right}table.rows th{text-align:left}table.rows td{padding:.3em .3em}table.rows.fixed{width:100%}div.row div label,table.rows.fixed td,table.rows.fixed th{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}table.rows.fixed th{white-space:normal}table.rows td.delete,table.rows td.view{width:1%;white-space:nowrap}table.rows.fixed th.view{width:2em}table.rows.fixed th.delete{width:2.7em}div.rows{clear:both}div.row{float:left;margin-right:4px;min-width:24%}.nofloat{float:none}div.row div{margin:0;padding:.1em .2em;border-bottom:solid 1px #fff}div.row div.view .button{margin-bottom:5px}div.row div.delete .button{margin-top:5px}div.row div:last-child{border-bottom:none;padding-bottom:0}div.row div.delete label,div.row div.view label{display:none}div.row div.delete,div.row div.view{text-align:center}div.row div label,ul.row li label{padding:.1em .5em .1em 0;min-width:20%;display:inline-block}.button{font:inherit;display:inline-block;text-decoration:none;line-height:1.6em;cursor:pointer;white-space:nowrap;box-sizing:border-box;margin:0 .1em 0 0;padding:0 .3em;border-radius:4px;border:none;color:#3572b0;background-color:#eee;background:linear-gradient(to bottom right,#eee,#ddd);box-shadow:0 1px 1px #bbb}.bottom,.center,.menu,.nav,.rows{clear:both;display:table}.bottom,.buttons,.center,.menu,.nav,.rows,td.button{margin-left:auto;margin-right:auto}div.buttons{text-align:center;margin-top:.5em}form.menu{padding:.5em;background-color:#fafafa;max-width:1024px}form.menu .button.add{float:right;margin-top:.2em}form.menu .criterias{border-top:dashed 1px #ddd;margin-top:.3em;padding-top:.3em;clear:both}form.menu .criterias span.label{border-right:solid 1px #fff;border-radius:3px;margin:0 .2em;white-space:nowrap;float:left}form.menu .criterias span.label:last-child{border-right:none}form.menu select:focus{max-width:auto}form.menu select{max-width:20%}form.menu .criterias input[type=text]{width:4em}div.row label,form.edit .fields label{width:25%;text-align:right;display:inline-block;margin-right:1em;vertical-align:top}div.row .label span,form.edit .fields .label span{width:54%;display:inline-block;text-align:left;vertical-align:middle;margin-top:.2em}form.edit .fields input[size],form.edit .fields select,form.edit .fields textarea{width:65%}
index 456011ef04fb69e6658055ac67b6bdd91757c286..e5b1858cf3dd5675af0ac09b9b937754ed91228e 100644 (file)
@@ -1 +1 @@
-function form_clean(e){var t;for(i=0;i<e.length;i++)"none"!=(t=e.elements[i]).style.display&&("text"==t.type?t.value="":!t.type.match(/^select/)||"limit"!=t.name&&"format"!=t.name||(t.selectedIndex=0))}function form_submit_clean(e){var t=0,n="",o=e.getAttribute("action");if("get"!=e.getAttribute("method"))return!0;for(t=0;t<e.length;t++){var r=e[t];r.name&&(""!=r.value&&"undefined"!=r.value&&(n+=(n?"&":"?")+encodeURI(r.name)+"="+encodeURI(r.value)))}return n=("?"==o?"":o)+n,e.reset(),window.location=n,!1}document.addEventListener("DOMContentLoaded",function(){NodeList.prototype.forEach=Array.prototype.forEach;var e=window._dbq["param.format"]?"."+window._dbq["param.format"]:"";if(e=="."+window._dbq["default.format"]&&(e=""),document.querySelectorAll("form").forEach(function(e){e.onsubmit=function(){if(this.elements.limit){var e=this.elements.limit;"undefined"!=window._dbq.default_limit&&e.value==window._dbq.default_limit&&e.removeAttribute("value")}return form_submit_clean(this)}}),document.querySelectorAll("form.menu").forEach(function(t){t.setAttribute("action",window.location.toString().replace(/\?.*$/,"")),t.querySelectorAll("form.menu select.format").forEach(function(e){e.removeAttribute("name"),e.onchange=function(){return this.form.setAttribute("action",window._dbq["table.base"]+"."+this.value),this.form.onsubmit()}}),t.querySelectorAll("form.menu select.tables").forEach(function(t){t.removeAttribute("name"),t.onchange=function(){return this.form.setAttribute("action",window._dbq["db.base"]+"/"+this.value+e),form_clean(this.form),this.form.onsubmit()}}),t.querySelectorAll("form.menu select.limit").forEach(function(e){e.onchange=function(){return this.form.onsubmit()}})}),document.querySelector(".nav.bottom")&&document.querySelector("table.rows")&&document.querySelector("table.rows").insertAdjacentHTML("beforebegin",'<div class="nav top">'+document.querySelector(".nav.bottom").innerHTML+"</div>"),document.querySelectorAll("table").forEach(function(e){parseInt(e.offsetWidth)>parseInt(window.innerWidth)&&(e.className=e.className.replace(/(^| +)fixed($| )/,"")+" fixed",e.className=e.className.trim())}),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",'&nbsp;<input type="button" class="clear '+e.className+'" onclick="form_clean(this.form)" value="'+window._dbq["text.clear"]+'" />'+(window._dbq.perm>=window._dbq.perms.write?'&nbsp;<input type="button" class="add '+e.className+'" onclick="window.location=\''+window._dbq["table.base"]+'/add/\'" value="'+window._dbq["text.add"]+'"/>':""))}),document.querySelector("th.delete")){var t=document.createElement("a");t.setAttribute("href","#"),t.innerHTML=document.querySelector("th.delete").innerHTML,document.querySelector("th.delete").innerHTML="",t.onclick=function(){var e=document.querySelectorAll("form.rm");for((document.querySelector(".rows")?document.querySelector(".rows"):"").className="loader",j=0;j<e.length;++j){var t=e[j],n=t.getAttribute("action"),o=[],r=t.getElementsByTagName("input");for(i=0;i<r.length;++i){var a=r[i];o.push(a.name+"="+encodeURI(a.value))}var l=new XMLHttpRequest;l.open("POST",n,!0),l.setRequestHeader("Content-type","application/x-www-form-urlencoded"),l.onload=function(t){if(4===l.readyState){if(j!=e.length)return;location.reload()}},l.send(o.join("&"))}return!1},document.querySelector("th.delete").appendChild(t)}});
+function form_clean(e){var t;for(i=0;i<e.length;i++)"none"!=(t=e.elements[i]).style.display&&("text"==t.type?t.value="":!t.type.match(/^select/)||"limit"!=t.name&&"format"!=t.name||(t.selectedIndex=0))}function form_submit_clean(e){var t=0,n="",o=e.getAttribute("action");if("get"!=e.getAttribute("method"))return!0;for(t=0;t<e.length;t++){var r=e[t];r.name&&(""!=r.value&&"undefined"!=r.value&&(n+=(n?"&":"?")+encodeURI(r.name)+"="+encodeURI(r.value)))}return n=("?"==o?"":o)+n,e.reset(),window.location=n,!1}function url2select(e){var t=new XMLHttpRequest;t.open("GET",e,!0),t.onload=function(e){4===t.readyState&&console.log(t.responseText)},t.send()}document.addEventListener("DOMContentLoaded",function(){NodeList.prototype.forEach=Array.prototype.forEach;var e=window._dbq["param.format"]?"."+window._dbq["param.format"]:"";if(e=="."+window._dbq["default.format"]&&(e=""),document.querySelectorAll("form").forEach(function(e){e.onsubmit=function(){if(this.elements.limit){var e=this.elements.limit;"undefined"!=window._dbq.default_limit&&e.value==window._dbq.default_limit&&e.removeAttribute("value")}return form_submit_clean(this)}}),document.querySelectorAll("form.menu").forEach(function(t){t.setAttribute("action",window.location.toString().replace(/\?.*$/,"")),t.querySelectorAll("form.menu select.format").forEach(function(e){e.removeAttribute("name"),e.onchange=function(){return this.form.setAttribute("action",window._dbq["table.base"]+"."+this.value),this.form.onsubmit()}}),t.querySelectorAll("form.menu select.tables").forEach(function(t){t.removeAttribute("name"),t.onchange=function(){return this.form.setAttribute("action",window._dbq["db.base"]+"/"+this.value+e),form_clean(this.form),this.form.onsubmit()}}),t.querySelectorAll("form.menu select.limit").forEach(function(e){e.onchange=function(){return this.form.onsubmit()}})}),document.querySelector(".nav.bottom")&&document.querySelector("table.rows")&&document.querySelector("table.rows").insertAdjacentHTML("beforebegin",'<div class="nav top">'+document.querySelector(".nav.bottom").innerHTML+"</div>"),document.querySelectorAll("table").forEach(function(e){parseInt(e.offsetWidth)>parseInt(window.innerWidth)&&(e.className=e.className.replace(/(^| +)fixed($| )/,"")+" fixed",e.className=e.className.trim())}),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",'&nbsp;<input type="button" class="clear '+e.className+'" onclick="form_clean(this.form)" value="'+window._dbq["text.clear"]+'" />'+(window._dbq.perm>=window._dbq.perms.write?'&nbsp;<input type="button" class="add '+e.className+'" onclick="window.location=\''+window._dbq["table.base"]+'/add/\'" value="'+window._dbq["text.add"]+'"/>':""))}),document.querySelector("th.delete")){var t=document.createElement("a");t.setAttribute("href","#"),t.innerHTML=document.querySelector("th.delete").innerHTML,document.querySelector("th.delete").innerHTML="",t.onclick=function(){var e=document.querySelectorAll("form.rm");for((document.querySelector(".rows")?document.querySelector(".rows"):"").className="loader",j=0;j<e.length;++j){var t=e[j],n=t.getAttribute("action"),o=[],r=t.getElementsByTagName("input");for(i=0;i<r.length;++i){var a=r[i];o.push(a.name+"="+encodeURI(a.value))}var l=new XMLHttpRequest;l.open("POST",n,!0),l.setRequestHeader("Content-type","application/x-www-form-urlencoded"),l.onload=function(t){if(4===l.readyState){if(j!=e.length)return;location.reload()}},l.send(o.join("&"))}return!1},document.querySelector("th.delete").appendChild(t)}document.querySelectorAll("body > h1 a.db, body > h1 a.table").forEach(function(e){var t=document.getElementById(e.className);if(t){var n=t.getAttribute("id"),o=document.createElement("select");return o.id="nav-"+n,o.innerHTML=t.innerHTML,o.onchange=function(){var e=this.id.replace(/^[^-]+-/,""),t=document.getElementById(e);console.log(e+" "+this.value),t.value=this.value,t.onchange()},t.parentElement.style.display="none",e.parentNode.replaceChild(o,e),!1}})});