diff --git a/packages/Webkul/Admin/src/DataGrids/Settings/EmailTemplateDataGrid.php b/packages/Webkul/Admin/src/DataGrids/Settings/EmailTemplateDataGrid.php index 05ffb2d07..d74659055 100644 --- a/packages/Webkul/Admin/src/DataGrids/Settings/EmailTemplateDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/Settings/EmailTemplateDataGrid.php @@ -3,14 +3,12 @@ namespace Webkul\Admin\DataGrids\Settings; use Illuminate\Support\Facades\DB; -use Webkul\UI\DataGrid\DataGrid; +use Webkul\DataGrid\DataGrid; class EmailTemplateDataGrid extends DataGrid { /** * Prepare query builder. - * - * @return void */ public function prepareQueryBuilder() { @@ -23,7 +21,7 @@ public function prepareQueryBuilder() $this->addFilter('id', 'email_templates.id'); - $this->setQueryBuilder($queryBuilder); + return $queryBuilder; } /** @@ -31,25 +29,29 @@ public function prepareQueryBuilder() * * @return void */ - public function addColumns() + public function prepareColumns() { $this->addColumn([ - 'index' => 'id', - 'label' => trans('admin::app.datagrid.id'), - 'type' => 'string', - 'sortable' => true, + 'index' => 'id', + 'label' => trans('admin::app.settings.email-template.index.datagrid.id'), + 'type' => 'string', + 'sortable' => true, + 'searchable' => true, + 'filterable' => true, ]); $this->addColumn([ - 'index' => 'name', - 'label' => trans('admin::app.datagrid.name'), - 'type' => 'string', - 'sortable' => true, + 'index' => 'name', + 'label' => trans('admin::app.settings.email-template.index.datagrid.name'), + 'type' => 'string', + 'sortable' => true, + 'searchable' => true, + 'filterable' => true, ]); $this->addColumn([ 'index' => 'subject', - 'label' => trans('admin::app.datagrid.subject'), + 'label' => trans('admin::app.settings.email-template.index.datagrid.subject'), 'type' => 'string', 'sortable' => true, ]); @@ -63,18 +65,19 @@ public function addColumns() public function prepareActions() { $this->addAction([ - 'title' => trans('ui::app.datagrid.edit'), + 'index' => 'delete', + 'icon' => 'icon-edit', + 'title' => trans('admin::app.settings.email-template.index.datagrid.edit'), 'method' => 'GET', - 'route' => 'admin.settings.email_templates.edit', - 'icon' => 'pencil-icon', + 'url' => fn ($row) => route('admin.settings.email_templates.edit', $row->id), ]); $this->addAction([ - 'title' => trans('ui::app.datagrid.delete'), - 'method' => 'DELETE', - 'route' => 'admin.settings.email_templates.delete', - 'confirm_text' => trans('ui::app.datagrid.mass-action.delete', ['resource' => 'type']), - 'icon' => 'trash-icon', + 'index' => 'delete', + 'icon' => 'icon-delete', + 'title' => trans('admin::app.settings.email-template.index.datagrid.delete'), + 'method' => 'DELETE', + 'url' => fn ($row) => route('admin.settings.email_templates.delete', $row->id), ]); } } diff --git a/packages/Webkul/Admin/src/Http/Controllers/Settings/EmailTemplateController.php b/packages/Webkul/Admin/src/Http/Controllers/Settings/EmailTemplateController.php index 32f2ada1e..0ebe50ef4 100755 --- a/packages/Webkul/Admin/src/Http/Controllers/Settings/EmailTemplateController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Settings/EmailTemplateController.php @@ -2,7 +2,11 @@ namespace Webkul\Admin\Http\Controllers\Settings; +use Illuminate\Http\JsonResponse; +use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Event; +use Illuminate\View\View; +use Webkul\Admin\DataGrids\Settings\EmailTemplateDataGrid; use Webkul\Admin\Http\Controllers\Controller; use Webkul\EmailTemplate\Repositories\EmailTemplateRepository; use Webkul\Workflow\Helpers\Entity; @@ -21,13 +25,11 @@ public function __construct( /** * Display a listing of the email template. - * - * @return \Illuminate\View\View */ - public function index() + public function index(): View|JsonResponse { if (request()->ajax()) { - return app(\Webkul\Admin\DataGrids\Settings\EmailTemplateDataGrid::class)->toJson(); + return datagrid(EmailTemplateDataGrid::class)->process(); } return view('admin::settings.email-templates.index'); @@ -47,10 +49,8 @@ public function create() /** * Store a newly created email templates in storage. - * - * @return \Illuminate\Http\Response */ - public function store() + public function store(): RedirectResponse { $this->validate(request(), [ 'name' => 'required', @@ -64,18 +64,15 @@ public function store() Event::dispatch('settings.email_templates.create.after', $emailTemplate); - session()->flash('success', trans('admin::app.settings.email-templates.create-success')); + session()->flash('success', trans('admin::app.settings.email-template.index.create-success')); return redirect()->route('admin.settings.email_templates.index'); } /** * Show the form for editing the specified email template. - * - * @param int $id - * @return \Illuminate\View\View */ - public function edit($id) + public function edit(int $id): View { $emailTemplate = $this->emailTemplateRepository->findOrFail($id); @@ -86,11 +83,8 @@ public function edit($id) /** * Update the specified email template in storage. - * - * @param int $id - * @return \Illuminate\Http\Response */ - public function update($id) + public function update(int $id): RedirectResponse { $this->validate(request(), [ 'name' => 'required', @@ -104,39 +98,36 @@ public function update($id) Event::dispatch('settings.email_templates.update.after', $emailTemplate); - session()->flash('success', trans('admin::app.settings.email-templates.update-success')); + session()->flash('success', trans('admin::app.settings.email-template.index.update-success')); return redirect()->route('admin.settings.email_templates.index'); } /** * Remove the specified email template from storage. - * - * @param int $id - * @return \Illuminate\Http\Response */ - public function destroy($id) + public function destroy(int $id): JsonResponse { $emailTemplate = $this->emailTemplateRepository->findOrFail($id); try { Event::dispatch('settings.email_templates.delete.before', $id); - $this->emailTemplateRepository->delete($id); + $emailTemplate->delete($id); Event::dispatch('settings.email_templates.delete.after', $id); return response()->json([ - 'message' => trans('admin::app.settings.email-templates.delete-success'), + 'message' => trans('admin::app.settings.email-template.index.delete-success'), ], 200); } catch (\Exception $exception) { return response()->json([ - 'message' => trans('admin::app.settings.email-templates.delete-failed'), + 'message' => trans('admin::app.settings.email-template.index.delete-failed'), ], 400); } return response()->json([ - 'message' => trans('admin::app.settings.email-templates.delete-failed'), + 'message' => trans('admin::app.settings.email-template.index.delete-failed'), ], 400); } } diff --git a/packages/Webkul/Admin/src/Http/Controllers/TinyMCEController.php b/packages/Webkul/Admin/src/Http/Controllers/TinyMCEController.php new file mode 100644 index 000000000..af125c1e3 --- /dev/null +++ b/packages/Webkul/Admin/src/Http/Controllers/TinyMCEController.php @@ -0,0 +1,51 @@ +storeMedia(); + + if (! empty($media)) { + return response()->json([ + 'location' => $media['file_url'], + ]); + } + + return response()->json([]); + } + + /** + * Store media. + * + * @return array + */ + public function storeMedia() + { + if (! request()->hasFile('file')) { + return []; + } + + return [ + 'file' => $path = request()->file('file')->store($this->storagePath), + 'file_name' => request()->file('file')->getClientOriginalName(), + 'file_url' => Storage::url($path), + ]; + } +} diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php index 0edb0472a..00a4ea2da 100644 --- a/packages/Webkul/Admin/src/Resources/lang/en/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php @@ -294,6 +294,47 @@ ], ], ], + + 'email-template' => [ + 'index' => [ + 'create-btn' => 'Create Email Template', + 'title' => 'Email Templates', + 'create-success' => 'Email Template created successfully.', + 'update-success' => 'Email Template updated successfully.', + 'delete-success' => 'Email Template deleted successfully.', + 'delete-failed' => 'Email Template can not be deleted.', + + 'datagrid' => [ + 'delete' => 'Delete', + 'edit' => 'Edit', + 'id' => 'ID', + 'name' => 'Name', + 'subject' => 'Subject', + ], + ], + + 'create' => [ + 'title' => 'Create Email Template', + 'save-btn' => 'Save Email Template', + 'email-template' => 'Email Template', + 'subject' => 'Subject', + 'content' => 'Content', + 'subject-placeholders' => 'Subject Placeholders', + 'general' => 'General', + 'name' => 'Name', + ], + + 'edit' => [ + 'title' => 'Edit Email Template', + 'save-btn' => 'Save Email Template', + 'email-template' => 'Email Template', + 'subject' => 'Subject', + 'content' => 'Content', + 'subject-placeholders' => 'Subject Placeholders', + 'general' => 'General', + 'name' => 'Name', + ], + ], ], 'activities' => [ diff --git a/packages/Webkul/Admin/src/Resources/views/components/form/control-group/control.blade.php b/packages/Webkul/Admin/src/Resources/views/components/form/control-group/control.blade.php index bdcb4df63..123088b99 100644 --- a/packages/Webkul/Admin/src/Resources/views/components/form/control-group/control.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/components/form/control-group/control.blade.php @@ -107,10 +107,8 @@ class="flex w-full items-center overflow-hidden rounded-md border text-sm text-g @if ($attributes->get('tinymce', false) || $attributes->get(':tinymce', false)) - + /> @endif diff --git a/packages/Webkul/Admin/src/Resources/views/components/tinymce/index.blade.php b/packages/Webkul/Admin/src/Resources/views/components/tinymce/index.blade.php index eb800aef6..0437990ed 100644 --- a/packages/Webkul/Admin/src/Resources/views/components/tinymce/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/components/tinymce/index.blade.php @@ -1,3 +1,5 @@ +@php($placeholders = app('\Webkul\Workflow\Helpers\Entity')->getEmailTemplatePlaceholders()) + @pushOnce('scripts') @@ -15,173 +17,13 @@ type="text/x-template" id="v-tinymce-template" > - -
- - - - -

- - - @lang('admin::app.components.tinymce.ai-generation.title') -

- - - - - - - - @lang('admin::app.components.tinymce.ai-generation.model') - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @lang('admin::app.components.tinymce.ai-generation.prompt') - - - - - - - - -
- -
- - - - - @lang('admin::app.components.tinymce.ai-generation.generated-content') - - - - - - @lang('admin::app.components.tinymce.ai-generation.generated-content-info') - - - - - - -
- -
- -
-
-
diff --git a/packages/Webkul/Admin/src/Resources/views/settings/email-templates/create.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/email-templates/create.blade.php index cf1f3addf..9d95e6569 100644 --- a/packages/Webkul/Admin/src/Resources/views/settings/email-templates/create.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/settings/email-templates/create.blade.php @@ -1,195 +1,227 @@ -@extends('admin::layouts.master') -@section('page_title') - {{ __('admin::app.settings.email-templates.create-title') }} -@stop - -@section('content-wrapper') -
- {!! view_render_event('admin.settings.email_templates.create.header.before') !!} + + + + @lang('admin::app.settings.email-template.create.title') + + + {!! view_render_event('krayin.admin.email_template.create.form.before') !!} + + +
+
+
+ +
- -
-

{{ __('admin::app.settings.email-templates.create-title') }}

+
+ +
+ +
- {!! view_render_event('admin.settings.email_templates.create.header.after') !!} - -
-
-
-
-
- {!! view_render_event('admin.settings.email_templates.create.form_buttons.before') !!} - - - - - {{ __('admin::app.layouts.back') }} - - - {!! view_render_event('admin.settings.email_templates.create.form_buttons.after') !!} + + + + {!! view_render_event('krayin.admin.email_template.create.form.after') !!} + + @pushOnce('scripts') + - - + + -@endpush \ No newline at end of file + + @endPushOnce + diff --git a/packages/Webkul/Admin/src/Resources/views/settings/email-templates/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/email-templates/edit.blade.php index ad66b42c2..30f27c3a4 100644 --- a/packages/Webkul/Admin/src/Resources/views/settings/email-templates/edit.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/settings/email-templates/edit.blade.php @@ -1,197 +1,230 @@ -@extends('admin::layouts.master') -@section('page_title') - {{ __('admin::app.settings.email-templates.edit-title') }} -@stop - -@section('content-wrapper') -
- {!! view_render_event('admin.settings.email_templates.edit.header.before', ['emailTemplate' => $emailTemplate]) !!} + + + + @lang('admin::app.settings.email-template.edit.title') + + + {!! view_render_event('krayin.admin.email_template.edit.form.before') !!} + + +
+
+
+ +
- -
-

{{ __('admin::app.settings.email-templates.edit-title') }}

+
+ +
+ +
- {!! view_render_event('admin.settings.email_templates.edit.header.after', ['emailTemplate' => $emailTemplate]) !!} - - -
-
-
-
- {!! view_render_event('admin.settings.email_templates.edit.form_buttons.before', ['emailTemplate' => $emailTemplate]) !!} - - - - - {{ __('admin::app.layouts.back') }} - - - {!! view_render_event('admin.settings.email_templates.edit.form_buttons.after', ['emailTemplate' => $emailTemplate]) !!} + + + + {!! view_render_event('krayin.admin.email_template.edit.form.after') !!} + + @pushOnce('scripts') + - - + + -@endpush \ No newline at end of file + + @endPushOnce + diff --git a/packages/Webkul/Admin/src/Resources/views/settings/email-templates/index.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/email-templates/index.blade.php index dc827bda0..16e62fb4a 100644 --- a/packages/Webkul/Admin/src/Resources/views/settings/email-templates/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/settings/email-templates/index.blade.php @@ -1,29 +1,32 @@ -@extends('admin::layouts.master') + + + @lang('admin::app.settings.email-template.index.title') + -@section('page_title') - {{ __('admin::app.settings.email-templates.title') }} -@stop +
+
+
+ +
-@section('content-wrapper') -
- - - - @if (bouncer()->hasPermission('settings.automation.email_templates.create')) - - @endif - +
-@stop + + + + diff --git a/packages/Webkul/Admin/src/Routes/rest-routes.php b/packages/Webkul/Admin/src/Routes/rest-routes.php new file mode 100644 index 000000000..50da7fb83 --- /dev/null +++ b/packages/Webkul/Admin/src/Routes/rest-routes.php @@ -0,0 +1,14 @@ + ['admin_locale'], 'prefix' => config('app.admin_path')], function () { + /** + * Tinymce file upload handler. + */ + Route::post('tinymce/upload', [TinyMCEController::class, 'upload'])->name('admin.tinymce.upload'); +}); diff --git a/packages/Webkul/Admin/src/Routes/web.php b/packages/Webkul/Admin/src/Routes/web.php index 1ae9b0d5f..d7222795a 100644 --- a/packages/Webkul/Admin/src/Routes/web.php +++ b/packages/Webkul/Admin/src/Routes/web.php @@ -13,4 +13,9 @@ /** * Contacts routes. */ -require 'contacts-routes.php'; \ No newline at end of file +require 'contacts-routes.php'; + +/** + * Rest routes. + */ +require 'rest-routes.php'; diff --git a/routes/breadcrumbs.php b/routes/breadcrumbs.php index 0ff20a49a..44246f285 100644 --- a/routes/breadcrumbs.php +++ b/routes/breadcrumbs.php @@ -263,19 +263,19 @@ // Settings > Email Templates Breadcrumbs::for('settings.email_templates', function (BreadcrumbTrail $trail) { $trail->parent('settings'); - $trail->push(trans('admin::app.layouts.email-templates'), route('admin.settings.email_templates.index')); + $trail->push(trans('admin::app.settings.email-template.index.title'), route('admin.settings.email_templates.index')); }); // Dashboard > Email Templates > Create Email Template Breadcrumbs::for('settings.email_templates.create', function (BreadcrumbTrail $trail) { $trail->parent('settings.email_templates'); - $trail->push(trans('admin::app.settings.email-templates.create-title'), route('admin.settings.email_templates.create')); + $trail->push(trans('admin::app.settings.email-template.create.title'), route('admin.settings.email_templates.create')); }); // Dashboard > Email Templates > Edit Email Template Breadcrumbs::for('settings.email_templates.edit', function (BreadcrumbTrail $trail, $emailTemplate) { $trail->parent('settings.email_templates'); - $trail->push(trans('admin::app.settings.email-templates.edit-title'), route('admin.settings.email_templates.edit', $emailTemplate->id)); + $trail->push(trans('admin::app.settings.email-template.edit.title'), route('admin.settings.email_templates.edit', $emailTemplate->id)); }); // Settings > Workflows