From a2d36c222e229f8863631452651b67aa5dc6f8ab Mon Sep 17 00:00:00 2001 From: Hao Sun Date: Wed, 19 Apr 2023 10:33:08 +0800 Subject: [PATCH] * zin: split form to form and formPanel --- module/program/ui/create.html.php | 2 +- zin/func.php | 3 +- zin/wg/form/v1.php | 22 ++------------ zin/wg/formpanel/v1.php | 50 +++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 zin/wg/formpanel/v1.php diff --git a/module/program/ui/create.html.php b/module/program/ui/create.html.php index 1b56f40275..999fe497f4 100644 --- a/module/program/ui/create.html.php +++ b/module/program/ui/create.html.php @@ -13,7 +13,7 @@ jsVar('weekend', $config->execution->weekend); useData('title', $parentID ? $lang->program->children : $lang->program->create); -form +formPanel ( on::change('#parent', 'onParentChange'), on::change('#budget', 'onBudgetChange'), diff --git a/zin/func.php b/zin/func.php index 7b1dde7a1d..514b01b4d1 100644 --- a/zin/func.php +++ b/zin/func.php @@ -22,7 +22,8 @@ function textarea() {return createWg('textarea', func_get_args());} function radio() {return createWg('radio', func_get_args());} function switcher() {return createWg('switcher', func_get_args());} function checkbox() {return createWg('checkbox', func_get_args());} -function form() {return createWg('form', func_get_args());} +function form() {return createWg('form', func_get_args());} +function formPanel() {return createWg('formPanel', func_get_args());} function control() {return createWg('control', func_get_args());} function select() {return createWg('select', func_get_args());} function formLabel() {return createWg('formLabel', func_get_args());} diff --git a/zin/wg/form/v1.php b/zin/wg/form/v1.php index e975964f61..24de08338d 100644 --- a/zin/wg/form/v1.php +++ b/zin/wg/form/v1.php @@ -1,11 +1,10 @@ 'panel-form rounded-md shadow ring-0 canvas px-4 pb-4 mb-4 mx-auto', - 'size' => 'lg', 'grid' => true, 'method' => 'post', 'target' => 'ajax', 'actions' => ['save', 'back'], ]; - protected function created() - { - $this->setDefaultProps(['title' => data('title')]); - } - public function onBuildItem($item) { if(!($item instanceof item)) @@ -67,7 +59,7 @@ class form extends panel ); } - protected function buildForm() + protected function build() { list($items, $grid, $labelWidth, $url, $target, $method) = $this->prop(['items', 'grid', 'labelWidth', 'url', 'target', 'method']); @@ -90,18 +82,10 @@ class form extends panel ( setClass('form', $grid ? 'form-grid' : NULL, $target === 'ajax' ? 'form-ajax' : ''), set(['action' => $url, 'target' => $target === 'ajax' ? NULL : $target, 'method' => $method]), + set($this->getRestProps()), empty($labelWidth) ? NULL : setCssVar('form-label-width', $labelWidth), $list, $actions ); } - - protected function buildBody() - { - return div - ( - setClass('panel-body'), - $this->buildForm(), - ); - } } diff --git a/zin/wg/formpanel/v1.php b/zin/wg/formpanel/v1.php new file mode 100644 index 0000000000..b307ed8060 --- /dev/null +++ b/zin/wg/formpanel/v1.php @@ -0,0 +1,50 @@ + 'panel-form rounded-md shadow ring-0 canvas px-4 pb-4 mb-4 mx-auto', + 'size' => 'lg', + 'grid' => true, + 'method' => 'post', + 'target' => 'ajax', + 'actions' => ['save', 'back'], + ]; + + protected function created() + { + $this->setDefaultProps(['title' => data('title')]); + } + + protected function buildBody() + { + $props = $this->props->pick(['method', 'url', 'actions', 'target', 'items', 'grid', 'labelWidth']); + return div + ( + setClass('panel-body'), + new form + ( + set($props), + $this->children() + ) + ); + } +}