From 58930cfab58333b9f99b2c2ec9d1d8c5f5abd84b Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 22 Apr 2019 21:28:24 +0000 Subject: [PATCH] --- ayanova/src/api/gzvalidate.js | 130 +++++++++++++++++----------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/ayanova/src/api/gzvalidate.js b/ayanova/src/api/gzvalidate.js index ee97c004..320a15f9 100644 --- a/ayanova/src/api/gzvalidate.js +++ b/ayanova/src/api/gzvalidate.js @@ -43,8 +43,8 @@ function isNumber(n) { //////////////////////////////////// // Get control from ref // -function getControl(v, ref) { - var ctrl = v.$refs[ref]; +function getControl(vm, ref) { + var ctrl = vm.$refs[ref]; return ctrl; } @@ -73,14 +73,14 @@ function getControlLabel(ctrl) { // Get errors for a particular field // from server error collection // -function getErrorsForField(v, ref) { +function getErrorsForField(vm, ref) { var ret = []; if (ref == "errorbox") { - ret = v.$_.filter(v.serverError.details, function(o) { + ret = vm.$_.filter(vm.serverError.details, function(o) { return !o.target; }); } else { - ret = v.$_.filter(v.serverError.details, function(o) { + ret = vm.$_.filter(vm.serverError.details, function(o) { if (!o.target) { return false; } @@ -95,7 +95,7 @@ function getErrorsForField(v, ref) { // ERROR BOX ERRORS // gathers any messages for error box on form which is the generic catch all for non field specific errors from server // and application itself locally -function getErrorBoxErrors(v, errs) { +function getErrorBoxErrors(vm, errs) { var hasErrors = false; var ret = ""; if (errs.length > 0) { @@ -107,9 +107,9 @@ function getErrorBoxErrors(v, errs) { } //any application errors? - if (v.appError) { + if (vm.appError) { hasErrors = true; - ret = v.appError + "\r\n----------\r\n" + ret; + ret = vm.appError + "\r\n----------\r\n" + ret; } if (!hasErrors) { @@ -123,8 +123,8 @@ export default { /////////////////////////////// // REQUIRED // - required(v, ref) { - var ctrl = getControl(v, ref); + required(vm, ref) { + var ctrl = getControl(vm, ref); if (typeof ctrl == "undefined") { return false; } @@ -135,18 +135,18 @@ export default { } // "ErrorRequiredFieldEmpty": "{0} is a required field. Please enter a value for {0}", - var err = v.$gzlocale.get("ErrorRequiredFieldEmpty"); + var err = vm.$gzlocale.get("ErrorRequiredFieldEmpty"); var fieldName = getControlLabel(ctrl); - err = v.$_.replace(err, "{0}", fieldName); + err = vm.$_.replace(err, "{0}", fieldName); //lodash replace only replaces first instance so need to do it twice - err = v.$_.replace(err, "{0}", fieldName); + err = vm.$_.replace(err, "{0}", fieldName); return err; }, /////////////////////////////// // MAXLENGTH // - maxLength(v, ref, max) { - var ctrl = getControl(v, ref); + maxLength(vm, ref, max) { + var ctrl = getControl(vm, ref); if (typeof ctrl == "undefined") { return false; } @@ -159,10 +159,10 @@ export default { if (value.length > max) { //get the localized rule text // "ErrorFieldLengthExceeded": "{0} can not exceed {1} characters.", - var err = v.$gzlocale.get("ErrorFieldLengthExceeded"); + var err = vm.$gzlocale.get("ErrorFieldLengthExceeded"); var fieldName = getControlLabel(ctrl); - err = v.$_.replace(err, "{0}", fieldName); - err = v.$_.replace(err, "{1}", max); + err = vm.$_.replace(err, "{0}", fieldName); + err = vm.$_.replace(err, "{1}", max); return err; } else { return false; @@ -171,20 +171,20 @@ export default { /////////////////////////////// // MAX 255 // - max255(v, ref) { - return this.maxLength(v, ref, 255); + max255(vm, ref) { + return this.maxLength(vm, ref, 255); }, /////////////////////////////// // DatePrecedence // (start date must precede end date) // - datePrecedence(v, refStart, refEnd) { - var ctrlStart = getControl(v, refStart); + datePrecedence(vm, refStart, refEnd) { + var ctrlStart = getControl(vm, refStart); if (typeof ctrlStart == "undefined") { return false; } - var ctrlEnd = getControl(v, refEnd); + var ctrlEnd = getControl(vm, refEnd); if (typeof ctrlEnd == "undefined") { return false; } @@ -199,8 +199,8 @@ export default { return false; } - valueStart = v.$dayjs(valueStart); - valueEnd = v.$dayjs(valueEnd); + valueStart = vm.$dayjs(valueStart); + valueEnd = vm.$dayjs(valueEnd); // if either is not valid. if (!valueStart || !valueEnd) { @@ -209,7 +209,7 @@ export default { if (valueStart.isAfter(valueEnd)) { // "ErrorStartDateAfterEndDate": "Start date must be earlier than stop / end date", - var err = v.$gzlocale.get("ErrorStartDateAfterEndDate"); + var err = vm.$gzlocale.get("ErrorStartDateAfterEndDate"); return err; } else { return false; @@ -218,8 +218,8 @@ export default { /////////////////////////////// // INTEGER IS VALID // - integerValid(v, ref) { - var ctrl = getControl(v, ref); + integerValid(vm, ref) { + var ctrl = getControl(vm, ref); if (typeof ctrl == "undefined") { return false; } @@ -237,7 +237,7 @@ export default { } // "ErrorFieldValueNotInteger": "Value must be an integer" - var err = v.$gzlocale.get("ErrorFieldValueNotInteger"); + var err = vm.$gzlocale.get("ErrorFieldValueNotInteger"); return err; }, @@ -245,11 +245,11 @@ export default { // DECIMAL // Basically anything that can be a number is valid // - decimalValid(v, ref) { + decimalValid(vm, ref) { //TODO: Handle commas and spaces in numbers - //as per v.$gzlocale rules for numbers + //as per vm.$gzlocale rules for numbers - var ctrl = getControl(v, ref); + var ctrl = getControl(vm, ref); if (typeof ctrl == "undefined") { return false; } @@ -267,7 +267,7 @@ export default { } // "ErrorFieldValueNotDecimal": "Value must be a number" - var err = v.$gzlocale.get("ErrorFieldValueNotDecimal"); + var err = vm.$gzlocale.get("ErrorFieldValueNotDecimal"); return err; }, @@ -275,28 +275,28 @@ export default { // SERVER ERRORS // Process and return server errors if any for form and field specified // - serverErrors(v, ref) { + serverErrors(vm, ref) { //CHECK PREREQUISITES IN DEV MODE TO ENSURE FORM ISN"T MISSING NEEDED DATA ATTRIBUTES ETC - if (v.$gzdevmode()) { + if (vm.$gzdevmode()) { //make sure serverErrors is defined on data - if (!v.$_.has(v, "serverError")) { + if (!vm.$_.has(vm, "serverError")) { throw "DEV ERROR gzvalidate::serverErrors -> serverError seems to be missing from form's vue data object"; } //make sure appError is defined on data - if (!v.$_.has(v, "appError")) { + if (!vm.$_.has(vm, "appError")) { throw "DEV ERROR gzvalidate::serverErrors -> appError seems to be missing from form's vue data object"; } //make sure errorBoxMessage is defined on data - if (!v.$_.has(v, "errorBoxMessage")) { + if (!vm.$_.has(vm, "errorBoxMessage")) { throw "DEV ERROR gzvalidate::serverErrors -> errorBoxMessage seems to be missing from form's vue data object"; } //ensure the error returned is in an expected format to catch coding errors at the server end - if (!v.$_.isEmpty(v.serverError)) { + if (!vm.$_.isEmpty(vm.serverError)) { //Make sure there is an error code if there is an error collection - if (!v.serverError.code) { + if (!vm.serverError.code) { throw "DEV ERROR gzvalidate::serverErrors -> server returned error without code"; } } @@ -304,35 +304,35 @@ export default { var ret = []; //check for errors if we have any errors - if (!v.$_.isEmpty(v.serverError)) { + if (!vm.$_.isEmpty(vm.serverError)) { //debugger; //First let's get the top level error code - var apiErrorCode = parseInt(v.serverError.code); + var apiErrorCode = parseInt(vm.serverError.code); //GENERAL ERROR if (ref == "errorbox") { //Add any general errors to ret - var err = v.$gzlocale.get("ErrorAPI" + apiErrorCode.toString()); - if (v.serverError.message) { - err = err + "\r\n" + v.serverError.message; + var err = vm.$gzlocale.get("ErrorAPI" + apiErrorCode.toString()); + if (vm.serverError.message) { + err = err + "\r\n" + vm.serverError.message; } ret.push(err); } //DETAIL ERRORS //{"error":{"code":"2200","details":[{"message":"Exception: Error converting value \"\" to type 'AyaNova.Biz.AUTHORIZATION_ROLES'. Path 'roles', line 1, position 141.","target":"roles","error":"2203"}],"message":"Object did not pass validation"}} //Specific field validation errors are in an array in "details" key - if (!v.$_.isEmpty(v.serverError.details)) { + if (!vm.$_.isEmpty(vm.serverError.details)) { //See if this key is in the details array - var errorsForField = getErrorsForField(v, ref); + var errorsForField = getErrorsForField(vm, ref); if (errorsForField.length > 0) { //iterate the errorsForField object and add each to return array of errors - v.$_.each(errorsForField, function(ve) { + vm.$_.each(errorsForField, function(ve) { var fldErr = ""; var fldErrorCode = parseInt(ve.error); fldErr = - v.$gzlocale.get("ErrorAPI" + fldErrorCode.toString()) + + vm.$gzlocale.get("ErrorAPI" + fldErrorCode.toString()) + " [" + ve.error + "]"; @@ -355,33 +355,33 @@ export default { // ClearServerErrors // Clear all server errors and app errors and ensure error box doesn't show // - deleteAllErrorBoxErrors(v) { + deleteAllErrorBoxErrors(vm) { //clear all keys from server error - v.$gzutil.removeAllPropertiesFromObject(v.serverError); + vm.$gzutil.removeAllPropertiesFromObject(vm.serverError); //clear app errors - v.appError = null; + vm.appError = null; //clear out actual message box display - v.errorBoxMessage = null; + vm.errorBoxMessage = null; }, /////////////////////////////// // setErrorBoxErrors // Gather server errors and set the appropriate keys // - setErrorBoxErrors(v) { - var errs = this.serverErrors(v, "errorbox"); - var ret = getErrorBoxErrors(v, errs); - v.errorBoxMessage = ret; + setErrorBoxErrors(vm) { + var errs = this.serverErrors(vm, "errorbox"); + var ret = getErrorBoxErrors(vm, errs); + vm.errorBoxMessage = ret; }, /////////////////////////////// // On onChange handler // This is required so that server errors can be cleared when input is changed // - onChange(v, ref) { + onChange(vm, ref) { if (triggeringChange) { return; } //If ref appears in the servererrors details collection, remove each one - var m = v.$_.remove(v.serverError.details, function(o) { + var m = vm.$_.remove(vm.serverError.details, function(o) { if (!o.target) { return false; } @@ -389,10 +389,10 @@ export default { }); //If there are no more errors in details then remove the whole thing as it's no longer required - if (v.serverError.details && v.serverError.details.length < 1) { - if (v.serverError.code == "2200") { + if (vm.serverError.details && vm.serverError.details.length < 1) { + if (vm.serverError.code == "2200") { //clear all keys from server error - v.$gzutil.removeAllPropertiesFromObject(v.serverError); + vm.$gzutil.removeAllPropertiesFromObject(vm.serverError); } } @@ -402,9 +402,9 @@ export default { //I added the triggering change guard but it actually doesn't seem to be required here, more investigation is required if (m.length > 0) { triggeringChange = true; - var val = v.obj[ref]; - v.obj[ref] = null; - v.obj[ref] = val; + var val = vm.obj[ref]; + vm.obj[ref] = null; + vm.obj[ref] = val; triggeringChange = false; } }