From 8ef14c6a1033096cfa37b4e1ccc5ac7073e096c7 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sun, 3 Apr 2016 03:34:46 +0100 Subject: [PATCH] Bed --- lib/js/nb.js | 70 ++++++++++++++++++++++++++++++++++++++++------ lib/php/config.php | 2 +- lib/php/db.php | 2 +- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/lib/js/nb.js b/lib/js/nb.js index e3e0c763..557ffab1 100644 --- a/lib/js/nb.js +++ b/lib/js/nb.js @@ -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 = $('').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() { } diff --git a/lib/php/config.php b/lib/php/config.php index 5782c8ae..fddceed9 100644 --- a/lib/php/config.php +++ b/lib/php/config.php @@ -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); diff --git a/lib/php/db.php b/lib/php/db.php index bcdde716..a8841a40 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -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; -- 2.47.3