From a9f6eea3dc5ae8c92290ffb3a7874c0d628e1dbf Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 19 Aug 2015 03:12:55 +0100 Subject: [PATCH] css, table2div --- lib/css/db.css | 5 ----- lib/js/nb.js | 44 +++++++++++++++++++++++++++++++++++++++++--- lib/php/db.php | 39 ++++++++------------------------------- lib/php/db/table.php | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 39 deletions(-) diff --git a/lib/css/db.css b/lib/css/db.css index 68d58b6b..5fdf4314 100644 --- a/lib/css/db.css +++ b/lib/css/db.css @@ -52,11 +52,6 @@ div.rows .row { text-align: left; } text-align: center; } -.db div.rows .nav { - margin: 0.3em; - padding: 0; -} - .db div.rows .row *:not([class~=buttons]):hover { opacity: 0.7; } diff --git a/lib/js/nb.js b/lib/js/nb.js index 8b227793..8dc52110 100644 --- a/lib/js/nb.js +++ b/lib/js/nb.js @@ -7,6 +7,47 @@ var nb = new NB(); function NB() { + this.ready = function(find) { + + // Behavior + $('form').submit(function(e){ + //alert('nb.form_submit_clean'); + //e.preventDefault(); + return nb.form_submit_clean(this); + }); + + // Used in css to trigger a resize + $('body').append(''); + } + + this.table2div = function(find) { + var th = [] + + var t = $(find); + if ($(t).hasClass('t2d')) return false; + $(t).addClass('t2d'); + + $(t.find('thead')).each(function(){ + $(this).find('th').each(function(){ + th.push(this.innerHTML); + }); + //$(this).css('display','none'); + }); + + //console.log(th.length); + + $(t.find('tbody tr')).each(function(){ + var i = 0; + $(this).find('td').each(function(){ + if (typeof th[i] != 'undefined' && th[i] != '') $(this).prepend(''); + //$(this).css('display','block'); + i++ + }); + //$(this).css('display','block'); + }); + + } + this.form_submit_clean = function(f) { var i = 0; var url = ''; @@ -155,9 +196,6 @@ function NB() { //return '' + items.join('') + ''; return items.join(''); - return '
' + items.join('') + '
'; - return '
' + items.join('') + '
'; - return '
' + items.join('') + '
'; } this.json2html = function(url) { diff --git a/lib/php/db.php b/lib/php/db.php index 8eeead53..fefcf381 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -349,49 +349,26 @@ EOF; $data = null; if ($action == 'tables') { + $this->print_header('json'); $data = $this->tables(); - - } elseif ($action == 'html_menu') { - echo $this->html_menu(); + echo json_encode($data); return true; } elseif ($action == 'fields') { + $this->print_header('json'); $data = $table->fields(); - - } elseif ($action == 'delete') { - if (!$table->delete($this->p(),$e)) bye($e); - header('Location: '.str_replace('&','&',$table->url_list())); - return true; - - } elseif ($action == 'insert') { - $table->insert($this->p()); - header('Location: ?table=' . $table->name); - #header('Location: '.str_replace('&','&',$this->url_list())); - return true; - - } elseif ($action == 'update') { - #$this->bye($this->p()); - $table->update($this->p()); - header('Location: ?table=' . $table->name); - #header('Location: '.str_replace('&','&',$this->url_list())); + echo json_encode($data); return true; - } elseif ($this->p('format') and !preg_match('/^(table|div)$/',$this->p('format'))) { - #} elseif ($action == 'table' and $this->p('format') and $this->p('table')) { - #} elseif ($is_html) { - - $table->rows(array( 'format' => $this->p('format'))); + } elseif ($action == 'html_menu') { + echo $this->html_menu(); return true; - } - if (isset($data)) { + } else { + if ($table->action()) return true; - $this->print_header('json'); - echo json_encode($data); - return true; } - #$this->bye("Db.action: Unknow action \"$action\""); return false; } diff --git a/lib/php/db/table.php b/lib/php/db/table.php index db0ac098..c31af228 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -747,6 +747,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. function rows_begin_table($fields) { $html = DB_HTML_NAV_TOP; + #$html .= ''.PHP_EOL; $html .= '
'.PHP_EOL; #if (!empty($opt)) $html .= '' .PHP_EOL; @@ -942,5 +943,42 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. return $this->db->exec($sql); } + function action() { + $action = $this->p('action'); + + if ($action == 'fields') { + $this->db->print_header('json'); + $data = $this->fields(); + echo json_encode($data); + return true; + + } elseif ($action == 'delete') { + if (!$this->delete($this->p(),$e)) bye($e); + header('Location: '.str_replace('&','&',$this->url_list())); + return true; + + } elseif ($action == 'insert') { + $this->insert($this->p()); + header('Location: ?table=' . $this->name); + #header('Location: '.str_replace('&','&',$this->url_list())); + return true; + + } elseif ($action == 'update') { + #$this->bye($this->p()); + $this->update($this->p()); + header('Location: ?table=' . $this->name); + #header('Location: '.str_replace('&','&',$this->url_list())); + return true; + + } elseif ($this->p('format') and !preg_match('/^(table|div)$/',$this->p('format'))) { + #} elseif ($action == 'table' and $this->p('format') and $this->p('table')) { + #} elseif ($is_html) { + + $this->rows(array( 'format' => $this->p('format'))); + return true; + } + + return false; + } } ?> -- 2.47.3
' . $this->nav($opt['count'],$opt['tot'],$opt['limit']) . '