From aac015dc0b71d48f1a1cf342f957ccf53bf5e715 Mon Sep 17 00:00:00 2001 From: Tom Fulton Date: Mon, 23 Jun 2014 20:58:42 -0400 Subject: [PATCH 1/3] Refactor property aliases for uniqueness Old: archetype-property--- New: archetype-property--- Basically, this adds the archetypePropertyAlias into the mix, to fix a case where you might have the same Archetype nested on a host Archetype twice (ie box 1 links, box 2 links within the same Archetype - there was no uniqueness) It also adds in the Property Alias in place of the Property "Index" (unintended side effect, but seems cool :)) --- app/controllers/controller.js | 4 ++++ app/directives/archetypeproperty.js | 26 ++++++++++++++++++++++++-- app/views/archetype.default.html | 4 ++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/controllers/controller.js b/app/controllers/controller.js index b70426a..b016205 100644 --- a/app/controllers/controller.js +++ b/app/controllers/controller.js @@ -11,6 +11,10 @@ //ini the model $scope.model.value = $scope.model.value || getDefaultModel($scope.model.config); + + // store the umbraco property alias to help generate unique IDs. Hopefully there's a better way to get this in the future :) + $scope.umbracoHostPropertyAlias = $scope.$parent.$parent.model.alias; + init(); //helper to get $eval the labelTemplate diff --git a/app/directives/archetypeproperty.js b/app/directives/archetypeproperty.js index b54dd10..1e21e77 100644 --- a/app/directives/archetypeproperty.js +++ b/app/directives/archetypeproperty.js @@ -55,7 +55,8 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c var config = null; var alias = configFieldsetModel.properties[scope.propertyConfigIndex].alias; var defaultValue = configFieldsetModel.properties[scope.propertyConfigIndex].value; - var umbracoPropertyAlias = scope.umbracoPropertyAlias; + var umbracoPropertyAlias = getUniquePropertyAlias(scope); + propertyAliasParts = []; // initialize container for invalid fieldset property identifiers (store on ngModelCtrl to separate Archetype validations, e.g. when there two Archetype properties on the same document) if(ngModelCtrl.invalidProperties == null) { ngModelCtrl.invalidProperties = []; @@ -155,6 +156,27 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c } } + var getPropertyAlias = function(currentScope) { + if (currentScope == null) + return ""; + if (currentScope.property) + return currentScope.property.alias; + } + + var propertyAliasParts = []; + var getUniquePropertyAlias = function (currentScope) { + var currentPropertyAlias = getPropertyAlias(currentScope); + if (currentPropertyAlias != null) + propertyAliasParts.push(currentPropertyAlias); + + if (currentScope.$parent) + getUniquePropertyAlias(currentScope.$parent); + + var alias = _.unique(propertyAliasParts).reverse().join("-"); + return alias; + }; + + function loadView(view, config, defaultValue, alias, umbracoPropertyAlias, scope, element, ngModelCtrl, validateProperty) { if (view) { @@ -184,7 +206,7 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c scope.model.config = config; //some items need an alias - scope.model.alias = "archetype-property-" + umbracoPropertyAlias + "-" + scope.fieldsetIndex + "-" + scope.propertyConfigIndex; + scope.model.alias = "archetype-property-" + umbracoPropertyAlias + "-" + scope.fieldsetIndex; //watch for changes since there is no two-way binding with the local model.value scope.$watch('model.value', function (newValue, oldValue) { diff --git a/app/views/archetype.default.html b/app/views/archetype.default.html index 13238df..ed6bde7 100644 --- a/app/views/archetype.default.html +++ b/app/views/archetype.default.html @@ -29,7 +29,7 @@
-