updated category code field dynamic show
This commit is contained in:
parent
6f50a4e685
commit
1789662440
|
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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 = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -20,13 +20,11 @@
|
|||
<x-slot name="body">
|
||||
<x-form.group.text name="name" label="{{ trans('general.name') }}" />
|
||||
|
||||
@if ($has_code)
|
||||
<x-form.group.text name="code" label="{{ trans('general.code') }}" />
|
||||
@endif
|
||||
|
||||
<x-form.group.color name="color" label="{{ trans('general.color') }}" />
|
||||
|
||||
<x-form.group.select name="type" label="{{ trans_choice('general.types', 1) }}" :options="$types" :selected="config('general.types')" change="updateParentCategories" group />
|
||||
<x-form.group.select name="type" label="{{ trans_choice('general.types', 1) }}" :options="$types" :selected="config('general.types')" change="changeCategories" group />
|
||||
|
||||
<x-form.group.text name="code" label="{{ trans('general.code') }}" v-show="show_code_field" />
|
||||
|
||||
<x-form.group.select name="parent_id" label="{{ trans('general.parent') . ' ' . trans_choice('general.categories', 1) }}" :options="[]" not-required dynamicOptions="categoriesBasedTypes" sort-options="false" v-disabled="selected_type" />
|
||||
|
||||
|
|
@ -45,5 +43,11 @@
|
|||
</x-form.container>
|
||||
</x-slot>
|
||||
|
||||
@push('scripts_start')
|
||||
<script type="text/javascript">
|
||||
var type_codes = {!! json_encode($type_codes) !!};
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
<x-script folder="settings" file="categories" />
|
||||
</x-layouts.admin>
|
||||
|
|
|
|||
|
|
@ -14,9 +14,6 @@
|
|||
<x-slot name="body">
|
||||
<x-form.group.text name="name" label="{{ trans('general.name') }}" />
|
||||
|
||||
@if ($has_code)
|
||||
<x-form.group.text name="code" label="{{ trans('general.code') }}" />
|
||||
@endif
|
||||
|
||||
<x-form.group.color name="color" label="{{ trans('general.color') }}" />
|
||||
|
||||
|
|
@ -25,7 +22,9 @@
|
|||
|
||||
<input type="hidden" name="type" value="{{ $category->type }}" />
|
||||
@else
|
||||
<x-form.group.select name="type" label="{{ trans_choice('general.types', 1) }}" :options="$types" change="updateParentCategories" group />
|
||||
<x-form.group.select name="type" label="{{ trans_choice('general.types', 1) }}" :options="$types" change="changeCategories" group />
|
||||
|
||||
<x-form.group.text name="code" label="{{ trans('general.code') }}" v-show="show_code_field" />
|
||||
|
||||
<x-form.group.select name="parent_id" label="{{ trans('general.parent') . ' ' . trans_choice('general.categories', 1) }}" :options="$parent_categories" not-required dynamicOptions="categoriesBasedTypes" sort-options="false" />
|
||||
|
||||
|
|
@ -52,5 +51,11 @@
|
|||
</x-form.container>
|
||||
</x-slot>
|
||||
|
||||
@push('scripts_start')
|
||||
<script type="text/javascript">
|
||||
var type_codes = {!! json_encode($type_codes) !!};
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
<x-script folder="settings" file="categories" />
|
||||
</x-layouts.admin>
|
||||
|
|
|
|||
Loading…
Reference in New Issue