diff --git a/src/vitis/client/javascript/externs/formReader/formReaderDrtv.js b/src/vitis/client/javascript/externs/formReader/formReaderDrtv.js index 8bfa3d57fc4fdb53f6c9dad257cfbca34eed7c4c..c015d81f4f7e035217db1b4abecf3d856063fcdf 100644 --- a/src/vitis/client/javascript/externs/formReader/formReaderDrtv.js +++ b/src/vitis/client/javascript/externs/formReader/formReaderDrtv.js @@ -405,6 +405,11 @@ formReader.formReaderDirective = function ($q, formReaderService, propertiesSrvc */ scope['isFieldPresent'] = function (oField, oTab, bCheckButtons) { + // Valeurs dynamiques + if (goog.isDefAndNotNull(oField['dynamic_value'])) { + this['setDynamicValue'](oField); + } + bCheckButtons = goog.isDefAndNotNull(bCheckButtons) ? bCheckButtons : false; // Visible @@ -425,9 +430,9 @@ formReader.formReaderDirective = function ($q, formReaderService, propertiesSrvc } catch (e) { isVisible = false; } - } else if(formReaderService["isCustomTernaryString"](oField["visible"])) { + } else if(formReaderService["isCustomTernaryString"](oField["visible"], true)) { try { - isVisible = scope.$eval(formReaderService["translateCustomTernaryString"](oField["visible"], scope['oFormValues'], scope['sFormDefinitionName'])); + isVisible = scope.$eval(formReaderService["translateCustomTernaryString"](oField["visible"], true, scope['oFormValues'], scope['sFormDefinitionName'])); } catch (e) { isVisible = false; } @@ -486,6 +491,22 @@ formReader.formReaderDirective = function ($q, formReaderService, propertiesSrvc } }; + + scope['setDynamicValue'] = function (oField) { + + var value = formReaderService['getFormValue'](oField['name']); + + if(formReaderService["isCustomTernaryString"](oField["dynamic_value"], false)) { + try { + value = scope.$eval(formReaderService["translateCustomTernaryString"](oField["dynamic_value"], false, scope['oFormValues'], scope['sFormDefinitionName'])); + formReaderService['setFormValue'](oField['name'], value, scope['oFormValues'], scope['sFormDefinitionName']); + } catch (e) { + console.error('error with ternary : ' + oField["dynamic_value"]); + } + } + + } + /** * Determine if the button has to be present * @param {object} oButton diff --git a/src/vitis/client/javascript/externs/formReader/formReaderSrvc.js b/src/vitis/client/javascript/externs/formReader/formReaderSrvc.js index f3baa43a1fde7180abd8099aeeee8cc80fccfaaf..f9f33470ef9ffb65b36b51a89c126b318b2ae467 100644 --- a/src/vitis/client/javascript/externs/formReader/formReaderSrvc.js +++ b/src/vitis/client/javascript/externs/formReader/formReaderSrvc.js @@ -686,10 +686,11 @@ formReader.formReaderService = function ($translate, $rootScope, $q, $log, $time * La chaine de caractère passée est une expression ternaire définie par l'administrateur * ex : "= {{puissance}} == 500" * @param {string} sString Chaine de caractère. + * @param {boolean} bIsCondition Trus si il s'agis d'une condition true/false * @return {boolean} */ - "isCustomTernaryString": function (sString) { - if (goog.isDefAndNotNull(this['translateCustomTernaryString'](sString))) { + "isCustomTernaryString": function (sString, bIsCondition) { + if (goog.isDefAndNotNull(this['translateCustomTernaryString'](sString, bIsCondition))) { return true; } else { return false; @@ -705,7 +706,7 @@ formReader.formReaderService = function ($translate, $rootScope, $q, $log, $time * @param {string} sFormDefinitionName * @return {string} */ - "translateCustomTernaryString": function (sString, oFormValues, sFormDefinitionName) { + "translateCustomTernaryString": function (sString, bIsCondition, oFormValues, sFormDefinitionName) { // Verif type if (!goog.isString(sString)) { @@ -717,10 +718,6 @@ formReader.formReaderService = function ($translate, $rootScope, $q, $log, $time return null; } - if (!goog.isDefAndNotNull(RegExp('==').exec(sString))) { - return null; - } - // Enlève le premier signe "=" sString = sString.substr(1); @@ -762,7 +759,9 @@ formReader.formReaderService = function ($translate, $rootScope, $q, $log, $time } // Ajoute le retour true/false - sString = sString + ' ? true : false'; + if (bIsCondition) { + sString = sString + ' ? true : false'; + } return sString; }, @@ -1267,7 +1266,6 @@ formReader.formReaderService = function ($translate, $rootScope, $q, $log, $time * @returns {string} */ "getFormValue": function (sName) { - $log.info("getFormValue"); if (!goog.isString(sName)) { return null; @@ -1283,14 +1281,56 @@ formReader.formReaderService = function ($translate, $rootScope, $q, $log, $time var sValue = oFormValues[sName.trim()]; - if (goog.isDefAndNotNull(sValue['selectedOption'])) { - if (goog.isDefAndNotNull(sValue['selectedOption']['value'])) { - sValue = sValue['selectedOption']['value']; + if (goog.isDefAndNotNull(sValue)) { + if (goog.isDefAndNotNull(sValue['selectedOption'])) { + if (goog.isDefAndNotNull(sValue['selectedOption']['value'])) { + sValue = sValue['selectedOption']['value']; + } } } return sValue; + }, + /** + * Set a form value + * @param {string} sName + * @param {string} sValue + * @returns {string} + */ + "setFormValue": function (sName, sValue, oFormValues, sFormDefinitionName) { + + if (!goog.isString(sName)) { + return null; + } + + sName = sName.trim(); + + oFormValues = goog.isDefAndNotNull(oFormValues) ? oFormValues : this['oFormValues']; + sFormDefinitionName = goog.isDefAndNotNull(sFormDefinitionName) ? sFormDefinitionName : this['sFormDefinitionName']; + + var oFormValues = oFormValues[sFormDefinitionName]; + + if (!goog.isDefAndNotNull(oFormValues)) { + console.error('oFormValues.sFormDefinitionName not defined'); + return null; + } + + var bIsList = false; + if (goog.isDefAndNotNull(oFormValues[sName])) { + if (goog.isDefAndNotNull(oFormValues[sName]['selectedOption'])) { + if (goog.isDefAndNotNull(oFormValues[sName]['selectedOption']['value'])) { + bIsList = true; + } + } + } + + if (bIsList) { + oFormValues[sName]['selectedOption']['value'] = sValue; + } else { + oFormValues[sName] = sValue; + } + return true; }, /** * Concats all the arguments passed