refs #1511 User companies input change multi select groups
This commit is contained in:
parent
2b42f3168e
commit
a96d6f22bc
@ -227,4 +227,23 @@ class Companies extends Controller
|
||||
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
|
||||
public function autocomplete()
|
||||
{
|
||||
$query = request('query');
|
||||
|
||||
$autocomplete = Company::autocomplete([
|
||||
'name' => $query
|
||||
]);
|
||||
|
||||
$companies = $autocomplete->get()->sortBy('name')->pluck('name', 'id');
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Get all companies.',
|
||||
'errors' => [],
|
||||
'count' => $companies->count(),
|
||||
'data' => ($companies->count()) ? $companies : null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -318,6 +318,32 @@ class Company extends Eloquent
|
||||
->select('companies.*');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope autocomplete.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param array $filter
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeAutocomplete($query, $filter)
|
||||
{
|
||||
return $query->join('settings', 'companies.id', '=', 'settings.company_id')
|
||||
->where(function ($query) use ($filter) {
|
||||
foreach ($filter as $key => $value) {
|
||||
$column = $key;
|
||||
|
||||
if (!in_array($key, $this->fillable)) {
|
||||
$column = 'company.' . $key;
|
||||
$query->orWhere('key', $column);
|
||||
$query->Where('value', 'LIKE', "%" . $value . "%");
|
||||
} else {
|
||||
$query->orWhere($column, 'LIKE', "%" . $value . "%");
|
||||
}
|
||||
}
|
||||
})
|
||||
->select('companies.*');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current balance.
|
||||
*
|
||||
|
@ -55,6 +55,10 @@ class Form extends Provider
|
||||
'name', 'text', 'icon', 'values', 'selected' => null, 'attributes' => ['required' => 'required'], 'col' => 'col-md-6', 'group_class' => null
|
||||
]);
|
||||
|
||||
Facade::component('multiSelectRemoteGroup', 'partials.form.multi_select_remote_group', [
|
||||
'name', 'text', 'icon', 'values', 'selected' => null, 'attributes' => ['required' => 'required'], 'col' => 'col-md-6', 'group_class' => null
|
||||
]);
|
||||
|
||||
Facade::component('selectGroup', 'partials.form.select_group', [
|
||||
'name', 'text', 'icon', 'values', 'selected' => null, 'attributes' => ['required' => 'required'], 'col' => 'col-md-6', 'group_class' => null
|
||||
]);
|
||||
|
@ -763,7 +763,7 @@
|
||||
|
||||
<span slot="infoBlock" class="badge badge-success badge-resize float-right" v-if="new_options[real_model]">{{ new_text }}</span>
|
||||
|
||||
<select :name="name" v-model="real_model" class="d-none">
|
||||
<select :name="name" :id="name" v-model="real_model" class="d-none">
|
||||
<option v-for="(label, value) in selectOptions" :key="value" :value="value">{{ label }}</option>
|
||||
</select>
|
||||
</span>
|
||||
@ -923,6 +923,7 @@ export default {
|
||||
add_new_html: '',
|
||||
form: {},
|
||||
new_options: false,
|
||||
couunt: 1,
|
||||
}
|
||||
},
|
||||
|
||||
@ -989,6 +990,24 @@ export default {
|
||||
|
||||
this.$emit('interface', this.real_model);
|
||||
this.$emit('change', this.real_model);
|
||||
|
||||
//this.$children[0].$children[0].$emit('keydown.native.tab');
|
||||
//this.$children[0].$children[0].handleMenuEnter();
|
||||
|
||||
this.$children[0].$children[0].visible = false;
|
||||
|
||||
/*
|
||||
this.$children[0].$children[0].setSoftFocus();
|
||||
if (this.$children[0].$children[0].visible) return;
|
||||
|
||||
let option = {};
|
||||
|
||||
option.value = this.real_model;
|
||||
|
||||
this.$children[0].$children[0].$nextTick(() => {
|
||||
this.$children[0].$children[0].scrollToOption(option);
|
||||
});
|
||||
*/
|
||||
},
|
||||
|
||||
async onAddItem() {
|
||||
@ -1180,7 +1199,17 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
this.change();
|
||||
if (this.real_model != value) {
|
||||
this.change();
|
||||
}
|
||||
|
||||
let e = $.Event('keyup');
|
||||
e.keyCode= 9; // tab
|
||||
$('#' + this.name).trigger(e);
|
||||
|
||||
let event = new window.KeyboardEvent('keydown', { keyCode: 9 }); // Tab key
|
||||
|
||||
window.dispatchEvent(event);
|
||||
},
|
||||
|
||||
value: function (value) {
|
||||
|
@ -12,7 +12,11 @@
|
||||
]"
|
||||
:error="formError">
|
||||
<el-select v-model="real_model" @input="change" disabled filterable v-if="disabled"
|
||||
:placeholder="placeholder">
|
||||
remote
|
||||
reserve-keyword
|
||||
:placeholder="placeholder"
|
||||
:remote-method="remoteMethod"
|
||||
:loading="loading">
|
||||
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
|
||||
<p class="el-select-dropdown__empty">
|
||||
{{ noMatchingDataText }}
|
||||
@ -85,7 +89,11 @@
|
||||
</el-select>
|
||||
|
||||
<el-select v-model="real_model" @input="change" filterable v-if="!disabled && !multiple"
|
||||
:placeholder="placeholder">
|
||||
remote
|
||||
reserve-keyword
|
||||
:placeholder="placeholder"
|
||||
:remote-method="remoteMethod"
|
||||
:loading="loading">
|
||||
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
|
||||
<p class="el-select-dropdown__empty">
|
||||
{{ noMatchingDataText }}
|
||||
@ -158,7 +166,11 @@
|
||||
</el-select>
|
||||
|
||||
<el-select v-model="real_model" @input="change" filterable v-if="!disabled && multiple && !collapse" multiple
|
||||
:placeholder="placeholder">
|
||||
remote
|
||||
reserve-keyword
|
||||
:placeholder="placeholder"
|
||||
:remote-method="remoteMethod"
|
||||
:loading="loading">
|
||||
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
|
||||
<p class="el-select-dropdown__empty">
|
||||
{{ noMatchingDataText }}
|
||||
@ -231,7 +243,11 @@
|
||||
</el-select>
|
||||
|
||||
<el-select v-model="real_model" @input="change" filterable v-if="!disabled && multiple && collapse" multiple collapse-tags
|
||||
:placeholder="placeholder">
|
||||
remote
|
||||
reserve-keyword
|
||||
:placeholder="placeholder"
|
||||
:remote-method="remoteMethod"
|
||||
:loading="loading">
|
||||
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
|
||||
<p class="el-select-dropdown__empty">
|
||||
{{ noMatchingDataText }}
|
||||
|
@ -48,7 +48,7 @@
|
||||
@endif
|
||||
|
||||
@permission('read-common-companies')
|
||||
{{ Form::multiSelectGroup('companies', trans_choice('general.companies', 2), 'user', $companies) }}
|
||||
{{ Form::multiSelectRemoteGroup('companies', trans_choice('general.companies', 2), 'user', $companies, [], ['required' => 'required', 'remote_action' => route('companies.autocomplete'), 'remote_type' => 'company']) }}
|
||||
@endpermission
|
||||
|
||||
@permission('read-auth-roles')
|
||||
|
@ -49,7 +49,7 @@
|
||||
@endif
|
||||
|
||||
@permission('read-common-companies')
|
||||
{{ Form::multiSelectGroup('companies', trans_choice('general.companies', 2), 'user', $companies, $user->company_ids, ['required' => 'required'], 'col-md-6') }}
|
||||
{{ Form::multiSelectRemoteGroup('companies', trans_choice('general.companies', 2), 'user', $companies, $user->company_ids, ['required' => 'required', 'remote_action' => route('companies.autocomplete'), 'remote_type' => 'company']) }}
|
||||
@endpermission
|
||||
|
||||
@permission('read-auth-roles')
|
||||
|
@ -0,0 +1,76 @@
|
||||
@stack($name . '_input_start')
|
||||
|
||||
<akaunting-select-remote
|
||||
class="{{ $col }}{{ isset($attributes['required']) ? ' required' : '' }}{{ isset($attributes['disabled']) ? ' disabled' : '' }}"
|
||||
|
||||
id="form-select-{{ $name }}"
|
||||
|
||||
@if (!empty($attributes['v-error']))
|
||||
:form-classes="[{'has-error': {{ $attributes['v-error'] }} }]"
|
||||
@else
|
||||
:form-classes="[{'has-error': form.errors.get('{{ $name }}') }]"
|
||||
@endif
|
||||
|
||||
icon="{{ $icon }}"
|
||||
title="{{ $text }}"
|
||||
placeholder="{{ trans('general.form.select.field', ['field' => $text]) }}"
|
||||
name="{{ $name }}"
|
||||
:options="{{ json_encode($values) }}"
|
||||
|
||||
@if (isset($selected) || old($name))
|
||||
:value="{{ json_encode(old($name, $selected)) }}"
|
||||
@endif
|
||||
|
||||
@if (!empty($attributes['model']))
|
||||
:model="{{ $attributes['model'] }}"
|
||||
@endif
|
||||
|
||||
:multiple="true"
|
||||
|
||||
@if (!empty($attributes['collapse']))
|
||||
:collapse="true"
|
||||
@endif
|
||||
|
||||
@if (!empty($attributes['v-model']))
|
||||
@interface="form.errors.clear('{{ $attributes['v-model'] }}'); {{ $attributes['v-model'] . ' = $event' }}"
|
||||
@elseif (!empty($attributes['data-field']))
|
||||
@interface="form.errors.clear('{{ 'form.' . $attributes['data-field'] . '.' . $name }}'); {{ 'form.' . $attributes['data-field'] . '.' . $name . ' = $event' }}"
|
||||
@else
|
||||
@interface="form.errors.clear('{{ $name }}'); form.{{ $name }} = $event"
|
||||
@endif
|
||||
|
||||
@if (!empty($attributes['change']))
|
||||
@change="{{ $attributes['change'] }}($event)"
|
||||
@endif
|
||||
|
||||
@if (isset($attributes['readonly']))
|
||||
:readonly="{{ $attributes['readonly'] }}"
|
||||
@endif
|
||||
|
||||
@if (isset($attributes['disabled']))
|
||||
:disabled="{{ $attributes['disabled'] }}"
|
||||
@endif
|
||||
|
||||
@if (isset($attributes['show']))
|
||||
v-if="{{ $attributes['show'] }}"
|
||||
@endif
|
||||
|
||||
@if (isset($attributes['v-error-message']))
|
||||
:form-error="{{ $attributes['v-error-message'] }}"
|
||||
@else
|
||||
:form-error="form.errors.get('{{ $name }}')"
|
||||
@endif
|
||||
|
||||
remote-action="{{ $attributes['remote_action'] }}"
|
||||
remote-type="'{{ $attributes['remote_type'] }}"
|
||||
|
||||
@if (!empty($attributes['currecny_code']))
|
||||
currency-code="{{ $attributes['currecny_code'] }}"
|
||||
@endif
|
||||
|
||||
loading-text="{{ trans('general.loading') }}"
|
||||
no-data-text="{{ trans('general.no_data') }}"
|
||||
no-matching-data-text="{{ trans('general.no_matching_data') }}"
|
||||
></akaunting-select-remote>
|
||||
|
||||
@stack($name . '_input_end')
|
@ -14,6 +14,7 @@ Route::group(['as' => 'uploads.', 'prefix' => 'uploads'], function () {
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'common'], function () {
|
||||
Route::get('companies/autocomplete', 'Common\Companies@autocomplete')->name('companies.autocomplete');
|
||||
Route::get('companies/{company}/switch', 'Common\Companies@switch')->name('companies.switch');
|
||||
Route::get('companies/{company}/enable', 'Common\Companies@enable')->name('companies.enable');
|
||||
Route::get('companies/{company}/disable', 'Common\Companies@disable')->name('companies.disable');
|
||||
|
Loading…
x
Reference in New Issue
Block a user