|
@@ -89,6 +89,7 @@ class Form implements Renderable
|
|
|
use HasBuilderEvents,
|
|
|
Concerns\HasEvents,
|
|
|
Concerns\HasFiles,
|
|
|
+ Concerns\HasSteps,
|
|
|
Macroable {
|
|
|
__call as macroCall;
|
|
|
}
|
|
@@ -572,38 +573,7 @@ class Form implements Renderable
|
|
|
{
|
|
|
$data = $data ?: $this->request->all();
|
|
|
|
|
|
- $this->build();
|
|
|
-
|
|
|
- $this->prepareStepFormFields($data);
|
|
|
-
|
|
|
- // Validate step form.
|
|
|
- if ($this->isStepFormValidationRequest()) {
|
|
|
- return $this->validateStepForm($data);
|
|
|
- }
|
|
|
-
|
|
|
- if (($response = $this->callSubmitted())) {
|
|
|
- return $response;
|
|
|
- }
|
|
|
-
|
|
|
- if ($response = $this->handleUploadFile($data)) {
|
|
|
- return $response;
|
|
|
- }
|
|
|
- if ($response = $this->handleFileDeleteBeforeCreate($data)) {
|
|
|
- return $response;
|
|
|
- }
|
|
|
-
|
|
|
- if ($response = $this->handleFileDeleteWhenCreating($data)) {
|
|
|
- return $response;
|
|
|
- }
|
|
|
-
|
|
|
- // Handle validation errors.
|
|
|
- if ($validationMessages = $this->validationMessages($data)) {
|
|
|
- return $this->makeValidationErrorsResponse($validationMessages);
|
|
|
- }
|
|
|
-
|
|
|
- if (($response = $this->prepare($data))) {
|
|
|
- $this->deleteFilesWhenCreating($data);
|
|
|
-
|
|
|
+ if ($response = $this->beforeStore($data)) {
|
|
|
return $response;
|
|
|
}
|
|
|
|
|
@@ -627,86 +597,49 @@ class Form implements Renderable
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
+ * Before store.
|
|
|
+ *
|
|
|
* @param array $data
|
|
|
- * @return void
|
|
|
+ * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|Response|void
|
|
|
*/
|
|
|
- protected function prepareStepFormFields(array $data)
|
|
|
+ protected function beforeStore(array $data)
|
|
|
{
|
|
|
- $stepBuilder = $this->builder->getStepBuilder();
|
|
|
-
|
|
|
- if (
|
|
|
- empty($stepBuilder)
|
|
|
- || empty($stepBuilder->count())
|
|
|
- || (! isset($data[StepBuilder::ALL_STEPS]) && ! $this->isStepFormValidationRequest())
|
|
|
- ) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ $this->build();
|
|
|
|
|
|
- $steps = $stepBuilder->all();
|
|
|
+ $this->prepareStepFormFields($data);
|
|
|
|
|
|
+ // Validate step form.
|
|
|
if ($this->isStepFormValidationRequest()) {
|
|
|
- $currentIndex = $data[StepBuilder::CURRENT_VALIDATION_STEP];
|
|
|
-
|
|
|
- if (empty($steps[$currentIndex])) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- foreach ($steps[$currentIndex]->field() as $field) {
|
|
|
- $this->pushField($field);
|
|
|
- }
|
|
|
- return;
|
|
|
+ return $this->validateStepForm($data);
|
|
|
}
|
|
|
|
|
|
- if (! empty($data[StepBuilder::ALL_STEPS])) {
|
|
|
- foreach ($steps as $stepForm) {
|
|
|
- foreach ($stepForm->field() as $field) {
|
|
|
- $this->pushField($field);
|
|
|
- }
|
|
|
- }
|
|
|
+ if (($response = $this->callSubmitted())) {
|
|
|
+ return $response;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * @return bool
|
|
|
- */
|
|
|
- protected function isStepFormValidationRequest()
|
|
|
- {
|
|
|
- $index = $this->request->get(StepBuilder::CURRENT_VALIDATION_STEP);
|
|
|
+ if ($response = $this->handleUploadFile($data)) {
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
+ if ($response = $this->handleFileDeleteBeforeCreate($data)) {
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
|
|
|
- return $index !== '' && $index !== null;
|
|
|
- }
|
|
|
+ if ($response = $this->handleFileDeleteWhenCreating($data)) {
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 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->makeValidationErrorsResponse($validationMessages);
|
|
|
}
|
|
|
|
|
|
- return $this->ajaxResponse('Success');
|
|
|
- }
|
|
|
+ if (($response = $this->prepare($data))) {
|
|
|
+ $this->deleteFilesWhenCreating($data);
|
|
|
|
|
|
- /**
|
|
|
- * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response|void
|
|
|
- */
|
|
|
- protected function responseDoneStep()
|
|
|
- {
|
|
|
- if (! $builder = $this->builder->getStepBuilder()) {
|
|
|
- return;
|
|
|
+ return $response;
|
|
|
}
|
|
|
-
|
|
|
- return response(
|
|
|
- $builder->getDoneStep()
|
|
|
- ->finish()
|
|
|
- ->render()
|
|
|
- );
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -801,7 +734,7 @@ class Form implements Renderable
|
|
|
* @param int $id
|
|
|
* @param array $input
|
|
|
*
|
|
|
- * @return bool||Response
|
|
|
+ * @return Response
|
|
|
*/
|
|
|
protected function handleOrderable(array $input = [])
|
|
|
{
|
|
@@ -829,12 +762,38 @@ class Form implements Renderable
|
|
|
{
|
|
|
$data = $data ?: $this->request->all();
|
|
|
|
|
|
+ if ($response = $this->beforeUpdate($id, $data)) {
|
|
|
+ return $response;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->updates = $this->prepareUpdate($this->updates);
|
|
|
+
|
|
|
+ $this->repository->update($this);
|
|
|
+
|
|
|
+ if (($result = $this->callSaved())) {
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->redirect(
|
|
|
+ $this->getRedirectUrl($id, $redirectTo),
|
|
|
+ trans('admin.update_succeeded')
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Before update.
|
|
|
+ *
|
|
|
+ * @param array $data
|
|
|
+ * @return Response|void
|
|
|
+ */
|
|
|
+ protected function beforeUpdate($id, array &$data)
|
|
|
+ {
|
|
|
$this->builder->setResourceId($id);
|
|
|
$this->builder->setMode(Builder::MODE_EDIT);
|
|
|
|
|
|
$this->build();
|
|
|
|
|
|
- if (($response = $this->callSubmitted())) {
|
|
|
+ if ($response = $this->callSubmitted()) {
|
|
|
return $response;
|
|
|
}
|
|
|
|
|
@@ -862,22 +821,9 @@ class Form implements Renderable
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- if (($response = $this->prepare($data))) {
|
|
|
+ if ($response = $this->prepare($data)) {
|
|
|
return $response;
|
|
|
}
|
|
|
-
|
|
|
- $this->updates = $this->prepareUpdate($this->updates);
|
|
|
-
|
|
|
- $this->repository->update($this);
|
|
|
-
|
|
|
- if (($result = $this->callSaved())) {
|
|
|
- return $result;
|
|
|
- }
|
|
|
-
|
|
|
- return $this->redirect(
|
|
|
- $this->getRedirectUrl($id, $redirectTo),
|
|
|
- trans('admin.update_succeeded')
|
|
|
- );
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1466,15 +1412,6 @@ class Form implements Renderable
|
|
|
return $this->rows;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @param Closure|null $builder
|
|
|
- * @return StepBuilder
|
|
|
- */
|
|
|
- public function step(\Closure $builder = null)
|
|
|
- {
|
|
|
- return $this->builder->step($builder);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Tools setting for form.
|
|
|
*
|