Files
salvato.newfreeplanet/src/components/CMyFieldDb/CMyFieldDb.ts

195 lines
4.2 KiB
TypeScript
Raw Normal View History

import { defineComponent, onMounted, PropType, ref, watch } from 'vue'
2021-09-16 21:08:02 +02:00
import { useQuasar } from 'quasar'
import { useI18n } from '@/boot/i18n'
import { useGlobalStore } from '@store/globalStore'
import { fieldsTable } from '@store/Modules/fieldsTable'
import { tools } from '@store/Modules/tools'
import { costanti } from '@costanti'
2021-11-04 16:02:14 +01:00
import { CMyPopupEdit } from '@/components/CMyPopupEdit'
2022-07-21 00:20:48 +02:00
import { IColGridTable, IOperators, ISpecialField } from 'model'
2021-11-22 18:28:45 +01:00
import MixinBase from '@/mixins/mixin-base'
2021-09-04 15:05:34 +02:00
2021-10-01 03:08:43 +02:00
2021-09-16 21:08:02 +02:00
export default defineComponent({
name: 'CMyFieldDb',
2022-11-23 10:27:36 +01:00
emits: ['save'],
2021-09-16 21:08:02 +02:00
props: {
title: {
type: String,
required: true,
},
hint: {
type: String,
required: false,
default: '',
},
2021-09-16 21:08:02 +02:00
mykey: {
type: String,
required: true,
},
mysubkey: {
type: String,
required: false,
default: '',
},
2022-07-21 00:20:48 +02:00
specialField: {
type: Object as PropType<ISpecialField>,
required: false,
default: null,
},
filter: {
type: [String, Function],
required: false,
default: null,
},
2021-10-08 00:38:22 +02:00
indrec: {
type: Number,
required: false,
default: -1,
},
maxlength: {
type: Number,
required: false,
default: 0,
},
2022-07-10 01:24:54 +02:00
minlength: {
type: Number,
required: false,
default: 0,
},
2021-10-08 00:38:22 +02:00
mysubsubkey: {
type: String,
required: false,
default: '',
},
2021-09-16 21:08:02 +02:00
type: {
type: Number,
required: true,
},
serv: {
type: Boolean,
required: false,
default: false,
},
canModify: {
type: Boolean,
required: false,
default: true,
},
2021-09-16 21:08:02 +02:00
disable: {
type: Boolean,
required: false,
default: false,
},
jointable: {
type: String,
required: false,
default: '',
},
table: {
type: String,
required: false,
default: 'settings',
},
myimg: {
type: String,
required: false,
default: '',
},
rec: {
type: Object,
required: false,
default: null,
},
mycol: {
2022-11-17 08:10:43 +01:00
type: Object as PropType<IColGridTable> | undefined,
required: false,
default: () => {
return { }
},
},
2021-09-16 21:08:02 +02:00
id: {
type: String,
required: false,
default: '',
},
idmain: {
type: String,
required: false,
default: '',
},
tablesel: {
type: String,
required: false,
default: '',
},
pickup: {
type: Boolean,
required: false,
default: false,
},
2021-09-16 21:08:02 +02:00
},
2021-11-04 16:02:14 +01:00
components: { CMyPopupEdit },
2021-09-16 21:08:02 +02:00
setup(props, { emit }) {
const $q = useQuasar()
const { t } = useI18n()
const globalStore = useGlobalStore()
const col = ref(<IColGridTable>{
name: 'test', fieldtype: 0, showWhen: costanti.showWhen.NewRec + costanti.showWhen.InEdit + costanti.showWhen.InView, visible: true, maxlength: props.maxlength, minlength: props.minlength
})
2021-11-04 16:02:14 +01:00
const row = ref({})
2021-09-16 21:08:02 +02:00
2021-11-22 18:28:45 +01:00
const { setValDb, getValDb } = MixinBase()
function showandsel(row: any, col: any, newval: any, valinitial: any) {
console.log('showandsel CMyFieldDb', row, col, newval)
if (newval !== valinitial) {
2022-07-21 00:20:48 +02:00
setValDb($q, props.mykey, newval, props.type, props.serv, props.table, props.mysubkey, props.id, props.indrec, props.mysubsubkey, props.specialField)
}
2022-11-23 10:27:36 +01:00
}
function save(newval: any) {
emit('save', newval)
2021-11-22 18:28:45 +01:00
}
function withBorder() {
2022-11-17 08:10:43 +01:00
if (col.value)
return col.value.fieldtype !== costanti.FieldType.onlydate && col.value.fieldtype !== costanti.FieldType.date
else
return false
}
function mounted() {
if (props.rec) {
row.value = props.rec
}
2022-11-17 08:10:43 +01:00
if (props.mycol && props.mycol.name !== '') {
col.value = props.mycol
2022-11-17 08:10:43 +01:00
} else {
2022-11-23 10:27:36 +01:00
// console.log('Tab = ', props.table, 'key=', props.mykey, 'mycolProp', props.mycol)
2022-11-17 08:10:43 +01:00
col.value = fieldsTable.getColByTable(props.table, props.mykey)
}
2022-11-17 08:10:43 +01:00
// console.log('COL = ', col.value, 'MyCol passed', props.mycol)
}
onMounted(mounted)
2021-09-16 21:08:02 +02:00
return {
2021-09-19 02:59:24 +02:00
tools,
costanti,
2021-10-01 03:08:43 +02:00
fieldsTable,
globalStore,
2021-11-04 16:02:14 +01:00
col,
row,
2021-11-22 18:28:45 +01:00
showandsel,
withBorder,
2022-11-23 10:27:36 +01:00
save,
2021-09-16 21:08:02 +02:00
}
},
})
2021-09-04 15:05:34 +02:00