From 6efa94c8a16be05d651256ed007d1f855f694bd6 Mon Sep 17 00:00:00 2001 From: chentao Date: Mon, 26 Jun 2023 14:00:43 +0800 Subject: [PATCH] * Refactor 'buildOperateMenu' function to render float toolbar on the product view page. --- module/product/model.php | 51 +++++++++++++++++++++------------ module/product/ui/view.html.php | 19 ++++++------ 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/module/product/model.php b/module/product/model.php index c0a94fb7f7..d739f7c364 100755 --- a/module/product/model.php +++ b/module/product/model.php @@ -1393,27 +1393,26 @@ class productModel extends model * @param object $product * @param string $type * @access public - * @return string + * @return array */ - public function buildOperateMenu(object $product, $type = 'view'): string + public function buildOperateMenu(object $product, string $type = 'view'): array { - $menu = ''; - $params = "product=$product->id"; - $divider = "
"; + /* Declare menu list. */ + $menuList = array + ( + 'main' => array(), + 'suffix' => array() + ); - if($type == 'view') - { - $menu .= $divider . $this->buildFlowMenu('product', $product, $type, 'direct') . $divider; + $params = "product=$product->id"; - $menu .= $this->buildMenu('product', 'close', $params, $product, $type, '', '', 'iframe', true, "data-app='product'"); - $menu .= $divider; - } + if($type == 'view') $menuList['main'][] = $this->buildMenu('product', 'close', $params, $product, $type, '', '', 'iframe', true, "data-app='product'"); - $menu .= $this->buildMenu('product', 'edit', $params, $product, $type); + $menuList['suffix'][] = $this->buildMenu('product', 'edit', $params, $product, $type); - if($type == 'view') $menu .= $this->buildMenu('product', 'delete', $params, $product, $type, 'trash', 'hiddenwin'); + if($type == 'view') $menuList['suffix'][] = $this->buildMenu('product', 'delete', $params, $product, $type, 'trash', 'hiddenwin'); - return $menu; + return $menuList; } /** @@ -1779,9 +1778,25 @@ class productModel extends model if(!$returnHtml) return $enabled; - $html = ''; - $type = $type == 'browse' ? 'list' : 'button'; - $html = common::buildIconButton($module, $method, $params, $data, $type, $icon, $target, $class, $onlyBody, $misc, $title, '', $enabled); - return $html; + global $lang, $app; + if(!$icon) $icon = isset($lang->icons[$method]) ? $lang->icons[$method] : $method; + if(empty($title)) + { + $title = $method; + if($method == 'create' && $icon == 'copy') $method = 'copy'; + if(isset($lang->$method) && is_string($lang->$method)) $title = $lang->$method; + if((isset($lang->$module->$method) || $app->loadLang($module)) && isset($lang->$module->$method)) + { + $title = $method == 'report' ? $lang->$module->$method->common : $lang->$module->$method; + } + } + + return array + ( + 'icon' => $icon, + 'text' => in_array($method, array('edit', 'delete')) ? '' : $title, + 'hint' => $title, + 'url' => helper::createLink($module, $method, $params, '', $onlyBody) + ); } } diff --git a/module/product/ui/view.html.php b/module/product/ui/view.html.php index 681ce0a65d..f63fa2f285 100644 --- a/module/product/ui/view.html.php +++ b/module/product/ui/view.html.php @@ -218,16 +218,17 @@ div /* Extend Fields. */ ), /* Float action toolbar. */ - div + floatToolbar ( - setClass('flex justify-center'), - toolbar( - isonlybody() ? null : btn( - set::icon('back'), - set::url($goBackLink), - $lang->goback - ) - ) + set(array_merge + ( + array('prefix' => isonlybody() ? null : array(array( + 'icon' => 'back', + 'url' => ($goBackLink), + 'text' => $lang->goback + ))), + $this->product->buildOperateMenu($product, 'view') + )) ) ), /* Action list. */