Explorar el Código

:hammer: 移除分步表单功能(移至扩展中心)

jqh hace 5 años
padre
commit
900e121021

+ 0 - 46
resources/views/form/done-step.blade.php

@@ -1,46 +0,0 @@
-<style>
-    .dcat-done-step {
-        max-width: 560px;
-        margin: 0 auto;
-        padding: 24px 0 8px;
-    }
-    .dcat-done-step .st-icon {
-        color: {{ Dcat\Admin\Admin::color()->success() }};
-        font-size: 72px;
-        text-align:center;
-    }
-    .dcat-done-step .st-content {
-        text-align:center;
-    }
-    .dcat-done-step .st-title {
-        font-size: 24px;
-    }
-    .dcat-done-step .st-desc {
-        color: rgba(0,0,0,.5);
-        font-size: 14px;
-        line-height: 1.6;
-    }
-    .dcat-done-step .st-btn {
-        margin: 30px 0 10px;
-    }
-</style>
-<div style="margin: 0 auto">
-    <div class="st-icon">
-        <svg viewBox="64 64 896 896" focusable="false" class="" data-icon="check-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 0 1-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"></path></svg>
-    </div>
-
-    <div class="st-content">
-        <div class="st-title">
-            {{ $title }}
-        </div>
-        <div class="st-desc">
-            {{ $description }}
-        </div>
-
-        <div class="st-btn">
-            <a class="btn btn-success" href="{{ $createUrl }}" >{{ trans('admin.continue_creating') }}</a>
-            &nbsp;
-            <a class="btn btn-white" href="{{ $backUrl }}"><i class="fa fa-long-arrow-left"></i> {{ trans('admin.back') }}</a>
-        </div>
-    </div>
-</div>

+ 0 - 10
resources/views/form/step-form.blade.php

@@ -1,10 +0,0 @@
-{!! $start !!}
-<div class="box-body fields-group">
-
-    @foreach($fields as $field)
-        {!! $field->render() !!}
-    @endforeach
-
-</div>
-
-{!! $end !!}

+ 0 - 308
resources/views/form/steps.blade.php

@@ -1,308 +0,0 @@
-<style>
-    .dcat-step .dcat-step-item:not(.active) > .dcat-step-item-container[role=button]:hover .dcat-step-icons,
-    .done > .dcat-step-item-container > .dcat-step-line:after,
-    .done .dcat-step-icons,
-    .active .dcat-step-icons {
-        border-color: @primary
-    }
-
-    .dcat-step .dcat-step-item:not(.active) > .dcat-step-item-container[role=button]:hover .dcat-step-icons .dcat-step-icon,
-    .dcat-step .dcat-step-item:not(.active) > .dcat-step-item-container[role=button]:hover .dcat-step-desc .dcat-step .dcat-step-item:not(.active) > .dcat-step-item-container[role=button]:hover .dcat-step-title,
-    .done .dcat-step-icons > .dcat-step-icon,
-    .active .dcat-step-icons > .dcat-step-icon {
-        color: @primary
-    }
-
-    .done > .dcat-step-item-container > .dcat-step-content > .dcat-step-title:after,
-    .done .dcat-step-icons > .dcat-step-icon .dcat-step-icon-dot,
-    .active .dcat-step-icons,
-    .active .dcat-step-icons > .dcat-step-icon .dcat-step-icon-dot {
-        background-color: @primary
-    }
-</style>
-
-@if($showHeader)
-    <div class="box-header with-border">
-        <h3 class="box-title" style="line-height:30px">{!! $form->title() !!}</h3>
-        <div class="pull-right">{!! $form->renderTools() !!}</div>
-    </div>
-@endif
-
-<div class="box-body">
-    @if($steps->count())
-        <div class="fields-group dcat-step-box" style="padding: {{ $steps->getOption('padding') }};max-width: {{ $steps->getOption('width') }}">
-
-            <ul class="dcat-step-horizontal dcat-step-label-horizontal dcat-step ">
-                @foreach($steps->all() as $step)
-                <li class="dcat-step-item">
-                    <a href="#{{ $step->getElementId() }}" class="dcat-step-item-container">
-                        <div class="dcat-step-line"></div>
-                        <div class="dcat-step-icons">
-                            <span class="dcat-step-icon" data-index="{{ $step->index() }}">{{ $step->index() + 1 }}</span>
-                        </div>
-                        <div class="dcat-step-content">
-                            <div class="dcat-step-title">{!! $step->title() !!}</div>
-                            <div class="dcat-step-desc"> {{ $step->description() }} </div>
-                        </div>
-                    </a>
-                </li>
-                @endforeach
-
-                <li class="dcat-step-item">
-                    <a href="#{{ $steps->done()->getElementId() }}" class="dcat-step-item-container">
-                        <div class="dcat-step-line"></div>
-                        <div class="dcat-step-icons">
-                            <span class="dcat-step-icon" data-index="{{ $steps->count() }}"> {{ $steps->count() + 1 }} </span>
-                        </div>
-                        <div class="dcat-step-content">
-                            <div class="dcat-step-title">{{ $steps->done()->title() }}</div>
-                            <div class="dcat-step-desc"></div>
-                        </div>
-                    </a>
-                </li>
-            </ul>
-            <div class="dcat-step-form">
-                {!! $steps->build() !!}
-
-                <div id="{{ $steps->done()->getElementId() }}" class="dcat-done-step" style="display: none;">
-                </div>
-            </div>
-        </div>
-    @endif
-</div>
-
-@foreach($form->hiddenFields() as $field)
-    {!! $field->render() !!}
-@endforeach
-
-<input type="hidden" class="current-step-input" name="{{ Dcat\Admin\Form\Step\Builder::CURRENT_VALIDATION_STEP }}" />
-<input type="hidden" class="all-steps-input" name="{{ Dcat\Admin\Form\Step\Builder::ALL_STEPS }}" />
-<input type="hidden" name="_token" value="{{ csrf_token() }}">
-
-@php
-$lastStep = $step;
-@endphp
-
-<script>
-Dcat.ready(function () {
-    var form = $('#{{ $form->getElementId() }}'),
-        box = form.find('.dcat-step-box'),
-        stepInput = form.find('.current-step-input'),
-        allStepInput = form.find('.all-steps-input'),
-        smartWizard,
-        isSubmitting;
-
-    var submitBtn = $('<button style="margin-left: 10px"></button>')
-        .text('{{ trans('admin.submit') }}')
-        .addClass('btn btn-primary step-submit-btn disabled d-none')
-        .on('click', function(){
-            var $t = $(this);
-
-            if ($t.hasClass('disabled') || isSubmitting) {
-               return false;
-            }
-
-            form.validator('validate');
-            if (form.find('.has-error').length > 0) {
-                return false;
-            }
-
-            allStepInput.val("1");
-            stepInput.val("");
-            $t.buttonLoading().removeClass('waves-effect');
-            isSubmitting = 1;
-
-            // 提交完整表单
-            submit(function (state, data) {
-                $t.buttonLoading(false);
-                isSubmitting = 0;
-
-                if (state) {
-                    if (data) {
-                        form.find('.dcat-done-step').html(data);
-                    }
-
-                    smartWizard.next();
-
-                    toggleBtn();
-                }
-            });
-
-            return false;
-
-        });
-
-    smartWizard = box.smartWizard({
-        selected: {{ $steps->getOption('selected') }},
-        transitionEffect: 'fade',
-        useURLhash: false,
-        keyNavigation: false,
-        showStepURLhash: false,
-        autoAdjustHeight: false,
-        lang: {
-            next: '{!! trans('admin.next_step') !!}',
-            previous: '{!! trans('admin.prev_step') !!}'
-        },
-        toolbarSettings: {
-            toolbarPosition: 'bottom',
-            toolbarExtraButtons: [submitBtn,],
-            toolbarButtonPosition: 'left'
-        },
-        anchorSettings: {
-            removeDoneStepOnNavigateBack: true,
-            enableAnchorOnDoneStep: false,
-        },
-    }).on('leaveStep', function (e, tab, idx, direction) {
-        @if ($leaving = $steps->getOption('leaving'))
-
-        var callbacks = [];
-
-        @foreach($leaving as $fun)
-            callbacks.push({!! $fun !!});
-        @endforeach
-
-        return callListeners(callbacks, buildArgs(e, tab, idx, direction));
-        @endif
-
-    }).on('showStep', function (e, tab, idx, direction) {
-        @if ($shown = $steps->getOption('shown'))
-
-        var callbacks = [];
-
-        @foreach($shown as $fun)
-        callbacks.push({!! $fun !!});
-        @endforeach
-
-        return callListeners(callbacks, buildArgs(e, tab, idx, direction));
-        @endif
-    });
-
-    @if ($steps->getOption('leaving') || $steps->getOption('shown'))
-
-    // 执行回调函数
-    function callListeners(func, args) {
-        for (var i in func) {
-            if (func[i](args) === false) {
-                return false;
-            }
-        }
-    }
-
-    // 获取步骤表单
-    function getForm(idx) {
-        return box.find('.dcat-step-form [data-toggle="validator"]').eq(idx);
-    }
-
-    // 构建参数
-    function buildArgs(e, tab, idx, direction) {
-        return {
-            event: e,
-            tab: tab,
-            index: idx,
-            direction: direction,
-            form: getForm(idx),
-            getFrom: function (idx) {
-                return getForm(idx)
-            },
-            formArray: getForm(idx).formToArray(),
-            getFormArray: function (idx) {
-                return getForm(idx).formToArray();
-            }
-        };
-    }
-    @endif
-
-    smartWizard = smartWizard.data('smartWizard');
-
-    // 上一步
-    var prev = box.find('.sw-btn-prev').click(function (e) {
-        e.preventDefault();
-        if (smartWizard.steps.index(this) !== smartWizard.current_index) {
-            smartWizard.prev();
-        }
-
-        toggleBtn();
-    });
-
-    // 下一步
-    var next = box.find('.sw-btn-next').click(function (e) {
-        e.preventDefault();
-
-        if ($(this).hasClass('disabled') || isSubmitting) {
-            return false;
-        }
-
-        var stepForm = form.find('.sw-container [data-toggle="validator"]').eq(smartWizard.current_index);
-
-        stepForm.validator('validate');
-        if (stepForm.find('.has-error').length > 0) {
-            return false;
-        }
-
-        var self = this;
-        $(self).buttonLoading().removeClass('waves-effect');
-        isSubmitting = 1;
-
-        // 发送表单到服务器进行验证
-        stepInput.val(smartWizard.current_index);
-        submit(function (state) {
-            $(self).buttonLoading(false);
-            isSubmitting = 0;
-
-            if (state) {
-                // 表单验证成功
-                if (smartWizard.steps.index(self) !== smartWizard.current_index) {
-                    smartWizard.next();
-                }
-
-                toggleBtn();
-            }
-
-        });
-    });
-
-    // 提交表单
-    function submit(after) {
-        Dcat.Form({
-            form: form,
-            after: function (state, b, c, d) {
-                after(state, b, c, d);
-
-                if (state) {
-                    return false;
-                }
-            }
-        });
-    }
-
-    // 按钮显示隐藏切换
-    function toggleBtn() {
-        var last = {{ $lastStep->index() }},
-            sbm = box.find('.step-submit-btn');
-
-        if (smartWizard.current_index == last) {
-            sbm.removeClass('disabled d-none');
-            next.hide();
-            prev.show();
-        } else {
-            sbm.addClass('disabled d-none');
-            if (smartWizard.current_index !== 0) {
-                prev.show();
-            } else {
-                prev.hide();
-            }
-
-            if (smartWizard.current_index != (last + 1)) {
-                next.show()
-            }
-        }
-
-        if (smartWizard.current_index == (last + 1)) {
-            box.find('.sw-btn-group').remove()
-        }
-    }
-
-    toggleBtn();
-});
-</script>
-

+ 0 - 6
src/Console/ExtensionMakeCommand.php

@@ -72,9 +72,6 @@ class ExtensionMakeCommand extends Command
         'resources/views',
         'resources/lang',
         'src/Models',
-        'src/Form',
-        'src/Grid',
-        'src/Show',
         'src/Http/Controllers',
         'src/Http/Middleware',
     ];
@@ -165,9 +162,6 @@ TREE;
         ├── {$this->className}ServiceProvider.php
         ├── Setting.php
         ├── Models
-        ├── Grid
-        ├── Form
-        ├── Show
         └── Http
             ├── routes.php
             ├── Middleware

+ 11 - 28
src/Form.php

@@ -92,7 +92,6 @@ class Form implements Renderable
     use HasFormResponse;
     use Concerns\HasEvents;
     use Concerns\HasFiles;
-    use Concerns\HasSteps;
     use Concerns\HandleCascadeFields;
     use Concerns\HasRows;
     use Concerns\HasTabs;
@@ -334,13 +333,7 @@ class Form implements Renderable
      */
     public function fields()
     {
-        $fields = $this->builder->fields();
-
-        if ($steps = $this->builder->stepBuilder()) {
-            $fields = $fields->merge($steps->fields());
-        }
-
-        return $fields;
+        return $this->builder->fields();
     }
 
     /**
@@ -610,10 +603,6 @@ class Form implements Renderable
                 return $this->sendResponse($response);
             }
 
-            if ($response = $this->responseMultipleStepsDonePage()) {
-                return $this->sendResponse($response);
-            }
-
             if (! $id) {
                 return $this->sendResponse(
                     $this->response()
@@ -654,29 +643,23 @@ class Form implements Renderable
 
         $this->build();
 
-        $this->prepareStepFormFields($this->inputs);
+        //$this->prepareStepFormFields($this->inputs);
 
         if (($response = $this->callSubmitted())) {
             return $response;
         }
-
-        // Validate step form.
-        if ($this->isStepFormValidationRequest()) {
-            return $this->validateStepForm($this->inputs);
-        }
+        //
+        //// Validate step form.
+        //if ($this->isStepFormValidationRequest()) {
+        //    return $this->validateStepForm($this->inputs);
+        //}
 
         if ($response = $this->handleUploadFile($this->inputs)) {
             return $response;
         }
 
-        if ($response = $this->handleFileDeleteBeforeCreate($this->inputs)) {
-            $this->deleteFileInStepFormStashData($this->inputs);
-
-            return $response;
-        }
-
-        if ($response = $this->handleFileDeleteWhenCreating($this->inputs)) {
-            $this->deleteFileInStepFormStashData($this->inputs);
+        if ($response = $this->deleteFileWhenCreating($this->inputs)) {
+            //$this->deleteFileInStepFormStashData($this->inputs);
 
             return $response;
         }
@@ -687,7 +670,7 @@ class Form implements Renderable
         }
 
         if (($response = $this->prepare($this->inputs))) {
-            $this->deleteFilesWhenCreating($this->inputs);
+            $this->deleteFiles($this->inputs, true);
 
             return $response;
         }
@@ -1248,7 +1231,7 @@ class Form implements Renderable
         $message = $this->mergeValidationMessages($failedValidators);
 
         if ($message->any() && $this->builder->isCreating()) {
-            $this->deleteFilesWhenCreating($input);
+            $this->deleteFiles($input, true);
         }
 
         return $message->any() ? $message : false;

+ 2 - 94
src/Form/Builder.php

@@ -134,11 +134,6 @@ class Builder
      */
     protected $showFooter = true;
 
-    /**
-     * @var StepBuilder
-     */
-    protected $stepBuilder;
-
     /**
      * @var array
      */
@@ -192,18 +187,6 @@ class Builder
         return $this->wrapper ? true : false;
     }
 
-    /**
-     * @param int $width
-     *
-     * @return $this
-     */
-    public function setDefaultBlockWidth(int $width)
-    {
-        $this->defaultBlockWidth = $width;
-
-        return $this;
-    }
-
     /**
      * Get form tools instance.
      *
@@ -224,38 +207,6 @@ class Builder
         return $this->footer;
     }
 
-    /**
-     * @param \Closure|StepForm[]|null $builder
-     *
-     * @return StepBuilder
-     */
-    public function multipleSteps($builder = null)
-    {
-        if (! $this->stepBuilder) {
-            $this->view = 'admin::form.steps';
-
-            $this->stepBuilder = new StepBuilder($this->form);
-        }
-
-        if ($builder) {
-            if ($builder instanceof \Closure) {
-                $builder($this->stepBuilder);
-            } elseif (is_array($builder)) {
-                $this->stepBuilder->add($builder);
-            }
-        }
-
-        return $this->stepBuilder;
-    }
-
-    /**
-     * @return StepBuilder
-     */
-    public function stepBuilder()
-    {
-        return $this->stepBuilder;
-    }
-
     /**
      * @param string $title
      * @param string $content
@@ -480,55 +431,13 @@ class Builder
      */
     public function field($name)
     {
-        $field = $this->fields->first(function (Field $field) use ($name) {
+        return $this->fields->first(function (Field $field) use ($name) {
             if (is_array($field->column())) {
                 return in_array($name, $field->column(), true) ? $field : null;
             }
 
             return $field === $name || $field->column() === $name;
         });
-
-        if (! $field) {
-            $field = $this->stepField($name);
-        }
-
-        return $field;
-    }
-
-    /**
-     * @param string $name
-     *
-     * @return Field|null
-     */
-    public function stepField($name)
-    {
-        if (! $builder = $this->stepBuilder()) {
-            return;
-        }
-
-        foreach ($builder->all() as $step) {
-            if ($field = $step->field($name)) {
-                return $field;
-            }
-        }
-    }
-
-    /**
-     * @return Field[]|Collection
-     */
-    public function stepFields()
-    {
-        $fields = new Collection();
-
-        if (! $builder = $this->stepBuilder()) {
-            return $fields;
-        }
-
-        foreach ($builder->all() as $step) {
-            $fields = $fields->merge($step->fields());
-        }
-
-        return $fields;
     }
 
     /**
@@ -840,7 +749,7 @@ class Builder
             $tabObj->addScript();
         }
 
-        if ($this->form->allowAjaxSubmit() && empty($this->stepBuilder)) {
+        if ($this->form->allowAjaxSubmit()) {
             $this->addSubmitScript();
         }
 
@@ -852,7 +761,6 @@ class Builder
             'width'      => $this->width,
             'elementId'  => $this->getElementId(),
             'showHeader' => $this->showHeader,
-            'steps'      => $this->stepBuilder,
             'fields'     => $this->fields,
             'rows'       => $this->rows(),
             'layout'     => $this->layout(),

+ 0 - 126
src/Form/Concerns/HasSteps.php

@@ -1,126 +0,0 @@
-<?php
-
-namespace Dcat\Admin\Form\Concerns;
-
-use Closure;
-use Dcat\Admin\Form\Builder;
-use Dcat\Admin\Form\Step\Builder as StepBuilder;
-use Dcat\Admin\Form\Step\Form as StepForm;
-
-/**
- * @property Builder $builder
- */
-trait HasSteps
-{
-    /**
-     * @param Closure|StepForm[]|null $builder
-     *
-     * @return StepBuilder
-     */
-    public function multipleSteps($builder = null)
-    {
-        return $this->builder->multipleSteps($builder);
-    }
-
-    /**
-     * @param array $data
-     *
-     * @return void
-     */
-    protected function prepareStepFormFields(array $data)
-    {
-        $stepBuilder = $this->builder->stepBuilder();
-
-        if (
-            empty($stepBuilder)
-            || empty($stepBuilder->count())
-            || (! isset($data[StepBuilder::ALL_STEPS]) && ! $this->isStepFormValidationRequest())
-        ) {
-            return;
-        }
-
-        $steps = $stepBuilder->all();
-
-        if ($this->isStepFormValidationRequest()) {
-            $currentIndex = $data[StepBuilder::CURRENT_VALIDATION_STEP];
-
-            if (empty($steps[$currentIndex])) {
-                return;
-            }
-
-            foreach ($steps[$currentIndex]->fields() as $field) {
-                $this->pushField($field);
-            }
-
-            return;
-        }
-
-        if (! empty($data[StepBuilder::ALL_STEPS])) {
-            foreach ($steps as $stepForm) {
-                foreach ($stepForm->fields() as $field) {
-                    $this->pushField($field);
-                }
-            }
-        }
-    }
-
-    /**
-     * @return bool
-     */
-    protected function isStepFormValidationRequest()
-    {
-        $index = $this->request->get(StepBuilder::CURRENT_VALIDATION_STEP);
-
-        return $index !== '' && $index !== null;
-    }
-
-    /**
-     * Validate step form.
-     *
-     * @param array $data
-     *
-     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
-     */
-    protected function validateStepForm(array $data)
-    {
-        // Handle validation errors.
-        if ($validationMessages = $this->validationMessages($data)) {
-            return $this->validationErrorsResponse($validationMessages);
-        }
-
-        // Stash input data.
-        $this->multipleSteps()->stash($data);
-
-        return $this
-            ->response()
-            ->success('Success')
-            ->send();
-    }
-
-    /**
-     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response|void
-     */
-    protected function responseMultipleStepsDonePage()
-    {
-        if (! $builder = $this->builder->stepBuilder()) {
-            return;
-        }
-
-        return response($builder->done()->render());
-    }
-
-    /**
-     * @param array $input
-     *
-     * @return void
-     */
-    protected function deleteFileInStepFormStashData($input = [])
-    {
-        if (empty($input['_column'])) {
-            return;
-        }
-
-        $this->multipleSteps()->stashIndexByField($input['_column']);
-        $this->multipleSteps()->forgetStash($input['_column']);
-    }
-}

+ 0 - 473
src/Form/Step/Builder.php

@@ -1,473 +0,0 @@
-<?php
-
-namespace Dcat\Admin\Form\Step;
-
-use Closure;
-use Dcat\Admin\Admin;
-use Dcat\Admin\Form as ParentForm;
-use Dcat\Admin\Form\StepForm as Form;
-use Illuminate\Support\Arr;
-use Illuminate\Support\Collection;
-
-class Builder
-{
-    const CURRENT_VALIDATION_STEP = 'CURRENT_VALIDATION_STEP';
-    const ALL_STEPS = 'ALL_STEPS';
-
-    /**
-     * @var ParentForm
-     */
-    protected $form;
-
-    /**
-     * @var Form[]
-     */
-    protected $stepForms = [];
-
-    /**
-     * @var Done
-     */
-    protected $done;
-
-    /**
-     * @var array
-     */
-    protected $options = [
-        'selected' => 0,
-        'width'    => '1000px',
-        'padding'  => '30px 18px 30px',
-        'remember' => false,
-        'shown'    => [],
-        'leaving'  => [],
-    ];
-
-    public function __construct(ParentForm $form)
-    {
-        $this->form = $form->saved(function () {
-            $this->flushStash();
-        });
-
-        $this->requireAssets();
-    }
-
-    /**
-     * @param string|Form|Form[] $title
-     * @param \Closure|null      $callback
-     *
-     * @return $this
-     */
-    public function add($title, ?\Closure $callback = null)
-    {
-        if (is_array($title)) {
-            foreach ($title as $key => $form) {
-                $this->addForm($form, $callback);
-            }
-
-            return $this;
-        }
-
-        $form = $title instanceof Form ? $title : new Form($this->form, $title);
-
-        $this->addForm($form, $callback);
-
-        return $this;
-    }
-
-    /**
-     * @param Form          $form
-     * @param \Closure|null $callback
-     *
-     * @return void
-     */
-    protected function addForm(Form $form, ?\Closure $callback = null)
-    {
-        $form->setIndex(count($this->stepForms));
-
-        $this->stepForms[] = $form;
-
-        if ($callback) {
-            $callback($form);
-        }
-    }
-
-    /**
-     * Get all step forms.
-     *
-     * @return Form[]
-     */
-    public function all()
-    {
-        return $this->stepForms;
-    }
-
-    /**
-     * @return ParentForm\Field[]|Collection
-     */
-    public function fields()
-    {
-        $fields = new Collection();
-
-        foreach ($this->all() as $form) {
-            $fields = $fields->merge($form->fields());
-        }
-
-        return $fields;
-    }
-
-    /**
-     * Counts all step forms.
-     *
-     * @return int
-     */
-    public function count()
-    {
-        return count($this->stepForms);
-    }
-
-    /**
-     * Set options.
-     *
-     * @param string|array $key
-     * @param mixed        $value
-     *
-     * @return $this
-     */
-    public function option($key, $value = null)
-    {
-        if (is_array($key)) {
-            $this->options = array_merge($this->options, $key);
-        } else {
-            $this->options[$key] = $value;
-        }
-
-        return $this;
-    }
-
-    /**
-     * Get options.
-     *
-     * @param string|null $key
-     * @param null        $default
-     *
-     * @return array|mixed|null
-     */
-    public function getOption($key = null, $default = null)
-    {
-        if ($key === null) {
-            return $this->options;
-        }
-
-        return $this->options[$key] ?? $default;
-    }
-
-    /**
-     * @param int $index
-     *
-     * @return $this
-     */
-    public function select(int $index)
-    {
-        return $this->option('selected', $index);
-    }
-
-    /**
-     * Set padding for container.
-     *
-     * @param string $padding
-     *
-     * @return $this
-     */
-    public function padding(string $padding)
-    {
-        return $this->option('padding', $padding);
-    }
-
-    /**
-     * Set max width for container.
-     *
-     * @param string $width
-     *
-     * @return $this
-     */
-    public function width(string $width)
-    {
-        return $this->option('width', $width);
-    }
-
-    /**
-     * Remember input data.
-     *
-     * @param bool $value
-     *
-     * @return $this
-     */
-    public function remember(bool $value = true)
-    {
-        return $this->option('remember', $value);
-    }
-
-    /**
-     * @param string|Closure $title
-     * @param Closure|null   $callback
-     *
-     * @return $this|Done
-     */
-    public function done($title = null, Closure $callback = null)
-    {
-        if ($title === null && $callback === null) {
-            if (! $this->done) {
-                $this->makeDefaultDonePage();
-            }
-
-            return $this->done;
-        }
-
-        if ($title instanceof Closure) {
-            $callback = $title;
-            $title = trans('admin.done');
-        }
-
-        $this->done = new Done($this->form, $title, $callback);
-
-        return $this;
-    }
-
-    /**
-     * @return void
-     */
-    protected function makeDefaultDonePage()
-    {
-        $this->done(function () {
-            $resource = $this->form->getResource(0);
-
-            $data = [
-                'title'       => trans('admin.save_succeeded'),
-                'description' => '',
-                'createUrl'   => $resource.'/create',
-                'backUrl'     => $resource,
-            ];
-
-            return view('admin::form.done-step', $data);
-        });
-    }
-
-    /**
-     * Stash input data.
-     *
-     * @param array $data
-     * @param bool  $merge
-     *
-     * @return void
-     */
-    public function stash(array $data, bool $merge = false)
-    {
-        if (! $this->options['remember']) {
-            return;
-        }
-
-        if ($merge) {
-            $data = array_merge($this->fetchStash(), $data);
-        }
-
-        session()->put($this->getStashKey(), $data);
-    }
-
-    /**
-     * Fetch input data.
-     *
-     * @return array
-     */
-    public function fetchStash()
-    {
-        if (! $this->options['remember']) {
-            return [];
-        }
-
-        return session()->get($this->getStashKey()) ?: [];
-    }
-
-    /**
-     * Flush input data.
-     *
-     * @return void
-     */
-    public function flushStash()
-    {
-        if (! $this->options['remember']) {
-            return;
-        }
-
-        session()->remove($this->getStashKey());
-    }
-
-    /**
-     * Forget input data by keys.
-     *
-     * @param string|array $keys
-     *
-     * @return void
-     */
-    public function forgetStash($keys)
-    {
-        $data = $this->fetchStash();
-
-        Arr::forget($data, $keys);
-
-        $this->stash($data);
-    }
-
-    /**
-     * @param string|\Dcat\Admin\Form\Field $field
-     *
-     * @return void
-     */
-    public function stashIndexByField($field)
-    {
-        if (! $this->options['remember']) {
-            return;
-        }
-
-        $data = $this->fetchStash();
-
-        $data[self::CURRENT_VALIDATION_STEP] = ($this->fieldIndex($field) ?: 0) - 1;
-
-        unset($data[self::ALL_STEPS]);
-
-        $this->stash($data);
-    }
-
-    /**
-     * @return string
-     */
-    protected function getStashKey()
-    {
-        return 'step-form-input:'.admin_controller_slug();
-    }
-
-    /**
-     * @return void
-     */
-    protected function requireAssets()
-    {
-        Admin::requireAssets('@smart-wizard');
-    }
-
-    /**
-     * @return void
-     */
-    protected function selectStep()
-    {
-        if (! $this->options['remember'] || ! $input = $this->fetchStash()) {
-            return;
-        }
-
-        $current = $input[static::CURRENT_VALIDATION_STEP] ?? null;
-        $allStep = $input[static::ALL_STEPS] ?? null;
-
-        unset($input[static::CURRENT_VALIDATION_STEP], $input[static::ALL_STEPS]);
-
-        if ($current !== null && $current !== '' && ! empty($input)) {
-            $this->select((int) ($current + 1));
-        }
-
-        if (! empty($allStep) && ! empty($input)) {
-            $this->select($this->count() - 1);
-        }
-    }
-
-    /**
-     * @return string
-     */
-    public function build()
-    {
-        $this->selectStep();
-
-        $this->prepareForm();
-
-        return $this->renderFields();
-    }
-
-    /**
-     * @return void
-     */
-    protected function prepareForm()
-    {
-        foreach ($this->stepForms as $step) {
-            $step->action($this->form->action());
-
-            foreach ($step->fields() as $field) {
-                $field->setForm($this->form);
-            }
-        }
-    }
-
-    /**
-     * @return string
-     */
-    public function renderFields()
-    {
-        $html = '';
-
-        foreach ($this->stepForms as $step) {
-            $html .= (string) $step->render();
-        }
-
-        return $html;
-    }
-
-    /**
-     * Register the "showStep" event listener.
-     *
-     * @param string $script
-     *
-     * @return $this
-     */
-    public function shown($script)
-    {
-        $script = value($script);
-
-        $this->options['shown'][] = <<<JS
-function (args) {
-    {$script}
-}
-JS;
-
-        return $this;
-    }
-
-    /**
-     * Register the "leaveStep" event listener.
-     *
-     * @param string $script
-     *
-     * @return $this
-     */
-    public function leaving($script)
-    {
-        $script = value($script);
-
-        $this->options['leaving'][] = <<<JS
-function (args) {
-    {$script}
-}
-JS;
-
-        return $this;
-    }
-
-    /**
-     * @param string|\Dcat\Admin\Form\Field $column
-     *
-     * @return false|int
-     */
-    public function fieldIndex($column)
-    {
-        foreach ($this->stepForms as $index => $form) {
-            if ($form->field($column)) {
-                return $index;
-            }
-        }
-
-        return false;
-    }
-}

+ 0 - 139
src/Form/Step/Done.php

@@ -1,139 +0,0 @@
-<?php
-
-namespace Dcat\Admin\Form\Step;
-
-use Dcat\Admin\Form;
-use Dcat\Admin\Support\Helper;
-use Illuminate\Contracts\Support\Renderable;
-use Illuminate\Support\Arr;
-use Illuminate\Support\Str;
-
-class Done
-{
-    /**
-     * @var Form
-     */
-    protected $form;
-
-    /**
-     * @var string
-     */
-    protected $title;
-
-    /**
-     * @var string
-     */
-    protected $contents;
-
-    /**
-     * @var \Closure
-     */
-    protected $builder;
-
-    /**
-     * @var string
-     */
-    protected $elementId;
-
-    public function __construct(Form $form, $title, \Closure $callback)
-    {
-        $this->form = $form;
-        $this->builder = $callback;
-        $this->elementId = 'step-finish-'.Str::random();
-
-        $this->title($title);
-    }
-
-    /**
-     * @return Form
-     */
-    public function form()
-    {
-        return $this->form;
-    }
-
-    /**
-     * @param string $title
-     *
-     * @return $this|string
-     */
-    public function title($title = null)
-    {
-        if ($title === null) {
-            return $this->title;
-        }
-
-        $this->title = value($title);
-
-        return $this;
-    }
-
-    /**
-     * @param string|\Closure|Renderable $contents
-     *
-     * @return $this
-     */
-    public function contents($contents)
-    {
-        $this->contents = $contents;
-
-        return $this;
-    }
-
-    /**
-     * @return string
-     */
-    public function getElementId(): string
-    {
-        return $this->elementId;
-    }
-
-    /**
-     * @return array
-     */
-    public function getNewId()
-    {
-        return $this->form->getKey();
-    }
-
-    /**
-     * @param string|null $key
-     * @param mixed|null  $default
-     *
-     * @return array|mixed
-     */
-    public function input($key = null, $default = null)
-    {
-        $input = $this->form->updates();
-
-        if ($key === null) {
-            return $input;
-        }
-
-        return Arr::get($input, $key, $default);
-    }
-
-    /**
-     * @return void
-     */
-    protected function callBuilder()
-    {
-        if (! $this->builder) {
-            return;
-        }
-
-        if ($value = call_user_func($this->builder, $this)) {
-            $this->contents($value);
-        }
-    }
-
-    /**
-     * @return string
-     */
-    public function render()
-    {
-        $this->callBuilder();
-
-        return Helper::render($this->contents);
-    }
-}

+ 0 - 239
src/Form/StepForm.php

@@ -1,239 +0,0 @@
-<?php
-
-namespace Dcat\Admin\Form;
-
-use Dcat\Admin\Form as ParentForm;
-use Dcat\Admin\Widgets\Form as WidgetForm;
-
-class StepForm extends WidgetForm
-{
-    /**
-     * @var string
-     */
-    protected $view = 'admin::form.step-form';
-
-    /**
-     * @var array
-     */
-    protected $buttons = [];
-
-    /**
-     * @var ParentForm
-     */
-    protected $form;
-
-    /**
-     * @var ParentForm\Step\Builder
-     */
-    protected $parent;
-
-    /**
-     * @var int
-     */
-    protected $index;
-
-    /**
-     * @var string
-     */
-    protected $title;
-
-    /**
-     * @var string
-     */
-    protected $description;
-
-    /**
-     * StepForm constructor.
-     *
-     * @param ParentForm $form
-     * @param string     $title
-     * @param int        $index
-     */
-    public function __construct(ParentForm $form, string $title = null, int $index = 0)
-    {
-        $this->setForm($form);
-        $this->initFields();
-
-        $this->setTitle($title);
-        $this->setIndex($index);
-    }
-
-    /**
-     * @param ParentForm $form
-     *
-     * @return $this
-     */
-    protected function setForm(?ParentForm $form)
-    {
-        $this->form = $form;
-        $this->parent = $form->builder()->stepBuilder();
-
-        $this->prepareFileFields();
-
-        return $this;
-    }
-
-    /**
-     * @param string|\Closure $title
-     *
-     * @return $this
-     */
-    public function setTitle($title)
-    {
-        $this->title = value($title);
-
-        return $this;
-    }
-
-    /**
-     * @return string
-     */
-    public function title()
-    {
-        return $this->title;
-    }
-
-    /**
-     * @param string|\Closure $content
-     *
-     * @return $this
-     */
-    public function setDescription($content)
-    {
-        $this->description = value($content);
-
-        return $this;
-    }
-
-    /**
-     * @return string
-     */
-    public function description()
-    {
-        return $this->description;
-    }
-
-    /**
-     * @param int $content
-     *
-     * @return $this
-     */
-    public function setIndex(int $index = null)
-    {
-        $this->index = $index;
-
-        return $this;
-    }
-
-    /**
-     * @return int
-     */
-    public function index()
-    {
-        return $this->index;
-    }
-
-    /**
-     * @return string
-     */
-    protected function open()
-    {
-        if ($this->index > 0) {
-            $this->setHtmlAttribute('style', 'display:none');
-        }
-
-        $this->setHtmlAttribute('data-toggle', 'validator');
-        $this->setHtmlAttribute('role', 'form');
-
-        return <<<HTML
-<div {$this->formatHtmlAttributes()}>
-HTML;
-    }
-
-    /**
-     * @return string
-     */
-    protected function close()
-    {
-        return '</div>';
-    }
-
-    /**
-     * @return void
-     */
-    protected function fillStash()
-    {
-        if ($this->data) {
-            return;
-        }
-
-        if ($input = $this->parent->fetchStash()) {
-            $this->fill($input);
-        }
-    }
-
-    /**
-     * @return void
-     */
-    protected function prepareFileFields()
-    {
-        $this->form->uploaded(function (ParentForm $form, ParentForm\Field $field, $file, $response) {
-            if (($value = $response->getData()) && ! empty($value->id)) {
-                $form->multipleSteps()->stash(
-                    [$field->column() => $value->id],
-                    true
-                );
-            }
-        });
-    }
-
-    /**
-     * @return string
-     */
-    public function render()
-    {
-        $this->fillStash();
-
-        return parent::render(); // TODO: Change the autogenerated stub
-    }
-
-    /**
-     * @param string $script
-     *
-     * @return $this
-     */
-    public function leaving($script)
-    {
-        $script = value($script);
-
-        $this->parent->leaving(
-            <<<JS
-if (args.index == {$this->index}) {
-    {$script}
-}
-JS
-        );
-
-        return $this;
-    }
-
-    /**
-     * @param string $script
-     *
-     * @return $this
-     */
-    public function shown($script)
-    {
-        $script = value($script);
-
-        $this->parent->shown(
-            <<<JS
-if (args.index == {$this->index}) {
-    {$script}
-}
-JS
-        );
-
-        return $this;
-    }
-}