Tab: " + tabCaption + "
"));
- // zb-00036 #29889 : fix property types getter
- var propertyTypes = t.GetPropertyTypes(cType.Id, false);
+ var propertyGroup = propertyTypeGroups.SingleOrDefault(x => x.Id == tab.Id || x.ParentId == tab.Id);
+ var propertyTypes = propertyGroup == null
+ ? tab.GetPropertyTypes(_contentType.Id, false)
+ : propertyGroup.GetPropertyTypes();
- if (propertyTypes.Length > 0)
+ if (propertyTypes.Any())
{
- HtmlInputHidden propSort = new HtmlInputHidden();
- propSort.ID = "propSort_" + t.Id.ToString() + "_Content";
+ var propSort = new HtmlInputHidden();
+ propSort.ID = "propSort_" + tab.Id.ToString() + "_Content";
PropertyTypes.Controls.Add(propSort);
_sortLists.Add(propSort);
- // zb-00036 #29889 : remove filter, not needed anymore
+ PropertyTypes.Controls.Add(new LiteralControl("
"));
- if (propertyTypes.Count() > 0)
+ foreach (cms.businesslogic.propertytype.PropertyType pt in propertyTypes)
{
- PropertyTypes.Controls.Add(new LiteralControl(""));
+ var gpw = new GenericPropertyWrapper();
+ gpw.ID = "gpw_" + pt.Id;
+ gpw.PropertyType = pt;
+ gpw.Tabs = tabs;
+ gpw.TabId = tab.Id;
+ gpw.DataTypeDefinitions = dtds;
+ gpw.Delete += new EventHandler(gpw_Delete);
+ gpw.FullId = "t_" + tab.Id.ToString() + "_Contents_" + +pt.Id;
- foreach (cms.businesslogic.propertytype.PropertyType pt in propertyTypes)
- {
- GenericProperties.GenericPropertyWrapper gpw = new umbraco.controls.GenericProperties.GenericPropertyWrapper();
+ PropertyTypes.Controls.Add(gpw);
+ _genericProperties.Add(gpw);
+ if (refresh)
+ gpw.GenricPropertyControl.UpdateInterface();
- // Changed by duckie, was:
- // gpw.ID = "gpw_" + editPropertyType.Alias;
- // Which is NOT unique!
- gpw.ID = "gpw_" + pt.Id;
-
- gpw.PropertyType = pt;
- gpw.Tabs = tabs;
- gpw.TabId = t.Id;
- gpw.DataTypeDefinitions = dtds;
- gpw.Delete += new EventHandler(gpw_Delete);
- gpw.FullId = "t_" + t.Id.ToString() + "_Contents_" + +pt.Id;
-
- PropertyTypes.Controls.Add(gpw);
- _genericProperties.Add(gpw);
- if (refresh)
- gpw.GenricPropertyControl.UpdateInterface();
- inTab.Add(pt.Id.ToString(), "");
- counter++;
- hasProperties = true;
- }
-
- PropertyTypes.Controls.Add(new LiteralControl("
"));
+ inTab.Add(pt.Id.ToString(), "");
+ counter++;
+ hasProperties = true;
}
+ PropertyTypes.Controls.Add(new LiteralControl("
"));
+
var jsSortable = @"
(function($) {
var propSortId = ""#" + propSort.ClientID + @""";
@@ -505,26 +488,26 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
// Generic properties tab
counter = 0;
bool propertyTabHasProperties = false;
- PlaceHolder propertiesPH = new PlaceHolder();
+ var propertiesPH = new PlaceHolder();
propertiesPH.ID = "propertiesPH";
PropertyTypes.Controls.Add(new LiteralControl("
Tab: Generic Properties
"));
PropertyTypes.Controls.Add(propertiesPH);
- HtmlInputHidden propSort_gp = new HtmlInputHidden();
+ var propSort_gp = new HtmlInputHidden();
propSort_gp.ID = "propSort_general_Content";
propertiesPH.Controls.Add(propSort_gp);
_sortLists.Add(propSort_gp);
propertiesPH.Controls.Add(new LiteralControl("
"));
- foreach (cms.businesslogic.propertytype.PropertyType pt in cType.PropertyTypes)
+ foreach (cms.businesslogic.propertytype.PropertyType pt in _contentType.PropertyTypes)
{
//This use to be:
//if (pt.ContentTypeId == cType.Id && !inTab.ContainsKey(pt.Id.ToString())
//But seriously, if it's not on a tab the tabId is 0, it's a lot easier to read IMO
- if (pt.ContentTypeId == cType.Id && pt.TabId == 0)
+ if (pt.ContentTypeId == _contentType.Id && pt.TabId == 0)
{
- GenericProperties.GenericPropertyWrapper gpw = new umbraco.controls.GenericProperties.GenericPropertyWrapper();
+ var gpw = new GenericPropertyWrapper();
// Changed by duckie, was:
// gpw.ID = "gpw_" + editPropertyType.Alias;
@@ -547,9 +530,7 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
}
}
-
propertiesPH.Controls.Add(new LiteralControl("
"));
- //propertiesPH.Controls.Add(new LiteralControl(""));
var jsSortable_gp = @"
(function($) {
@@ -575,7 +556,7 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
}
- private void SavePropertyTypes(ref SaveClickEventArgs e, IContentTypeComposition contentTypeItem)
+ private void SavePropertyType(ref SaveClickEventArgs e, IContentTypeComposition contentTypeItem)
{
this.CreateChildControls();
@@ -637,6 +618,8 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
//Loop through the _genericProperties ArrayList and update all existing PropertyTypes
foreach (GenericPropertyWrapper gpw in _genericProperties)
{
+ if(gpw.PropertyType == null) continue;
+
var propertyType = contentTypeItem.PropertyTypes.FirstOrDefault(x => x.Alias == gpw.PropertyType.Alias);
if (propertyType == null) continue;
@@ -654,6 +637,28 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
}
//Update the SortOrder of the PropertyTypes
+ foreach (HtmlInputHidden propSorter in _sortLists)
+ {
+ if (propSorter.Value.Trim() != "")
+ {
+ string tabId = propSorter.ID;
+ // remove leading "propSort_" and trailing "_Content"
+ tabId = tabId.Substring(9, tabId.Length - 9 - 8);
+ // calc the position of the prop SO i.e. after "t_
Contents[]="
+ int propSOPosition = "t_".Length + tabId.Length + "Contents[]=".Length + 1;
+
+ string[] tempSO = propSorter.Value.Split("&".ToCharArray());
+ for (int i = 0; i < tempSO.Length; i++)
+ {
+ string propSO = tempSO[i].Substring(propSOPosition);
+
+ int propertyTypeId = int.Parse(propSO);
+ var propertyType = contentTypeItem.PropertyTypes.FirstOrDefault(x => x.Id == propertyTypeId);
+ if (propertyType == null) continue;
+ propertyType.SortOrder = i;
+ }
+ }
+ }
}
private void SavePropertyTypesLegacy(ref SaveClickEventArgs e)
@@ -666,7 +671,7 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
if (DoesPropertyTypeAliasExist(gpData))
{
cms.businesslogic.propertytype.PropertyType pt =
- cType.AddPropertyType(
+ _contentType.AddPropertyType(
cms.businesslogic.datatype.DataTypeDefinition.GetDataTypeDefinition(gpData.Type),
Casing.SafeAliasWithForcingCheck(gpData.Alias.Trim()), gpData.Name);
pt.Mandatory = gpData.Mandatory;
@@ -675,7 +680,7 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
if (gpData.Tab != 0)
{
- cType.SetTabOnPropertyType(pt, gpData.Tab);
+ _contentType.SetTabOnPropertyType(pt, gpData.Tab);
}
gpData.Clear();
@@ -698,9 +703,9 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
pt.Mandatory = gpw.GenricPropertyControl.Mandatory;
pt.DataTypeDefinition = cms.businesslogic.datatype.DataTypeDefinition.GetDataTypeDefinition(gpw.GenricPropertyControl.Type);
if (gpw.GenricPropertyControl.Tab == 0)
- cType.removePropertyTypeFromTab(pt);
+ _contentType.removePropertyTypeFromTab(pt);
else
- cType.SetTabOnPropertyType(pt, gpw.GenricPropertyControl.Tab);
+ _contentType.SetTabOnPropertyType(pt, gpw.GenricPropertyControl.Tab);
pt.Save();
}
@@ -734,8 +739,8 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
private bool DoesPropertyTypeAliasExist(GenericProperty gpData)
{
- bool hasAlias = cType.getPropertyType(Casing.SafeAliasWithForcingCheck(gpData.Alias.Trim())) != null;
- ContentType ct = cType;
+ bool hasAlias = _contentType.getPropertyType(Casing.SafeAliasWithForcingCheck(gpData.Alias.Trim())) != null;
+ ContentType ct = _contentType;
while (ct.MasterContentType > 0)
{
ct = new ContentType(ct.MasterContentType);
@@ -754,11 +759,25 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
// Delete propertytype from contenttype
if (e.CommandName == "Delete")
{
- //TODO Update Legacy vs New API
int propertyId = int.Parse(e.Item.Cells[0].Text);
- cms.businesslogic.propertytype.PropertyType pt = cms.businesslogic.propertytype.PropertyType.GetPropertyType(propertyId);
- var rawName = pt.GetRawName();
- pt.delete();
+ string rawName = string.Empty;
+
+ if (_contentType.ContentTypeItem is IContentType || _contentType.ContentTypeItem is IMediaType)
+ {
+ var propertyType = _contentType.ContentTypeItem.PropertyTypes.FirstOrDefault(x => x.Id == propertyId);
+ if (propertyType != null && string.IsNullOrEmpty(propertyType.Alias) == false)
+ {
+ rawName = propertyType.Name;
+ _contentType.ContentTypeItem.RemovePropertyType(propertyType.Alias);
+ _contentType.Save();
+ }
+ }
+ else
+ {
+ cms.businesslogic.propertytype.PropertyType pt = cms.businesslogic.propertytype.PropertyType.GetPropertyType(propertyId);
+ rawName = pt.GetRawName();
+ pt.delete();
+ }
RaiseBubbleEvent(new object(), new SaveClickEventArgs("Property ´" + rawName + "´ deleted"));
@@ -771,76 +790,22 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
///
///
///
- protected void gpw_Delete(object sender, System.EventArgs e)
+ protected void gpw_Delete(object sender, EventArgs e)
{
- //TODO Update Legacy vs New API
+ var gpw = (GenericPropertyWrapper)sender;
- var gpw = (GenericProperties.GenericPropertyWrapper)sender;
- var alias = gpw.PropertyType.Alias;
-
- //We have to ensure that the property type is removed from the underlying IContentType object
- if (cType.ContentTypeItem != null)
+ if (_contentType.ContentTypeItem is IContentType || _contentType.ContentTypeItem is IMediaType)
{
- cType.ContentTypeItem.RemovePropertyType(alias);
- cType.Save();
+ _contentType.ContentTypeItem.RemovePropertyType(gpw.PropertyType.Alias);
+ _contentType.Save();
}
- gpw.GenricPropertyControl.PropertyType.delete();//Is this still needed? Maybe for legacy reasons..?
+ gpw.GenricPropertyControl.PropertyType.delete();
- LoadContentType(cType.Id);
- this.BindDataGenericProperties(true);
+ LoadContentType(_contentType.Id);
+ BindDataGenericProperties(true);
}
-
-
- /*public bool HasRows(System.Data.DataView dv)
- {
- return (dv.Count == 0);
- }*/
-
- /*private void dlTabs_ItemCommand(object source, DataListCommandEventArgs e)
- {
- if (e.CommandName == "Delete")
- {
- cType.DeleteVirtualTab(int.Parse(e.CommandArgument.ToString()));
- }
-
- if (e.CommandName == "MoveDown")
- {
- int TabId = int.Parse(e.CommandArgument.ToString());
- foreach (cms.businesslogic.ContentType.TabI t in cType.getVirtualTabs.ToList())
- {
- if (t.Id == TabId)
- {
- t.MoveDown();
- }
- }
- }
-
- if (e.CommandName == "MoveUp")
- {
- int TabId = int.Parse(e.CommandArgument.ToString());
- foreach (cms.businesslogic.ContentType.TabI t in cType.getVirtualTabs.ToList())
- {
- if (t.Id == TabId)
- {
- t.MoveUp();
- }
- }
- }
- bindTabs();
- bindDataGenericProperties(false);
- }*/
-
- /*protected void dlTab_itemdatabound(object sender, DataListItemEventArgs e)
- {
- if (int.Parse(((DataRowView)e.Item.DataItem).Row["propertyTypeGroupId"].ToString()) == 0)
- {
- ((Button)e.Item.FindControl("btnTabDelete")).Visible = false;
- ((Button)e.Item.FindControl("btnTabUp")).Visible = false;
- ((Button)e.Item.FindControl("btnTabDown")).Visible = false;
- }
- }*/
-
+
#endregion
#region "Tab" Pane
@@ -883,9 +848,9 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
dt.Columns.Add("id");
dt.Columns.Add("order");
- foreach (var grp in cType.PropertyTypeGroups)
+ foreach (var grp in _contentType.PropertyTypeGroups)
{
- if (grp.ContentTypeId == cType.Id)
+ if (grp.ContentTypeId == _contentType.Id && grp.ParentId == 0)
{
DataRow dr = dt.NewRow();
dr["name"] = grp.Name;
@@ -913,21 +878,21 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
{
get
{
- if (_DataTypeTable == null)
+ if (_dataTypeTable == null)
{
- _DataTypeTable = new DataTable();
- _DataTypeTable.Columns.Add("name");
- _DataTypeTable.Columns.Add("id");
+ _dataTypeTable = new DataTable();
+ _dataTypeTable.Columns.Add("name");
+ _dataTypeTable.Columns.Add("id");
- foreach (cms.businesslogic.datatype.DataTypeDefinition DataType in cms.businesslogic.datatype.DataTypeDefinition.GetAll())
+ foreach (var dataType in cms.businesslogic.datatype.DataTypeDefinition.GetAll())
{
- DataRow dr = _DataTypeTable.NewRow();
- dr["name"] = DataType.Text;
- dr["id"] = DataType.Id.ToString();
- _DataTypeTable.Rows.Add(dr);
+ DataRow dr = _dataTypeTable.NewRow();
+ dr["name"] = dataType.Text;
+ dr["id"] = dataType.Id.ToString();
+ _dataTypeTable.Rows.Add(dr);
}
}
- return _DataTypeTable;
+ return _dataTypeTable;
}
}
@@ -968,16 +933,31 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }});
{
if (txtNewTab.Text.Trim() != "")
{
- //TODO Update Legacy vs New API
- cType.AddVirtualTab(txtNewTab.Text);
+ if (_contentType.ContentTypeItem is IContentType || _contentType.ContentTypeItem is IMediaType)
+ {
+ var propertyGroup = new PropertyGroup { Name = txtNewTab.Text };
+ if (_contentType.ContentTypeItem.PropertyGroups.Any())
+ {
+ var first = _contentType.ContentTypeItem.PropertyGroups.OrderBy(x => x.SortOrder).First();
+ propertyGroup.SortOrder = first.SortOrder + 1;
+ }
+ _contentType.ContentTypeItem.PropertyGroups.Add(propertyGroup);
+ _contentType.Save();
+ }
+ else
+ {
+ _contentType.AddVirtualTab(txtNewTab.Text);
+ }
+
LoadContentType();
- SaveClickEventArgs ea = new SaveClickEventArgs(ui.Text("contentTypeTabCreated"));
- ea.IconType = umbraco.BasePages.BasePage.speechBubbleIcon.success;
+ var ea = new SaveClickEventArgs(ui.Text("contentTypeTabCreated"));
+ ea.IconType = BasePage.speechBubbleIcon.success;
RaiseBubbleEvent(new object(), ea);
txtNewTab.Text = "";
+
BindTabs();
BindDataGenericProperties(true);
}
@@ -998,11 +978,23 @@ Umbraco.Controls.TabView.onActiveTabChange(function(tabviewid, tabid, tabs) {
{
if (e.CommandName == "Delete")
{
- //TODO Update Legacy vs New API
- cType.DeleteVirtualTab(int.Parse(e.Item.Cells[0].Text));
+ int propertyGroupId = int.Parse(e.Item.Cells[0].Text);
+ if (_contentType.ContentTypeItem is IContentType || _contentType.ContentTypeItem is IMediaType)
+ {
+ var propertyGroup = _contentType.ContentTypeItem.PropertyGroups.FirstOrDefault(x => x.Id == propertyGroupId);
+ if (propertyGroup != null && string.IsNullOrEmpty(propertyGroup.Name) == false)
+ {
+ _contentType.ContentTypeItem.PropertyGroups.Remove(propertyGroup.Name);
+ _contentType.Save();
+ }
+ }
+ else
+ {
+ _contentType.DeleteVirtualTab(propertyGroupId);
+ }
- SaveClickEventArgs ea = new SaveClickEventArgs(ui.Text("contentTypeTabDeleted"));
- ea.IconType = umbraco.BasePages.BasePage.speechBubbleIcon.success;
+ var ea = new SaveClickEventArgs(ui.Text("contentTypeTabDeleted"));
+ ea.IconType = BasePage.speechBubbleIcon.success;
RaiseBubbleEvent(new object(), ea);
diff --git a/src/umbraco.cms/businesslogic/Content.cs b/src/umbraco.cms/businesslogic/Content.cs
index 6b8852e1de..012b2759ef 100644
--- a/src/umbraco.cms/businesslogic/Content.cs
+++ b/src/umbraco.cms/businesslogic/Content.cs
@@ -673,7 +673,7 @@ namespace umbraco.cms.businesslogic
continue;
//get the propertyId
- var property = propData.LastOrDefault(x => x.PropertyTypeId == pt.Id);
+ var property = propData.SingleOrDefault(x => x.PropertyTypeId == pt.Id);
if (property == null)
{
//continue;