]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 3 Apr 2016 05:20:32 +0000 (06:20 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 3 Apr 2016 05:20:32 +0000 (06:20 +0100)
lib/css/db.css
lib/js/nb.js

index 1efb6c756b8ab899a1a96f76e4933884b91a6f01..bea3dbf184b64ea2e53aef1513c97325fe7b2abd 100644 (file)
@@ -46,9 +46,7 @@
 table.rows th.key:before { content: "["; }
 table.rows th.key:after { content: "]"; }
 
-table.rows tr.row {
-  vertical-align: top;
-}
+table.rows tr { vertical-align: top; }
 
 .db div.rows .row *:not([class~=buttons]):hover {
   opacity: 0.7;
@@ -71,11 +69,6 @@ table.rows tr.row {
   white-space: normal;
   text-align: right;
 }
-/*
-.rows ul .button { float: right; }
-.rows .buttons { text-align: center; }
-div.rows div.buttons { float: right; }
-*/
 
 /*
   Menu
index 557ffab1a73da0d22fb8ac95db1173aba962107c..b3e1431c7e8f945daa5c739b689d67c86f2d4295 100644 (file)
@@ -344,6 +344,65 @@ function NB() {
     return items.join('');
   }
 
+       this.j2d = function(url) {
+    var rows = $('<table>');
+    var count = 0;
+
+    $.getJSON(url, function(json) {
+
+      $.each(json, function(i,rec){
+
+        $.each(rec, function(k,v){
+          var row = $('<tr>',{'class':k}).appendTo(rows);
+
+          $('<th>',{'text':k}).appendTo(row)
+          $('<td>',{'text':v}).appendTo(row)
+//console.log(rec);
+        });
+
+        count++;
+      });
+
+    });
+
+    return rows;
+  }
+
+       this.j2t = function(url) {
+    var rows = $('<table>');
+    var count = 0;
+
+    $.getJSON(url, function(json) {
+
+      $.each(json, function(i,rec){
+        var row = $('<tr>').appendTo(rows);
+
+        if (!count) {
+          $.each(rec, function(k,v){
+            $('<th>',{
+              'text': k,
+              'class': k,
+            }).appendTo(row)
+          });
+          row = $('<tr>').appendTo(rows);
+        }
+
+        $.each(rec, function(k,v){
+          $('<td>',{
+            'text': v,
+            'class': k,
+          }).appendTo(row)
+//console.log(rec);
+        });
+
+        count++;
+      });
+
+    });
+
+    return rows;
+  }
+
        this.j2h = function(url,dest,tag='ul',map) {
 
     var tags = {
@@ -363,8 +422,10 @@ function NB() {
     if (typeof tags[tag] == 'string') tags[tag] = tags[tag].split('.');
 //console.log(tags[tag]); return;
 
+    var rows = $('<'+tag+'>');
+
     $.getJSON(url, function(json) {
-      var rows = $('<'+tag+'>');
+      if (dest) $(dest).append(rows);
       tag == 'select' && rows.append($('<'+tags[tag]+'>').text(''));
 
       //if (typeof map != 'undefined') { json = $.map(json,map); }
@@ -372,9 +433,11 @@ function NB() {
 
       $.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]]
+        if (typeof map == 'undefined') {
+          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;
@@ -392,21 +455,21 @@ function NB() {
         //if (row == null) return;
 
 
-        item.text(v[0]);
-        item.attr('value',v[1]);
+        if (typeof map == 'undefined') {
+          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);
 
       });
 
-      $(dest).append(rows);
-
     });
+    return rows;
 
   }