close #2552 Added: Quick category modal add parent category field
This commit is contained in:
parent
91ce0e5aa8
commit
040527734d
@ -3,9 +3,10 @@
|
||||
namespace App\Http\Controllers\Modals;
|
||||
|
||||
use App\Abstracts\Http\Controller;
|
||||
use App\Jobs\Setting\CreateCategory;
|
||||
use Illuminate\Http\Request as IRequest;
|
||||
use App\Http\Requests\Setting\Category as Request;
|
||||
use App\Jobs\Setting\CreateCategory;
|
||||
use App\Models\Setting\Category;
|
||||
use Illuminate\Http\Request as IRequest;
|
||||
|
||||
class Categories extends Controller
|
||||
{
|
||||
@ -30,7 +31,21 @@ class Categories extends Controller
|
||||
{
|
||||
$type = $request->get('type', 'item');
|
||||
|
||||
$html = view('modals.categories.create', compact('type'))->render();
|
||||
$categories = [];
|
||||
|
||||
foreach (config('type.category') as $type => $config) {
|
||||
$categories[$type] = [];
|
||||
}
|
||||
|
||||
Category::enabled()->orderBy('name')->get()->each(function ($category) use (&$categories) {
|
||||
$categories[$category->type][] = [
|
||||
'id' => $category->id,
|
||||
'title' => $category->name,
|
||||
'level' => $category->level,
|
||||
];
|
||||
});
|
||||
|
||||
$html = view('modals.categories.create', compact('type', 'categories'))->render();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
|
@ -228,6 +228,8 @@ export default {
|
||||
'#efef32'
|
||||
],
|
||||
min_date: false,
|
||||
categoriesBasedTypes: null,
|
||||
isParentCategoryDisabled: true,
|
||||
}
|
||||
},
|
||||
|
||||
@ -288,6 +290,28 @@ export default {
|
||||
.catch(error => {
|
||||
});
|
||||
},
|
||||
|
||||
updateParentCategories(event) {
|
||||
if (event === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof JSON.parse(this.form.categories)[event] === 'undefined') {
|
||||
this.categoriesBasedTypes = [];
|
||||
this.isParentCategoryDisabled = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.form.parent_category_id) {
|
||||
this.form.parent_category_id = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.categoriesBasedTypes = JSON.parse(this.form.categories)[event];
|
||||
this.isParentCategoryDisabled = false;
|
||||
},
|
||||
}
|
||||
})
|
||||
});
|
||||
|
@ -125,6 +125,10 @@
|
||||
@change="{{ $attributes['change'] }}($event)"
|
||||
@endif
|
||||
|
||||
@if (! empty($attributes['focus']))
|
||||
@focus="{{ $attributes['focus'] }}"
|
||||
@endif
|
||||
|
||||
@if (! empty($attributes['visible-change']))
|
||||
@visible-change="{{ $attributes['visible-change'] }}"
|
||||
@endif
|
||||
|
@ -4,7 +4,11 @@
|
||||
|
||||
<x-form.group.color name="color" label="{{ trans('general.color') }}" form-group-class="col-span-6" />
|
||||
|
||||
<x-form.input.hidden name="type" :value="$type" />
|
||||
<x-form.group.select name="parent_id" label="{{ trans('general.parent') . ' ' . trans_choice('general.categories', 1) }}" :options="[]" not-required focus="updateParentCategories(form.type)" dynamicOptions="categoriesBasedTypes" sort-options="false" disabled="isParentCategoryDisabled" form-group-class="col-span-6" />
|
||||
|
||||
<x-form.input.hidden name="categories" value="{{ json_encode($categories) }}" />
|
||||
|
||||
<x-form.input.hidden name="type" :value="'{{ $type }}'" @change="updateParentCategories" />
|
||||
<x-form.input.hidden name="enabled" value="1" />
|
||||
</div>
|
||||
</x-form>
|
||||
|
Loading…
x
Reference in New Issue
Block a user