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

index 647b2134554e71285619451e8588ae877d654942..253718b2e1cb995b2732e6b72a1348a6957e22b9 100644 (file)
@@ -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) : '';
index 7a8d1ed4265449e8c547648ef6df4842b7f7a82a..e19e8ecd5ece20e5eb073863b909ed3c53c89b40 100644 (file)
@@ -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) {
index 3ae3787042e5ae7bdecdb6457616d08eaa502f59..6199767e282e18a529a19034c7c057e62a37a3c3 100644 (file)
@@ -45,6 +45,13 @@ h1 {
        border-bottom: dashed 1px #444444;
 }
 
+h1 select {
+       padding: 0;
+       border: none;
+       background: inherit;
+       font: inherit;
+}
+
 a {
        color: inherit;
 }
index ee78981573a585a07902ab5fe1d4aa8d7466c5bb..d4f327325d3698134eea0f6258b496d5f8692c1a 100644 (file)
+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",''
+                       +'&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']+'"/>'
+                               : ''
+                       )
+               );
+       });
+
+       if (document.querySelector("th.delete")) {
+
+               var a = document.createElement('a');
+               a.setAttribute('href','#');
+               a.innerHTML = document.querySelector("th.delete").innerHTML;// + '&nbsp;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",''
-      +'&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']+'"/>'
-        : ''
-      )
-    );
-  });
-
-  if (document.querySelector("th.delete")) {
-    var a = document.createElement('a');
-    a.setAttribute('href','#');
-    a.innerHTML = document.querySelector("th.delete").innerHTML;// + '&nbsp;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();
+}