text-align: center;
}
-.db div.rows .nav {
- margin: 0.3em;
- padding: 0;
-}
-
.db div.rows .row *:not([class~=buttons]):hover {
opacity: 0.7;
}
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 = '';
//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) {
$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('&','&',$table->url_list()));
- return true;
-
- } elseif ($action == 'insert') {
- $table->insert($this->p());
- header('Location: ?table=' . $table->name);
- #header('Location: '.str_replace('&','&',$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('&','&',$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;
}
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;
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('&','&',$this->url_list()));
+ return true;
+
+ } elseif ($action == 'insert') {
+ $this->insert($this->p());
+ header('Location: ?table=' . $this->name);
+ #header('Location: '.str_replace('&','&',$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('&','&',$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;
+ }
}
?>