diff --git a/src/Umbraco.Core/Models/ContentTypeBase.cs b/src/Umbraco.Core/Models/ContentTypeBase.cs index fe2d1a3810..d255cc91a8 100644 --- a/src/Umbraco.Core/Models/ContentTypeBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeBase.cs @@ -329,6 +329,14 @@ namespace Umbraco.Core.Models /// Returns True if a PropertyType with the passed in alias exists, otherwise False public abstract bool PropertyTypeExists(string propertyTypeAlias); + /// + /// Adds a PropertyGroup. + /// This method will also check if a group already exists with the same name and link it to the parent. + /// + /// Name of the PropertyGroup to add + /// Returns True if a PropertyGroup with the passed in name was added, otherwise False + public abstract bool AddPropertyGroup(string groupName); + /// /// Adds a PropertyType to a specific PropertyGroup /// diff --git a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs index 88d11e9851..d7b91c038b 100644 --- a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs @@ -125,6 +125,35 @@ namespace Umbraco.Core.Models return CompositionPropertyTypes.Any(x => x.Alias == propertyTypeAlias); } + /// + /// Adds a PropertyGroup. + /// This method will also check if a group already exists with the same name and link it to the parent. + /// + /// Name of the PropertyGroup to add + /// Returns True if a PropertyGroup with the passed in name was added, otherwise False + public override bool AddPropertyGroup(string groupName) + { + if (PropertyGroups.Any(x => x.Name == groupName)) + return false; + + var propertyGroup = new PropertyGroup {Name = groupName, SortOrder = 0}; + + if (CompositionPropertyGroups.Any(x => x.Name == groupName)) + { + var first = CompositionPropertyGroups.First(x => x.Name == groupName && x.ParentId.HasValue == false); + propertyGroup.ParentId = first.Id; + } + + if (PropertyGroups.Any()) + { + var last = PropertyGroups.Last(); + propertyGroup.SortOrder = last.SortOrder + 1; + } + + PropertyGroups.Add(propertyGroup); + return true; + } + /// /// Adds a PropertyType to a specific PropertyGroup /// diff --git a/src/Umbraco.Core/Models/IContentTypeBase.cs b/src/Umbraco.Core/Models/IContentTypeBase.cs index 41c2938a0a..11a3b8aee6 100644 --- a/src/Umbraco.Core/Models/IContentTypeBase.cs +++ b/src/Umbraco.Core/Models/IContentTypeBase.cs @@ -91,5 +91,13 @@ namespace Umbraco.Core.Models /// to add /// Returns True if PropertyType was added, otherwise False bool AddPropertyType(PropertyType propertyType); + + /// + /// Adds a PropertyGroup. + /// This method will also check if a group already exists with the same name and link it to the parent. + /// + /// Name of the PropertyGroup to add + /// Returns True if a PropertyGroup with the passed in name was added, otherwise False + bool AddPropertyGroup(string groupName); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs b/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs index 4721090614..9449f2c375 100644 --- a/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs @@ -55,6 +55,7 @@ namespace Umbraco.Core.Persistence.Factories HelpText = typeDto.HelpText, Mandatory = typeDto.Mandatory, SortOrder = typeDto.SortOrder, + ValidationRegExp = typeDto.ValidationRegExp, PropertyGroupId = groupDto.Id }; @@ -106,7 +107,8 @@ namespace Umbraco.Core.Persistence.Factories HelpText = propertyType.HelpText, Mandatory = propertyType.Mandatory, Name = propertyType.Name, - SortOrder = propertyType.SortOrder + SortOrder = propertyType.SortOrder, + ValidationRegExp = propertyType.ValidationRegExp }; if (tabId != default(int)) diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs index 5ae358c81f..69cfd0ce25 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs @@ -259,14 +259,6 @@ namespace Umbraco.Core.Persistence.Repositories : Convert.ToInt32(Database.Insert(tabDto)); if (propertyGroup.HasIdentity == false) propertyGroup.Id = groupPrimaryKey; //Set Id on new PropertyGroup - - //Ensure that the PropertyGroup's Id is set on the PropertyTypes within a group - //unless the PropertyGroupId has already been changed. - foreach (var propertyType in propertyGroup.PropertyTypes) - { - if ((propertyType.IsPropertyDirty("PropertyGroupId") && propertyType.PropertyGroupId == 0) == false) - propertyType.PropertyGroupId = propertyGroup.Id; - } } //Run through all PropertyTypes to insert or update entries @@ -337,7 +329,8 @@ namespace Umbraco.Core.Persistence.Repositories Name = dto.Name, HelpText = dto.HelpText, Mandatory = dto.Mandatory, - SortOrder = dto.SortOrder + SortOrder = dto.SortOrder, + ValidationRegExp = dto.ValidationRegExp }).ToList(); //Reset dirty properties diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs index 5fb1e1211b..e9ceb046bc 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs @@ -314,6 +314,7 @@ namespace umbraco.controls if (defaultData != null) { defaultData.PropertyTypeAlias = property.Key; + defaultData.NodeId = _content.Id; } property.Value.DataEditor.Save(); } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs index b8e33be1fc..f4d8d2e6fd 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs @@ -10,6 +10,7 @@ using System.Web.UI.WebControls; using ClientDependency.Core; using Umbraco.Core; using Umbraco.Core.Models; +using umbraco.cms.businesslogic.propertytype; using umbraco.cms.businesslogic.web; using umbraco.cms.helpers; using umbraco.controls.GenericProperties; @@ -17,6 +18,7 @@ using umbraco.IO; using umbraco.presentation; using umbraco.BasePages; using ContentType = umbraco.cms.businesslogic.ContentType; +using PropertyType = Umbraco.Core.Models.PropertyType; namespace umbraco.controls { @@ -394,6 +396,15 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }}); { var tabs = _contentType.getVirtualTabs; var propertyTypeGroups = _contentType.PropertyTypeGroups.ToList(); + /*if (_contentType.ContentTypeItem != null) + { + var compositionIds = _contentType.ContentTypeItem.CompositionIds(); + foreach (var compositionId in compositionIds) + { + var groupsFromContentType = PropertyTypeGroup.GetPropertyTypeGroupsFromContentType(compositionId); + propertyTypeGroups.AddRange(groupsFromContentType); + } + }*/ var dtds = cms.businesslogic.datatype.DataTypeDefinition.GetAll(); PropertyTypes.Controls.Clear(); @@ -405,7 +416,7 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }}); gp = new GenericPropertyWrapper(); gp.ID = "GenericPropertyNew"; gp.Tabs = tabs; - gp.PropertyGroups = propertyTypeGroups; + //gp.PropertyGroups = propertyTypeGroups; gp.DataTypeDefinitions = dtds; PropertyTypeNew.Controls.Add(gp); PropertyTypeNew.Controls.Add(new LiteralControl("")); @@ -415,7 +426,7 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }}); gp = (GenericPropertyWrapper)PropertyTypeNew.Controls[1]; gp.ID = "GenericPropertyNew"; gp.Tabs = tabs; - gp.PropertyGroups = propertyTypeGroups; + //gp.PropertyGroups = propertyTypeGroups; gp.DataTypeDefinitions = dtds; gp.UpdateEditControl(); gp.GenricPropertyControl.UpdateInterface(); @@ -432,7 +443,7 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }}); string tabCaption = tab.ContentType == _contentType.Id ? tab.GetRawCaption() : tab.GetRawCaption() + " (inherited from " + new ContentType(tab.ContentType).Text + ")"; PropertyTypes.Controls.Add(new LiteralControl("

Tab: " + tabCaption + "

")); - var propertyGroup = propertyTypeGroups.SingleOrDefault(x => x.Id == tab.Id || x.ParentId == tab.Id); + var propertyGroup = propertyTypeGroups.SingleOrDefault(x => x.ParentId == tab.Id); var propertyTypes = propertyGroup == null ? tab.GetPropertyTypes(_contentType.Id, false) : propertyGroup.GetPropertyTypes(); @@ -441,7 +452,7 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }}); if (propertyGroup != null && propertyGroup.ParentId > 0) propertyGroupId = propertyGroup.Id; - if (propertyTypes.Any()) + if (propertyTypes.Any(x => x.ContentTypeId == _contentType.Id)) { var propSort = new HtmlInputHidden(); propSort.ID = "propSort_" + propertyGroupId.ToString() + "_Content"; @@ -453,13 +464,13 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }}); foreach (cms.businesslogic.propertytype.PropertyType pt in propertyTypes) { //If the PropertyType doesn't belong on this ContentType skip it and continue to the next one - if(pt.ContentTypeId != _contentType.Id) continue; + //if(pt.ContentTypeId != _contentType.Id) continue; var gpw = new GenericPropertyWrapper(); gpw.ID = "gpw_" + pt.Id; gpw.PropertyType = pt; gpw.Tabs = tabs; - gp.PropertyGroups = propertyTypeGroups; + //gpw.PropertyGroups = propertyTypeGroups; gpw.TabId = propertyGroupId; gpw.DataTypeDefinitions = dtds; gpw.Delete += new EventHandler(gpw_Delete); @@ -535,7 +546,7 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }}); gpw.PropertyType = pt; gpw.Tabs = tabs; - gpw.PropertyGroups = propertyTypeGroups; + //gpw.PropertyGroups = propertyTypeGroups; gpw.DataTypeDefinitions = dtds; gpw.Delete += new EventHandler(gpw_Delete); gpw.FullId = "t_general_Contents_" + pt.Id; @@ -650,11 +661,43 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }}); propertyType.Description = gpw.GenricPropertyControl.Description; propertyType.ValidationRegExp = gpw.GenricPropertyControl.Validation; propertyType.Mandatory = gpw.GenricPropertyControl.Mandatory; - propertyType.PropertyGroupId = gpw.GenricPropertyControl.Tab; propertyType.DataTypeDatabaseType = dataTypeDefinition.DatabaseType; propertyType.DataTypeDefinitionId = dataTypeDefinition.Id; propertyType.DataTypeId = dataTypeDefinition.ControlId; + if (propertyType.PropertyGroupId != gpw.GenricPropertyControl.Tab) + { + if (gpw.GenricPropertyControl.Tab == 0) + { + propertyType.PropertyGroupId = 0; + } + else if (contentTypeItem.PropertyGroups.Any(x => x.Id == gpw.GenricPropertyControl.Tab)) + { + propertyType.PropertyGroupId = gpw.GenricPropertyControl.Tab; + } + else if (contentTypeItem.PropertyGroups.Any(x => x.ParentId == gpw.GenricPropertyControl.Tab)) + { + var propertyGroup = contentTypeItem.PropertyGroups.First(x => x.ParentId == gpw.GenricPropertyControl.Tab); + propertyType.PropertyGroupId = propertyGroup.Id; + } + else + { + if ( + contentTypeItem.CompositionPropertyGroups.Any( + x => x.ParentId == gpw.GenricPropertyControl.Tab)) + { + var propertyGroups = contentTypeItem.CompositionPropertyGroups.Where(x => x.ParentId == gpw.GenricPropertyControl.Tab); + var propertyGroup = propertyGroups.First(); + propertyType.PropertyGroupId = propertyGroup.Id; + } + else + { + var propertyGroup = contentTypeItem.CompositionPropertyGroups.First(x => x.Id == gpw.GenricPropertyControl.Tab); + contentTypeItem.AddPropertyGroup(propertyGroup.Name); + } + } + } + //Is only called to flush cache since gpw.PropertyType.Save() isn't called // clear local cache cms.businesslogic.cache.Cache.ClearCacheItem("UmbracoPropertyTypeCache" + gpw.PropertyType.Id); @@ -961,13 +1004,7 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }}); { if (_contentType.ContentTypeItem is IContentType || _contentType.ContentTypeItem is IMediaType) { - var propertyGroup = new PropertyGroup { Name = txtNewTab.Text }; - if (_contentType.ContentTypeItem.PropertyGroups.Any()) - { - var last = _contentType.ContentTypeItem.PropertyGroups.OrderBy(x => x.SortOrder).Last(); - propertyGroup.SortOrder = last.SortOrder + 1; - } - _contentType.ContentTypeItem.PropertyGroups.Add(propertyGroup); + _contentType.ContentTypeItem.AddPropertyGroup(txtNewTab.Text); _contentType.Save(); } else diff --git a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs index 03851a9341..d72212aa5f 100644 --- a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs +++ b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs @@ -210,6 +210,7 @@ namespace umbraco.cms.businesslogic.datatype } return _nodeId.Value; } + internal set { _nodeId = value; } } #endregion