From 4ea29cbf3983b5895c2e623b977bff8bce42164d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B6=9B?= Date: Thu, 2 Feb 2023 16:01:13 +0800 Subject: [PATCH] + zin: add pageheader widget --- module/program/ui/browse.html.php | 31 ++++++++++-- zin/wg.func.php | 3 ++ zin/wg/pageheader/v1.php | 78 +++++++++++++++++++++++++++++++ zin/wg/pageheading/v1.php | 63 +++++++++++++++++++++++++ zin/wg/pagenavbar/v1.php | 56 ++++++++++++++++++++++ 5 files changed, 228 insertions(+), 3 deletions(-) create mode 100644 zin/wg/pageheading/v1.php create mode 100644 zin/wg/pagenavbar/v1.php diff --git a/module/program/ui/browse.html.php b/module/program/ui/browse.html.php index 2550270b0e..0e3464e346 100644 --- a/module/program/ui/browse.html.php +++ b/module/program/ui/browse.html.php @@ -1,10 +1,35 @@ text, + set('url', \commonModel::createMenuLink($menuItem, $app->tab)), + setClass('primary'), + ); +} + page ( - set ('title', $title), - h ('h1', 'hello2')->setClass('text-danger'), + set ('title', $title), + pageheader + ( + pageheading + ( + $lang->{$app->tab}->common, + set('icon', $app->tab), + set('url', \helper::createLink($app->tab, 'browse')), + ), + pagenavbar + ( + set('menus', $mainMenus) + ), + ), + h ('h1', 'hello2')->setClass('text-danger'), btn ( 'Primary', @@ -32,7 +57,7 @@ page 'body', html(''), ), - $listChildren + //$listChildren ); /* diff --git a/zin/wg.func.php b/zin/wg.func.php index e61188c900..8817621fb8 100755 --- a/zin/wg.func.php +++ b/zin/wg.func.php @@ -36,3 +36,6 @@ function pagebase() {return createWg('pagebase', func_get_args());} function page() {return createWg('page', func_get_args());} function dtable() {return createWg('dtable', func_get_args());} +function pageheader() {return createWg('pageheader', func_get_args());} +function pageheading() {return createWg('pageheading', func_get_args());} +function pagenavbar() {return createWg('pagenavbar', func_get_args());} diff --git a/zin/wg/pageheader/v1.php b/zin/wg/pageheader/v1.php index a460fe5136..981c597cd2 100644 --- a/zin/wg/pageheader/v1.php +++ b/zin/wg/pageheader/v1.php @@ -1,6 +1,8 @@ 'header'); + + static $customprops = 'heading,navbar,toolbar'; + + public $heading; + + public $navbar; + + public $toolbar; + + /** + * Accept child node. + * + * @param object|string $child + * @param bool $strAsHtml + * @access protected + * @return object|string + */ + protected function acceptChild($child, $strAsHtml = false) + { + if(class_exists('\zin\wg\pageheading') and $child instanceof \zin\wg\pageheading) + { + $this->heading = $child; + return NULL; + } + + if(class_exists('\zin\wg\pagenavbar') and $child instanceof \zin\wg\pagenavbar) + { + $this->navbar = $child; + return NULL; + } + + if(class_exists('\zin\wg\pagetoolbar') and $child instanceof \zin\wg\pagetoolbar) + { + $this->toolbar = $child; + return NULL; + } + + /* Invoke parent method; */ + $child = parent::acceptChild($child, $strAsHtml); + + if(!$strAsHtml && is_string($child) && !$this->props->has('name')) + { + $this->prop('name', $child); + return NULL; + } + + return $child; + } + + /** + * Build builder. + * + * @param bool $isPrint + * @param object $parent + * @access protected + * @return object + */ + protected function build($isPrint = false, $parent = NULL) + { + $builder = parent::build($isPrint, $parent); + + $container = h5::div()->addClass('container'); + + /* Heading. */ + $container->append($this->heading); + + /* Navigation Bar. */ + $container->append($this->navbar); + + /* Tool Bar. */ + $container->append($this->toolbar); + + $builder->append($container); + + return $builder; + } } diff --git a/zin/wg/pageheading/v1.php b/zin/wg/pageheading/v1.php new file mode 100644 index 0000000000..2ab4b4520c --- /dev/null +++ b/zin/wg/pageheading/v1.php @@ -0,0 +1,63 @@ + 'heading'); + + static $customProps = 'text,icon,url'; + + /** + * Accept child node. + * + * @param object|string $child + * @param bool $strAsHtml + * @access protected + * @return object|string + */ + protected function acceptChild($child, $strAsHtml = false) + { + /* Invoke parent method; */ + $child = parent::acceptChild($child, $strAsHtml); + + if(!$strAsHtml && is_string($child) && !$this->props->has('text')) + { + $this->prop('text', $child); + return NULL; + } + + return $child; + } + + /** + * Build builder. + * + * @param bool $isPrint + * @param object $parent + * @access protected + * @return object + */ + protected function build($isPrint = false, $parent = NULL) + { + $icon = $this->prop('icon'); + $text = $this->prop('text'); + $url = $this->prop('url'); + + $builder = parent::build($isPrint, $parent); + + if(!empty($icon)) $builder->append(new icon($icon)); + + if(empty($text)) return $builder; + + if(!empty($url)) $builder->append(\zin\btn($text, \zin\set('url', $url))->addClass('primary')); + else $builder->append(h5::span($text)->addClass('text')); + + return $builder; + } +} diff --git a/zin/wg/pagenavbar/v1.php b/zin/wg/pagenavbar/v1.php new file mode 100644 index 0000000000..31d898aa08 --- /dev/null +++ b/zin/wg/pagenavbar/v1.php @@ -0,0 +1,56 @@ + 'navbar'); + + static $customProps = 'text,menus'; + + /** + * Accept child node. + * + * @param object $child + * @param bool $strAsHtml + * @access protected + * @return mixed object|string + */ + protected function acceptChild($child, $strAsHtml = false) + { + /* Invoke parent method; */ + $child = parent::acceptChild($child, $strAsHtml); + + if(!$strAsHtml && is_string($child) && !$this->props->has('text')) + { + $this->prop('text', $child); + return NULL; + } + + return $child; + } + + /** + * Build builder. + * + * @param bool $isPrint + * @param object $parent + * @access protected + * @return object + */ + protected function build($isPrint = false, $parent = NULL) + { + $builder = parent::build($isPrint, $this); + + $menu = h5::menu(\zin\setClass('nav')); + foreach($this->prop('menus') as $item) $menu->append(h5::li(\zin\setClass('nav-item'), $item)); + $builder->append($menu); + + return $builder; + } +}