From 1960093f5faaac2521831c9bdaaba61ce8272d6f Mon Sep 17 00:00:00 2001 From: suraj kashyap Date: Wed, 31 Jul 2024 15:07:56 +0530 Subject: [PATCH 1/3] Webform create and edit page and setup vite. --- .../Settings/WebFormController.php | 295 +++++++ packages/Webkul/Admin/src/Http/helpers.php | 6 +- .../Admin/src/Resources/assets/css/app.css | 2 +- .../Admin/src/Resources/assets/js/app.js | 2 + .../Resources/assets/js/plugins/draggable.js | 10 + .../components/layouts/header/index.blade.php | 2 +- .../views/components/layouts/index.blade.php | 2 +- .../views/settings/web-forms/create.blade.php | 660 +++++++++++++++ .../views/settings/web-forms/edit.blade.php | 767 ++++++++++++++++++ .../settings/web-forms/form-js.blade.php | 0 .../settings/web-forms/form-js/form.blade.php | 0 .../views/settings/web-forms/index.blade.php | 1 - .../settings/web-forms/preview.blade.php | 0 .../Admin/src/Routes/settings-routes.php | 28 + packages/Webkul/{Core => Admin}/src/Vite.php | 2 +- packages/Webkul/WebForm/src/Http/helpers.php | 8 + packages/Webkul/WebForm/src/Http/routes.php | 28 - .../src/Providers/WebFormServiceProvider.php | 2 + .../WebForm/src/Resources/assets/js/app.js | 0 .../src/Resources/assets/js/web-form.js | 4 - .../views/settings/web-forms/create.blade.php | 8 - .../views/settings/web-forms/edit.blade.php | 563 ------------- packages/Webkul/WebForm/src/Vite.php | 43 + 23 files changed, 1823 insertions(+), 610 deletions(-) create mode 100644 packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php create mode 100644 packages/Webkul/Admin/src/Resources/assets/js/plugins/draggable.js create mode 100644 packages/Webkul/Admin/src/Resources/views/settings/web-forms/create.blade.php create mode 100644 packages/Webkul/Admin/src/Resources/views/settings/web-forms/edit.blade.php rename packages/Webkul/{WebForm => Admin}/src/Resources/views/settings/web-forms/form-js.blade.php (100%) rename packages/Webkul/{WebForm => Admin}/src/Resources/views/settings/web-forms/form-js/form.blade.php (100%) rename packages/Webkul/{WebForm => Admin}/src/Resources/views/settings/web-forms/index.blade.php (99%) rename packages/Webkul/{WebForm => Admin}/src/Resources/views/settings/web-forms/preview.blade.php (100%) rename packages/Webkul/{Core => Admin}/src/Vite.php (97%) create mode 100755 packages/Webkul/WebForm/src/Http/helpers.php create mode 100644 packages/Webkul/WebForm/src/Resources/assets/js/app.js delete mode 100644 packages/Webkul/WebForm/src/Resources/assets/js/web-form.js delete mode 100644 packages/Webkul/WebForm/src/Resources/views/settings/web-forms/create.blade.php delete mode 100644 packages/Webkul/WebForm/src/Resources/views/settings/web-forms/edit.blade.php create mode 100644 packages/Webkul/WebForm/src/Vite.php diff --git a/packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php b/packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php new file mode 100644 index 000000000..9cad629eb --- /dev/null +++ b/packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php @@ -0,0 +1,295 @@ +ajax()) { + return datagrid(WebFormDataGrid::class)->process(); + } + + return view('admin::settings.web-forms.index'); + } + + /** + * Show the form for creating a new resource. + */ + public function create(): View + { + $tempAttributes = $this->attributeRepository->findWhereIn('entity_type', ['persons', 'leads']); + + $attributes = []; + + foreach ($tempAttributes as $attribute) { + if ($attribute->entity_type == 'persons' + && ( + $attribute->code == 'name' + || $attribute->code == 'emails' + || $attribute->code == 'contact_numbers' + ) + ) { + $attributes['default'][] = $attribute; + } else { + $attributes['other'][] = $attribute; + } + } + + return view('admin::settings.web-forms.create', compact('attributes')); + } + + /** + * Store a newly created email templates in storage. + */ + public function store(): RedirectResponse + { + $this->validate(request(), [ + 'title' => 'required', + 'submit_button_label' => 'required', + 'submit_success_action' => 'required', + 'submit_success_content' => 'required', + ]); + + Event::dispatch('settings.web_forms.create.before'); + + $data = request()->all(); + + $data['create_lead'] = isset($data['create_lead']) ? 1 : 0; + + $webForm = $this->webFormRepository->create($data); + + Event::dispatch('settings.web_forms.create.after', $webForm); + + session()->flash('success', trans('admin::app.settings.web-forms.create-success')); + + return redirect()->route('admin.settings.web_forms.index'); + } + + /** + * Show the form for editing the specified email template. + */ + public function edit(int $id): View + { + $webForm = $this->webFormRepository->findOrFail($id); + + $attributes = $this->attributeRepository->findWhere([ + ['entity_type', 'IN', ['persons', 'leads']], + ['id', 'NOTIN', $webForm->attributes()->pluck('attribute_id')->toArray()], + ]); + + return view('admin::settings.web-forms.edit', compact('webForm', 'attributes')); + } + + /** + * Update the specified email template in storage. + */ + public function update(int $id): RedirectResponse + { + $this->validate(request(), [ + 'title' => 'required', + 'submit_button_label' => 'required', + 'submit_success_action' => 'required', + 'submit_success_content' => 'required', + ]); + + Event::dispatch('settings.web_forms.update.before', $id); + + $data = request()->all(); + + $data['create_lead'] = isset($data['create_lead']) ? 1 : 0; + + $webForm = $this->webFormRepository->update($data, $id); + + Event::dispatch('settings.web_forms.update.after', $webForm); + + session()->flash('success', trans('admin::app.settings.web-forms.update-success')); + + return redirect()->route('admin.settings.web_forms.index'); + } + + /** + * Remove the specified email template from storage. + */ + public function destroy(int $id): JsonResponse + { + $webForm = $this->webFormRepository->findOrFail($id); + + try { + Event::dispatch('settings.web_forms.delete.before', $id); + + $webForm->delete($id); + + Event::dispatch('settings.web_forms.delete.after', $id); + + return response()->json([ + 'message' => trans('admin::app.settings.web-forms.delete-success'), + ], 200); + } catch (\Exception $exception) { + return response()->json([ + 'message' => trans('admin::app.settings.web-forms.delete-failed'), + ], 400); + } + } + + /** + * Remove the specified email template from storage. + */ + public function formJS(int $id): Response + { + $webForm = $this->webFormRepository->findOneByField('form_id', $id); + + return response() + ->view('admin::settings.web-forms.form-js', compact('webForm')) + ->header('Content-Type', 'text/javascript'); + } + + /** + * Remove the specified email template from storage. + */ + public function formStore(int $id): JsonResponse + { + $person = $this->personRepository + ->getModel() + ->where('emails', 'like', '%'.request('persons.emails.0.value').'%') + ->first(); + + if ($person) { + request()->request->add(['persons' => array_merge(request('persons'), ['id' => $person->id])]); + } + + app(WebForm::class); + + $webForm = $this->webFormRepository->findOrFail($id); + + if ($webForm->create_lead) { + request()->request->add(['entity_type' => 'leads']); + + Event::dispatch('lead.create.before'); + + $data = request('leads'); + + $data['entity_type'] = 'leads'; + + $data['person'] = request('persons'); + + $data['status'] = 1; + + $pipeline = $this->pipelineRepository->getDefaultPipeline(); + + $stage = $pipeline->stages()->first(); + + $data['lead_pipeline_id'] = $pipeline->id; + + $data['lead_pipeline_stage_id'] = $stage->id; + + $data['title'] = request('leads.title') ?: 'Lead From Web Form'; + + $data['lead_value'] = request('leads.lead_value') ?: 0; + + if (! request('leads.lead_source_id')) { + $source = $this->sourceRepository->findOneByField('name', 'Web Form'); + + if (! $source) { + $source = $this->sourceRepository->first(); + } + + $data['lead_source_id'] = $source->id; + } + + $data['lead_type_id'] = request('leads.lead_type_id') ?: $this->typeRepository->first()->id; + + $lead = $this->leadRepository->create($data); + + Event::dispatch('lead.create.after', $lead); + } else { + if (! $person) { + Event::dispatch('contacts.person.create.before'); + + $data = request('persons'); + + request()->request->add(['entity_type' => 'persons']); + + $data['entity_type'] = 'persons'; + + $person = $this->personRepository->create($data); + + Event::dispatch('contacts.person.create.after', $person); + } + } + + if ($webForm->submit_success_action == 'message') { + return response()->json([ + 'message' => $webForm->submit_success_content, + ], 200); + } else { + return response()->json([ + 'redirect' => $webForm->submit_success_content, + ], 200); + } + } + + /** + * Remove the specified email template from storage. + */ + public function preview(int $id): View + { + $webForm = $this->webFormRepository->findOneByField('form_id', $id); + + if (is_null($webForm)) { + abort(404); + } + + return view('admin::settings.web-forms.preview'); + } + + /** + * Preview the web form from datagrid. + */ + public function view(int $id): View + { + $webForm = $this->webFormRepository->findOneByField('id', $id); + + request()->merge(['id' => $webForm->form_id]); + + if (is_null($webForm)) { + abort(404); + } + + return view('admin::settings.web-forms.preview'); + } +} diff --git a/packages/Webkul/Admin/src/Http/helpers.php b/packages/Webkul/Admin/src/Http/helpers.php index 25856a30d..4c78896d0 100755 --- a/packages/Webkul/Admin/src/Http/helpers.php +++ b/packages/Webkul/Admin/src/Http/helpers.php @@ -1,5 +1,7 @@ { + /** + * Global component registration; + */ + app.component("draggable", Draggable); + }, +}; diff --git a/packages/Webkul/Admin/src/Resources/views/components/layouts/header/index.blade.php b/packages/Webkul/Admin/src/Resources/views/components/layouts/header/index.blade.php index 071352aa3..4aa06afa3 100644 --- a/packages/Webkul/Admin/src/Resources/views/components/layouts/header/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/components/layouts/header/index.blade.php @@ -6,7 +6,7 @@ {{ config('app.name') }} diff --git a/packages/Webkul/Admin/src/Resources/views/components/layouts/index.blade.php b/packages/Webkul/Admin/src/Resources/views/components/layouts/index.blade.php index b70d26723..f197be73b 100644 --- a/packages/Webkul/Admin/src/Resources/views/components/layouts/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/components/layouts/index.blade.php @@ -39,7 +39,7 @@ class="{{ request()->cookie('dark_mode') ? 'dark' : '' }}" @stack('meta') {{ - vite()->set(['src/Resources/assets/css/app.css', 'src/Resources/assets/js/app.js']) + admin_vite()->set(['src/Resources/assets/css/app.css', 'src/Resources/assets/js/app.js']) }} + + @lang('Create Webform') + + + +
+
+
+ +
+ +
+ @lang('Create Webform') +
+
+ +
+ +
+ +
+
+
+ + +
+ + @pushOnce('scripts') + + + + + + + + @endPushOnce + diff --git a/packages/Webkul/Admin/src/Resources/views/settings/web-forms/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/web-forms/edit.blade.php new file mode 100644 index 000000000..8cc3bed50 --- /dev/null +++ b/packages/Webkul/Admin/src/Resources/views/settings/web-forms/edit.blade.php @@ -0,0 +1,767 @@ + + + @lang('Edit WebForm') + + + +
+
+
+ +
+ +
+ @lang('Edit WebForm') +
+
+ +
+ +
+ + + + @lang('Preview') + + + +
+
+
+ + + +
+ + @pushOnce('scripts') + + + + + + + + @endPushOnce +
diff --git a/packages/Webkul/WebForm/src/Resources/views/settings/web-forms/form-js.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/web-forms/form-js.blade.php similarity index 100% rename from packages/Webkul/WebForm/src/Resources/views/settings/web-forms/form-js.blade.php rename to packages/Webkul/Admin/src/Resources/views/settings/web-forms/form-js.blade.php diff --git a/packages/Webkul/WebForm/src/Resources/views/settings/web-forms/form-js/form.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/web-forms/form-js/form.blade.php similarity index 100% rename from packages/Webkul/WebForm/src/Resources/views/settings/web-forms/form-js/form.blade.php rename to packages/Webkul/Admin/src/Resources/views/settings/web-forms/form-js/form.blade.php diff --git a/packages/Webkul/WebForm/src/Resources/views/settings/web-forms/index.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/web-forms/index.blade.php similarity index 99% rename from packages/Webkul/WebForm/src/Resources/views/settings/web-forms/index.blade.php rename to packages/Webkul/Admin/src/Resources/views/settings/web-forms/index.blade.php index 2be27703e..c57d66169 100644 --- a/packages/Webkul/WebForm/src/Resources/views/settings/web-forms/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/settings/web-forms/index.blade.php @@ -78,7 +78,6 @@ class="primary-button" " }}' - /> - -
- -
- - - - - -@stop - -@push('scripts') - - - - - - -@endpush \ No newline at end of file diff --git a/packages/Webkul/WebForm/src/Vite.php b/packages/Webkul/WebForm/src/Vite.php new file mode 100644 index 000000000..af3315a9c --- /dev/null +++ b/packages/Webkul/WebForm/src/Vite.php @@ -0,0 +1,43 @@ +packageAssetDirectory, '/').'/'.$url; + + return BaseVite::useHotFile($this->hotFile) + ->useBuildDirectory($this->buildDirectory) + ->asset($viteUrl); + } + + /** + * Set bagisto vite. + * + * @param mixed $entryPoints + * @return mixed + */ + public function set($entryPoints) + { + return BaseVite::useHotFile($this->hotFile) + ->useBuildDirectory($this->buildDirectory) + ->withEntryPoints($entryPoints); + } +} From 493a49e2308c57488f8a72a41bdab15d02854fb5 Mon Sep 17 00:00:00 2001 From: suraj kashyap Date: Wed, 31 Jul 2024 16:12:13 +0530 Subject: [PATCH 2/3] add web form. --- .../Settings/WebFormController.php | 133 +-------- .../components/layouts/anonymous.blade.php | 2 +- .../Resources/views/sessions/login.blade.php | 2 +- .../settings/web-forms/form-js/form.blade.php | 267 ------------------ .../Admin/src/Routes/settings-routes.php | 20 +- .../Http/Controllers/WebFormController.php | 140 +-------- packages/Webkul/WebForm/src/Http/routes.php | 4 - .../src/Providers/WebFormServiceProvider.php | 5 +- .../views/components/layouts/index.blade.php | 74 ++++- .../settings/web-forms/form-js.blade.php | 0 .../settings/web-forms/form-js/form.blade.php | 237 ++++++++++++++++ .../settings/web-forms/preview.blade.php | 0 packages/Webkul/WebForm/src/Routes/routes.php | 17 ++ 13 files changed, 343 insertions(+), 558 deletions(-) delete mode 100644 packages/Webkul/Admin/src/Resources/views/settings/web-forms/form-js/form.blade.php delete mode 100644 packages/Webkul/WebForm/src/Http/routes.php rename packages/Webkul/{Admin => WebForm}/src/Resources/views/settings/web-forms/form-js.blade.php (100%) create mode 100644 packages/Webkul/WebForm/src/Resources/views/settings/web-forms/form-js/form.blade.php rename packages/Webkul/{Admin => WebForm}/src/Resources/views/settings/web-forms/preview.blade.php (100%) create mode 100644 packages/Webkul/WebForm/src/Routes/routes.php diff --git a/packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php b/packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php index 9cad629eb..71cdcc9bb 100644 --- a/packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php @@ -4,19 +4,17 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; -use Illuminate\Http\Response; use Illuminate\Support\Facades\Event; use Illuminate\View\View; +use Webkul\Admin\Http\Controllers\Controller; use Webkul\Attribute\Repositories\AttributeRepository; use Webkul\Contact\Repositories\PersonRepository; use Webkul\Lead\Repositories\LeadRepository; use Webkul\Lead\Repositories\PipelineRepository; use Webkul\Lead\Repositories\SourceRepository; use Webkul\Lead\Repositories\TypeRepository; -use Webkul\WebForm\Http\Requests\WebForm; -use Webkul\WebForm\Repositories\WebFormRepository; use Webkul\WebForm\DataGrids\WebFormDataGrid; -use Webkul\Admin\Http\Controllers\Controller; +use Webkul\WebForm\Repositories\WebFormRepository; class WebFormController extends Controller { @@ -165,131 +163,4 @@ public function destroy(int $id): JsonResponse ], 400); } } - - /** - * Remove the specified email template from storage. - */ - public function formJS(int $id): Response - { - $webForm = $this->webFormRepository->findOneByField('form_id', $id); - - return response() - ->view('admin::settings.web-forms.form-js', compact('webForm')) - ->header('Content-Type', 'text/javascript'); - } - - /** - * Remove the specified email template from storage. - */ - public function formStore(int $id): JsonResponse - { - $person = $this->personRepository - ->getModel() - ->where('emails', 'like', '%'.request('persons.emails.0.value').'%') - ->first(); - - if ($person) { - request()->request->add(['persons' => array_merge(request('persons'), ['id' => $person->id])]); - } - - app(WebForm::class); - - $webForm = $this->webFormRepository->findOrFail($id); - - if ($webForm->create_lead) { - request()->request->add(['entity_type' => 'leads']); - - Event::dispatch('lead.create.before'); - - $data = request('leads'); - - $data['entity_type'] = 'leads'; - - $data['person'] = request('persons'); - - $data['status'] = 1; - - $pipeline = $this->pipelineRepository->getDefaultPipeline(); - - $stage = $pipeline->stages()->first(); - - $data['lead_pipeline_id'] = $pipeline->id; - - $data['lead_pipeline_stage_id'] = $stage->id; - - $data['title'] = request('leads.title') ?: 'Lead From Web Form'; - - $data['lead_value'] = request('leads.lead_value') ?: 0; - - if (! request('leads.lead_source_id')) { - $source = $this->sourceRepository->findOneByField('name', 'Web Form'); - - if (! $source) { - $source = $this->sourceRepository->first(); - } - - $data['lead_source_id'] = $source->id; - } - - $data['lead_type_id'] = request('leads.lead_type_id') ?: $this->typeRepository->first()->id; - - $lead = $this->leadRepository->create($data); - - Event::dispatch('lead.create.after', $lead); - } else { - if (! $person) { - Event::dispatch('contacts.person.create.before'); - - $data = request('persons'); - - request()->request->add(['entity_type' => 'persons']); - - $data['entity_type'] = 'persons'; - - $person = $this->personRepository->create($data); - - Event::dispatch('contacts.person.create.after', $person); - } - } - - if ($webForm->submit_success_action == 'message') { - return response()->json([ - 'message' => $webForm->submit_success_content, - ], 200); - } else { - return response()->json([ - 'redirect' => $webForm->submit_success_content, - ], 200); - } - } - - /** - * Remove the specified email template from storage. - */ - public function preview(int $id): View - { - $webForm = $this->webFormRepository->findOneByField('form_id', $id); - - if (is_null($webForm)) { - abort(404); - } - - return view('admin::settings.web-forms.preview'); - } - - /** - * Preview the web form from datagrid. - */ - public function view(int $id): View - { - $webForm = $this->webFormRepository->findOneByField('id', $id); - - request()->merge(['id' => $webForm->form_id]); - - if (is_null($webForm)) { - abort(404); - } - - return view('admin::settings.web-forms.preview'); - } } diff --git a/packages/Webkul/Admin/src/Resources/views/components/layouts/anonymous.blade.php b/packages/Webkul/Admin/src/Resources/views/components/layouts/anonymous.blade.php index 194ed4c38..a8ee61086 100644 --- a/packages/Webkul/Admin/src/Resources/views/components/layouts/anonymous.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/components/layouts/anonymous.blade.php @@ -35,7 +35,7 @@ @stack('meta') {{ - vite()->set(['src/Resources/assets/css/app.css', 'src/Resources/assets/js/app.js']) + admin_vite()->set(['src/Resources/assets/css/app.css', 'src/Resources/assets/js/app.js']) }} @endif diff --git a/packages/Webkul/Admin/src/Resources/views/settings/web-forms/form-js/form.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/web-forms/form-js/form.blade.php deleted file mode 100644 index a200b159e..000000000 --- a/packages/Webkul/Admin/src/Resources/views/settings/web-forms/form-js/form.blade.php +++ /dev/null @@ -1,267 +0,0 @@ - - - - - -
-
-
-
-
-
-
- krayin -

{{ $webForm->title }}

-

{{ $webForm->description }}

-
- -
-
- - -
- @foreach ($webForm->attributes as $attribute) - @php - $parentAttribute = $attribute->attribute; - - $fieldName = $parentAttribute->entity_type . '[' . $parentAttribute->code . ']'; - @endphp - -
- - - @switch($parentAttribute->type) - @case('text') - is_required ? 'required' : '' }} - /> - - @break; - - @case('date') - @case('datetime') - is_required ? 'required' : '' }} - /> - - @break; - - @case('textarea') - - - @break; - - @case('email') - is_required ? 'required' : '' }} - /> - - - - @break; - - @case('phone') - is_required ? 'required' : '' }} - /> - - - - @break; - - @case('select') - @case('lookup') - - - @break; - - @case('multiselect') - - - @break; - - @case('checkbox') -
- @php - $options = $parentAttribute->lookup_type - ? app('Webkul\Attribute\Repositories\AttributeRepository')->getLookUpOptions($parentAttribute->lookup_type) - : $parentAttribute->options()->orderBy('sort_order')->get(); - @endphp - - @foreach ($options as $option) - - - - - {{ $option->name }} - - @endforeach -
- - @break; - - @case('file') - @case('image') - - - @break; - - @case('boolean') - - - @break; - - @case('address') - - @break; - @endswitch -
- @endforeach - -
- -
- -
-
-
-
-
-
\ No newline at end of file diff --git a/packages/Webkul/Admin/src/Routes/settings-routes.php b/packages/Webkul/Admin/src/Routes/settings-routes.php index 1968f03bd..e4e302509 100644 --- a/packages/Webkul/Admin/src/Routes/settings-routes.php +++ b/packages/Webkul/Admin/src/Routes/settings-routes.php @@ -68,29 +68,21 @@ * WebForms Routes. */ Route::controller(WebFormController::class)->prefix('web-forms')->group(function () { - Route::get('forms/{id}/form.js', 'formJS')->name('admin.settings.web_forms.form_js'); - - Route::get('forms/{id}/form.html', 'preview')->name('admin.settings.web_forms.preview'); - - Route::post('forms/{id}', 'formStore')->name('admin.settings.web_forms.form_store'); - Route::group(['middleware' => ['user']], function () { Route::get('', 'index')->name('admin.settings.web_forms.index'); - - Route::get('form/{id}/form.html', 'view')->name('admin.settings.web_forms.view'); - + Route::get('create', 'create')->name('admin.settings.web_forms.create'); - + Route::post('create', 'store')->name('admin.settings.web_forms.store'); - + Route::get('edit/{id?}', 'edit')->name('admin.settings.web_forms.edit'); - + Route::put('edit/{id}', 'update')->name('admin.settings.web_forms.update'); - + Route::delete('{id}', 'destroy')->name('admin.settings.web_forms.delete'); }); }); - + /** * Workflows Routes. */ diff --git a/packages/Webkul/WebForm/src/Http/Controllers/WebFormController.php b/packages/Webkul/WebForm/src/Http/Controllers/WebFormController.php index b192eb0b6..4e6b4d790 100644 --- a/packages/Webkul/WebForm/src/Http/Controllers/WebFormController.php +++ b/packages/Webkul/WebForm/src/Http/Controllers/WebFormController.php @@ -3,7 +3,6 @@ namespace Webkul\WebForm\Http\Controllers; use Illuminate\Http\JsonResponse; -use Illuminate\Http\RedirectResponse; use Illuminate\Http\Response; use Illuminate\Support\Facades\Event; use Illuminate\View\View; @@ -15,7 +14,7 @@ use Webkul\Lead\Repositories\TypeRepository; use Webkul\WebForm\Http\Requests\WebForm; use Webkul\WebForm\Repositories\WebFormRepository; -use Webkul\WebForm\DataGrids\WebFormDataGrid; + class WebFormController extends Controller { /** @@ -33,143 +32,12 @@ public function __construct( protected TypeRepository $typeRepository ) {} - /** - * Display a listing of the email template. - */ - public function index(): View|JsonResponse - { - if (request()->ajax()) { - return datagrid(WebFormDataGrid::class)->process(); - } - - return view('web_form::settings.web-forms.index'); - } - - /** - * Show the form for creating a new resource. - */ - public function create(): View - { - $tempAttributes = $this->attributeRepository->findWhereIn('entity_type', ['persons', 'leads']); - - $attributes = []; - - foreach ($tempAttributes as $attribute) { - if ($attribute->entity_type == 'persons' - && ( - $attribute->code == 'name' - || $attribute->code == 'emails' - || $attribute->code == 'contact_numbers' - ) - ) { - $attributes['default'][] = $attribute; - } else { - $attributes['other'][] = $attribute; - } - } - - return view('web_form::settings.web-forms.create', compact('attributes')); - } - - /** - * Store a newly created email templates in storage. - */ - public function store(): RedirectResponse - { - $this->validate(request(), [ - 'title' => 'required', - 'submit_button_label' => 'required', - 'submit_success_action' => 'required', - 'submit_success_content' => 'required', - ]); - - Event::dispatch('settings.web_forms.create.before'); - - $data = request()->all(); - - $data['create_lead'] = isset($data['create_lead']) ? 1 : 0; - - $webForm = $this->webFormRepository->create($data); - - Event::dispatch('settings.web_forms.create.after', $webForm); - - session()->flash('success', trans('admin::app.settings.web-forms.create-success')); - - return redirect()->route('admin.settings.web_forms.index'); - } - - /** - * Show the form for editing the specified email template. - */ - public function edit(int $id): View - { - $webForm = $this->webFormRepository->findOrFail($id); - - $attributes = $this->attributeRepository->findWhere([ - ['entity_type', 'IN', ['persons', 'leads']], - ['id', 'NOTIN', $webForm->attributes()->pluck('attribute_id')->toArray()], - ]); - - return view('web_form::settings.web-forms.edit', compact('webForm', 'attributes')); - } - - /** - * Update the specified email template in storage. - */ - public function update(int $id): RedirectResponse - { - $this->validate(request(), [ - 'title' => 'required', - 'submit_button_label' => 'required', - 'submit_success_action' => 'required', - 'submit_success_content' => 'required', - ]); - - Event::dispatch('settings.web_forms.update.before', $id); - - $data = request()->all(); - - $data['create_lead'] = isset($data['create_lead']) ? 1 : 0; - - $webForm = $this->webFormRepository->update($data, $id); - - Event::dispatch('settings.web_forms.update.after', $webForm); - - session()->flash('success', trans('admin::app.settings.web-forms.update-success')); - - return redirect()->route('admin.settings.web_forms.index'); - } - /** * Remove the specified email template from storage. */ - public function destroy(int $id): JsonResponse + public function formJS(string $formId): Response { - $webForm = $this->webFormRepository->findOrFail($id); - - try { - Event::dispatch('settings.web_forms.delete.before', $id); - - $webForm->delete($id); - - Event::dispatch('settings.web_forms.delete.after', $id); - - return response()->json([ - 'message' => trans('admin::app.settings.web-forms.delete-success'), - ], 200); - } catch (\Exception $exception) { - return response()->json([ - 'message' => trans('admin::app.settings.web-forms.delete-failed'), - ], 400); - } - } - - /** - * Remove the specified email template from storage. - */ - public function formJS(int $id): Response - { - $webForm = $this->webFormRepository->findOneByField('form_id', $id); + $webForm = $this->webFormRepository->findOneByField('form_id', $formId); return response() ->view('web_form::settings.web-forms.form-js', compact('webForm')) @@ -264,7 +132,7 @@ public function formStore(int $id): JsonResponse /** * Remove the specified email template from storage. */ - public function preview(int $id): View + public function preview(string $id): View { $webForm = $this->webFormRepository->findOneByField('form_id', $id); diff --git a/packages/Webkul/WebForm/src/Http/routes.php b/packages/Webkul/WebForm/src/Http/routes.php deleted file mode 100644 index ff7eafdc3..000000000 --- a/packages/Webkul/WebForm/src/Http/routes.php +++ /dev/null @@ -1,4 +0,0 @@ -loadRoutesFrom(__DIR__.'/../Http/routes.php'); + $this->loadRoutesFrom(__DIR__.'/../Routes/routes.php'); $this->loadTranslationsFrom(__DIR__.'/../Resources/lang', 'web_form'); $this->loadViewsFrom(__DIR__.'/../Resources/views', 'web_form'); + Blade::anonymousComponentPath(__DIR__.'/../Resources/views/components'); + $this->loadMigrationsFrom(__DIR__.'/../Database/Migrations'); $this->app->register(ModuleServiceProvider::class); diff --git a/packages/Webkul/WebForm/src/Resources/views/components/layouts/index.blade.php b/packages/Webkul/WebForm/src/Resources/views/components/layouts/index.blade.php index 90c7f401d..1e7433e90 100644 --- a/packages/Webkul/WebForm/src/Resources/views/components/layouts/index.blade.php +++ b/packages/Webkul/WebForm/src/Resources/views/components/layouts/index.blade.php @@ -1,4 +1,72 @@ - - {{ vite()->set(['src/Resources/assets/css/app.css']) }} + - + + + + {{ $title ?? '' }} + + + + + + + + + set(['src/Resources/assets/css/app.css', 'src/Resources/assets/js/app.js']) + }} + + + + + + + + + + @stack('styles') + + + +
+ {{ $slot }} +
+ + + \ No newline at end of file diff --git a/packages/Webkul/Admin/src/Resources/views/settings/web-forms/form-js.blade.php b/packages/Webkul/WebForm/src/Resources/views/settings/web-forms/form-js.blade.php similarity index 100% rename from packages/Webkul/Admin/src/Resources/views/settings/web-forms/form-js.blade.php rename to packages/Webkul/WebForm/src/Resources/views/settings/web-forms/form-js.blade.php diff --git a/packages/Webkul/WebForm/src/Resources/views/settings/web-forms/form-js/form.blade.php b/packages/Webkul/WebForm/src/Resources/views/settings/web-forms/form-js/form.blade.php new file mode 100644 index 000000000..a8ddb4015 --- /dev/null +++ b/packages/Webkul/WebForm/src/Resources/views/settings/web-forms/form-js/form.blade.php @@ -0,0 +1,237 @@ + + + @lang('Form Preview') + + +
+
+ + krayin + +

{{ $webForm->title }}

+ +

{{ $webForm->description }}

+ +
+ +
+
+ @foreach ($webForm->attributes as $attribute) + @php + $parentAttribute = $attribute->attribute; + + $fieldName = $parentAttribute->entity_type . '[' . $parentAttribute->code . ']'; + @endphp + +
+ + + @switch($parentAttribute->type) + @case('text') + is_required ? 'required' : '' }} + placeholder="{{ $attribute->placeholder }}" + class="w-full rounded border border-gray-200 px-2.5 py-2 text-sm font-normal text-gray-800 transition-all hover:border-gray-400 focus:border-gray-400 dark:border-gray-800 dark:bg-gray-900 dark:text-gray-300 dark:hover:border-gray-400 dark:focus:border-gray-400" + /> + + @break; + + @case('date') + @case('datetime') + is_required ? 'required' : '' }} + class="w-full rounded border border-gray-200 px-2.5 py-2 text-sm font-normal text-gray-800 transition-all hover:border-gray-400 focus:border-gray-400 dark:border-gray-800 dark:bg-gray-900 dark:text-gray-300 dark:hover:border-gray-400 dark:focus:border-gray-400" + /> + + @break; + + @case('textarea') + + + @break; + + @case('email') + is_required ? 'required' : '' }} + class="w-full rounded border border-gray-200 px-2.5 py-2 text-sm font-normal text-gray-800 transition-all hover:border-gray-400 focus:border-gray-400 dark:border-gray-800 dark:bg-gray-900 dark:text-gray-300 dark:hover:border-gray-400 dark:focus:border-gray-400" + /> + + + + @break; + + @case('phone') + is_required ? 'required' : '' }} + class="w-full rounded border border-gray-200 px-2.5 py-2 text-sm font-normal text-gray-800 transition-all hover:border-gray-400 focus:border-gray-400 dark:border-gray-800 dark:bg-gray-900 dark:text-gray-300 dark:hover:border-gray-400 dark:focus:border-gray-400" + /> + + + + @break; + + @case('select') + @case('lookup') + + + @break; + + @case('multiselect') + + + @break; + + @case('checkbox') +
+ @php + $options = $parentAttribute->lookup_type + ? app('Webkul\Attribute\Repositories\AttributeRepository')->getLookUpOptions($parentAttribute->lookup_type) + : $parentAttribute->options()->orderBy('sort_order')->get(); + @endphp + + @foreach ($options as $option) + + + + + {{ $option->name }} + + @endforeach +
+ + @break; + + @case('file') + @case('image') + + + @break; + + @case('boolean') + + + @break; + + @case('address') + + @break; + @endswitch +
+ @endforeach +
+ +
+ + +
+
+
+
+
+
\ No newline at end of file diff --git a/packages/Webkul/Admin/src/Resources/views/settings/web-forms/preview.blade.php b/packages/Webkul/WebForm/src/Resources/views/settings/web-forms/preview.blade.php similarity index 100% rename from packages/Webkul/Admin/src/Resources/views/settings/web-forms/preview.blade.php rename to packages/Webkul/WebForm/src/Resources/views/settings/web-forms/preview.blade.php diff --git a/packages/Webkul/WebForm/src/Routes/routes.php b/packages/Webkul/WebForm/src/Routes/routes.php new file mode 100644 index 000000000..1ec40e307 --- /dev/null +++ b/packages/Webkul/WebForm/src/Routes/routes.php @@ -0,0 +1,17 @@ +prefix('web-forms')->group(function () { + Route::get('forms/{id}/form.js', 'formJS')->name('admin.settings.web_forms.form_js'); + + Route::get('forms/{id}/form.html', 'preview')->name('admin.settings.web_forms.preview'); + + Route::post('forms/{id}', 'formStore')->name('admin.settings.web_forms.form_store'); + + Route::group(['middleware' => ['user']], function () { + Route::get('form/{id}/form.html', 'view')->name('admin.settings.web_forms.view'); + }); +}); \ No newline at end of file From 71858d77fd2170201a31a4ad642f733ead8cb69c Mon Sep 17 00:00:00 2001 From: suraj kashyap Date: Wed, 31 Jul 2024 16:58:17 +0530 Subject: [PATCH 3/3] Webform is completed., --- .../Settings/WebFormController.php | 8 +- .../Admin/src/Resources/lang/en/app.php | 70 ++++++++++++++ .../views/settings/web-forms/create.blade.php | 78 ++++++++------- .../views/settings/web-forms/edit.blade.php | 96 +++++++++---------- .../views/settings/web-forms/index.blade.php | 10 +- .../WebForm/src/DataGrids/WebFormDataGrid.php | 10 +- packages/Webkul/WebForm/src/Routes/routes.php | 3 +- 7 files changed, 176 insertions(+), 99 deletions(-) diff --git a/packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php b/packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php index 71cdcc9bb..f09e800e2 100644 --- a/packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php @@ -93,7 +93,7 @@ public function store(): RedirectResponse Event::dispatch('settings.web_forms.create.after', $webForm); - session()->flash('success', trans('admin::app.settings.web-forms.create-success')); + session()->flash('success', trans('admin::app.settings.webforms.index.create-success')); return redirect()->route('admin.settings.web_forms.index'); } @@ -135,7 +135,7 @@ public function update(int $id): RedirectResponse Event::dispatch('settings.web_forms.update.after', $webForm); - session()->flash('success', trans('admin::app.settings.web-forms.update-success')); + session()->flash('success', trans('admin::app.settings.webforms.index.update-success')); return redirect()->route('admin.settings.web_forms.index'); } @@ -155,11 +155,11 @@ public function destroy(int $id): JsonResponse Event::dispatch('settings.web_forms.delete.after', $id); return response()->json([ - 'message' => trans('admin::app.settings.web-forms.delete-success'), + 'message' => trans('admin::app.settings.webforms.index.delete-success'), ], 200); } catch (\Exception $exception) { return response()->json([ - 'message' => trans('admin::app.settings.web-forms.delete-failed'), + 'message' => trans('admin::app.settings.webforms.index.delete-failed'), ], 400); } } diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php index 1f0ecf504..8898e16d6 100644 --- a/packages/Webkul/Admin/src/Resources/lang/en/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php @@ -491,6 +491,76 @@ ], ], + 'webforms' => [ + 'index' => [ + 'title' => 'Webforms', + 'create-btn' => 'Create Webform', + 'create-success' => 'Webform created successfully.', + 'update-success' => 'Webform updated successfully.', + 'delete-success' => 'Webform deleted successfully.', + 'delete-failed' => 'Webform can not be deleted.', + 'datagrid' => [ + 'id' => 'ID', + 'title' => 'Title', + 'edit' => 'Edit', + 'delete' => 'Delete', + ], + ], + + 'create' => [ + 'title' => 'Create Webform', + 'save-btn' => 'Save Webform', + 'submit-success-action' => 'Submit Success Action', + 'general' => 'General', + 'create-lead' => 'Create Lead', + 'customize-webform' => 'Customize Webform', + 'customize-webform-info' => 'Customize your web form with element colors of your choosing.', + 'backgroud-color' => 'Backgroud Color', + 'form-backgroud-color' => 'Form Backgroud Color', + 'form-title-color' => 'Form Title Color', + 'form-submit-btn-color' => 'Form Submit Button Color', + 'attribute-label-color' => 'Attribute Label Color', + 'attributes' => 'Attributes', + 'attributes-info' => 'Add custom attributes to the form.', + 'add-attribute-btn' => 'Add Attribute Button', + 'description' => 'Description', + 'submit-button-label' => 'Submit Button Label', + 'form-background-color' => 'Form Backgroud Color', + 'form-submit-button-color' => 'Form Submit Button Color', + 'display-custom-message' => 'Display custom message', + ], + + 'edit' => [ + 'title' => 'Edit Webform', + 'embed' => 'Embded', + 'preview' => 'Preview', + 'save-btn' => 'Save Webform', + 'submit-success-action' => 'Submit Success Action', + 'general' => 'General', + 'create-lead' => 'Create Lead', + 'customize-webform' => 'Customize Webform', + 'customize-webform-info' => 'Customize your web form with element colors of your choosing.', + 'backgroud-color' => 'Backgroud Color', + 'form-backgroud-color' => 'Form Backgroud Color', + 'form-title-color' => 'Form Title Color', + 'form-background-color' => 'Form Backgroud Color', + 'form-submit-btn-color' => 'Form Submit Button Color', + 'attribute-label-color' => 'Attribute Label Color', + 'attributes' => 'Attributes', + 'attributes-info' => 'Add custom attributes to the form.', + 'add-attribute-btn' => 'Add Attribute Button', + 'description' => 'Description', + 'submit-button-label' => 'Submit Button Label', + 'redirect-to-url' => 'Redirect To URL', + 'copied' => 'Copied', + 'copy' => 'Copy', + 'public-url' => 'Public URL', + 'code-snippet' => 'Code Snippet', + 'form-submit-button-color' => 'Form Submit Button Color', + 'display-custom-message' => 'Display custom message', + ], + ], + 'email-template' => [ 'index' => [ 'create-btn' => 'Create Email Template', diff --git a/packages/Webkul/Admin/src/Resources/views/settings/web-forms/create.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/web-forms/create.blade.php index a349b187f..ff74db4b2 100644 --- a/packages/Webkul/Admin/src/Resources/views/settings/web-forms/create.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/settings/web-forms/create.blade.php @@ -1,6 +1,6 @@ - @lang('Create Webform') + @lang('admin::app.settings.webforms.create.title') @@ -11,7 +11,7 @@
- @lang('Create Webform') + @lang('admin::app.settings.webforms.create.title')
@@ -22,7 +22,7 @@ type="submit" class="primary-button" > - @lang('Create Webform') + @lang('admin::app.settings.webforms.create.save-btn') @@ -44,7 +44,7 @@ class="primary-button"

- @lang('Create Webform') + @lang('admin::app.settings.webforms.create.title')

@@ -52,7 +52,7 @@ class="primary-button" - @lang('Submit Success Action ') + @lang('admin::app.settings.webforms.create.submit-success-action')
@@ -62,7 +62,7 @@ class="primary-button" id="submit_success_action" value="message" class="!w-1/4 rounded-r-none" - :label="trans('Submit Success Action')" + :label="trans('admin::app.settings.webforms.create.submit-success-action')" v-model="submitSuccessAction.value" >