From 0ea68f4f4285ab632b4bae84ac4a2e287051767f Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 4 Feb 2016 19:40:29 +0100 Subject: [PATCH] added logic for media and member type angular callbacks that existed for content types - assuming this is important and should be there for all content types. Added alias information to validation message returned from server. --- .../src/views/mediatypes/edit.controller.js | 35 +++++++++++++++++-- .../src/views/membertypes/edit.controller.js | 35 +++++++++++++++++-- .../Models/ContentEditing/ContentTypeSave.cs | 2 +- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/mediatypes/edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/mediatypes/edit.controller.js index 10db800151..8ece2cc9f1 100644 --- a/src/Umbraco.Web.UI.Client/src/views/mediatypes/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/mediatypes/edit.controller.js @@ -180,8 +180,39 @@ // type when server side validation fails - as opposed to content where we are capable of saving the content // item if server side validation fails redirectOnFailure: false, - //no-op for rebind callback... we don't really need to rebind for content types - rebindCallback: angular.noop + // we need to rebind... the IDs that have been created! + rebindCallback: function (origContentType, savedContentType) { + vm.contentType.id = savedContentType.id; + vm.contentType.groups.forEach(function (group) { + if (!group.name) return; + + var k = 0; + while (k < savedContentType.groups.length && savedContentType.groups[k].name != group.name) + k++; + if (k == savedContentType.groups.length) { + group.id = 0; + return; + } + + var savedGroup = savedContentType.groups[k]; + if (!group.id) group.id = savedGroup.id; + + group.properties.forEach(function (property) { + if (property.id || !property.alias) return; + + k = 0; + while (k < savedGroup.properties.length && savedGroup.properties[k].alias != property.alias) + k++; + if (k == savedGroup.properties.length) { + property.id = 0; + return; + } + + var savedProperty = savedGroup.properties[k]; + property.id = savedProperty.id; + }); + }); + } }).then(function (data) { //success syncTreeNode(vm.contentType, data.path); diff --git a/src/Umbraco.Web.UI.Client/src/views/membertypes/edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/membertypes/edit.controller.js index ed880da9b3..9c88f79015 100644 --- a/src/Umbraco.Web.UI.Client/src/views/membertypes/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/membertypes/edit.controller.js @@ -129,8 +129,39 @@ // type when server side validation fails - as opposed to content where we are capable of saving the content // item if server side validation fails redirectOnFailure: false, - //no-op for rebind callback... we don't really need to rebind for content types - rebindCallback: angular.noop + // we need to rebind... the IDs that have been created! + rebindCallback: function (origContentType, savedContentType) { + vm.contentType.id = savedContentType.id; + vm.contentType.groups.forEach(function (group) { + if (!group.name) return; + + var k = 0; + while (k < savedContentType.groups.length && savedContentType.groups[k].name != group.name) + k++; + if (k == savedContentType.groups.length) { + group.id = 0; + return; + } + + var savedGroup = savedContentType.groups[k]; + if (!group.id) group.id = savedGroup.id; + + group.properties.forEach(function (property) { + if (property.id || !property.alias) return; + + k = 0; + while (k < savedGroup.properties.length && savedGroup.properties[k].alias != property.alias) + k++; + if (k == savedGroup.properties.length) { + property.id = 0; + return; + } + + var savedProperty = savedGroup.properties[k]; + property.id = savedProperty.id; + }); + }); + } }).then(function (data) { //success syncTreeNode(vm.contentType, data.path); diff --git a/src/Umbraco.Web/Models/ContentEditing/ContentTypeSave.cs b/src/Umbraco.Web/Models/ContentEditing/ContentTypeSave.cs index 5d961487ad..62e1979076 100644 --- a/src/Umbraco.Web/Models/ContentEditing/ContentTypeSave.cs +++ b/src/Umbraco.Web/Models/ContentEditing/ContentTypeSave.cs @@ -91,7 +91,7 @@ namespace Umbraco.Web.Models.ContentEditing var lastProperty = duplicateProperties.Last().Last(); var propertyGroup = Groups.Single(x => x.Properties.Contains(lastProperty)); - yield return new ValidationResult("Duplicate property aliases not allowed", new[] + yield return new ValidationResult("Duplicate property aliases not allowed: " + lastProperty.Alias, new[] { string.Format("Groups[{0}].Properties[{1}].Alias", propertyGroup.SortOrder, lastProperty.SortOrder) });