akaunting/resources/assets/js/components/AkauntingSelect.vue

1283 lines
50 KiB
Vue
Raw Normal View History

2019-11-16 10:21:14 +03:00
<template>
<base-input
:label="title"
:name="name"
:readonly="readonly"
:disabled="disabled"
:class="[
{'readonly': readonly},
{'disabled': disabled},
formClasses
]"
:error="formError">
2020-04-20 00:19:50 +03:00
<span v-if="Array.isArray(selectOptions)">
<el-select v-model="real_model" @input="change" :disabled="disabled" filterable v-if="(disabled) && !multiple && !collapse"
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<template slot="prefix">
<span class="el-input__suffix-inner el-select-icon">
<i :class="'select-icon-position el-input__icon fa fa-' + icon"></i>
</span>
</template>
<el-option v-if="!group" v-for="(option, key) in selectOptions"
:key="key"
:label="option.value"
:value="option.key">
<span class="float-left">{{ option.value }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[option.key]">{{ new_text }}</span>
</el-option>
<!-- Todo sortable -->
<el-option-group
v-if="group"
v-for="(options, name) in selectOptions"
:key="name"
:label="name">
<el-option
v-for="(label, value) in options"
:key="value"
:label="label"
:value="value">
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
</el-option>
</el-option-group>
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :disabled="true" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
</el-select>
<el-select v-model="real_model" @input="change" :disabled="disabled" filterable v-if="!disabled && !multiple"
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<template slot="prefix">
<span class="el-input__suffix-inner el-select-icon">
<i :class="'select-icon-position el-input__icon fa fa-' + icon"></i>
</span>
</template>
<el-option v-if="!group" v-for="(option, key) in selectOptions"
:key="key"
:label="option.value"
:value="option.key">
<span class="float-left">{{ option.value }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[option.key]">{{ new_text }}</span>
</el-option>
<el-option-group
v-if="group"
v-for="(options, name) in selectOptions"
:key="name"
:label="name">
<el-option
v-for="(label, value) in options"
:key="value"
:label="label"
:value="value">
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
</el-option>
</el-option-group>
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :disabled="true" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
</el-select>
<el-select v-model="real_model" @input="change" filterable v-if="!disabled && multiple && !collapse" multiple
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<template slot="prefix">
<span class="el-input__suffix-inner el-select-icon">
<i :class="'select-icon-position el-input__icon fa fa-' + icon"></i>
</span>
</template>
<el-option v-if="!group" v-for="(option, key) in selectOptions"
:key="key"
:label="option.value"
:value="option.key">
<span class="float-left">{{ option.value }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[option.key]">{{ new_text }}</span>
</el-option>
<!-- Todo sortable -->
<el-option-group
v-if="group"
v-for="(options, name) in selectOptions"
:key="name"
:label="name">
<el-option
v-for="(label, value) in options"
:key="value"
:label="label"
:value="value">
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
</el-option>
</el-option-group>
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :disabled="true" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
</el-select>
<el-select v-model="real_model" @input="change" filterable disabled v-if="disabled && multiple && !collapse" multiple
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<template slot="prefix">
<span class="el-input__suffix-inner el-select-icon">
<i :class="'select-icon-position el-input__icon fa fa-' + icon"></i>
</span>
</template>
<el-option v-if="!group" v-for="(option, key) in selectOptions"
:key="key"
:label="option.value"
:value="option.key">
<span class="float-left">{{ option.value }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[option.key]">{{ new_text }}</span>
</el-option>
<!-- Todo sortable -->
<el-option-group
v-if="group"
v-for="(options, name) in selectOptions"
:key="name"
:label="name">
<el-option
v-for="(label, value) in options"
:key="value"
:label="label"
:value="value">
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
</el-option>
</el-option-group>
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :disabled="true" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
</el-select>
<el-select v-model="real_model" @input="change" filterable v-if="!disabled && multiple && collapse" multiple collapse-tags
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<template slot="prefix">
<span class="el-input__suffix-inner el-select-icon">
<i :class="'select-icon-position el-input__icon fa fa-' + icon"></i>
</span>
</template>
<el-option v-if="!group" v-for="(option, key) in selectOptions"
:key="key"
:label="option.value"
:value="option.key">
<span class="float-left">{{ option.value }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[option.key]">{{ new_text }}</span>
</el-option>
<!-- Todo sortable -->
<el-option-group
v-if="group"
v-for="(options, name) in selectOptions"
:key="name"
:label="name">
<el-option
v-for="(label, value) in options"
:key="value"
:label="label"
:value="value">
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
</el-option>
</el-option-group>
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :disabled="true" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
</el-select>
<component v-bind:is="add_new_html" @submit="onSubmit" @cancel="onCancel"></component>
<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">
<option v-for="(label, value) in selectOptions" :key="value" :value="value">{{ label }}</option>
</select>
</span>
<span v-else>
<el-select v-model="real_model" @input="change" :disabled="disabled" filterable v-if="(disabled) && !multiple && !collapse"
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<template slot="prefix">
<span class="el-input__suffix-inner el-select-icon">
<i :class="'select-icon-position el-input__icon fa fa-' + icon"></i>
</span>
</template>
2020-04-20 00:19:50 +03:00
<el-option v-if="!group" v-for="(label, value) in selectOptions"
2019-11-16 10:21:14 +03:00
:key="value"
:label="label"
:value="value">
2020-03-06 18:04:23 +03:00
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
2019-11-16 10:21:14 +03:00
</el-option>
2019-12-25 15:02:55 +03:00
2020-04-20 00:19:50 +03:00
<!-- Todo sortable -->
<el-option-group
v-if="group"
v-for="(options, name) in selectOptions"
:key="name"
:label="name">
<el-option
v-for="(label, value) in options"
:key="value"
:label="label"
:value="value">
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
</el-option>
</el-option-group>
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :disabled="true" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
</el-select>
<el-select v-model="real_model" @input="change" filterable v-if="!Array.isArray(selectOptions) && !disabled && !multiple"
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
2020-04-20 00:19:50 +03:00
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<template slot="prefix">
<span class="el-input__suffix-inner el-select-icon">
<i :class="'select-icon-position el-input__icon fa fa-' + icon"></i>
</span>
</template>
<el-option v-if="!group" v-for="(label, value) in selectOptions"
2019-12-25 15:02:55 +03:00
:key="value"
:label="label"
:value="value">
2020-03-06 18:04:23 +03:00
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
2019-12-25 15:02:55 +03:00
</el-option>
2020-04-20 00:19:50 +03:00
<el-option-group
v-if="group"
v-for="(options, name) in selectOptions"
:key="name"
:label="name">
<el-option
v-for="(label, value) in options"
:key="value"
:label="label"
:value="value">
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
</el-option>
</el-option-group>
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :disabled="true" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
</el-select>
<el-select v-model="real_model" @input="change" filterable v-if="!disabled && multiple && !collapse" multiple
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
2020-04-20 00:19:50 +03:00
<template slot="prefix">
<span class="el-input__suffix-inner el-select-icon">
<i :class="'select-icon-position el-input__icon fa fa-' + icon"></i>
</span>
</template>
<el-option v-if="!group" v-for="(label, value) in selectOptions"
:key="value"
:label="label"
:value="value">
2020-03-06 18:04:23 +03:00
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
</el-option>
2020-04-20 00:19:50 +03:00
<!-- Todo sortable -->
<el-option-group
v-if="group"
v-for="(options, name) in selectOptions"
:key="name"
:label="name">
<el-option
v-for="(label, value) in options"
:key="value"
:label="label"
:value="value">
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
</el-option>
</el-option-group>
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :disabled="true" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
</el-select>
<el-select v-model="real_model" @input="change" filterable disabled v-if="disabled && multiple && !collapse" multiple
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
2020-04-20 00:19:50 +03:00
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<template slot="prefix">
<span class="el-input__suffix-inner el-select-icon">
<i :class="'select-icon-position el-input__icon fa fa-' + icon"></i>
</span>
</template>
<el-option v-if="!group" v-for="(label, value) in selectOptions"
2019-12-20 20:12:43 +03:00
:key="value"
:label="label"
:value="value">
2020-03-06 18:04:23 +03:00
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
2019-12-20 20:12:43 +03:00
</el-option>
2019-12-25 15:02:55 +03:00
2020-04-20 00:19:50 +03:00
<!-- Todo sortable -->
<el-option-group
v-if="group"
v-for="(options, name) in selectOptions"
:key="name"
:label="name">
<el-option
v-for="(label, value) in options"
:key="value"
:label="label"
:value="value">
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
</el-option>
</el-option-group>
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :disabled="true" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
</el-select>
<el-select v-model="real_model" @input="change" filterable v-if="!disabled && multiple && collapse" multiple collapse-tags
:placeholder="placeholder">
<div v-if="addNew.status && options.length != 0" class="el-select-dropdown__wrap" slot="empty">
<p class="el-select-dropdown__empty">
{{ noMatchingDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
<div v-else-if="addNew.status && options.length == 0" slot="empty">
<p class="el-select-dropdown__empty">
{{ noDataText }}
</p>
<ul class="el-scrollbar__view el-select-dropdown__list">
<li class="el-select-dropdown__item el-select__footer">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</li>
</ul>
</div>
2020-04-20 00:19:50 +03:00
<template slot="prefix">
<span class="el-input__suffix-inner el-select-icon">
<i :class="'select-icon-position el-input__icon fa fa-' + icon"></i>
</span>
</template>
<el-option v-if="!group" v-for="(label, value) in selectOptions"
2019-11-16 10:21:14 +03:00
:key="value"
:label="label"
:value="value">
2020-03-06 18:04:23 +03:00
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
2019-11-16 10:21:14 +03:00
</el-option>
2019-12-25 15:02:55 +03:00
2020-04-20 00:19:50 +03:00
<!-- Todo sortable -->
<el-option-group
v-if="group"
v-for="(options, name) in selectOptions"
:key="name"
:label="name">
<el-option
v-for="(label, value) in options"
:key="value"
:label="label"
:value="value">
<span class="float-left">{{ label }}</span>
<span class="badge badge-pill badge-success float-right mt-2" v-if="new_options[value]">{{ new_text }}</span>
</el-option>
</el-option-group>
<el-option v-if="addNew.status && options.length != 0" class="el-select__footer" :disabled="true" :value="add_new">
<div @click="onAddItem">
<i class="fas fa-plus"></i>
<span>
{{ add_new_text }}
</span>
</div>
</el-option>
</el-select>
2020-01-03 14:04:00 +03:00
2020-04-20 00:19:50 +03:00
<component v-bind:is="add_new_html" @submit="onSubmit" @cancel="onCancel"></component>
2020-03-06 18:04:23 +03:00
2020-04-20 00:19:50 +03:00
<span slot="infoBlock" class="badge badge-success badge-resize float-right" v-if="new_options[real_model]">{{ new_text }}</span>
<select :name="name" :id="name" v-model="real_model" class="d-none">
2020-04-20 00:19:50 +03:00
<option v-for="(label, value) in selectOptions" :key="value" :value="value">{{ label }}</option>
</select>
</span>
2019-11-16 10:21:14 +03:00
</base-input>
</template>
<script>
2020-02-17 18:44:58 +03:00
import Vue from 'vue';
import { Select, Option, OptionGroup, ColorPicker } from 'element-ui';
2019-11-16 10:21:14 +03:00
import AkauntingModalAddNew from './AkauntingModalAddNew';
2020-01-03 14:04:00 +03:00
import AkauntingModal from './AkauntingModal';
import AkauntingMoney from './AkauntingMoney';
2020-01-03 14:04:00 +03:00
import AkauntingRadioGroup from './forms/AkauntingRadioGroup';
import AkauntingSelect from './AkauntingSelect';
import AkauntingDate from './AkauntingDate';
import AkauntingRecurring from './AkauntingRecurring';
import Form from './../plugins/form';
2019-11-16 10:21:14 +03:00
export default {
name: "akaunting-select",
components: {
[Select.name]: Select,
[Option.name]: Option,
[OptionGroup.name]: OptionGroup,
[ColorPicker.name]: ColorPicker,
AkauntingModalAddNew,
AkauntingRadioGroup,
AkauntingSelect,
AkauntingModal,
AkauntingMoney,
AkauntingDate,
AkauntingRecurring,
2019-11-16 10:21:14 +03:00
},
props: {
title: {
type: String,
default: '',
description: "Selectbox label text"
2019-11-16 10:21:14 +03:00
},
placeholder: {
type: String,
default: '',
description: "Selectbox input placeholder text"
2019-11-16 10:21:14 +03:00
},
formClasses: {
2020-01-18 16:36:36 +03:00
type: Array,
default: null,
description: "Selectbox input class name"
},
formError: {
type: String,
default: null,
description: "Selectbox input error message"
},
name: {
type: String,
default: null,
description: "Selectbox attribute name"
},
value: {
2020-03-19 20:56:37 +03:00
type: [String, Number, Array, Object],
default: '',
description: "Selectbox selected value"
},
2020-01-18 16:36:36 +03:00
options: null,
option_sortable: {
type: String,
default: 'value',
description: "Option Sortable type (key|value)"
},
2020-02-14 14:56:58 +03:00
model: {
2020-03-19 20:56:37 +03:00
type: [String, Number, Array, Object],
default: '',
2020-02-14 14:56:58 +03:00
description: "Selectbox selected model"
},
2019-11-16 10:21:14 +03:00
icon: {
type: String,
description: "Prepend icon (left)"
},
2020-01-03 14:04:00 +03:00
addNew: {
type: Object,
default: function () {
return {
text: 'Add New Item',
status: false,
path: null,
type: 'modal', // modal, inline
2020-03-09 11:57:06 +03:00
field: {},
2020-03-06 18:04:23 +03:00
new_text: 'New',
buttons: {}
2020-01-03 14:04:00 +03:00
};
},
description: "Selectbox Add New Item Feature"
},
group: {
type: Boolean,
default: false,
description: "Selectbox option group status"
},
multiple: {
type: Boolean,
default: false,
description: "Multible feature status"
},
readonly: {
type: Boolean,
default: false,
description: "Selectbox disabled status"
},
disabled: {
type: Boolean,
default: false,
description: "Selectbox disabled status"
},
collapse: {
type: Boolean,
default: false,
description: "Selectbox collapse status"
},
noDataText: {
type: String,
default: 'No Data',
description: "Selectbox empty options message"
},
noMatchingDataText: {
type: String,
default: 'No Matchign Data',
description: "Selectbox search option not found item message"
}
2019-11-16 10:21:14 +03:00
},
data() {
return {
2020-03-06 18:04:23 +03:00
add_new: {
text: this.addNew.text,
show: false,
path: this.addNew.path,
type: this.addNew.type, // modal, inline
2020-03-09 11:57:06 +03:00
field: this.addNew.field,
2020-03-06 18:04:23 +03:00
buttons: this.addNew.buttons
},
2020-01-03 14:04:00 +03:00
add_new_text: this.addNew.text,
2020-03-06 18:04:23 +03:00
new_text: this.addNew.new_text,
2019-11-16 10:21:14 +03:00
selectOptions: this.options,
real_model: this.model,
2020-01-03 14:04:00 +03:00
add_new_html: '',
form: {},
2020-03-06 18:04:23 +03:00
new_options: false,
couunt: 1,
2019-11-16 10:21:14 +03:00
}
},
2020-03-06 18:04:23 +03:00
created() {
2020-04-20 00:19:50 +03:00
/*
if (this.group != true && Object.keys(this.options).length) {
let sortable = [];
let option_sortable = this.option_sortable;
for (var option_key in this.options) {
sortable.push({
'key' : option_key,
'value': this.options[option_key]
});
}
if (option_sortable == 'value') {
sortable.sort(function(a, b) {
var sortableA = a[option_sortable].toUpperCase();
var sortableB = b[option_sortable].toUpperCase();
let comparison = 0;
if (sortableA > sortableB) {
comparison = 1;
} else if (sortableA < sortableB) {
comparison = -1;
}
return comparison;
});
}
this.options = sortable;
}
2020-04-20 00:19:50 +03:00
*/
2020-03-06 18:04:23 +03:00
this.new_options = {};
},
2019-11-16 10:21:14 +03:00
mounted() {
this.real_model = this.value;
2020-03-17 17:11:41 +03:00
if (this.model.length) {
2020-03-19 20:56:37 +03:00
if (eval(this.model) !== undefined) {
this.real_model = eval(this.model);
} else {
this.real_model = this.model;
}
2020-03-17 17:11:41 +03:00
}
2020-03-13 18:08:49 +03:00
if (this.multiple && !this.real_model.length) {
this.real_model = [];
}
2019-11-16 10:21:14 +03:00
this.$emit('interface', this.real_model);
setTimeout(function() {
this.change();
}.bind(this), 800);
2019-11-16 10:21:14 +03:00
},
methods: {
change() {
if (typeof(this.real_model) === 'object' && typeof(this.real_model.type) !== 'undefined') {
return false;
}
2019-11-16 10:21:14 +03:00
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);
});
*/
2019-11-16 10:21:14 +03:00
},
async onAddItem() {
2019-11-16 10:21:14 +03:00
// Get Select Input value
if (this.title) {
var value = this.$children[0].$children[0].$children[0].$refs.input.value;
} else {
var value = this.$children[0].$children[0].$refs.input.value;
}
2019-11-16 10:21:14 +03:00
if (this.add_new.type == 'inline') {
if (value === '') {
return false;
}
await this.addInline(value);
2020-01-03 14:04:00 +03:00
} else {
await this.onModal(value);
2020-01-03 14:04:00 +03:00
}
},
addInline(value) {
},
onModal(value) {
let add_new = this.add_new;
2020-01-03 14:04:00 +03:00
2020-03-07 16:17:24 +03:00
window.axios.get(this.add_new.path)
2020-01-03 14:04:00 +03:00
.then(response => {
2020-03-06 18:04:23 +03:00
add_new.show = true;
2020-01-03 14:04:00 +03:00
add_new.html = response.data.html;
this.$children[0].$children[0].visible = false;
2020-01-03 14:04:00 +03:00
this.add_new_html = Vue.component('add-new-component', function (resolve, reject) {
resolve({
2020-03-06 18:04:23 +03:00
template: '<div><akaunting-modal-add-new :show="add_new.show" @submit="onSubmit" @cancel="onCancel" :buttons="add_new.buttons" :title="add_new.text" :is_component=true :message="add_new.html"></akaunting-modal-add-new></div>',
2020-01-03 14:04:00 +03:00
components: {
AkauntingModalAddNew,
2020-01-03 14:04:00 +03:00
AkauntingRadioGroup,
AkauntingSelect,
AkauntingModal,
AkauntingMoney,
2020-01-03 14:04:00 +03:00
AkauntingDate,
AkauntingRecurring,
[ColorPicker.name]: ColorPicker,
2020-01-03 14:04:00 +03:00
},
data: function () {
return {
add_new: add_new,
2020-01-03 14:04:00 +03:00
}
},
methods: {
onSubmit(event) {
this.$emit('submit', event);
2020-03-06 18:04:23 +03:00
},
onCancel(event) {
this.$emit('cancel', event);
2020-01-03 14:04:00 +03:00
}
}
})
});
})
.catch(e => {
this.errors.push(e);
})
.finally(function () {
// always executed
});
},
onSubmit(event) {
this.form = event;
2020-01-03 14:04:00 +03:00
this.loading = true;
let data = this.form.data();
2020-03-07 16:17:24 +03:00
FormData.prototype.appendRecursive = function(data, wrapper = null) {
for(var name in data) {
if (wrapper) {
if ((typeof data[name] == 'object' || data[name].constructor === Array) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) {
this.appendRecursive(data[name], wrapper + '[' + name + ']');
} else {
this.append(wrapper + '[' + name + ']', data[name]);
}
} else {
if ((typeof data[name] == 'object' || data[name].constructor === Array) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) {
this.appendRecursive(data[name], name);
} else {
this.append(name, data[name]);
}
}
}
};
let form_data = new FormData();
form_data.appendRecursive(data);
window.axios({
method: this.form.method,
url: this.form.action,
data: form_data,
headers: {
'X-CSRF-TOKEN': window.Laravel.csrfToken,
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'multipart/form-data'
}
})
2020-01-03 14:04:00 +03:00
.then(response => {
this.form.loading = false;
2020-01-03 14:04:00 +03:00
if (response.data.success) {
2020-03-13 18:08:49 +03:00
if (!Object.keys(this.options).length) {
this.selectOptions = {};
}
2020-03-09 11:57:06 +03:00
this.selectOptions[response.data.data[this.add_new.field.key]] = response.data.data[this.add_new.field.value];
this.new_options[response.data.data[this.add_new.field.key]] = response.data.data[this.add_new.field.value];
if (this.multiple) {
this.real_model.push(response.data.data[this.add_new.field.key].toString());
} else {
this.real_model = response.data.data[this.add_new.field.key].toString();
}
2020-03-06 18:04:23 +03:00
this.add_new.show = false;
this.add_new.html = '';
this.add_new_html = null;
this.$emit('new', response.data.data);
this.change();
let documentClasses = document.body.classList;
documentClasses.remove("modal-open");
2020-01-03 14:04:00 +03:00
}
})
.catch(error => {
this.form.loading = false;
this.form.onFail(error);
2020-01-03 14:04:00 +03:00
this.method_show_html = error.message;
});
},
2020-03-06 18:04:23 +03:00
onCancel() {
this.add_new.show = false;
this.add_new.html = null;
this.add_new_html = null;
let documentClasses = document.body.classList;
documentClasses.remove("modal-open");
2020-03-06 18:04:23 +03:00
},
2020-01-03 14:04:00 +03:00
addModal() {
},
2019-11-16 10:21:14 +03:00
},
watch: {
options: function (options) {
// update options
this.selectOptions = options;
2020-03-07 16:17:24 +03:00
if (Object.keys(this.new_options).length) {
2020-03-13 18:08:49 +03:00
if (!Object.keys(this.options).length) {
this.selectOptions = {};
}
2020-03-07 16:17:24 +03:00
for (let [key, value] of Object.entries(this.new_options)) {
if (!this.selectOptions[key]) {
this.selectOptions[key] = value;
}
}
}
},
2020-02-18 17:17:28 +03:00
real_model: function (value) {
2020-03-21 21:01:30 +03:00
if (this.multiple) {
return;
}
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) {
2020-02-14 17:58:12 +03:00
if (this.multiple) {
this.real_model = value;
} else {
this.real_model = value.toString();
}
2020-02-14 14:56:58 +03:00
},
2020-02-18 17:17:28 +03:00
2020-02-14 14:56:58 +03:00
model: function (value) {
2020-02-14 17:58:12 +03:00
if (this.multiple) {
this.real_model = value;
} else {
this.real_model = value.toString();
}
2019-11-16 10:21:14 +03:00
}
},
}
</script>
<style scoped>
.form-group .modal {
z-index: 3050;
}
.el-select-dropdown__empty {
padding: 10px 0 0 !important;
}
.el-select__footer {
text-align: center;
border-top: 1px solid #dee2e6;
padding: 0px;
cursor: pointer;
color: #3c3f72;
font-weight: bold;
height: 38px;
line-height: 38px;
margin-top: 5px;
margin-bottom: -6px;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
}
.el-select__footer.el-select-dropdown__item.hover {
background-color: inherit !important;
}
.el-select__footer.el-select-dropdown__item:hover, .el-select__footer.el-select-dropdown__item:focus {
background-color: #3c3f72 !important;
color: white !important;
border-top-color: #3c3f72;
}
.el-select__footer div span {
margin-left: 5px;
}
2020-03-06 18:04:23 +03:00
.badge-resize {
float: right;
margin-top: -32px;
margin-right: 35px;
position: relative;
}
2020-07-06 20:50:36 +03:00
</style>