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..f09e800e2 --- /dev/null +++ b/packages/Webkul/Admin/src/Http/Controllers/Settings/WebFormController.php @@ -0,0 +1,166 @@ +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.webforms.index.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.webforms.index.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.webforms.index.delete-success'), + ], 200); + } catch (\Exception $exception) { + return response()->json([ + 'message' => trans('admin::app.settings.webforms.index.delete-failed'), + ], 400); + } + } +} 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/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/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']) }} 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']) }} @endif 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 new file mode 100644 index 000000000..ff74db4b2 --- /dev/null +++ b/packages/Webkul/Admin/src/Resources/views/settings/web-forms/create.blade.php @@ -0,0 +1,668 @@ + + + @lang('admin::app.settings.webforms.create.title') + + + + + + + + + + + @lang('admin::app.settings.webforms.create.title') + + + + + + + + @lang('admin::app.settings.webforms.create.save-btn') + + + + + + + + + @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..d6a25b93e --- /dev/null +++ b/packages/Webkul/Admin/src/Resources/views/settings/web-forms/edit.blade.php @@ -0,0 +1,767 @@ + + + @lang('admin::app.settings.webforms.edit.title') + + + + + + + + + + + @lang('admin::app.settings.webforms.edit.title') + + + + + + + + @lang('admin::app.settings.webforms.edit.embed') + + + + @lang('admin::app.settings.webforms.edit.preview') + + + + @lang('admin::app.settings.webforms.edit.save-btn') + + + + + + + + + + @pushOnce('scripts') + + + + + + + + @endPushOnce + 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 89% 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..1efd5b9a8 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 @@ -1,6 +1,6 @@ - @lang('Webforms') + @lang('admin::app.settings.webforms.index.title') @@ -12,7 +12,7 @@ - @lang('Webforms') + @lang('admin::app.settings.webforms.index.title') @@ -23,7 +23,7 @@ type="button" class="primary-button" > - @lang('Create Webform') + @lang('admin::app.settings.webforms.index.create-btn') @@ -46,7 +46,7 @@ class="primary-button" - @lang('Webforms') + @lang('admin::app.settings.webforms.index.title') @@ -59,7 +59,7 @@ class="primary-button" href="{{ route('admin.settings.web_forms.create') }}" class="primary-button" > - @lang('Create Webform') + @lang('admin::app.settings.webforms.index.create-btn') {!! view_render_event('krayin.admin.settings.web_forms.index.create_button.after') !!} @@ -78,7 +78,6 @@ class="primary-button" " }}' - /> - - - - {{ __('web_form::app.copy') }} - - - - - - - -@stop - -@push('scripts') - - - - - - -@endpush \ No newline at end of file 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 index a200b159e..a8ddb4015 100644 --- 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 @@ -1,77 +1,31 @@ - - - - - - - - - - - - - - {{ $webForm->title }} - {{ $webForm->description }} - - - - - - - This is message - - - - - + + + @lang('Form Preview') + + + + + + + + {{ $webForm->title }} + + {{ $webForm->description }} + + + + + @foreach ($webForm->attributes as $attribute) @php $parentAttribute = $attribute->attribute; @@ -79,20 +33,24 @@ $fieldName = $parentAttribute->entity_type . '[' . $parentAttribute->code . ']'; @endphp - - + + {{ $attribute->name ?? $parentAttribute->name }} @switch($parentAttribute->type) @case('text') is_required ? 'required' : '' }} + type="text" + id="{{ $fieldName }}" + name="{{ $fieldName }}" + {{ $attribute->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; @@ -100,21 +58,21 @@ class="control" @case('date') @case('datetime') is_required ? 'required' : '' }} + type="text" + name="{{ $fieldName }}" + id="{{ $fieldName }}" + {{ $attribute->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') is_required ? 'required' : '' }} + name="{{ $fieldName }}" + id="{{ $fieldName }}" + {{ $attribute->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; @@ -123,29 +81,29 @@ class="control" 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' : '' }} + type="text" + name="{{ $fieldName }}[0][value]" + placeholder="{{ $attribute->placeholder }}" + id="{{ $fieldName }}" + {{ $attribute->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') is_required ? 'required' : '' }} + id="{{ $fieldName }}" + name="{{ $fieldName }}" + {{ $attribute->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" > @php $options = $parentAttribute->lookup_type @@ -184,7 +142,12 @@ class="control" @break; @case('multiselect') - + @php $options = $parentAttribute->lookup_type @@ -229,17 +192,20 @@ class="control" @case('file') @case('image') + 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('boolean') - + Yes No @@ -252,16 +218,20 @@ class="control" @endswitch @endforeach + - - - {{ $webForm->submit_button_label }} - - - - - + + + + {{ $webForm->submit_button_label }} + + + - \ No newline at end of file + \ No newline at end of file diff --git a/packages/Webkul/WebForm/src/Routes/routes.php b/packages/Webkul/WebForm/src/Routes/routes.php new file mode 100644 index 000000000..804729242 --- /dev/null +++ b/packages/Webkul/WebForm/src/Routes/routes.php @@ -0,0 +1,16 @@ +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'); + }); +}); 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); + } +}
{{ $webForm->description }}
This is message