]> git.nbdom.net Git - nb.git/commitdiff
lib/lua/nb.lua
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 7 Jun 2018 20:17:06 +0000 (21:17 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 7 Jun 2018 20:17:06 +0000 (21:17 +0100)
lib/php/db/field.php
lib/php/db/table.php
lib/php/mime.php
www/dbq/dbq.php
www/dbq/html/default.css
www/dbq/html/default.js
www/dbq/html/default.min.css

index f72f456e682bd75310884fd4a43f374457c4e465..b06226b07bf18798e647cf541d8bc45da0194017 100644 (file)
@@ -14,6 +14,7 @@ class field extends nb {
   public $extra;
   public $extras;
   public $preffix = '';
+  public $html_edit_hide_min_size = 500;
 
   public function __sleep() { return [
     'name',
@@ -140,9 +141,15 @@ class field extends nb {
        } else {
                                # NB 09.02.18: needed ? 
                                if ($tag == 'textarea' and $type != 'text') $tag = 'input';
+
+                               # Html friendly
                                if ($media = Mime::html($value,'',$mime)) {
-                                       $tag = 'input';
-                                       $type = 'hidden';
+                                       if ($this->html_edit_hide_min_size
+                                               and $this->html_edit_hide_min_size <= mb_strlen($value)
+                                       ) {
+                                               $tag = 'input';
+                                               $type = 'hidden';
+                                       }
                                        $h .= $media;
                                }
 
@@ -156,8 +163,10 @@ class field extends nb {
 
        $html .= '<div class="'.join(' ',$class).'">'
                                .'<label for="'.$this->name.'">'.htmlspecialchars(prettyText($this->name)).'</label>'
+                               .'<span class="field">'
+                               .$h
+                               .'</span>'
                        ;
-                       $html .= $h;
 
                        # If more than one value, add js code to add more fields
                        if ($multi) $html .= '<a href="#" onclick="var i=this.parentNode;var j=i.cloneNode(true);j.querySelectorAll(\'input, textarea, select\').forEach(function(e) {e.value=\'\';}); i.parentNode.insertBefore(j, i.nextSibling);console.log(i.className); return false;">+</a>';
index 49e7f9982c4c2ce036d3aa2aeb235f7b9ee0782c..46b0cd329348474ba184475c42bf41030dea1dca 100644 (file)
@@ -42,7 +42,7 @@ Class Table extends nb {
        public $idtemplate;
 
        public static $params = [
-               'db', 'table', 'limit', 'debug', 'action',
+               'db', 'table', 'limit', 'orderby', 'debug', 'action',
                'page', 'paged', # wordpress
        ];
 
@@ -835,12 +835,10 @@ Class Table extends nb {
                        }
 
                        $name = $field->sql_name(true);
-# NB 12.01.18                  if (!$field->text()) $name = $field->sql_name_cast_text();
 
                        if ($field->extras) {
                                $k = $this->extras[$k]->sql_name();
 
-# NB 04.01.18       } elseif ($field->numeric() and $field->null) {
                        } elseif ($match) {
                                if ($field->null) $k = 'COALESCE('.$name.','.$this->db()->quote('').")";
 
index a246754bc2e98cb21c03e8317a4d15491392b54d..24ba6cdaf3990ff17f2b121c408b4968e41f51f2 100644 (file)
@@ -729,6 +729,34 @@ class Mime {
                return $m[1];
        }
 
+       public static function html_youtube_embed($str) {
+               if (!preg_match(',//www.youtube.com/watch\?v=([^&\s]+),',$str,$m)) return $str;
+               return ''
+               #.'<details>'
+               .'<iframe'
+                       .' class="youtube-embed"'
+                       .' type="text/html"'
+                       .' src="//www.youtube.com/embed/'.$m[1].'?enablejsapi=1"'
+                       .' frameborder="0"'
+               .'></iframe>'
+               #.'<details>'
+               ;
+               return ''
+               #.'<a target="_blank" href="//www.youtube.com/v/'.$m[1].'?color2=FBE9EC&amp;version=3">'
+               .'<object type="application/x-shockwave-flash" class="youtube-embed" data="//www.youtube.com/v/'.$m[1].'?color2=FBE9EC&amp;version=3">'
+                       .'<param name="movie" value="//www.youtube.com/v/'.$m[1].'?color2=FBE9EC&amp;version=3" />'
+                       .'<param name="allowFullScreen" value="true" />'
+                       .'<param name="allowscriptaccess" value="always" />'
+               .'</object>'
+               #.'</a>'
+               ;
+       }
+
+       public static function html_img_data($str) {
+               $v = self::is_base64($str) ? $v : base64_encode($str);
+               return '<img src="data:image/jpeg;base64,'.$v.'" />';
+       }
+
        public static function html(&$str,$default=null,&$mime=null) {
 
                if (!$str) return $str;
@@ -742,10 +770,14 @@ class Mime {
 
                if ($mime === null) $mime = self::getContent($str);
 
-               if (preg_match('@^image/@',$mime)) {
-                       $v = self::is_base64($str) ? $v : base64_encode($str);
-                       return '<img src="data:image/jpeg;base64,'.$v.'" />';
+               if ($mime == 'text/plain') {
+                       if (preg_match(',//www.youtube.com/watch\?v=,',$str)) return self::html_youtube_embed($str);
+
+               } elseif (preg_match('@^image/@',$mime)) {
+                       return self::html_img_data($str);
+
                }
+               #return $str .= '|'.$mime;
 
                if ($default === null) $default = $str;
                return $default;
index e74e3c519086b1a4a5cbb9b5503212eb8454e38d..bc08c78d842a91cc79d088123fe5f17c0fb50e52 100644 (file)
@@ -338,7 +338,8 @@ class DbQ extends nb {
 
                        if ($this->http->user()) {
                                $bottom[] = '<a href="' . $this->base . '/logout"'
-                                       .(!empty($this->db->conf['ldap']) and $this->http->user()
+                                       .(
+                                               ( !empty($this->db->conf['ldap']) and $this->http->user() )
                                                ? ' style="background:url(\'' . $this->base . '/ldap/me.jpg?w=20\') right no-repeat;padding-right:22px"'
                                                : ''
                                        )
index 3f86da04e92a9b7d891026f910868b418096c787..4b2d858da0bbc9a7706ded79965da0f5f034f406 100644 (file)
@@ -126,7 +126,6 @@ ul.row,
 form.edit,
 .menu,
 .block,
-iframe,
 pre
 {
        border-radius: 4px;
@@ -226,6 +225,10 @@ div.row div {
 .rows .row img {
        height: 1.2em;
 }
+.rows .row .youtube-embed {
+       height: 150px;
+       width: 250px;
+}
 
 div.row div.view .button { margin-bottom: 5px; }
 div.row div.delete .button { margin-top: 5px; }
@@ -355,13 +358,16 @@ form.edit .fields label {
 
 div.row .label span,
 form.edit .fields .label span {
-       width: 54%;
        display: inline-block;
        text-align: left;
        vertical-align: middle;
        margin-top: 0.2em;
 }
 
+form.edit .fields .field {
+       width: 54%;
+}
+
 form.edit .fields input[size],
 form.edit .fields textarea, form.edit .fields select {
        width: 65%;
@@ -370,3 +376,10 @@ form.edit .fields textarea, form.edit .fields select {
 form.edit .fields img {
        max-height: 90px;
 }
+.youtube-embed {
+       float: left;
+}
+/*
+       border: solid 1px red;
+form.edit .fields label { clear: right; }
+*/
index d2a996d6564d5f428229684b57229e3334df6b19..9c39a313500ccfe05789c637f924b905c514718b 100644 (file)
@@ -138,6 +138,7 @@ document.addEventListener("DOMContentLoaded", function() {
        //
        if (document.querySelector("body.no-db")) document.querySelectorAll("body > h1 a.db, body > h1 a.table").forEach(function(e) {
 
+               //console.log(e.className+': '+window._dbq[e.className+'.base']);
                var base = window._dbq[e.className+'.base'].replace(/\/[^\/]+$/,'');
                var url = base + (base == '' ? '/ls' : '') + '.json';
                var fields = e.className == 'db' ? ['id','id'] : ['name','name'];
@@ -203,36 +204,41 @@ function form_submit_clean(f) {
 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) {
-               var obj = {
-                       'rows': JSON.parse(xhttp.responseText),
-                       'debug': function() {
-                               console.log(obj.rows);
-                       },
-                       'select': function(k,v,sel='undefined') {
-                               var select = document.createElement('select');
-                               obj['rows'].forEach(function(row) {
-                                       var keys = Object.keys(row);
-                                       var opt = document.createElement('option');
-                                       opt.value = row[k];
-                                       opt.innerHTML = dbqPrettyText(row[v]);
-                                       select.appendChild(opt);
-                               });
-                               if (sel != 'undefined') select.value = sel;
-                               return select;
-                       },
-               };
-               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];
+
+       xhttp.onload = function (e) {
+               if (xhttp.readyState === 4 && xhttp.status >= 300) console.log('dbqGet: Url not found: '+url);
+               if (xhttp.readyState === 4 && xhttp.status < 300) {
+                       var obj = {
+                               'rows': JSON.parse(xhttp.responseText),
+                               'debug': function() {
+                                       console.log(obj.rows);
+                               },
+                               'select': function(k,v,sel='undefined') {
+                                       var select = document.createElement('select');
+                                       obj['rows'].forEach(function(row) {
+                                               var keys = Object.keys(row);
+                                               var opt = document.createElement('option');
+                                               opt.value = row[k];
+                                               opt.innerHTML = dbqPrettyText(row[v]);
+                                               select.appendChild(opt);
+                                       });
+                                       if (sel != 'undefined') select.value = sel;
+                                       return select;
+                               },
+                       };
+                       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);
                }
-               //console.log(xhttp.responseText);
-               //var row = JSON.parse(xhttp.responseText);
-               //console.log(row);
-       } };
+       };
        xhttp.send();
 }
 
index 0e3772f6e9e6a28810f8c59d7a3385ab29aeb9ce..d0a711ba124ed9b3202e4e5504110e824d6c8c95 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}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}.rows .row img{height:1.2em}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%}form.edit .fields img{max-height:90px}
+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,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}.rows .row img{height:1.2em}.rows .row .youtube-embed{height:150px;width:250px}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{display:inline-block;text-align:left;vertical-align:middle;margin-top:.2em}form.edit .fields .field{width:54%}form.edit .fields input[size],form.edit .fields select,form.edit .fields textarea{width:65%}form.edit .fields img{max-height:90px}.youtube-embed{float:left}