From 0c8e14affce23f45d7ae6b04b3a8526b9c27aa0c Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 16 Jan 2018 06:12:16 +0000 Subject: [PATCH] www/dbq/html/default.js --- lib/php/page.php | 19 +- www/dbq/dbq.php | 23 +-- www/dbq/html/default.css | 7 + www/dbq/html/default.js | 368 +++++++++++++++++++++------------------ 4 files changed, 221 insertions(+), 196 deletions(-) diff --git a/lib/php/page.php b/lib/php/page.php index 647b2134..253718b2 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -70,14 +70,6 @@ class Page extends nb { unset($opt['content_type']); if (!$this->content_type()) $this->content_type($this->client_content_type()); - // Nav -# NB 19.12.16 list($title,$html) = [[],[]]; -# NB 19.12.16 if (isset($opt['nav_'])) { -# NB 19.12.16 list($title,$html) = self::nav_parse($opt['nav']); -# NB 19.12.16 unset($opt['nav']); -# NB 19.12.16 } -# NB 06.12.16 if ( empty($this->title) ) $this->title = !empty($title) ? join($this->sep,$title) : $this->filename2title(); - // Statics foreach ([ 'charset', @@ -91,13 +83,6 @@ class Page extends nb { // Opt parent::__construct($opt); - // Defaults -# NB 19.12.16 if ( empty($this->title) and !empty($title) ) $this->title = join($this->sep,$title); -# NB 19.12.16 if ( empty($this->h1) and !empty($html) ) $this->h1 = join($this->sep,$html); -# NB 19.12.16 #if ( !empty($title) and empty($this->title) ) $this->title = join($this->sep,$title); -# NB 19.12.16 #if ( empty($this->title) ) $this->title = $this->filename2title(); -# NB 19.12.16 if ( empty($this->h1) and ! empty($this->title) ) $this->h1 = $this->title; - // Call / Print if (!empty($this->call)) $this->call($this->call); @@ -106,9 +91,7 @@ class Page extends nb { /* Funtions */ - public static function out($v) { - echo $v; - } + public static function out($v) { echo $v; } public static function title2filename($title,$content_type='') { $ext = $content_type ? self::mime2ext($content_type) : ''; diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 7a8d1ed4..e19e8ecd 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -248,8 +248,9 @@ class DbQ extends nb { .(empty($this->params['action']) ? ' action-'.self::PARAM_DB_DEFAULT : ' action-'.($this->params['action'] == 'add' ? 'vi' : $this->params['action'])) ; + $this->page->begin(); - } + } # if (empty($this->_nopage)) { #die($obj); #if (is_scalar($obj)) { @@ -449,21 +450,21 @@ class DbQ extends nb { private function row_parse_pre(&$r=[]) { static $row_parse_pre; - if (empty($r)) { - $row_parse_pre = $this->db()->row_parse_pre; + if (empty($r)) { + $row_parse_pre = $this->db()->row_parse_pre; return; } - if (empty($row_parse_pre)) return; + if (empty($row_parse_pre)) return; $row_parse_pre($r,$this->table); } private function row_parse_post(&$r=[]) { static $row_parse_post; - if (empty($r)) { - $row_parse_post = $this->db()->row_parse_post; + if (empty($r)) { + $row_parse_post = $this->db()->row_parse_post; return; } - if (empty($row_parse_post)) return; + if (empty($row_parse_post)) return; $row_parse_post($r,$this->table); } @@ -516,11 +517,11 @@ class DbQ extends nb { private function ar_unshift( array & $array, $key, $val) { # NB 05.01.18: Escape html ??????? we use reverse # NB 05.01.18 return $array + [ $key => $val ]; - $array = array_reverse($array, 1); - $array[$key] = $val; - $array = array_reverse($array, 1); + $array = array_reverse($array, 1); + $array[$key] = $val; + $array = array_reverse($array, 1); - return $array; + return $array; } public static function uri_add_referer($rm) { diff --git a/www/dbq/html/default.css b/www/dbq/html/default.css index 3ae37870..6199767e 100644 --- a/www/dbq/html/default.css +++ b/www/dbq/html/default.css @@ -45,6 +45,13 @@ h1 { border-bottom: dashed 1px #444444; } +h1 select { + padding: 0; + border: none; + background: inherit; + font: inherit; +} + a { color: inherit; } diff --git a/www/dbq/html/default.js b/www/dbq/html/default.js index ee789815..d4f32732 100644 --- a/www/dbq/html/default.js +++ b/www/dbq/html/default.js @@ -1,173 +1,207 @@ +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","" + +"
"+document.querySelector(".nav.bottom").innerHTML+"
" + ); + } + + // 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",'' + +' ' + +( window._dbq['perm'] >= window._dbq['perms']['write'] + ? ' ' + : '' + ) + ); + }); + + 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"+document.querySelector(".nav.bottom").innerHTML+"" - ); - } - - // 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",'' - +' ' - +( window._dbq['perm'] >= window._dbq['perms']['write'] - ? ' ' - : '' - ) - ); - }); - - 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(); +} -- 2.47.3