From a6340bb850f35e648d581f2abee5766a24f9a082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Tue, 29 Sep 2020 14:24:19 +0200 Subject: [PATCH] refactor to one method --- .../nestedcontent/nestedcontent.controller.js | 59 ++++++++----------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/nestedcontent/nestedcontent.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/nestedcontent/nestedcontent.controller.js index b7e97099fb..55e6ba28c8 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/nestedcontent/nestedcontent.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/nestedcontent/nestedcontent.controller.js @@ -491,23 +491,7 @@ for (var t = 0; t < variant.tabs.length; t++) { var tab = variant.tabs[t]; for (var p = 0; p < tab.properties.length; p++) { - var prop = tab.properties[p]; - - if (prop.propertyAlias === undefined) { - prop.propertyAlias = prop.alias; - // NOTE: This is super ugly, the reason it is like this is because it controls the label/html id in the umb-property component at a higher level. - // not pretty :/ but we can't change this now since it would require a bunch of plumbing to be able to change the id's higher up. - prop.alias = model.alias + "___" + prop.alias; - } - - // this is hacky, but we need to make sure we have the right things for the model. - if(prop.ncMandatory === undefined) { - prop.ncMandatory = prop.validation.mandatory; - prop.validation = { - mandatory: false, - pattern: "" - }; - } + extendPropertyWithNCData(tab.properties[p]); } } @@ -622,6 +606,30 @@ } } + function extendPropertyWithNCData(prop) { + + if (prop.propertyAlias === undefined) { + // store the original alias before we change below, see notes + prop.propertyAlias = prop.alias; + + // NOTE: This is super ugly, the reason it is like this is because it controls the label/html id in the umb-property component at a higher level. + // not pretty :/ but we can't change this now since it would require a bunch of plumbing to be able to change the id's higher up. + prop.alias = model.alias + "___" + prop.alias; + } + + // TODO: Do we need to deal with this separately? + // Force validation to occur server side as this is the + // only way we can have consistency between mandatory and + // regex validation messages. Not ideal, but it works. + if(prop.ncMandatory === undefined) { + prop.ncMandatory = prop.validation.mandatory; + prop.validation = { + mandatory: false, + pattern: "" + }; + } + } + function createNode(scaffold, fromNcEntry) { var node = Utilities.copy(scaffold); @@ -635,22 +643,7 @@ for (var p = 0; p < tab.properties.length; p++) { var prop = tab.properties[p]; - // store the original alias before we change below, see notes - prop.propertyAlias = prop.alias; - - // NOTE: This is super ugly, the reason it is like this is because it controls the label/html id in the umb-property component at a higher level. - // not pretty :/ but we can't change this now since it would require a bunch of plumbing to be able to change the id's higher up. - prop.alias = model.alias + "___" + prop.alias; - - // TODO: Do we need to deal with this separately? - // Force validation to occur server side as this is the - // only way we can have consistency between mandatory and - // regex validation messages. Not ideal, but it works. - prop.ncMandatory = prop.validation.mandatory; - prop.validation = { - mandatory: false, - pattern: "" - }; + extendPropertyWithNCData(prop); if (fromNcEntry && fromNcEntry[prop.propertyAlias]) { prop.value = fromNcEntry[prop.propertyAlias];