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

1210 lines
32 KiB
TypeScript
Raw Normal View History

2025-03-01 14:14:43 +01:00
import type { PropType } from 'vue';
2025-08-12 19:43:36 +02:00
import {
defineComponent,
onMounted,
onBeforeMount,
ref,
toRef,
watch,
computed,
} from 'vue';
import { useI18n } from 'vue-i18n';
import { useUserStore } from '@store/UserStore';
import { useGlobalStore } from '@store/globalStore';
import { useQuasar } from 'quasar';
import type { IColGridTable, IImgGallery, ISpecialField } from 'model';
import { CMyChipList } from '../CMyChipList';
import { CDate } from '../CDate';
import { CDateTime } from '../CDateTime';
import { CDateTimeStartEnd } from '../CDateTimeStartEnd';
2025-08-12 19:43:36 +02:00
import { CLabel } from '../CLabel';
import { CMyToggleList } from '../CMyToggleList';
import { CMySelect } from '../CMySelect';
import { CCurrencyValue } from '../CCurrencyValue';
import { CMapEditAddressByCoord } from '../CMapEditAddressByCoord';
import { CInput } from '../CInput';
import { CMyEditor } from '../CMyEditor';
import { CMyEditorAI } from '../CMyEditorAI';
import { CGallery } from '../CGallery';
import { CPickColor } from '../CPickColor';
import { CSelectImage } from '../CSelectImage';
import { CAccomodation } from '../CAccomodation';
import { tools } from '@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'
2025-08-12 19:43:36 +02:00
import { fieldsTable } from '@store/Modules/fieldsTable';
import MixinBase from '@src/mixins/mixin-base';
import MixinUsers from '@src/mixins/mixin-users';
import { toolsext } from '@store/Modules/toolsext';
import { shared_consts } from '@src/common/shared_vuejs';
import { useRouter } from 'vue-router';
2021-09-16 21:08:02 +02:00
export default defineComponent({
name: 'CMyPopupEdit',
emits: ['showandsave', 'update:row', 'show', 'save', 'annulla', 'update_col'],
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,
},
rec: {
type: Object,
required: false,
default: null,
},
2022-11-17 08:10:43 +01:00
fielddb: {
type: Boolean,
required: false,
default: false,
},
2024-01-13 16:21:19 +01:00
dense: {
type: Boolean,
required: false,
default: false,
},
justifycenter: {
type: Boolean,
required: false,
default: true,
},
isrec: {
type: Boolean,
required: false,
default: false,
},
2021-11-04 16:02:14 +01:00
mycol: {
type: Object as PropType<IColGridTable | undefined | null>,
required: false,
default: undefined,
2021-09-16 21:08:02 +02:00
},
canEdit: {
type: Boolean,
required: false,
default: false,
},
insertMode: {
type: Boolean,
required: false,
default: false,
},
2021-12-11 22:12:44 +01:00
canModify: {
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: '',
},
field2: {
type: String,
required: false,
default: '',
},
2021-09-16 21:08:02 +02:00
subfield: {
type: String,
required: false,
default: '',
},
subfield2: {
type: String,
required: false,
default: '',
},
2021-11-04 16:02:14 +01:00
mysubsubkey: {
type: String,
required: false,
default: '',
},
2022-07-21 00:20:48 +02:00
specialField: {
type: Object as PropType<ISpecialField>,
required: false,
default: null,
},
2021-11-04 16:02:14 +01:00
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',
},
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: '',
},
2022-07-21 00:20:48 +02:00
filter: {
type: [String, Function],
required: false,
default: null,
},
2022-01-26 01:31:07 +01:00
field_extra: {
type: String,
required: false,
default: '',
},
value_extra: {
type: [String, Number],
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, Number],
2021-11-04 16:02:14 +01:00
required: false,
default: '',
},
idmain: {
type: String,
required: false,
default: '',
},
tablesel: {
type: String,
required: false,
default: '',
},
pickup: {
type: Boolean,
required: false,
default: false,
},
2022-11-17 08:10:43 +01:00
nosaveToDb: {
type: Boolean,
required: false,
default: false,
},
notAllowAtChar: {
type: Boolean,
required: false,
default: false,
},
2022-11-17 08:10:43 +01:00
path: {
type: String,
required: false,
default: '',
},
2021-09-16 21:08:02 +02:00
},
components: {
2025-08-12 19:43:36 +02:00
CMyChipList,
CDateTime,
CDateTimeStartEnd,
2025-08-12 19:43:36 +02:00
CDate,
CMyToggleList,
CMySelect,
CMyEditor,
CGallery,
CMyEditorAI,
CCurrencyValue,
CLabel,
CAccomodation,
CSelectImage,
CMapEditAddressByCoord,
CInput,
CPickColor,
},
2021-09-16 21:08:02 +02:00
setup(props, { emit }) {
2025-08-12 19:43:36 +02:00
const $q = useQuasar();
const { t } = useI18n();
const userStore = useUserStore();
const globalStore = useGlobalStore();
2021-09-16 21:08:02 +02:00
2025-08-12 19:43:36 +02:00
const myvalue = ref(null as any);
const myvalue2 = ref(null as any);
2025-08-12 19:43:36 +02:00
const myvalueprec = ref('false');
const countryname = ref('');
const visueditor = ref(false);
const visuhtml = ref(false);
const showeditor = ref(false);
2021-09-16 21:08:02 +02:00
2025-08-12 19:43:36 +02:00
const hoverPreview = ref(false);
2025-08-12 19:43:36 +02:00
const myImgGall = ref([{}] as IImgGallery[]);
2021-11-04 16:02:14 +01:00
2025-08-12 19:43:36 +02:00
const $router = useRouter();
2022-12-10 02:01:26 +01:00
2025-08-12 19:43:36 +02:00
const loaded = ref(false);
const myColor = ref('#FF00AA55'); // Colore con trasparenza iniziale
2025-08-12 19:43:36 +02:00
const popupEditRef = ref(null);
2025-04-11 18:49:42 +02:00
const colorPicker = ref(null);
2025-08-12 19:43:36 +02:00
const addstrrequired = ref('');
2022-11-17 08:10:43 +01:00
const col = ref(<IColGridTable>{
name: 'test',
fieldtype: 0,
2025-08-12 19:43:36 +02:00
showWhen:
costanti.showWhen.NewRec + costanti.showWhen.InEdit + costanti.showWhen.InView,
visible: true,
2022-07-10 01:24:54 +02:00
maxlength: props.mycol ? props.mycol.maxlength : 0,
2025-08-12 19:43:36 +02:00
minlength: props.mycol ? props.mycol.minlength : undefined,
});
2021-11-04 16:02:14 +01:00
const copyToClipboard = (text) => {
2025-08-12 19:43:36 +02:00
navigator.clipboard
.writeText(text)
.then(() => {
$q.notify({
message: 'Testo copiato negli appunti!',
color: 'positive',
icon: 'check',
2025-08-12 19:43:36 +02:00
position: 'top',
});
})
2025-08-12 19:43:36 +02:00
.catch((err) => {
console.error('Errore durante la copia:', err);
$q.notify({
message: 'Errore nella copia',
color: 'negative',
icon: 'error',
2025-08-12 19:43:36 +02:00
position: 'top',
});
});
};
2025-08-12 19:43:36 +02:00
const { setValDb, getValDb } = MixinBase();
const { getMyUsername } = MixinUsers();
2021-11-04 16:02:14 +01:00
2025-08-12 19:43:36 +02:00
const myrealrow = toRef(props, 'row');
2025-08-12 19:43:36 +02:00
watch(
() => props.row,
(newval, oldval) => {
refresh();
}
);
2025-08-12 19:43:36 +02:00
watch(
() => props.rec,
(newval, oldval) => {
refresh();
},
{ deep: true }
);
2025-08-12 19:43:36 +02:00
const myrow = ref(<any>null);
const mypath = ref('');
/* const myrow = computed(() => {
return props.rec && props.isrec ? props.rec : props.row
})
*/
2021-11-04 16:02:14 +01:00
function crea() {
// console.log('crea', isFieldDb(), 'props.mycol', props.mycol)
2021-11-04 16:02:14 +01:00
if (props.mycol && props.mycol.name && props.mycol.name !== 'test') {
2025-08-12 19:43:36 +02:00
col.value = { ...props.mycol };
2021-11-04 16:02:14 +01:00
} else {
if (col.value.name === 'test') {
2025-08-12 19:43:36 +02:00
col.value.name = props.field;
if (props.subfield) {
2025-08-12 19:43:36 +02:00
col.value.name += '.' + props.subfield;
}
}
2025-08-12 19:43:36 +02:00
col.value.jointable = props.jointable;
if (props.filter) col.value.filter = props.filter;
col.value.fieldtype = props.type;
if (props.type === costanti.FieldType.imagerec) {
myImgGall.value = [
{
_id: '',
imagefile: myvalue.value,
vers_img: 1,
alt: 'img',
},
];
} else if (props.type === costanti.FieldType.imgfile_sfuso) {
myImgGall.value = [
{
_id: '',
imagefile: myvalue.value,
vers_img: 1,
alt: 'img',
},
];
2022-11-17 08:10:43 +01:00
} else if (props.type === costanti.FieldType.imgcard) {
2025-08-12 19:43:36 +02:00
myImgGall.value = [myvalue.value];
2022-11-17 08:10:43 +01:00
}
// console.log('* col', col.value);
2022-11-17 08:10:43 +01:00
}
2022-11-17 08:10:43 +01:00
if (props.type) {
2025-08-12 19:43:36 +02:00
col.value.fieldtype = props.type;
2022-11-17 08:10:43 +01:00
}
2022-11-17 08:10:43 +01:00
if (props.isrec) {
} else {
if (isFieldDb()) {
2025-08-12 19:43:36 +02:00
myvalue.value = getValDb(
props.field,
props.serv,
'',
props.table,
props.subfield,
props.id,
props.idmain,
props.indrec,
props.mysubsubkey,
props.specialField
);
myvalue2.value = getValDb(
props.field2,
props.serv,
'',
props.table,
props.subfield2,
props.id,
props.idmain,
props.indrec,
'',
props.specialField
);
} else {
2025-08-12 19:43:36 +02:00
if (props.mycol && props.mycol.name) col.value = { ...props.mycol };
}
2021-11-04 16:02:14 +01:00
}
2025-08-12 19:43:36 +02:00
addstrrequired.value = col.value.required ? '* ' : '';
// console.log('popupedit myvalue.value: ', myvalue.value)
if (props.tablesel) {
// let obj = tools.getParamsByTable(props.table)
// console.log('OBJ:', obj)
if (true) {
// console.log(' CAMPO', props.field + '.' + props.subfield)
2025-08-12 19:43:36 +02:00
const myval = tools.getLabelFooterByRow(
myrow.value,
props.field + '.' + props.subfield,
props.table
);
if (myval) myvalue.value = myval;
// console.log(' RECORD INPUT', myrow.value)
// console.log(' VALORE OUTPUT: ', myvalue.value)
}
}
if (props.path) {
2025-08-12 19:43:36 +02:00
mypath.value = props.path;
} else {
2025-03-01 14:14:43 +01:00
if (tools.existProp(col.value, 'path'))
2025-08-12 19:43:36 +02:00
mypath.value = col.value.path ? col.value.path : '';
}
2021-11-04 16:02:14 +01:00
// console.log('CMyFieldDb crea', myvalue)
}
2025-08-12 19:43:36 +02:00
watch(
() => props.id,
(newval, oldval) => {
crea();
}
);
2021-11-04 16:02:14 +01:00
function isFieldDb() {
2022-11-17 08:10:43 +01:00
// return props.type !== 0
2025-08-12 19:43:36 +02:00
return props.fielddb;
2021-11-04 16:02:14 +01:00
}
2021-09-16 21:08:02 +02:00
function isviewfield() {
2025-08-12 19:43:36 +02:00
return props.view === 'field';
2021-09-16 21:08:02 +02:00
}
function changeval(newval: any) {
2022-09-20 11:14:08 +02:00
// console.log('changeval update:row', newval)
if (!props.isrec) {
2025-08-12 19:43:36 +02:00
emit('update:row', props.row);
}
2025-08-12 19:43:36 +02:00
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) {
2025-08-12 19:43:36 +02:00
newval = newval.value;
2021-09-16 21:08:02 +02:00
}
}
async function addNewValue(value: any) {
// console.log('addNewValue', value, col.value)
if (col.value.allowNewValue && col.value.jointable) {
2025-08-12 19:43:36 +02:00
const myrec: any = {};
2025-08-12 19:43:36 +02:00
const mylabel = fieldsTable.getLabelByTable(col.value.jointable);
myrec[mylabel] = value;
if (col.value.filter_field && props.value_extra) {
2025-08-12 19:43:36 +02:00
myrec[col.value.filter_field] = props.value_extra;
}
// console.log('value_extra', props.value_extra)
if (props.table) {
2025-08-12 19:43:36 +02:00
return await globalStore.saveNewRecord(col.value.jointable, myrec);
}
}
2025-08-12 19:43:36 +02:00
return null;
}
function changeValRecCoordAddr(newval: any) {
// console.log('changeValRecCoordAddr', newval, 'myrow', myrow.value[col.value.name])
if (!myrow.value[col.value.name]) {
2025-08-12 19:43:36 +02:00
myrow.value[col.value.name] = {};
}
if (newval.coordinates && newval.coordinates.lat) {
2025-08-12 19:43:36 +02:00
newval.coordinates.lat = tools.convertToDecimal6(newval.coordinates.lat);
newval.coordinates.lng = tools.convertToDecimal6(newval.coordinates.lng);
}
// console.log('newval...', newval)
2025-08-12 19:43:36 +02:00
return changevalRecOrig(newval);
}
2021-09-16 21:08:02 +02:00
function changevalRec(newval: any) {
2025-08-12 19:43:36 +02:00
return changevalRecOrig(newval, props.subfield);
}
function changevalRecOrig(newval: any, subcol: string = '') {
2025-08-12 19:43:36 +02:00
console.log('changevalRec', newval)
// if (!props.insertMode || (props.insertMode && col.value.fieldtype !== costanti.FieldType.multioption)) {
if (col.value && col.value.allowchar === costanti.ALLOWCHAR_CODE) {
2025-08-12 19:43:36 +02:00
newval = tools.removespaces_slash(newval);
}
if (col.value.fieldtype === costanti.FieldType.username_telegram) {
2025-08-12 19:43:36 +02:00
newval = tools.removeatIniziale(newval);
}
// console.log('popuppedit: changevalRec', newval, 'COLName', col.value.name)
2022-08-30 17:00:32 +02:00
// console.log('row', props.row, 'col', props.mycol, 'newval', newval)
// console.log('row[col.value.name]', props.row[col.value.name])
2025-08-12 19:43:36 +02:00
if (props.type === costanti.FieldType.imagerec) {
// console.log('image', newval)
}
2025-08-12 19:43:36 +02:00
if (props.type === costanti.FieldType.imgfile_sfuso) {
newval = newval?.imagefile
}
if (props.notAllowAtChar) {
2025-08-12 19:43:36 +02:00
newval = tools.rimuoviAtPrimoCarattere(newval);
}
if (subcol) {
2025-08-12 19:43:36 +02:00
const arrcol = col.value.name.split('.');
if (arrcol.length > 0) {
2025-08-12 19:43:36 +02:00
const primo = arrcol[0];
let sec = null;
if (arrcol.length > 1) sec = arrcol[1];
if (sec) {
if (!myrow.value[primo]) {
2025-08-12 19:43:36 +02:00
myrow.value[primo] = {};
}
2025-08-12 19:43:36 +02:00
myrow.value[primo][sec] = newval;
} else {
2025-08-12 19:43:36 +02:00
myrow.value[primo] = newval;
}
/*if (!myrow.value[col.value.name]) {
myrow.value[col.value.name] = {}
}
myrow.value[col.value.name][subcol] = newval*/
// console.log('myrow.value[col.value.name]', myrow.value[col.value.name])
}
} else {
2025-08-12 19:43:36 +02:00
myrow.value[col.value.name] = newval;
}
2022-02-04 23:48:53 +01:00
// console.log('changevalRec update:row', myrow.value)
// emit('update:row', myrow.value)
2025-08-12 19:43:36 +02:00
emit('update_col', col.value.name, newval);
if (props.isInModif) OpenEdit();
2025-08-12 19:43:36 +02:00
emit('save', newval);
// }
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) {
2025-08-12 19:43:36 +02:00
newval = newval.value;
2021-09-16 21:08:02 +02:00
}
2025-08-12 19:43:36 +02:00
changevalRec(newval);
2021-09-16 21:08:02 +02:00
2025-08-12 19:43:36 +02:00
myvalue.value = newval;
2021-09-16 21:08:02 +02:00
}
function updatedata() {
2025-08-12 19:43:36 +02:00
mounted();
2021-09-16 21:08:02 +02:00
}
function mounted() {
//console.log('mounted CMyPopupEdit')
2025-08-12 19:43:36 +02:00
myrow.value = props.rec && props.isrec ? { ...props.rec } : { ...props.row };
// console.log('myrow', myrow.value?.arrvariazioni?.[0])
try {
// console.log('mounted', 'isFieldDb()', myrow.value, 'sub', props.subfield, 'field', props.field)
if (isFieldDb() && !props.isrec) {
// console.log(' . none...')
2021-11-04 16:02:14 +01:00
} else {
if (props.subfield !== '') {
if (myrow.value[props.field] === undefined) {
2025-08-12 19:43:36 +02:00
myrow.value[props.field] = {};
myvalue.value = '';
} else {
2025-08-12 19:43:36 +02:00
myvalue.value = myrow.value[props.field][props.subfield];
}
} else {
2025-08-12 19:43:36 +02:00
let miorecord = myrow.value;
if (props.table === 'arrvariazioni') {
2025-08-12 19:43:36 +02:00
miorecord = myrow.value.arrvariazioni[0];
}
if (props.field !== '') {
myvalue.value = miorecord[props.field];
} else {
2025-08-12 19:43:36 +02:00
myvalue.value = myrow.value;
}
if (props.field2 !== '') {
myvalue2.value = miorecord[props.field2];
}
2021-11-04 16:02:14 +01:00
}
// console.log('props.field', props.field, 'props.subfield', props.subfield, 'myvalue: ', myvalue)
2021-09-16 21:08:02 +02:00
}
if (props.type === costanti.FieldType.verifica && !myvalue.value) {
myvalue.value = {
esito: costanti.VALIDATO.NO,
username: '',
note: '',
2025-08-12 19:43:36 +02:00
};
}
2025-08-12 19:43:36 +02:00
} catch (e) { }
2021-09-16 21:08:02 +02:00
// console.log('popupedit: myvalue.value', myvalue.value)
2021-10-28 00:37:48 +02:00
// console.log('myvalue.value', myvalue.value)
2025-08-12 19:43:36 +02:00
myvalueprec.value = myvalue.value;
2025-08-12 19:43:36 +02:00
crea();
2022-11-17 08:10:43 +01:00
if (!loaded.value) {
if (col.value.fieldtype === costanti.FieldType.listimages) {
if (myvalue.value === '' || myvalue.value === undefined) {
// console.log('set default myvalue.value ')
myvalue.value = {
title: 'Galleria',
directory: 'none',
2025-08-12 19:43:36 +02:00
list: [],
};
}
} else if (col.value.fieldtype === costanti.FieldType.listobj) {
if (myvalue.value === '' || myvalue.value === undefined) {
// console.log('set default myvalue.value ')
2025-08-12 19:43:36 +02:00
myvalue.value = [
{
type: 0, // Letto matrimoniale / letto singolo / divano-letto / almaca / a terra sul tappeto (per sacco a pelo)
location: 0, // in camera privata / in camera condivisa / in soggiorno / in camper / in tenda / in giardino / all'aperto
num: 0,
},
];
}
} else if (col.value.fieldtype === costanti.FieldType.coordinates) {
if (myvalue.value === '' || myvalue.value === undefined) {
// console.log('set default myvalue.value ')
myvalue.value = {
address: '',
2025-08-12 19:43:36 +02:00
coordinates: [0, 0],
};
}
if (!myvalue.value.address) {
2025-08-12 19:43:36 +02:00
myvalue.value.address = '';
}
if (!myvalue.value.coordinates) {
2025-08-12 19:43:36 +02:00
myvalue.value.coordinates = [0, 0];
}
}
}
2025-08-12 19:43:36 +02:00
loaded.value = true;
// console.log('MOUNTED - myvalue.value', myvalue.value)
2021-09-16 21:08:02 +02:00
// console.log('myvalueprec', myvalueprec)
}
function refresh() {
2025-08-12 19:43:36 +02:00
mounted();
}
2021-09-16 21:08:02 +02:00
function OpenEdit() {
// console.log('OpenEdit')
2025-08-12 19:43:36 +02:00
emit('show');
2021-09-16 21:08:02 +02:00
}
2022-05-08 13:19:35 +02:00
function OpenEditDateToday() {
// console.log('OpenEdit')
2025-08-12 19:43:36 +02:00
myvalue.value = new Date();
emit('show');
2022-05-08 13:19:35 +02:00
}
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
async function SaveValueInt(newVal: any, valinitial: any) {
2025-08-12 19:43:36 +02:00
console.log('SaveValueInt', newVal, valinitial);
2021-09-16 21:08:02 +02:00
let copynewval = { ...newVal };
let isEnd = false;
if (copynewval.which === 'start' || copynewval.which === 'end') {
newVal = copynewval.current;
valinitial = copynewval.prev;
if (copynewval.which === 'end') {
isEnd = true;
}
}
if (col.value.fieldtype === costanti.FieldType.verifica) {
2025-08-12 19:43:36 +02:00
newVal.username = userStore.my.username;
newVal.data = tools.getDateNow();
}
if (props.tablesel) {
if (true) {
2025-08-12 19:43:36 +02:00
const mystrcol = '_id';
const mycol = fieldsTable.getColByTable(props.tablesel, mystrcol);
if (mycol) {
2025-08-12 19:43:36 +02:00
if (newVal) newVal = newVal[mystrcol];
}
}
}
if (props.notAllowAtChar) {
2025-08-12 19:43:36 +02:00
newVal = tools.rimuoviAtPrimoCarattere(newVal);
myvalue.value = newVal;
}
2025-08-12 19:43:36 +02:00
console.log('newVal', newVal);
2021-11-04 16:02:14 +01:00
if (isFieldDb()) {
if (isEnd) {
await savefield2(newVal, valinitial, $q);
} else {
await savefield(newVal, valinitial, $q);
}
2021-09-16 21:08:02 +02:00
} else {
let subfield = props.subfield;
let field = props.field;
if (isEnd) {
subfield = props.subfield2;
field = props.field2;
}
2021-11-04 16:02:14 +01:00
// Update value in table memory
if (subfield !== '') {
if (myrow.value[field] === undefined) myrow.value[field] = {};
myrow.value[field][subfield] = newVal;
2021-11-04 16:02:14 +01:00
} else {
if (field !== '') myrow.value[field] = newVal;
else {
if (!props.isrec) {
// @ts-ignore
2025-08-12 19:43:36 +02:00
myrealrow.value = newVal;
}
}
2021-11-04 16:02:14 +01:00
}
2021-09-16 21:08:02 +02:00
}
2025-08-12 19:43:36 +02:00
console.log('SaveValueInt', newVal, valinitial);
emit('save', newVal, valinitial, copynewval.which!);
2021-11-04 16:02:14 +01:00
}
2021-09-16 21:08:02 +02:00
async function savefield(value: any, initialval: any, myq: any) {
if (!props.insertMode) {
let ret = null;
2025-08-12 19:43:36 +02:00
myvalue.value = value;
return tools.saveInDBForTypes(
myq,
props.field,
myvalue.value,
props.type,
props.serv,
props.table,
props.subfield,
props.id,
props.indrec,
props.mysubsubkey,
props.specialField
);
}
2021-09-16 21:08:02 +02:00
}
async function savefield2(value: any, initialval: any, myq: any) {
if (!props.insertMode) {
let ret = null;
myvalue2.value = value;
return tools.saveInDBForTypes(
myq,
props.field2,
myvalue2.value,
props.type,
props.serv,
props.table,
props.subfield2,
props.id,
props.indrec,
props.mysubsubkey,
props.specialField
);
}
}
2021-09-16 21:08:02 +02:00
function annulla(val: any) {
2025-08-12 19:43:36 +02:00
emit('annulla', true);
2021-09-16 21:08:02 +02:00
}
2021-11-04 16:02:14 +01:00
function savefieldboolean(value: any) {
2025-08-12 19:43:36 +02:00
if (myvalue.value === undefined) myvalue.value = 'true';
else myvalue.value = value;
tools.saveInDBForTypes(
$q,
props.field,
myvalue,
props.type,
props.serv,
props.table,
props.subfield,
props.id,
props.indrec,
props.mysubsubkey,
props.specialField
);
2021-11-04 16:02:14 +01:00
}
2021-09-16 21:08:02 +02:00
function Savedb(newVal: any, valinitial: any) {
// console.log('Savedb', newVal)
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) {
2025-08-12 19:43:36 +02:00
newVal = true;
myvalueprec.value = myvalue.value;
myvalue.value = newVal;
2021-09-16 21:08:02 +02:00
}
// console.log('DOPO myvalue', myvalue, newVal, myvalueprec)
}
// console.log('Savedb: type', col.value.fieldtype);
2025-08-12 19:43:36 +02:00
if (col.value.fieldtype === costanti.FieldType.imagerec) {
console.log('newVal.imagefile', newVal);
if (newVal === '') {
myvalue.value = '';
2025-05-11 21:59:16 +02:00
} else {
2025-08-12 19:43:36 +02:00
myvalue.value = newVal;
2025-05-11 21:59:16 +02:00
}
// myvalue.value = tools.getImgFileToSaveByFilename(newVal)
2025-08-12 19:43:36 +02:00
} else if (col.value.fieldtype === costanti.FieldType.imgfile_sfuso) {
console.log('newVal.imagefile', newVal);
if (newVal === '') {
myvalue.value = '';
} else {
myvalue.value = newVal.imagefile;
newVal = tools.getDirUpload() + mypath.value + myvalue.value
}
2022-11-17 08:10:43 +01:00
} else if (col.value.fieldtype === costanti.FieldType.imgcard) {
2025-08-12 19:43:36 +02:00
console.log('newVal.imagefile', newVal);
myvalue.value = newVal;
} else if (col.value.fieldtype === costanti.FieldType.image_and_filename) {
2025-08-12 19:43:36 +02:00
newVal = tools.getDirUpload() + mypath.value + newVal;
console.log('newVal.imagefile', newVal);
myvalue.value = newVal;
2021-11-04 16:02:14 +01:00
}
if (col.value.fieldtype === costanti.FieldType.listobj) {
2025-08-12 19:43:36 +02:00
myvalue.value.accomodation = newVal;
}
// console.log('Savedb', newVal)
2021-09-16 21:08:02 +02:00
2025-08-12 19:43:36 +02:00
emit('showandsave', props.row, props.mycol, newVal, valinitial);
visueditor.value = false;
2021-09-16 21:08:02 +02:00
}
function visuValByType(val: any, col: IColGridTable, row: any) {
2025-08-12 19:43:36 +02:00
if (col === undefined || row === undefined) return;
2021-09-16 21:08:02 +02:00
// 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) {
2025-08-12 19:43:36 +02:00
return '[]';
2021-09-16 21:08:02 +02:00
} else {
2025-08-12 19:43:36 +02:00
return tools.getstrDateTime(val);
2021-09-16 21:08:02 +02:00
}
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) {
2025-08-12 19:43:36 +02:00
return '[]';
2021-09-16 21:08:02 +02:00
} else {
2025-08-12 19:43:36 +02:00
return tools.getstrDate(val);
2021-09-16 21:08:02 +02:00
}
2021-11-04 16:02:14 +01:00
} else if (col.fieldtype === costanti.FieldType.boolean) {
2025-08-12 19:43:36 +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) {
2025-08-12 19:43:36 +02:00
if (val === undefined) return '[---]';
else return globalStore.getArrStrByValueBinary(col, val);
} else if (
col.fieldtype === costanti.FieldType.select ||
col.fieldtype === costanti.FieldType.option
) {
if (val === undefined) return '[---]';
else return globalStore.getValueByTable(col, val);
} else if (
col.fieldtype === costanti.FieldType.nationality ||
col.fieldtype === costanti.FieldType.select_by_server ||
col.fieldtype === costanti.FieldType.multiselect_by_server
) {
if (!val) return '[---]';
else return val;
} else if (col.fieldtype === costanti.FieldType.intcode) {
2025-08-12 19:43:36 +02:00
if (!val) return '[---]';
else return val;
2021-11-04 16:02:14 +01:00
} else if (col.fieldtype === costanti.FieldType.multiselect) {
2025-08-12 19:43:36 +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) {
2025-08-12 19:43:36 +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.password) {
2025-08-12 19:43:36 +02:00
if (val === undefined) return '[---]';
else return '***************';
2021-09-16 21:08:02 +02:00
} else {
2021-12-17 18:30:18 +01:00
if (val === undefined || val === null) {
if (props.canEdit)
2025-08-12 19:43:36 +02:00
return ' <span class="text-grey">(' + t('reg.select') + ')</span> ';
else return '';
2021-12-17 18:30:18 +01:00
} else if (val === '') {
if (props.canEdit)
2025-08-12 19:43:36 +02:00
return ' <span class="text-grey">(' + t('reg.select') + ')</span> ';
else return '';
2021-09-16 21:08:02 +02:00
} else {
2025-08-12 19:43:36 +02:00
let mystr = '';
let mylink = '';
2022-01-03 21:53:41 +01:00
2025-08-12 19:43:36 +02:00
if (col.link) mylink = col.link.replace(col.name, val);
2022-01-03 21:53:41 +01:00
if (col.tipovisu === costanti.TipoVisu.LINK && col.link) {
2025-08-12 19:43:36 +02:00
return "<a href='" + mylink + "'>" + val + '</a>';
2022-01-03 21:53:41 +01:00
} else if (col.tipovisu === costanti.TipoVisu.BUTTON && col.link) {
2025-08-12 19:43:36 +02:00
return '';
2022-01-03 21:53:41 +01:00
}
2021-09-16 21:08:02 +02:00
if (props.showall) {
2025-08-12 19:43:36 +02:00
return val;
2021-09-16 21:08:02 +02:00
} else {
2025-08-12 19:43:36 +02:00
mystr = tools.firstchars(val, tools.MAX_CHARACTERS);
2021-09-16 21:08:02 +02:00
}
if (val) {
2025-08-12 19:43:36 +02:00
if (val.length > tools.MAX_CHARACTERS) mystr += '...';
2021-09-16 21:08:02 +02:00
} else {
2025-08-12 19:43:36 +02:00
return val;
2021-09-16 21:08:02 +02:00
}
2025-08-12 19:43:36 +02:00
return mystr;
2021-09-16 21:08:02 +02:00
}
}
}
2022-11-11 18:16:28 +01:00
function getclassCol(mycol: any) {
if (mycol) {
2025-08-12 19:43:36 +02:00
let myclstr =
mycol.disable || isviewfield() ? '' : props.canEdit ? 'colmodif' : '';
myclstr +=
mycol.fieldtype === costanti.FieldType.date ||
mycol.fieldtype === costanti.FieldType.onlydate
? ' coldate flex flex-container'
: '';
return myclstr;
2021-09-16 21:08:02 +02:00
} else {
2025-08-12 19:43:36 +02:00
return '';
2021-09-16 21:08:02 +02:00
}
}
2021-10-01 19:42:21 +02:00
2021-11-04 16:02:14 +01:00
function mycl() {
if (props.disable) {
2025-08-12 19:43:36 +02:00
return 'cldisable';
2021-11-04 16:02:14 +01:00
}
}
2025-08-12 19:43:36 +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)
2025-08-12 19:43:36 +02:00
myvalueprec.value = myvalue.value;
myvalue.value = iso2;
countryname.value = name;
2021-09-16 21:08:02 +02:00
}
function intcode_change(coderec: any) {
2025-08-12 19:43:36 +02:00
myvalueprec.value = myvalue.value;
myvalue.value = '+' + coderec.dialCode;
2021-09-16 21:08:02 +02:00
}
function onInput(phone: any, phoneObject: any, input: any) {
if (phoneObject?.formatted) {
2025-08-12 19:43:36 +02:00
myvalue.value = phoneObject.formatted;
2021-09-16 21:08:02 +02:00
}
}
2021-11-04 16:02:14 +01:00
function uploaded(info: any) {
if (info.files) {
if (info.files[0].name.imagefile) {
2025-08-12 19:43:36 +02:00
myvalue.value =
tools.geturlrelativeprofile() +
'/' +
getMyUsername() +
'/' +
info.files[0].name.imagefile;
} else {
2025-08-12 19:43:36 +02:00
myvalue.value =
tools.geturlrelativeprofile() +
'/' +
getMyUsername() +
'/' +
info.files[0].name;
}
2025-08-12 19:43:36 +02:00
console.log('uploaded', myvalue.value);
savefield(myvalue.value, '', $q);
2021-11-04 16:02:14 +01:00
}
// info.files[0].name
}
function removephoto() {
2025-08-12 19:43:36 +02:00
myvalue.value = '';
SaveValueInt(myvalue.value, '');
2021-11-04 16:02:14 +01:00
}
2021-12-03 22:47:53 +01:00
function noPopupeditByCol(mycol: IColGridTable) {
2025-08-12 19:43:36 +02:00
return (
mycol.fieldtype !== costanti.FieldType.html &&
mycol.fieldtype !== costanti.FieldType.imagerec &&
mycol.fieldtype !== costanti.FieldType.imgfile_sfuso &&
mycol.fieldtype !== costanti.FieldType.imgcard &&
mycol.fieldtype !== costanti.FieldType.listimages &&
mycol.fieldtype !== costanti.FieldType.listobj &&
mycol.fieldtype !== costanti.FieldType.number
);
2021-12-03 22:47:53 +01:00
}
2022-01-23 23:25:19 +01:00
function getTitleEditor(col: IColGridTable, row: any) {
2025-08-12 19:43:36 +02:00
let title = '';
2025-03-01 14:14:43 +01:00
if (col.field_extra1) {
2022-01-23 23:25:19 +01:00
try {
2025-08-12 19:43:36 +02:00
title = tools.getValue(row, col.field_extra1, col.subfield_extra1);
} catch (e) {}
2022-01-23 23:25:19 +01:00
}
2025-08-12 19:43:36 +02:00
return title;
2022-01-23 23:25:19 +01:00
}
2022-12-10 02:01:26 +01:00
function gotoPage(link: string) {
2025-08-12 19:43:36 +02:00
$router.push(link);
2022-12-10 02:01:26 +01:00
}
function nameKeydown(e: any, col: any) {
if (col.fieldtype === costanti.FieldType.username_telegram) {
2025-08-12 19:43:36 +02:00
if (!/^[a-z0-9_]*$/i.test(e.key)) {
e.preventDefault();
}
} else {
if (col.allowchar === costanti.ALLOWCHAR_CODE) {
if (/^\W$/.test(e.key)) {
e.preventDefault();
}
}
}
}
2022-11-17 08:10:43 +01:00
2025-04-11 18:49:42 +02:00
function handleCancel() {
// Gestisci la chiusura del q-popup-edit
2025-08-12 19:43:36 +02:00
console.log('Chiusura di q-popup-edit');
2025-04-11 18:49:42 +02:00
}
function handleKeydown(event) {
// Interrompi la propagazione del tasto ESC
2025-08-12 19:43:36 +02:00
if (event.key === 'Escape') {
2025-04-11 18:49:42 +02:00
event.stopPropagation();
2025-08-12 19:43:36 +02:00
console.log('Tasto ESC intercettato e bloccato');
2025-04-11 18:49:42 +02:00
popupEditRef.value.hide();
}
}
function updateValidazione(esito: any) {
2025-08-12 19:43:36 +02:00
myvalue.value.esito = esito;
myvalue.value.data = tools.getDateNow();
myvalue.value.username = userStore.my.username;
changevalRec(myvalue.value);
Savedb(myvalue.value, '');
}
2025-08-12 19:43:36 +02:00
onBeforeMount(mounted);
2021-11-04 16:02:14 +01:00
function handleShowAndSave(payload: any) {
Savedb(payload);
changevalRec(payload);
}
function openColorPicker() {
// Apre la finestra del picker
colorPicker.value.openDialog();
}
2021-09-16 21:08:02 +02:00
return {
myvalue,
myvalue2,
2021-09-16 21:08:02 +02:00
countryname,
visueditor,
2022-01-03 21:53:41 +01:00
visuhtml,
2021-09-16 21:08:02 +02:00
showeditor,
isviewfield,
changeval,
changevalRec,
addNewValue,
2021-09-16 21:08:02 +02:00
changevalRecHours,
updatedata,
OpenEdit,
2022-05-08 13:19:35 +02:00
OpenEditDateToday,
2021-09-16 21:08:02 +02:00
SaveValueInt,
annulla,
Savedb,
visuValByType,
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,
2022-01-26 01:31:07 +01:00
userStore,
2021-11-04 16:02:14 +01:00
removephoto,
isFieldDb,
col,
myImgGall,
2021-12-03 22:47:53 +01:00
noPopupeditByCol,
2022-01-23 23:25:19 +01:00
getTitleEditor,
2022-11-18 18:54:30 +01:00
myrow,
2022-11-23 10:27:36 +01:00
shared_consts,
nameKeydown,
2022-12-10 02:01:26 +01:00
gotoPage,
mypath,
changeValRecCoordAddr,
addstrrequired,
2025-04-11 18:49:42 +02:00
t,
handleKeydown,
handleCancel,
popupEditRef,
copyToClipboard,
updateValidazione,
handleShowAndSave,
openColorPicker,
colorPicker,
myColor,
hoverPreview,
2025-08-12 19:43:36 +02:00
};
},
});