123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- namespace Dcat\Admin\Form;
- use Dcat\Admin\Exception\RuntimeException;
- use Dcat\Admin\Form;
- use Dcat\Admin\Widgets\Form as WidgetForm;
- /**
- * Class BlockForm.
- *
- *
- * @mixin Form
- */
- class BlockForm extends WidgetForm
- {
- /**
- * @var Form
- */
- protected $form;
- /**
- * @var Builder
- */
- protected $builder;
- /**
- * @var string
- */
- protected $title;
- /**
- * @var \Dcat\Admin\Layout\Row
- */
- public $layoutRow;
- public function __construct(Form $form)
- {
- $this->form = $form;
- $this->builder = $form->builder();
- $this->initFields();
- $this->initFormAttributes();
- }
- /**
- * 设置标题.
- *
- * @param string $title
- *
- * @return $this
- */
- public function title($title)
- {
- $this->title = $title;
- return $this;
- }
- /**
- * 显示底部内容.
- *
- * @return $this
- */
- public function showFooter()
- {
- $this->ajax(true);
- $this->disableSubmitButton(false);
- $this->disableResetButton(false);
- return $this;
- }
- /**
- * 在当前列增加一块表单.
- *
- * @param \Closure $callback
- *
- * @return $this
- */
- public function next(\Closure $callback)
- {
- $this->layoutRow->column(
- 12,
- $form = $this->form
- ->builder()
- ->layout()
- ->form()
- );
- $callback($form);
- return $this;
- }
- public function pushField(Field $field)
- {
- $field->attribute(Field::BUILD_IGNORE, true);
- $this->form->builder()->pushField((clone $field)->display(false));
- $this->fields->push($field);
- if ($this->layout()->hasColumns()) {
- $this->layout()->addField($field);
- }
- $field->setForm($this->form);
- $field->setParent($this);
- $field->width($this->width['field'], $this->width['label']);
- $field::requireAssets();
- return $this;
- }
- public function render()
- {
- $class = $this->title ? '' : 'pt-1';
- $view = parent::render();
- return <<<HTML
- <div class='box {$class} mb-1'>
- {$this->renderHeader()} {$view}
- </div>
- HTML;
- }
- protected function renderHeader()
- {
- if (! $this->title) {
- return;
- }
- return <<<HTML
- <div class="box-header with-border" style="margin-bottom: .5rem">
- <h3 class="box-title">{$this->title}</h3>
- </div>
- HTML;
- }
- public function getKey()
- {
- return $this->form->getKey();
- }
- public function model()
- {
- return $this->form->model();
- }
- public function __call($method, $arguments)
- {
- try {
- return parent::__call($method, $arguments);
- } catch (RuntimeException $e) {
- return $this->form->$method($arguments);
- }
- }
- public function fillFields(array $data)
- {
- }
- }
|