Files
myprojplanet_vite/src/components/CMyPopupEdit/CMyPopupEdit.ts

586 lines
15 KiB
TypeScript
Raw Normal View History

import { defineComponent, onMounted, onBeforeMount, PropType, ref, toRef, watch } from 'vue'
2021-09-16 21:08:02 +02:00
import { useI18n } from '@src/boot/i18n'
import { useUserStore } from '@store/UserStore'
import { useGlobalStore } from '@store/globalStore'
import { useQuasar } from 'quasar'
2021-11-04 16:02:14 +01:00
import { IColGridTable, IImgGallery } from 'model'
2021-09-16 21:08:02 +02:00
import { CMyChipList } from '../CMyChipList'
import { CDate } from '../CDate'
import { CDateTime } from '../CDateTime'
import { CMyToggleList } from '../CMyToggleList'
import { CMySelect } from '../CMySelect'
import { CMyEditor } from '../CMyEditor'
import { CGallery } from '../CGallery'
import { tools } from '@store/Modules/tools'
import { costanti } from '@costanti'
2021-12-03 22:47:53 +01:00
// @ts-ignore
// import VueTelInput from 'vue3-tel-input'
// import 'vue3-tel-input/dist/vue3-tel-input.css'
2021-09-16 21:08:02 +02:00
import { fieldsTable } from '@store/Modules/fieldsTable'
2021-11-04 16:02:14 +01:00
import MixinBase from '@/mixins/mixin-base'
import MixinUsers from '@/mixins/mixin-users'
2021-09-16 21:08:02 +02:00
export default defineComponent({
name: 'CMyPopupEdit',
2021-11-22 18:28:45 +01:00
emits: ['showandsave', 'update:row', 'show', 'save', 'annulla'],
2021-09-16 21:08:02 +02:00
props: {
2021-11-04 16:02:14 +01:00
title: {
type: String,
required: false,
default: '',
},
2021-09-16 21:08:02 +02:00
row: {
type: Object,
required: true,
},
2021-11-04 16:02:14 +01:00
mycol: {
type: Object as PropType<IColGridTable>,
2021-09-16 21:08:02 +02:00
required: true,
},
canEdit: {
type: Boolean,
required: false,
default: false,
},
isInModif: {
type: Boolean,
required: false,
default: false,
},
2021-09-16 21:08:02 +02:00
field: {
type: String,
required: false,
default: '',
},
subfield: {
type: String,
required: false,
default: '',
},
2021-11-04 16:02:14 +01:00
mysubsubkey: {
type: String,
required: false,
default: '',
},
serv: {
type: Boolean,
required: false,
default: false,
},
indrec: {
type: Number,
required: false,
default: -1,
},
type: {
type: Number,
required: false,
default: 0,
},
2021-09-16 21:08:02 +02:00
showall: {
type: Boolean,
required: false,
default: false,
},
view: {
type: String,
required: false,
default: 'row',
},
minuteinterval: {
type: String,
required: false,
default: '5',
},
disable: {
type: Boolean,
required: false,
default: false,
},
visulabel: {
type: Boolean,
required: false,
default: false,
},
2021-11-04 16:02:14 +01:00
jointable: {
type: String,
required: false,
default: '',
},
2021-10-28 00:37:48 +02:00
table: {
type: String,
required: false,
default: '',
},
2021-11-04 16:02:14 +01:00
myimg: {
type: String,
required: false,
default: '',
},
id: {
type: String,
required: false,
default: '',
},
idmain: {
type: String,
required: false,
default: '',
},
2021-09-16 21:08:02 +02:00
},
components: { CMyChipList, CDateTime, CDate, CMyToggleList, CMySelect, CMyEditor, CGallery },
setup(props, { emit }) {
const $q = useQuasar()
const { t } = useI18n()
const userStore = useUserStore()
const globalStore = useGlobalStore()
2021-10-28 00:37:48 +02:00
const myvalue = ref(<any>'')
2021-09-16 21:08:02 +02:00
const myvalueprec = ref('false')
const countryname = ref('')
const visueditor = ref(false)
2021-10-28 00:37:48 +02:00
const showeditor = ref(false)
2021-09-16 21:08:02 +02:00
2021-11-04 16:02:14 +01:00
const myImgGall = ref(<IImgGallery[]>[{}])
const col = ref(<IColGridTable> { name: 'test', fieldtype: 0 })
2021-09-16 21:08:02 +02:00
const myrow = toRef(props, 'row')
2021-11-04 16:02:14 +01:00
const { setValDb, getValDb } = MixinBase()
const { getMyUsername } = MixinUsers()
watch(() => props.row, (newval, oldval) => {
refresh()
})
2021-11-04 16:02:14 +01:00
function crea() {
// console.log('crea', isFieldDb())
2021-11-04 16:02:14 +01:00
if (isFieldDb()) {
// mykey -> field
// mysubkey -> subfield
// table -> table
// serv -> serv
// id -> id
// idmain -> idmain
// console.table(props)
myvalue.value = getValDb(props.field, props.serv, '', props.table, props.subfield, props.id, props.idmain)
// console.log('myvalue.value', myvalue.value)
col.value.jointable = props.jointable
col.value.fieldtype = props.type
col.value.label = props.title
if (props.type === costanti.FieldType.image) {
myImgGall.value = [{
_id: '',
imagefile: myvalue.value,
2021-11-23 15:59:26 +01:00
// order: 1,
2021-11-04 16:02:14 +01:00
alt: 'img',
}]
}
// console.log('col', col.value);
2021-11-04 16:02:14 +01:00
} else {
col.value = {...props.mycol}
}
// console.log('CMyFieldDb crea', myvalue)
}
watch(() => props.id, (newval, oldval) => {
crea()
})
function isFieldDb(){
return props.type !== 0
}
2021-09-16 21:08:02 +02:00
function isviewfield() {
return props.view === 'field'
}
function changeval(newval: any) {
console.log('changeval update:row', newval)
2021-10-28 00:37:48 +02:00
emit('update:row', props.row)
if (props.isInModif)
OpenEdit()
2021-09-16 21:08:02 +02:00
}
function getrealval(newval: any) {
2021-11-04 16:02:14 +01:00
if (col.value.fieldtype === costanti.FieldType.hours) {
2021-09-16 21:08:02 +02:00
newval = newval.value
}
}
function changevalRec(newval: any) {
console.log('popypedit: changevalRec', newval)
2021-11-04 16:02:14 +01:00
// console.log('row', props.row, 'col', props.mycol, 'newval', newval)
// console.log('row[col.value.name]', props.row[col.value.name])
2021-12-03 22:47:53 +01:00
if (props.type === costanti.FieldType.image) {
console.log('image', newval)
}
2021-11-04 16:02:14 +01:00
myrow.value[col.value.name] = newval
2021-10-28 00:37:48 +02:00
// console.log('changevalRec update:row', newval)
2021-09-16 21:08:02 +02:00
emit('update:row', props.row)
if (props.isInModif)
OpenEdit()
2021-09-16 21:08:02 +02:00
}
function changevalRecHours(newval: any) {
2021-11-04 16:02:14 +01:00
if (col.value.fieldtype === costanti.FieldType.hours) {
2021-09-16 21:08:02 +02:00
newval = newval.value
}
changevalRec(newval)
myvalue.value = newval
}
function updatedata() {
mounted()
}
function mounted() {
// console.log('mounted', 'isFieldDb()', isFieldDb())
2021-11-04 16:02:14 +01:00
if (isFieldDb()) {
2021-09-16 21:08:02 +02:00
} else {
2021-11-04 16:02:14 +01:00
if (props.subfield !== '') {
if (props.row[props.field] === undefined) {
myrow.value[props.field] = {}
myvalue.value = ''
} else {
myvalue.value = myrow.value[props.field][props.subfield]
}
} else {
if (props.field !== '')
myvalue.value = myrow.value[props.field]
else {
// @ts-ignore
myvalue.value = myrow.value
}
2021-09-16 21:08:02 +02:00
}
}
// console.log('popupedit: myvalue.value', myvalue.value)
2021-11-04 16:02:14 +01:00
if (col.value.fieldtype === costanti.FieldType.listimages) {
2021-10-28 00:37:48 +02:00
if (myvalue.value === '' || myvalue.value === undefined) {
// console.log('set default myvalue.value ')
2021-10-28 00:37:48 +02:00
myvalue.value = {
title: 'Galleria',
directory: 'none',
2021-11-22 18:28:45 +01:00
list: []
2021-10-28 00:37:48 +02:00
}
}
}
// console.log('myvalue.value', myvalue.value)
2021-09-16 21:08:02 +02:00
myvalueprec.value = myvalue.value
// console.log('myvalueprec', myvalueprec)
}
function refresh() {
mounted()
}
2021-09-16 21:08:02 +02:00
function OpenEdit() {
// console.log('OpenEdit')
emit('show')
}
2021-11-04 16:02:14 +01:00
/*function getval() {
2021-09-16 21:08:02 +02:00
let myval: any = 'false'
if ((props.subfield !== '') && (props.subfield !== '')) {
if (myrow.value[props.field] === undefined) {
myrow.value[props.field] = {}
myval = ''
} else {
myval = myrow.value[props.field][props.subfield]
}
} else {
if (props.field !== '')
myval = myrow.value[props.field]
else
myval = myrow.value
}
return myval
2021-11-04 16:02:14 +01:00
}*/
2021-09-16 21:08:02 +02:00
function SaveValueInt(newVal: any, valinitial: any) {
2021-10-03 16:11:29 +02:00
// console.log('SaveValueInt', newVal, valinitial)
2021-09-16 21:08:02 +02:00
2021-11-04 16:02:14 +01:00
if (isFieldDb()) {
savefield(newVal, valinitial, $q);
2021-09-16 21:08:02 +02:00
} else {
2021-11-04 16:02:14 +01:00
// Update value in table memory
if (props.subfield !== '') {
if (myrow.value[props.field] === undefined)
myrow.value[props.field] = {}
myrow.value[props.field][props.subfield] = newVal
} else {
if (props.field !== '')
myrow.value[props.field] = newVal
else
myrow.value = newVal
}
emit('save', newVal, valinitial)
2021-09-16 21:08:02 +02:00
}
2021-11-04 16:02:14 +01:00
}
2021-09-16 21:08:02 +02:00
2021-11-04 16:02:14 +01:00
function savefield(value: any, initialval: any, myq: any) {
myvalue.value = value
setValDb(myq, props.field, myvalue.value, props.type, props.serv, props.table, props.subfield, props.id, props.indrec, props.mysubsubkey)
2021-09-16 21:08:02 +02:00
}
2021-11-04 16:02:14 +01:00
2021-09-16 21:08:02 +02:00
function annulla(val: any) {
emit('annulla', true)
}
2021-11-04 16:02:14 +01:00
function savefieldboolean(value: any) {
if (myvalue.value === undefined)
myvalue.value = 'true'
else
myvalue.value = value
setValDb($q, props.field, myvalue, props.type, props.serv, props.table, props.subfield, props.id, props.indrec, props.mysubsubkey)
}
2021-09-16 21:08:02 +02:00
function Savedb(newVal: any, valinitial: any) {
2021-11-22 18:28:45 +01:00
console.log('Savedb')
2021-09-16 21:08:02 +02:00
2021-11-04 16:02:14 +01:00
if (col.value.fieldtype === costanti.FieldType.boolean) {
2021-09-16 21:08:02 +02:00
// console.log('myvalue', myvalue, newVal, myvalueprec)
if (myvalueprec.value === undefined) {
newVal = true
myvalueprec.value = myvalue.value
myvalue.value = newVal
2021-10-01 19:42:21 +02:00
2021-09-16 21:08:02 +02:00
}
// console.log('DOPO myvalue', myvalue, newVal, myvalueprec)
}
2021-11-04 16:02:14 +01:00
if (col.value.fieldtype === costanti.FieldType.image) {
console.log('newVal.imagefile', newVal)
myvalue.value = newVal
}
2021-09-16 21:08:02 +02:00
// console.log('Savedb', newVal)
2021-11-04 16:02:14 +01:00
emit('showandsave', props.row, props.mycol, newVal, valinitial)
2021-09-16 21:08:02 +02:00
visueditor.value = false
}
function visuValByType(val: any, col: IColGridTable, row: any) {
if (col === undefined || row === undefined)
return
// let val = ''
2021-11-04 16:02:14 +01:00
// if (col.subfield !== '') {
// if (row[col.field] === undefined)
// row[col.field] = {}
2021-09-16 21:08:02 +02:00
//
2021-11-04 16:02:14 +01:00
// val = row[col.field][col.subfield]
2021-09-16 21:08:02 +02:00
// } else {
2021-11-04 16:02:14 +01:00
// val = row[col.field]
2021-09-16 21:08:02 +02:00
// }
//
2021-11-04 16:02:14 +01:00
if (col.fieldtype === costanti.FieldType.date) {
2021-09-16 21:08:02 +02:00
if (val === undefined) {
return '[]'
} else {
return tools.getstrDateTime(val)
}
2021-11-04 16:02:14 +01:00
} else if (col.fieldtype === costanti.FieldType.onlydate) {
2021-09-16 21:08:02 +02:00
if (val === undefined) {
return '[]'
} else {
return tools.getstrDate(val)
}
2021-11-04 16:02:14 +01:00
} else if (col.fieldtype === costanti.FieldType.boolean) {
2021-09-16 21:08:02 +02:00
return (val) ? t('dialog.yes') : t('dialog.no')
2021-11-04 16:02:14 +01:00
} else if (col.fieldtype === costanti.FieldType.binary) {
2021-09-16 21:08:02 +02:00
if (val === undefined)
return '[---]'
else
return globalStore.getArrStrByValueBinary(col, val)
2021-11-04 16:02:14 +01:00
} else if (col.fieldtype === costanti.FieldType.select) {
2021-09-16 21:08:02 +02:00
if (val === undefined)
return '[---]'
else
return globalStore.getValueByTable(col, val)
2021-11-04 16:02:14 +01:00
} else if (col.fieldtype === costanti.FieldType.multiselect) {
2021-09-16 21:08:02 +02:00
if (val === undefined)
return '[---]'
else
return globalStore.getMultiValueByTable(col, val)
2021-11-04 16:02:14 +01:00
} else if (col.fieldtype === costanti.FieldType.multioption) {
if (val === undefined)
return '[---]'
else
return globalStore.getMultiValueByTable(col, val)
} else if (col.fieldtype === costanti.FieldType.password) {
if (val === undefined)
return '[---]'
else
return '***************'
2021-09-16 21:08:02 +02:00
} else {
if (val === undefined || val === null)
2021-11-04 16:02:14 +01:00
return ' <span class="text-grey">(' + t('reg.select') + ')</span> '
2021-09-16 21:08:02 +02:00
else if (val === '') {
2021-11-04 16:02:14 +01:00
return ' <span class="text-grey">(' + t('reg.select') + ')</span> '
2021-09-16 21:08:02 +02:00
} else {
let mystr = ''
if (props.showall) {
return val
} else {
mystr = tools.firstchars(val, tools.MAX_CHARACTERS)
}
if (val) {
if (val.length > tools.MAX_CHARACTERS)
mystr += '...'
} else {
return val
}
return mystr
}
}
}
function visInNewRec(col: any) {
2021-11-04 16:02:14 +01:00
return !col.notShowInNewRec
2021-09-16 21:08:02 +02:00
}
function getclassCol(col: any) {
if (col) {
2021-11-04 16:02:14 +01:00
let mycl = (col.disable || isviewfield()) ? '' : 'colmodif'
mycl += ((col.fieldtype === costanti.FieldType.date) || (col.fieldtype === costanti.FieldType.onlydate)) ? ' coldate flex flex-container' : ''
2021-09-16 21:08:02 +02:00
return mycl
} else {
return ''
}
}
2021-10-01 19:42:21 +02:00
2021-11-04 16:02:14 +01:00
function mycl() {
if (props.disable) {
return 'cldisable'
}
}
2021-10-01 19:42:21 +02:00
function selectcountry({ name, iso2, dialCode }: {name: string, iso2: string, dialCode: string}) {
2021-09-16 21:08:02 +02:00
// console.log(name, iso2, dialCode)
myvalueprec.value = myvalue.value
myvalue.value = iso2
countryname.value = name
}
function intcode_change(coderec: any) {
myvalueprec.value = myvalue.value
myvalue.value = '+' + coderec.dialCode
}
function onInput(phone: any, phoneObject: any, input: any) {
if (phoneObject?.formatted) {
myvalue.value = phoneObject.formatted
}
}
2021-10-28 00:37:48 +02:00
function getTitleGall() {
2021-11-04 16:02:14 +01:00
if (fieldsTable.tableForUsers.includes(props.table)) {
return 'Profilo'
} else {
return fieldsTable.getTitleImgByTable(props.table);
}
2021-10-28 00:37:48 +02:00
}
function getDirectoryGall() {
if (fieldsTable.tableForUsers.includes(props.table)) {
return 'profile/' + userStore.my.username + '/' + props.table
2021-11-04 16:02:14 +01:00
}else if (props.table === 'users') {
return 'profile/' + userStore.my.username
2021-10-28 00:37:48 +02:00
} else {
return props.table
}
}
2021-11-04 16:02:14 +01:00
function uploaded(info: any) {
if (info.files) {
myvalue.value = tools.geturlrelativeprofile()+ '/' + getMyUsername() + '/' + info.files[0].name
console.log('uploaded', myvalue.value)
savefield(myvalue.value, '', $q)
}
// info.files[0].name
}
function removephoto() {
myvalue.value = ''
SaveValueInt(myvalue.value, '')
}
2021-12-03 22:47:53 +01:00
function noPopupeditByCol(mycol: IColGridTable) {
return (mycol.fieldtype !== costanti.FieldType.html
&& mycol.fieldtype !== costanti.FieldType.image
&& mycol.fieldtype !== costanti.FieldType.listimages
&& mycol.fieldtype !== costanti.FieldType.number
)
}
2021-11-04 16:02:14 +01:00
onBeforeMount(mounted)
2021-09-16 21:08:02 +02:00
2021-11-04 16:02:14 +01:00
crea()
2021-09-16 21:08:02 +02:00
return {
myvalue,
countryname,
visueditor,
showeditor,
isviewfield,
changeval,
changevalRec,
changevalRecHours,
updatedata,
OpenEdit,
SaveValueInt,
annulla,
Savedb,
visuValByType,
visInNewRec,
getclassCol,
selectcountry,
intcode_change,
tools,
2021-09-19 02:59:24 +02:00
costanti,
2021-09-16 21:08:02 +02:00
fieldsTable,
onInput,
2021-10-01 03:08:43 +02:00
globalStore,
2021-10-28 00:37:48 +02:00
getTitleGall,
getDirectoryGall,
2021-11-04 16:02:14 +01:00
removephoto,
isFieldDb,
col,
myImgGall,
2021-12-03 22:47:53 +01:00
noPopupeditByCol,
2021-09-16 21:08:02 +02:00
}
}
})