diff --git a/app/Http/Controllers/Admin/PostController.php b/app/Http/Controllers/Admin/PostController.php index 1ac51ec..f851a34 100644 --- a/app/Http/Controllers/Admin/PostController.php +++ b/app/Http/Controllers/Admin/PostController.php @@ -34,6 +34,8 @@ class PostController extends XController ['title' => "Detail", 'class' => 'btn-outline-light', 'icon' => 'ri-eye-line'], 'destroy' => ['title' => "Remove", 'class' => 'btn-outline-danger delete-confirm', 'icon' => 'ri-close-line'], + 'group' => + ['title' => "Edit group", 'class' => 'btn-outline-light edit-group-btn', 'icon' => 'ri-list-check-3'], ]; @@ -164,4 +166,33 @@ class PostController extends XController return parent::restoreing(Post::withTrashed()->where('id', $item)->first()); } /*restore**/ + + + /** + * @param $id Post's id + * @return \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|\Illuminate\View\View + */ + public function groupEdit($id) + { + + $post = Post::find($id); + $groups = Group::all(['id', 'name', 'parent_id']); + return view('admin.posts.group-edit', compact('post', 'groups')); + } + + /** + * @param Post $item + * @param Request $request + * @return array|\Illuminate\Http\RedirectResponse + */ + public function groupSave(Post $item, Request $request) + { + $item->groups()->sync($request->input('cat')); + logAdmin(__METHOD__, __CLASS__, $item->id); + if ($request->ajax()) { + return ['OK' => true, 'message' => __('Groups saved successfully')]; + } else { + return redirect()->back()->with(['message' => __('Groups saved successfully')]); + } + } } diff --git a/app/Http/Controllers/Admin/ProductController.php b/app/Http/Controllers/Admin/ProductController.php index 16c286d..58f559e 100644 --- a/app/Http/Controllers/Admin/ProductController.php +++ b/app/Http/Controllers/Admin/ProductController.php @@ -226,6 +226,11 @@ class ProductController extends XController return view('admin.products.category-edit', compact('product', 'cats')); } + /** + * @param Product $item + * @param Request $request + * @return array|\Illuminate\Http\RedirectResponse + */ public function categorySave(Product $item, Request $request) { $item->categories()->sync($request->input('cat')); diff --git a/resources/js/panel/fast-edit.js b/resources/js/panel/fast-edit.js index de2fe3e..589a32f 100644 --- a/resources/js/panel/fast-edit.js +++ b/resources/js/panel/fast-edit.js @@ -10,6 +10,17 @@ document.addEventListener('DOMContentLoaded', function () { }); }); + document.querySelectorAll('.edit-group-btn')?.forEach(function (el) { + el.setAttribute('href', '#group-category'); + el.addEventListener('click', function (e) { + e.preventDefault(); + let id = this.closest('tr').querySelector('input.chkbox').getAttribute('value'); + const url = document.querySelector('#group-edit-url').value + id; + document.querySelector('#iframe-modal iframe').setAttribute('src', url); + document.querySelector('#iframe-modal').style.display = 'block'; + + }); + }); document.querySelector('#iframe-modal')?.addEventListener('click', function (e) { if (e.target == this) { diff --git a/resources/lang/fa.json b/resources/lang/fa.json index 517f1d1..21d68a7 100644 --- a/resources/lang/fa.json +++ b/resources/lang/fa.json @@ -118,6 +118,7 @@ "Catalog": "کاتالوگ", "Categories": "دسته‌ها", "Categories list": "فهرست دسته‌ها", + "Categories saved successfully": "دسته ها با موفقیت به روز شدند", "Category": "دسته", "Category name": "نام دسته", "Category slug": "نامک دسته", @@ -265,6 +266,7 @@ "Group slug": "نامک سرفصل", "Groups": "سرفصل‌ها", "Groups list": "فهرست سرفصل‌ها", + "Groups saved successfully": "سرفصل ها با موفقیت به روز شدند", "Guest": "میهمان", "GuestLogs list": "فهرست لاگ میهمان ها", "Height": "قد", @@ -320,6 +322,7 @@ "Latest products": "واپسین محصولات", "Latitude": "عرض جغرافیایی", "Leave model ID empty to apply all items": "اگر قصد دارید ارزیابی بر روی تمام موارد مدل اعمال شود آن‌را خالی رها کنید", + "Like": "پسند", "Link": "پیوند", "Login": "ورود", "Logout": "خروج", diff --git a/resources/views/admin/posts/group-edit.blade.php b/resources/views/admin/posts/group-edit.blade.php new file mode 100644 index 0000000..29cd6cc --- /dev/null +++ b/resources/views/admin/posts/group-edit.blade.php @@ -0,0 +1,27 @@ +@include('components.panel-header') +
+
+
+ +
+@csrf +
+ @include('components.err') +
+ {{__("Groups")}} [{{$post->title}}] +
+ +
+ +
+@include('components.panel-footer') diff --git a/resources/views/admin/posts/post-list.blade.php b/resources/views/admin/posts/post-list.blade.php index 96d80d6..84a1ca7 100644 --- a/resources/views/admin/posts/post-list.blade.php +++ b/resources/views/admin/posts/post-list.blade.php @@ -8,6 +8,12 @@ {{__("Posts list")}} - @endsection @section('filter') + +
+
+ +
+
{{-- Other filters --}} @endsection @section('bulk') diff --git a/routes/web.php b/routes/web.php index 957a218..cfc933b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -182,6 +182,8 @@ Route::prefix(config('app.panel.prefix'))->name('admin.')->group( Route::get('restore/{item}', [\App\Http\Controllers\Admin\PostController::class, 'restore'])->name('restore'); Route::post('bulk', [\App\Http\Controllers\Admin\PostController::class, "bulk"])->name('bulk'); Route::get('trashed', [\App\Http\Controllers\Admin\PostController::class, "trashed"])->name('trashed'); + Route::get('group/edit/{id}', [\App\Http\Controllers\Admin\PostController::class, 'groupEdit'])->name('group-edit'); + Route::post('group/save/{item}', [\App\Http\Controllers\Admin\PostController::class, 'groupSave'])->name('group-save'); }); Route::prefix('attachments')->name('attachment.')->group( function () {