diff --git a/app/Http/Controllers/Settings/Categories.php b/app/Http/Controllers/Settings/Categories.php index 5a4848b81..decdb6fcd 100644 --- a/app/Http/Controllers/Settings/Categories.php +++ b/app/Http/Controllers/Settings/Categories.php @@ -84,13 +84,12 @@ class Categories extends Controller $types = $this->getCategoryTypes(true, true); $categories = []; - $has_code = false; + $type_codes = []; foreach (config('type.category') as $type => $config) { - if (empty($config['hide']) || ! in_array('code', $config['hide'])) { - $has_code = true; - } + $show_code = empty($config['hide']) || ! in_array('code', $config['hide']); + $type_codes[$type] = $show_code; $categories[$type] = []; } @@ -102,7 +101,7 @@ class Categories extends Controller ]; }); - return view('settings.categories.create', compact('types', 'categories', 'has_code')); + return view('settings.categories.create', compact('types', 'categories', 'type_codes')); } /** @@ -173,14 +172,12 @@ class Categories extends Controller $edited_category_id = $category->id; $categories = []; - $has_code = false; + $type_codes = []; foreach (config('type.category') as $type => $config) { - if (empty($config['hide']) || ! in_array('code', $config['hide'])) { - $has_code = true; - break; - } + $show_code = empty($config['hide']) || ! in_array('code', $config['hide']); + $type_codes[$type] = $show_code; $categories[$type] = []; } @@ -213,7 +210,7 @@ class Categories extends Controller $parent_categories = $categories[$category->type] ?? []; - return view('settings.categories.edit', compact('category', 'types', 'type_disabled', 'categories', 'parent_categories', 'has_code')); + return view('settings.categories.edit', compact('category', 'types', 'type_disabled', 'categories', 'parent_categories', 'type_codes')); } /** diff --git a/resources/assets/js/views/settings/categories.js b/resources/assets/js/views/settings/categories.js index a946236b6..683d5f0e4 100644 --- a/resources/assets/js/views/settings/categories.js +++ b/resources/assets/js/views/settings/categories.js @@ -30,16 +30,32 @@ const app = new Vue({ form: new Form('category'), bulk_action: new BulkAction('categories'), categoriesBasedTypes: null, - selected_type: true + selected_type: true, + type_codes: {}, + show_code_field: false + } + }, + + mounted() { + if (typeof type_codes !== 'undefined') { + this.type_codes = type_codes; + + if (this.form.type) { + this.show_code_field = this.type_codes[this.form.type] || false; + } } }, methods: { - updateParentCategories(event) { + changeCategories(event) { if (event === '') { return; } + if (this.type_codes[event] !== undefined) { + this.show_code_field = this.type_codes[event]; + } + if (typeof JSON.parse(this.form.categories)[event] === 'undefined') { this.categoriesBasedTypes = []; diff --git a/resources/views/settings/categories/create.blade.php b/resources/views/settings/categories/create.blade.php index ed12cc5dd..7713207b5 100644 --- a/resources/views/settings/categories/create.blade.php +++ b/resources/views/settings/categories/create.blade.php @@ -20,13 +20,11 @@ - @if ($has_code) - - @endif - - + + + @@ -45,5 +43,11 @@ + @push('scripts_start') + + @endpush + diff --git a/resources/views/settings/categories/edit.blade.php b/resources/views/settings/categories/edit.blade.php index 35c121729..adb8ba2a7 100644 --- a/resources/views/settings/categories/edit.blade.php +++ b/resources/views/settings/categories/edit.blade.php @@ -14,9 +14,6 @@ - @if ($has_code) - - @endif @@ -25,7 +22,9 @@ @else - + + + @@ -52,5 +51,11 @@ + @push('scripts_start') + + @endpush +