From 3efec3325dd9b84e526eda1a2527434554372e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Tue, 29 Sep 2020 13:00:24 +0200 Subject: [PATCH 1/3] revert specific hack for NC when copying data. --- .../nestedcontent/nestedcontent.controller.js | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) 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 2d39e3a4c0..c1db03255f 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 @@ -22,7 +22,9 @@ // Loop through all inner properties: for (var k in obj) { - propClearingMethod(obj[k], clipboardService.TYPES.RAW); + var innerProp = obj[k]; + + propClearingMethod(innerProp, clipboardService.TYPES.RAW); } } } @@ -441,6 +443,26 @@ function clearNodeForCopy(clonedData) { delete clonedData.key; delete clonedData.$$hashKey; + + var variant = clonedData.variants[0]; + 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 we have ncSpecific data, lets revert to standard data model. + if (prop.propertyAlias) { + prop.alias = prop.propertyAlias; + delete prop.propertyAlias; + } + + if(prop.ncMandatory !== undefined) { + prop.validation.mandatory = prop.ncMandatory; + delete prop.ncMandatory; + } + } + } + } vm.showCopy = clipboardService.isSupported(); @@ -466,6 +488,31 @@ // generate a new key. newNode.key = String.CreateGuid(); + // Ensure we have NC data in place: + var variant = newNode.variants[0]; + 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: "" + }; + } + } + } + vm.nodes.push(newNode); setDirty(); //updateModel();// done by setting current node... From ab74d1c5db7993896da49ef326960b0d06929776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Tue, 29 Sep 2020 13:06:38 +0200 Subject: [PATCH 2/3] bringing this back to original. --- .../propertyeditors/nestedcontent/nestedcontent.controller.js | 4 +--- 1 file changed, 1 insertion(+), 3 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 c1db03255f..b7e97099fb 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 @@ -22,9 +22,7 @@ // Loop through all inner properties: for (var k in obj) { - var innerProp = obj[k]; - - propClearingMethod(innerProp, clipboardService.TYPES.RAW); + propClearingMethod(obj[k], clipboardService.TYPES.RAW); } } } 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 3/3] 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];