HUGE REFACTOR / CLEANUP
if there is a issue it's probably something in here that was changed
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
/* xeslint-disable */
|
||||
///////////////////////////////
|
||||
// gzform
|
||||
//
|
||||
@@ -31,7 +30,6 @@ function isInt(value) {
|
||||
return false;
|
||||
}
|
||||
x = parseFloat(value);
|
||||
// console.log("isInt:", x);
|
||||
return (x | 0) === x;
|
||||
}
|
||||
|
||||
@@ -47,27 +45,14 @@ function isNumber(n) {
|
||||
// Get control from ref
|
||||
//
|
||||
function getControl(vm, ref) {
|
||||
let ctrl = vm.$refs[ref];
|
||||
// if (vm.$ay.dev) {
|
||||
// // //NOTE: Due to automatic code formatting some refs will come here with newlines in them resulting in no matches
|
||||
// // console.log("ref before is", ref);
|
||||
// // let tref = ref.replace(/\s/g, "");
|
||||
// // console.log("gzform::getcontrol, ref is ", { tref: tref, ref: ref });
|
||||
// if (ctrl == null) {
|
||||
// console.log(`gzform::getControl ref ${ref} not found on form`);
|
||||
// } else {
|
||||
// console.log(`gzform::getControl ref ${ref} *WAS* found on form!`);
|
||||
// }
|
||||
// }
|
||||
return ctrl;
|
||||
return vm.$refs[ref];
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
// Get value from control
|
||||
//
|
||||
function getControlValue(ctrl) {
|
||||
let value = ctrl.value;
|
||||
return value;
|
||||
return ctrl.value;
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
@@ -149,23 +134,23 @@ export default {
|
||||
return true;
|
||||
}
|
||||
|
||||
let ctrl = getControl(vm, ref);
|
||||
const ctrl = getControl(vm, ref);
|
||||
if (typeof ctrl == "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
let value = getControlValue(ctrl);
|
||||
const value = getControlValue(ctrl);
|
||||
if (!isEmpty(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// "ErrorRequiredFieldEmpty": "{0} is a required field. Please enter a value for {0}",
|
||||
let err = vm.$ay.t("ErrorRequiredFieldEmpty");
|
||||
let fieldName = getControlLabel(ctrl);
|
||||
const fieldName = getControlLabel(ctrl);
|
||||
err = err.replace("{0}", fieldName);
|
||||
//replace only replaces first instance so need to do it twice
|
||||
err = err.replace("{0}", fieldName);
|
||||
//Update the form status
|
||||
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: false
|
||||
@@ -180,12 +165,12 @@ export default {
|
||||
if (vm.formState.loading) {
|
||||
return true;
|
||||
}
|
||||
let ctrl = getControl(vm, ref);
|
||||
const ctrl = getControl(vm, ref);
|
||||
if (typeof ctrl == "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
let value = getControlValue(ctrl);
|
||||
const value = getControlValue(ctrl);
|
||||
if (isEmpty(value)) {
|
||||
return true;
|
||||
}
|
||||
@@ -194,10 +179,10 @@ export default {
|
||||
//get the translated rule text
|
||||
// "ErrorFieldLengthExceeded": "{0} can not exceed {1} characters.",
|
||||
let err = vm.$ay.t("ErrorFieldLengthExceeded");
|
||||
let fieldName = getControlLabel(ctrl);
|
||||
const fieldName = getControlLabel(ctrl);
|
||||
err = err.replace("{0}", fieldName);
|
||||
err = err.replace("{1}", max);
|
||||
//Update the form status
|
||||
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: false
|
||||
@@ -224,12 +209,12 @@ export default {
|
||||
if (vm.formState.loading) {
|
||||
return true;
|
||||
}
|
||||
let ctrlStart = getControl(vm, refStart);
|
||||
const ctrlStart = getControl(vm, refStart);
|
||||
if (typeof ctrlStart == "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
let ctrlEnd = getControl(vm, refEnd);
|
||||
const ctrlEnd = getControl(vm, refEnd);
|
||||
if (typeof ctrlEnd == "undefined") {
|
||||
return true;
|
||||
}
|
||||
@@ -255,8 +240,8 @@ export default {
|
||||
|
||||
if (valueStart > valueEnd) {
|
||||
// "ErrorStartDateAfterEndDate": "Start date must be earlier than stop / end date",
|
||||
let err = vm.$ay.t("ErrorStartDateAfterEndDate");
|
||||
//Update the form status
|
||||
const err = vm.$ay.t("ErrorStartDateAfterEndDate");
|
||||
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: false
|
||||
@@ -274,21 +259,21 @@ export default {
|
||||
if (vm.formState.loading) {
|
||||
return true;
|
||||
}
|
||||
let ctrlFirst = getControl(vm, refFirst);
|
||||
const ctrlFirst = getControl(vm, refFirst);
|
||||
if (typeof ctrlFirst == "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
let ctrlSecond = getControl(vm, refSecond);
|
||||
const ctrlSecond = getControl(vm, refSecond);
|
||||
if (typeof ctrlSecond == "undefined") {
|
||||
return true;
|
||||
}
|
||||
let valueFirst = getControlValue(ctrlFirst);
|
||||
let valueSecond = getControlValue(ctrlSecond);
|
||||
const valueFirst = getControlValue(ctrlFirst);
|
||||
const valueSecond = getControlValue(ctrlSecond);
|
||||
|
||||
if (valueFirst != valueSecond) {
|
||||
let err = vm.$ay.t("ErrorNoMatch");
|
||||
//Update the form status
|
||||
const err = vm.$ay.t("ErrorNoMatch");
|
||||
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: false
|
||||
@@ -305,27 +290,15 @@ export default {
|
||||
if (vm.formState.loading) {
|
||||
return true;
|
||||
}
|
||||
let ctrl = getControl(vm, ref);
|
||||
const ctrl = getControl(vm, ref);
|
||||
if (typeof ctrl == "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
let value = getControlValue(ctrl);
|
||||
|
||||
//this block doesn't work and shouldn't be here afaict
|
||||
//if you type a letter for example it presents as empty, I guess because it's set to a numeric input type
|
||||
//in any case, empty isn't a valid integer so it should show as a broken rule when a letter or empty is entered
|
||||
// if (isEmpty(value)) {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
const value = getControlValue(ctrl);
|
||||
if (isInt(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// "ErrorFieldValueNotInteger": "Value must be an integer"
|
||||
let err = vm.$ay.t("ErrorFieldValueNotInteger");
|
||||
//Update the form status
|
||||
const err = vm.$ay.t("ErrorFieldValueNotInteger");
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: false
|
||||
@@ -343,15 +316,12 @@ export default {
|
||||
//TODO: Handle commas and spaces in numbers
|
||||
//as per window.$gz.translation rules for numbers
|
||||
|
||||
let ctrl = getControl(vm, ref);
|
||||
const ctrl = getControl(vm, ref);
|
||||
if (typeof ctrl == "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
//DEBUG
|
||||
//logControl("decimalValid", ctrl, ref);
|
||||
|
||||
let value = getControlValue(ctrl);
|
||||
const value = getControlValue(ctrl);
|
||||
if (isEmpty(value)) {
|
||||
return true;
|
||||
}
|
||||
@@ -360,9 +330,7 @@ export default {
|
||||
return true;
|
||||
}
|
||||
|
||||
// "ErrorFieldValueNotDecimal": "Value must be a number"
|
||||
let err = vm.$ay.t("ErrorFieldValueNotDecimal");
|
||||
//Update the form status
|
||||
const err = vm.$ay.t("ErrorFieldValueNotDecimal");
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: false
|
||||
@@ -380,12 +348,12 @@ export default {
|
||||
return true;
|
||||
}
|
||||
|
||||
let ctrl = getControl(vm, ref);
|
||||
const ctrl = getControl(vm, ref);
|
||||
if (typeof ctrl == "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
let value = getControlValue(ctrl);
|
||||
const value = getControlValue(ctrl);
|
||||
if (isEmpty(value)) {
|
||||
return true;
|
||||
}
|
||||
@@ -399,11 +367,10 @@ export default {
|
||||
return true;
|
||||
}
|
||||
|
||||
// "ErrorFieldValueNumberGreaterThanMax": "Value must be less than XX"
|
||||
let err = `${vm.$ay
|
||||
const err = `${vm.$ay
|
||||
.t("ErrorFieldValueNumberGreaterThanMax")
|
||||
.replace("{0}", maxValue)} ${maxValue}`;
|
||||
//Update the form status
|
||||
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: false
|
||||
@@ -421,12 +388,12 @@ export default {
|
||||
return true;
|
||||
}
|
||||
|
||||
let ctrl = getControl(vm, ref);
|
||||
const ctrl = getControl(vm, ref);
|
||||
if (typeof ctrl == "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
let value = getControlValue(ctrl);
|
||||
const value = getControlValue(ctrl);
|
||||
if (isEmpty(value)) {
|
||||
return true;
|
||||
}
|
||||
@@ -441,11 +408,10 @@ export default {
|
||||
return true;
|
||||
}
|
||||
|
||||
// "ErrorFieldValueNumberLessThanMin": "Value must be more than XX"
|
||||
let err = `${vm.$ay
|
||||
const err = `${vm.$ay
|
||||
.t("ErrorFieldValueNumberLessThanMin")
|
||||
.replace("{0}", minValue)} ${minValue}`;
|
||||
//Update the form status
|
||||
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: false
|
||||
@@ -459,15 +425,12 @@ export default {
|
||||
if (vm.formState.loading) {
|
||||
return true;
|
||||
}
|
||||
let ctrl = getControl(vm, ref);
|
||||
const ctrl = getControl(vm, ref);
|
||||
if (typeof ctrl == "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
//DEBUG
|
||||
//logControl("emailValid", ctrl, ref);
|
||||
|
||||
let value = getControlValue(ctrl);
|
||||
const value = getControlValue(ctrl);
|
||||
if (isEmpty(value)) {
|
||||
return true;
|
||||
}
|
||||
@@ -476,8 +439,8 @@ export default {
|
||||
return true;
|
||||
}
|
||||
|
||||
let err = vm.$ay.t("ErrorAPI2203"); //"Invalid value"
|
||||
//Update the form status
|
||||
const err = vm.$ay.t("ErrorAPI2203"); //"Invalid value"
|
||||
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: false
|
||||
@@ -492,7 +455,7 @@ export default {
|
||||
return true;
|
||||
}
|
||||
|
||||
let template =
|
||||
const template =
|
||||
window.$gz.store.state.formCustomTemplate[vm.formCustomTemplateKey];
|
||||
if (template === undefined) {
|
||||
return true;
|
||||
@@ -500,36 +463,31 @@ export default {
|
||||
//See if control formCustomTemplateFieldName is in server required fields collection
|
||||
//this is a collection of both custom field definitions and standard form fields that are required
|
||||
//since all names are unique can just filter out the one we need by name which will inherently ignore custom fields by default
|
||||
//de-lodash
|
||||
// let templateItem = window.$gz. _.find(template, [
|
||||
// "fld",
|
||||
// formCustomTemplateFieldName
|
||||
// ]);
|
||||
|
||||
let templateItem = template.find(z => z.fld == formCustomTemplateFieldName);
|
||||
const templateItem = template.find(
|
||||
z => z.fld == formCustomTemplateFieldName
|
||||
);
|
||||
|
||||
//templateItem.required
|
||||
if (templateItem === undefined || templateItem.required !== true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let ctrl = getControl(vm, ref);
|
||||
const ctrl = getControl(vm, ref);
|
||||
if (typeof ctrl == "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
let value = getControlValue(ctrl);
|
||||
const value = getControlValue(ctrl);
|
||||
if (!isEmpty(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// "ErrorRequiredFieldEmpty": "{0} is a required field. Please enter a value for {0}",
|
||||
let err = vm.$ay.t("ErrorRequiredFieldEmpty");
|
||||
let fieldName = getControlLabel(ctrl);
|
||||
const fieldName = getControlLabel(ctrl);
|
||||
err = err.replace("{0}", fieldName);
|
||||
//replace only replaces first instance so need to do it twice
|
||||
err = err.replace("{0}", fieldName);
|
||||
//Update the form status
|
||||
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: false
|
||||
@@ -549,18 +507,17 @@ export default {
|
||||
return true;
|
||||
}
|
||||
|
||||
let value = subvm.GetValueForField(templateItem.dataKey);
|
||||
const value = subvm.GetValueForField(templateItem.dataKey);
|
||||
if (!isEmpty(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//It's empty and it's required so return error
|
||||
// "ErrorRequiredFieldEmpty": "{0} is a required field. Please enter a value for {0}",
|
||||
let err = vm.$ay.t("ErrorRequiredFieldEmpty");
|
||||
err = err.replace("{0}", fieldName);
|
||||
//replace only replaces first instance so need to do it twice
|
||||
err = err.replace("{0}", fieldName);
|
||||
//Update the form status
|
||||
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: false
|
||||
@@ -577,14 +534,12 @@ export default {
|
||||
// errors in the UI by Vuetify
|
||||
//
|
||||
serverErrors(vm, ref) {
|
||||
let ret = [];
|
||||
const ret = [];
|
||||
|
||||
//check for errors if we have any errors
|
||||
if (!window.$gz.util.objectIsEmpty(vm.formState.serverError)) {
|
||||
//de-lodash
|
||||
//First let's get the top level error code
|
||||
|
||||
let apiErrorCode = parseInt(vm.formState.serverError.code);
|
||||
const apiErrorCode = parseInt(vm.formState.serverError.code);
|
||||
//Not all server errors mean the form is invalid, exceptions here
|
||||
let formValid = false;
|
||||
|
||||
@@ -616,7 +571,6 @@ export default {
|
||||
err = err + "\r\n" + vm.formState.serverError.message;
|
||||
}
|
||||
|
||||
//Update the form status
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: formValid
|
||||
@@ -629,14 +583,14 @@ export default {
|
||||
//Specific field validation errors are in an array in "details" key
|
||||
if (!window.$gz.util.objectIsEmpty(vm.formState.serverError.details)) {
|
||||
//See if this key is in the details array
|
||||
let errorsForField = getErrorsForField(vm, ref);
|
||||
const errorsForField = getErrorsForField(vm, ref);
|
||||
if (errorsForField.length > 0) {
|
||||
//iterate the errorsForField object and add each to return array of errors
|
||||
//de-lodash
|
||||
//window.$gz. _.each(errorsForField, function(ve) {
|
||||
errorsForField.forEach(function(ve) {
|
||||
let fldErr = "";
|
||||
let fldErrorCode = parseInt(ve.error);
|
||||
const fldErrorCode = parseInt(ve.error);
|
||||
fldErr =
|
||||
vm.$ay.t("ErrorAPI" + fldErrorCode.toString()) +
|
||||
" [" +
|
||||
@@ -657,7 +611,6 @@ export default {
|
||||
}
|
||||
});
|
||||
|
||||
//Update the form status
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: false
|
||||
@@ -772,7 +725,7 @@ export default {
|
||||
vm.formState.appError = null;
|
||||
//clear out actual message box display
|
||||
vm.formState.errorBoxMessage = null;
|
||||
//Update the form status
|
||||
|
||||
this.setFormState({
|
||||
vm: vm,
|
||||
valid: true
|
||||
@@ -783,8 +736,8 @@ export default {
|
||||
// Gather server errors and set the appropriate keys
|
||||
//
|
||||
setErrorBoxErrors(vm) {
|
||||
let errs = this.serverErrors(vm, "generalerror");
|
||||
let ret = getErrorBoxErrors(vm, errs);
|
||||
const errs = this.serverErrors(vm, "generalerror");
|
||||
const ret = getErrorBoxErrors(vm, errs);
|
||||
vm.formState.errorBoxMessage = ret;
|
||||
},
|
||||
///////////////////////////////
|
||||
@@ -796,7 +749,7 @@ export default {
|
||||
//
|
||||
//
|
||||
fieldValueChanged(vm, ref, formReference) {
|
||||
let that = this;
|
||||
const that = this;
|
||||
let formControl = null;
|
||||
if (formReference == undefined) {
|
||||
formControl = vm.$refs.form;
|
||||
@@ -806,9 +759,6 @@ export default {
|
||||
formControl = vm.$refs[formReference];
|
||||
}
|
||||
|
||||
//NOTE: Due to automatic code formatting some refs may come here with newlines in them resulting in no matches
|
||||
// ref = ref.replace(/\s/g, "");
|
||||
|
||||
//dev error on form?
|
||||
if (formControl == null) {
|
||||
if (vm.$ay.dev) {
|
||||
@@ -829,7 +779,7 @@ export default {
|
||||
}
|
||||
|
||||
//# REMOVE SERVER ERRORS FOR THIS FIELD REF
|
||||
let targetRef = ref.toLowerCase();
|
||||
const targetRef = ref.toLowerCase();
|
||||
|
||||
//NOTE: This block of code is meant to remove all detailed server errors where the Target matches the current referenced control
|
||||
//Then it checks to see if there is anything left in details as this might have been all there was and if so removes that whole thing
|
||||
@@ -876,7 +826,7 @@ export default {
|
||||
|
||||
if (targetFieldHasServerError) {
|
||||
triggeringChange = true;
|
||||
let val = vm.obj[ref];
|
||||
const val = vm.obj[ref];
|
||||
vm.obj[ref] = null;
|
||||
vm.obj[ref] = val;
|
||||
triggeringChange = false;
|
||||
@@ -927,12 +877,10 @@ export default {
|
||||
// and temporary ones are stored in session storage and don't persist a refresh
|
||||
//
|
||||
getFormSettings(formKey) {
|
||||
let formSettings = {
|
||||
return {
|
||||
temp: JSON.parse(sessionStorage.getItem(formKey)),
|
||||
saved: window.$gz.store.state.formSettings[formKey]
|
||||
};
|
||||
|
||||
return formSettings;
|
||||
},
|
||||
////////////////////////////////////
|
||||
// Set form settings
|
||||
@@ -940,14 +888,6 @@ export default {
|
||||
// requires object with one or both keys {temp:{...tempformsettings...},saved:{...persistedformsettings...}}
|
||||
//
|
||||
setFormSettings(formKey, formSettings) {
|
||||
// if (window.$gz.dev) {
|
||||
// if (!formSettings.saved && !formSettings.temp) {
|
||||
// throw new Error(
|
||||
// "gzform:setFormSettings - saved AND temp keys are both missing from form data!"
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
if (formSettings.saved) {
|
||||
window.$gz.store.commit("setFormSettings", {
|
||||
formKey: formKey,
|
||||
@@ -962,7 +902,7 @@ export default {
|
||||
// Get last report used from form settings
|
||||
//
|
||||
getLastReport(formKey) {
|
||||
let fs = window.$gz.store.state.formSettings[formKey];
|
||||
const fs = window.$gz.store.state.formSettings[formKey];
|
||||
if (fs == null || fs.lastReport == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -971,12 +911,7 @@ export default {
|
||||
// Set last report used in form settings
|
||||
//
|
||||
setLastReport(formKey, reportSelected) {
|
||||
// console.log("setLastReport called", {
|
||||
// formKey: formKey,
|
||||
// reportSelected: reportSelected
|
||||
// });
|
||||
let fs = window.$gz.store.state.formSettings[formKey];
|
||||
//console.log("setlast report retrieved formsettings is:",fs)
|
||||
if (fs == null) {
|
||||
fs = {};
|
||||
}
|
||||
@@ -1010,8 +945,6 @@ export default {
|
||||
// Get validity of referenced control
|
||||
//
|
||||
controlIsValid(vm, ref) {
|
||||
// //NOTE: Due to automatic code formatting some refs will come here with newlines in them resulting in no matches
|
||||
// ref = ref.replace(/\s/g, "");
|
||||
if (vm.$refs[ref]) {
|
||||
return vm.$refs[ref].valid;
|
||||
}
|
||||
@@ -1023,7 +956,7 @@ export default {
|
||||
controlsAreAllValid(vm, refs) {
|
||||
//if any are not valid return false
|
||||
for (let i = 0; i < refs.length; i++) {
|
||||
let item = refs[i];
|
||||
const item = refs[i];
|
||||
if (vm.$refs[item]) {
|
||||
if (!vm.$refs[item].valid) {
|
||||
return false;
|
||||
@@ -1037,7 +970,7 @@ export default {
|
||||
//
|
||||
handleObjectNotFound(vm) {
|
||||
window.$gz.eventBus.$emit("notify-error", vm.$ay.t("ErrorAPI2010"));
|
||||
// navigate backwards after small delay to show error
|
||||
//after small delay to show error
|
||||
//(the navigate removes the toast notification immediately)
|
||||
setTimeout(function() {
|
||||
vm.$router.go(-1);
|
||||
|
||||
Reference in New Issue
Block a user