]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 3 Apr 2016 02:34:46 +0000 (03:34 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 3 Apr 2016 02:34:46 +0000 (03:34 +0100)
lib/js/nb.js
lib/php/config.php
lib/php/db.php

index e3e0c76321a3de712a90b72c05c9f43b1d64f575..557ffab1a73da0d22fb8ac95db1173aba962107c 100644 (file)
@@ -344,23 +344,70 @@ function NB() {
     return items.join('');
   }
 
-       this.j2h = function(url) {
-    var tag = 'select';
+       this.j2h = function(url,dest,tag='ul',map) {
+
     var tags = {
+      'table'  : 'tr.td',
       'select' : 'option',
       'ul'     : 'li',
     }
 
-    $.getJSON(url, function(json){
-      var select = $('<'+tag+'>');
-      $('#nb-msg').append(select);
-      tag == 'select' && select.append($('<'+tags[tag]+'>').text("Select"));
+    var m;
+    if (m = tag.match(/^(\w+)\.(.*)$/)) {
+      tag = m[1];
+      tags[m[1]] = m[2];
+    } else if(typeof tags[tag] == 'undefined' || tags[tag] == null) {
+      tags[tag] = tag;
+    }
+
+    if (typeof tags[tag] == 'string') tags[tag] = tags[tag].split('.');
+//console.log(tags[tag]); return;
+
+    $.getJSON(url, function(json) {
+      var rows = $('<'+tag+'>');
+      tag == 'select' && rows.append($('<'+tags[tag]+'>').text(''));
+
+      //if (typeof map != 'undefined') { json = $.map(json,map); }
+      //console.log(json.toSource());
+
+      $.each(json, function(k, v){
+
+        if ($.type(v) == 'object') { v = $.map(v,function(v,k){return v})[0]; v = [v,v]; }
+        if ($.type(v) == 'string') v = [v,v];
+        if (v.length==1) v = [v[0],v[0]]
+
+        var row = null;
+        var item;
+        $.each(tags[tag],function(i,t){
+//console.log(t+': '+row);
+          item = $('<'+t+'>');
+          if (row == null) {
+            row = item;
+          } else {
+            row.append(item);
+          }
+        });
+        //row = $('<'+tags[tag]+'>');
+
+        //if (row == null) return;
+
+
+        item.text(v[0]);
+        item.attr('value',v[1]);
+        if (typeof map != 'undefined') { (map)(item,v); }
+        //if (tags[tag] == 'td') row = $('<tr>').append(row);
+        //if (typeof map != 'undefined') { $.each(row,map); }
+
+        else {
+        }
+        rows.append(row);
 
-      $.each(json, function(i, obj){
-        select.append($('<'+tags[tag]+'>').text(obj.name).attr('value', obj.name));
       });
 
+      $(dest).append(rows);
+
     });
+
   }
 
   this.json2html = function(url) {
@@ -404,6 +451,11 @@ function NB() {
 
 };
 /*
+  Statics
 */
-
+NB.get_http = NB.prototype.get_http
+NB.dump = NB.prototype.dump
+NB.urlParam = NB.prototype.urlParam
+//NB.prototype.test =  function(v) { console.log(v)}
+//NB.test = function() { console.log(that.dump('zaza'))}
 //NB.prototype.your_method = function() { }
index 5782c8aeb671a851fad5c8eb1225f7e53fc2a0bd..fddceed9f827b0825bb46d465a9c2db41b21688d 100644 (file)
@@ -7,6 +7,7 @@
 */
 
 require(dirname(__FILE__).'/nb.php');
+if (nb::php_cli()) argv2request();
 
 if (empty($_SERVER['DEV'])) return;
 date_default_timezone_set('Europe/London');
@@ -20,7 +21,6 @@ ini_set('include_path',''
 
 #define('NB_EOL','');
 #define('NB_PROD',true);
-if (nb::php_cli()) argv2request();
 
 ini_set('display_errors', 'On');
 if (nb::php_cli() or nb::p('txt_errors')) ini_set('html_errors', false);
index bcdde716f7106e2aa6074f2b49c52abe6c1aa574..a8841a402aecf456da52444e2a28d066823ee975 100644 (file)
@@ -468,8 +468,8 @@ EOF;
 
   public function action($table=null) {
     #if ($this->p('format') == 'table') $this->pset('format','');
-    $this->pdef('format',($this->php_cli() ? 'csv' : ''));
     $actions = explode(',',$this->p('action'));
+    $this->pdef('format',($this->php_cli() ? 'csv' : ''));
     $rows = array();
     $return = false;