|
|
@@ -121,7 +121,12 @@ class UI {
|
|
|
$firstRow = $row;
|
|
|
break;
|
|
|
}
|
|
|
- $cols = array_keys((array)$firstRow);
|
|
|
+ $cols = array_filter(
|
|
|
+ array_keys((array)$firstRow),
|
|
|
+ function ($col) {
|
|
|
+ return ('@' != substr($col, 0, 1));
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
// if (empty($cols)) return;
|
|
|
$hiddenCols = V::get('hidden_cols', array(), $params);
|
|
|
@@ -152,7 +157,9 @@ class UI {
|
|
|
foreach ($rows as $row) {
|
|
|
$i++;
|
|
|
$trAttrs = array();
|
|
|
- if (!empty($row['__js_on_click'])) $trAttrs['onClick'] = $row['__js_on_click'];
|
|
|
+ if (!empty($row['@onClick'])) $trAttrs['onClick'] = $row['@onClick'];
|
|
|
+ if (!empty($row['@class'])) $trAttrs['class'] = $row['@class'];
|
|
|
+ if (!empty($row['@style'])) $trAttrs['style'] = $row['@style'];
|
|
|
self::startTag('tr', $trAttrs); echo "\n";
|
|
|
if ($showLp) { self::tag('th', [ 'style' => "padding:2px; color:#ccc" ], $i); echo "\n"; }
|
|
|
foreach ($cols as $colName) {
|
|
|
@@ -239,4 +246,83 @@ class UI {
|
|
|
UI::endTag('script', "\n");
|
|
|
}
|
|
|
|
|
|
+ public static function includeView($viewPath, $data = array()) {
|
|
|
+ if (!file_exists($viewPath)) throw new Exception("view file '" . basename($viewPath) . "' not exists!");
|
|
|
+ if (false === strpos($viewPath, APP_PATH_ROOT)) throw new Exception("Access Denied to include view '" . basename($viewPath) . "'!");
|
|
|
+ if (is_array($data) && !empty($data)) {
|
|
|
+ extract($data);
|
|
|
+ }
|
|
|
+ include $viewPath;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function postButton($label, $params = []) {
|
|
|
+ UI::startTag('form', [
|
|
|
+ 'action' => V::get('action', '', $params),
|
|
|
+ 'method' => V::get('method', 'post', $params),
|
|
|
+ 'style' => "display:inline"
|
|
|
+ ]);
|
|
|
+ foreach (V::get('data', [], $params, 'array') as $name => $value) {
|
|
|
+ UI::emptyTag('input', ['type'=>'hidden', 'name'=>$name, 'value'=>$value]);
|
|
|
+ }
|
|
|
+ UI::tag('button', ['type'=>'submit', 'class' => 'btn ' . V::get('class', 'btn-default btn-xs', $params)], $label);
|
|
|
+ UI::endTag('form');
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function hButtonPost($label, $params = []) {
|
|
|
+ $fields = [];
|
|
|
+ if (!empty($params['data'])) foreach ($params['data'] as $k => $v) $fields[] = self::h('input', ['type'=>'hidden', 'name'=>$k, 'value'=>$v]);
|
|
|
+ $fields[] = self::h('button', ['type'=>'submit', 'class' => 'btn ' . V::get('class', 'btn-default btn-xs', $params)], $label);
|
|
|
+ return self::h('form', [
|
|
|
+ 'action' => V::get('action', '', $params),
|
|
|
+ 'method' => V::get('method', 'post', $params),
|
|
|
+ 'style' => "display:inline"
|
|
|
+ ],
|
|
|
+ $fields
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function h($tagName, $params = [], $childrens = []) {
|
|
|
+ $emptyTags = [];
|
|
|
+ $emptyTags[] = 'hr';
|
|
|
+ $emptyTags[] = 'br';
|
|
|
+ $emptyTags[] = 'input';
|
|
|
+ $emptyTags[] = 'link';
|
|
|
+ $emptyTags[] = 'area';
|
|
|
+ $emptyTags[] = 'base';
|
|
|
+ $emptyTags[] = 'col';
|
|
|
+ $emptyTags[] = 'embed';
|
|
|
+ $emptyTags[] = 'img';
|
|
|
+ $emptyTags[] = 'keygen';
|
|
|
+ $emptyTags[] = 'meta';
|
|
|
+ $emptyTags[] = 'param';
|
|
|
+ $emptyTags[] = 'source';
|
|
|
+ $emptyTags[] = 'track';
|
|
|
+ $emptyTags[] = 'wbr';
|
|
|
+ if (in_array($tagName, $emptyTags)) return '<' . $tagName . (empty($params) ? '' : ' ' . self::hAttributes($params)) . '/>';
|
|
|
+ return '<' . $tagName . (empty($params) ? '' : ' ' . self::hAttributes($params)) . '>' . self::hChildrens($childrens) . '</' . $tagName . '>';
|
|
|
+ }
|
|
|
+ public static function hAttributes($params = []) {
|
|
|
+ $attr = [];
|
|
|
+ foreach ($params as $k => $v) {
|
|
|
+ if (is_array($v)) {
|
|
|
+ $attr[] = "{$k}=\"" . implode(" ", $v) . "\"";
|
|
|
+ } else {
|
|
|
+ $attr[] = "{$k}=\"{$v}\"";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return implode(" ", $attr);
|
|
|
+ }
|
|
|
+ public static function hChildrens($childrens = []) {
|
|
|
+ if (empty($childrens)) return '';
|
|
|
+ if (is_string($childrens)) return $childrens;
|
|
|
+ if (!is_array($childrens)) throw new Exception("Unsupported children type");
|
|
|
+ return array_reduce(
|
|
|
+ $childrens,
|
|
|
+ function ($curry, $child) {
|
|
|
+ return "{$curry}{$child}";
|
|
|
+ },
|
|
|
+ ""
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
}
|