]> git.nbdom.net Git - nb.git/commitdiff
css, table2div
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 19 Aug 2015 02:12:55 +0000 (03:12 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 19 Aug 2015 02:12:55 +0000 (03:12 +0100)
lib/css/db.css
lib/js/nb.js
lib/php/db.php
lib/php/db/table.php

index 68d58b6be0458a781f7321f857cc4b7433293c19..5fdf431417245b6c98e5ea4b1e09c2bcfe4696b3 100644 (file)
@@ -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;
 }
index 8b227793874cddb166d52e33c9bc138667c4bdf4..8dc52110f81c1622caeead433568db764ef0b15f 100644 (file)
@@ -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('<span id="_responsive" style="display:none"></span>');
+  }
+
+  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('<label class="t2d-th">'+th[i]+'</label>');
+        //$(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 '<colgroup class="_test">' + items.join('') + '</colgroup>';
     return items.join('');
-    return '<div class="_test">' + items.join('') + '</div>';
-    return '<dl class="_test">' + items.join('') + '</dl>';
-    return '<div>' + items.join('') + '</div>';
   }
 
   this.json2html = function(url) {
index 8eeead53c63328f644e949a4cfbf7e868063e582..fefcf381352982c00d88fa315ab375a6e915a90b 100644 (file)
@@ -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('&amp;','&',$table->url_list()));
-      return true;
-
-    } elseif ($action == 'insert') {
-      $table->insert($this->p());
-      header('Location: ?table=' . $table->name);
-      #header('Location: '.str_replace('&amp;','&',$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('&amp;','&',$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;
   }
 
index db0ac0980a16e10e9384420ec001c56d82ef9a8c..c31af228c5258f73456ef7b48333085b1ceb069f 100644 (file)
@@ -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 .= '<table data-role="table" class="ui-responsive rows '.$this->name.'">'.PHP_EOL;
     $html .= '<table class="rows '.$this->name.'">'.PHP_EOL;
     #if (!empty($opt)) $html .= '<caption>' . $this->nav($opt['count'],$opt['tot'],$opt['limit']) . '</caption>' .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('&amp;','&',$this->url_list()));
+      return true;
+
+    } elseif ($action == 'insert') {
+      $this->insert($this->p());
+      header('Location: ?table=' . $this->name);
+      #header('Location: '.str_replace('&amp;','&',$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('&amp;','&',$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;
+  }
 }
 ?>