re-factor / cleanup

This commit is contained in:
2022-01-11 22:08:38 +00:00
parent e871708b20
commit e0be8a7cfe
251 changed files with 14680 additions and 15693 deletions

View File

@@ -13,11 +13,11 @@
<!-- DATETIME -->
<div v-if="item.type === 1">
<gz-date-time-picker
:ref="item.fld"
v-model="_self[item.dataKey]"
:readonly="readonly"
:disabled="disabled"
:label="$ay.t(item.tKey)"
:ref="item.fld"
:data-cy="item.fld"
:error-messages="form().serverErrors(parentVM, item.fld)"
:rules="[
@@ -34,11 +34,11 @@
<!-- DATE -->
<div v-else-if="item.type === 2">
<gz-date-picker
:ref="item.fld"
v-model="_self[item.dataKey]"
:readonly="readonly"
:disabled="disabled"
:label="$ay.t(item.tKey)"
:ref="item.fld"
:data-cy="item.fld"
:error-messages="form().serverErrors(parentVM, item.fld)"
:rules="[
@@ -54,11 +54,11 @@
<!-- TIME -->
<div v-else-if="item.type === 3">
<gz-time-picker
:ref="item.fld"
v-model="_self[item.dataKey]"
:readonly="readonly"
:disabled="disabled"
:label="$ay.t(item.tKey)"
:ref="item.fld"
:data-cy="item.fld"
:error-messages="form().serverErrors(parentVM, item.fld)"
:rules="[
@@ -74,11 +74,11 @@
<!-- TEXT -->
<div v-else-if="item.type === 4">
<v-textarea
:ref="item.fld"
v-model="_self[item.dataKey]"
:readonly="readonly"
:disabled="disabled"
:label="$ay.t(item.tKey)"
:ref="item.fld"
:data-cy="item.fld"
:error-messages="form().serverErrors(parentVM, item.fld)"
:rules="[
@@ -96,11 +96,11 @@
<!-- INTEGER -->
<div v-else-if="item.type === 5">
<v-text-field
:ref="item.fld"
v-model="_self[item.dataKey]"
:readonly="readonly"
:disabled="disabled"
:label="$ay.t(item.tKey)"
:ref="item.fld"
:data-cy="item.fld"
:error-messages="form().serverErrors(parentVM, item.fld)"
:rules="[
@@ -120,11 +120,11 @@
<!-- BOOL -->
<div v-else-if="item.type === 6">
<v-checkbox
:ref="item.fld"
v-model="_self[item.dataKey]"
:readonly="readonly"
:disabled="disabled"
:label="$ay.t(item.tKey)"
:ref="item.fld"
:data-cy="item.fld"
:error-messages="form().serverErrors(parentVM, item.fld)"
:rules="[
@@ -140,11 +140,11 @@
<!-- DECIMAL -->
<div v-else-if="item.type === 7">
<gz-decimal
:ref="item.fld"
v-model="_self[item.dataKey]"
:readonly="readonly"
:disabled="disabled"
:label="$ay.t(item.tKey)"
:ref="item.fld"
:data-cy="item.fld"
:error-messages="form().serverErrors(parentVM, item.fld)"
:rules="[
@@ -160,11 +160,11 @@
<!-- CURRENCY -->
<div v-else-if="item.type === 8">
<gz-currency
:ref="item.fld"
v-model="_self[item.dataKey]"
:readonly="readonly"
:disabled="disabled"
:label="$ay.t(item.tKey)"
:ref="item.fld"
:data-cy="item.fld"
:error-messages="form().serverErrors(parentVM, item.fld)"
:rules="[
@@ -190,10 +190,6 @@
</template>
<script>
export default {
data() {
return {};
},
props: {
value: {
default: "{}",
@@ -208,124 +204,8 @@ export default {
type: Object
}
},
methods: {
form() {
//nothing
return window.$gz.form;
},
fieldValueChanged(ref) {
if (
!this.parentVM.formState.loading &&
!this.parentVM.formState.readonly
) {
window.$gz.form.fieldValueChanged(this.parentVM, ref);
}
},
GetValueForField: function(dataKey) {
let cData = {};
//get the data out of the JSON string value
if (this.value != null) {
cData = JSON.parse(this.value);
}
//Custom field types can be changed by the user and cause old entered data to be invalid for that field type
//Here we need to take action if the data is of an incompatible type for the control field type and attempt to coerce or simply nullify if not co-ercable the data
// - CURRENT TEXT fields could handle any data so they don't need to be changed
// - CURRENT BOOL fields can only handle empty or true false so they would need to be set null
// - CURRENT TIME, DATE, DATETIME are pretty specific but all use a datetime string so any value not datetime like should be nulled
// - CURRENT NUMBER, CURRENCY are also pretty specific but easy to identify if not fully numeric and then sb nulled or attempt to convert then null if not
const ctrlType = this.$store.state.formCustomTemplate[this.formKey].find(
z => z.dataKey == dataKey
).type;
//First get current value for the data that came from the server
let ret = cData[dataKey];
//Only process if value is non-null since all control types can handle null
if (ret != null) {
//check types that matter
/*thes are all types, not necessarily all custom field types
NoType = 0,
DateTime = 1,
Date = 2,
Time = 3,
Text = 4,
Integer = 5,
Bool = 6,
Decimal = 7,
Currency = 8,
Tags = 9,
Enum = 10,
EmailAddress = 11,
HTTP = 12,
InternalId = 13,
MemorySize=14
*/
switch (ctrlType) {
//DateLike?
case 1:
case 2:
case 3:
//can it be parsed into a date using the same library as the components use?
if (!window.$gz.DateTime.fromISO(ret).isValid) {
ret = null;
}
break;
case 6:
//if it's not already a boolean
if (!window.$gz.util.isBoolean(ret)) {
//it's not a bool and it's not null, it came from some other data type,
//perhaps though, it's a truthy string so check for that before giving up and nulling
if (window.$gz.util.isString(ret)) {
ret = window.$gz.util.stringToBoolean(ret);
break;
}
if (ret === 1) {
ret = true;
break;
}
if (ret === 0) {
ret = false;
break;
}
}
break;
case 8:
case 7:
if (!window.$gz.util.isNumeric(ret)) {
ret = window.$gz.util.stringToFloat(ret);
break;
}
break;
}
}
return ret;
},
SetValueForField: function(dataKey, newValue) {
//Get the current data out of the json string value
//
let cData = {};
if (this.value != null) {
cData = JSON.parse(this.value);
}
if (!window.$gz.util.has(cData, dataKey)) {
cData[dataKey] = null;
}
//handle null or undefined
if (newValue === null || newValue === undefined) {
cData[dataKey] = null;
} else {
//then set item in the cData
cData[dataKey] = newValue.toString();
}
this.$emit("input", JSON.stringify(cData));
}
data() {
return {};
},
computed: {
availableCustomFields() {
@@ -474,6 +354,125 @@ export default {
this.SetValueForField("c16", newValue);
}
}
},
methods: {
form() {
//nothing
return window.$gz.form;
},
fieldValueChanged(ref) {
if (
!this.parentVM.formState.loading &&
!this.parentVM.formState.readonly
) {
window.$gz.form.fieldValueChanged(this.parentVM, ref);
}
},
GetValueForField: function(dataKey) {
let cData = {};
//get the data out of the JSON string value
if (this.value != null) {
cData = JSON.parse(this.value);
}
//Custom field types can be changed by the user and cause old entered data to be invalid for that field type
//Here we need to take action if the data is of an incompatible type for the control field type and attempt to coerce or simply nullify if not co-ercable the data
// - CURRENT TEXT fields could handle any data so they don't need to be changed
// - CURRENT BOOL fields can only handle empty or true false so they would need to be set null
// - CURRENT TIME, DATE, DATETIME are pretty specific but all use a datetime string so any value not datetime like should be nulled
// - CURRENT NUMBER, CURRENCY are also pretty specific but easy to identify if not fully numeric and then sb nulled or attempt to convert then null if not
const ctrlType = this.$store.state.formCustomTemplate[this.formKey].find(
z => z.dataKey == dataKey
).type;
//First get current value for the data that came from the server
let ret = cData[dataKey];
//Only process if value is non-null since all control types can handle null
if (ret != null) {
//check types that matter
/*thes are all types, not necessarily all custom field types
NoType = 0,
DateTime = 1,
Date = 2,
Time = 3,
Text = 4,
Integer = 5,
Bool = 6,
Decimal = 7,
Currency = 8,
Tags = 9,
Enum = 10,
EmailAddress = 11,
HTTP = 12,
InternalId = 13,
MemorySize=14
*/
switch (ctrlType) {
//DateLike?
case 1:
case 2:
case 3:
//can it be parsed into a date using the same library as the components use?
if (!window.$gz.DateTime.fromISO(ret).isValid) {
ret = null;
}
break;
case 6:
//if it's not already a boolean
if (!window.$gz.util.isBoolean(ret)) {
//it's not a bool and it's not null, it came from some other data type,
//perhaps though, it's a truthy string so check for that before giving up and nulling
if (window.$gz.util.isString(ret)) {
ret = window.$gz.util.stringToBoolean(ret);
break;
}
if (ret === 1) {
ret = true;
break;
}
if (ret === 0) {
ret = false;
break;
}
}
break;
case 8:
case 7:
if (!window.$gz.util.isNumeric(ret)) {
ret = window.$gz.util.stringToFloat(ret);
break;
}
break;
}
}
return ret;
},
SetValueForField: function(dataKey, newValue) {
//Get the current data out of the json string value
//
let cData = {};
if (this.value != null) {
cData = JSON.parse(this.value);
}
if (!window.$gz.util.has(cData, dataKey)) {
cData[dataKey] = null;
}
//handle null or undefined
if (newValue === null || newValue === undefined) {
cData[dataKey] = null;
} else {
//then set item in the cData
cData[dataKey] = newValue.toString();
}
this.$emit("input", JSON.stringify(cData));
}
}
};
</script>