]> git.nbdom.net Git - nb.git/commitdiff
action
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 8 Aug 2015 13:35:57 +0000 (14:35 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 8 Aug 2015 13:35:57 +0000 (14:35 +0100)
lib/js/nb.js
lib/php/db.php
lib/php/nb.php
lib/php/page.php

index f2f07592bd08072ee6a29e94dd88a1d6f6314037..48f94bee86e0dffc2cc998b5d7f312d558d7341e 100644 (file)
@@ -122,6 +122,36 @@ function NB() {
 
   };
 
+  this.json_debug = function(url) {
+    $.getJSON(url,function(data) {
+      var tag = '';
+      if (typeof(data) == 'string') {
+        tag = 'span';
+      } else if ($.isArray(data)) {
+        tag = 'ul';
+      } else {
+        tag = 'fieldset';
+      }
+      var items = [];
+      $.each( data, function( key, val ) {
+        //console.log(key+' = '+val);
+        if (tag == 'span') {
+          tag = 'span class="'+key+'"'
+          items.push( v );
+        } else if (tag == 'ul') {
+          items.push( '<li class="'+val+'">'+val+'</li>' );
+        } else if (tag == 'fieldset') {
+          items.push( '<dl class="'+key+'"><dt>'+key+'</dt><dd>'+val+'</dd>' );
+        }
+      });
+      $( '<'+tag+'/>', {
+        //"class": "my-new-list",
+        html: items.join( "" )
+      }).prependTo( "#msg" );
+      //console.log(typeof(data));
+    });
+  }
+
 };
 
 //NB.prototype.your_method = function() { }
index e4f64e064a6bc7668183e1cb0db8d4ddff22fd77..271481deab20ef8d78f0b376e9361619ecbfa770 100644 (file)
@@ -336,6 +336,41 @@ EOF;
     return '"'.$value.'"';
   }
 
+  function action() {
+    $action = $this->p('action');
+    if (strpos($action,'db.') !== 0) return false;
+    $action = substr($action,3);
+
+    $data = null;
+    
+    if ($action == 'tables') {
+      $data = $this->tables();
+
+    } elseif ($action == 'html_menu') {
+      echo $this->html_menu();
+      return true;
+
+    } elseif ($action == 'fields') {
+      $data = $this->table($this->p('table'))->fields();
+
+    } elseif ($action == 'table' and $this->p('format') and $this->p('table')) {
+
+      $this->print_header($this->p('format'));
+      $this->table($this->p('table'))->rows(array( 'format' => $this->p('format'),));
+      return true;
+    }
+    #bye( $action );
+    if (isset($data)) {
+
+      $this->print_header('json');
+      echo json_encode($data);
+      return true;
+    }
+
+    $this->bye("Db.action: Unknow action \"$action\"");
+    return false;
+  }
+
 }
 
 ?>
index a7ef8380e7aee2e27978f34440d1db56356b6f93..bb7389c51819547e75b1da10552eca9350121600 100644 (file)
@@ -28,5 +28,13 @@ class nb {
     return ($_REQUEST[$name] = $value);
   }
 
+  /*
+   * Function: bye
+   * Set a value for param, delete it if null
+   */
+  static function bye($msg='') {
+    return bye($msg);
+  }
+
 }
 ?>
index 284a26c55af8f2e0f0798d6bea4ea965e7bdc001..7665e05c28f56cf2efb91d5f2fb0ed3338b82930 100644 (file)
@@ -315,6 +315,7 @@ class Page extends nb {
   }
 
   function path() {
+    if (empty($_SERVER['REQUEST_URI'])) return '';
     return preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']);
   }