From e8361c2ab51cf5f30bf6ae7bab8f77ce149a051c Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Fri, 18 Jan 2013 11:45:01 -0100 Subject: [PATCH] Allow specified content types to be created at the root level --- .../controls/ContentTypeControlNew.ascx | 4 + .../controls/ContentTypeControlNew.ascx | 4 + .../controls/ContentTypeControlNew.ascx.cs | 3 + .../ContentTypeControlNew.ascx.designer.cs | 18 ++++ .../umbraco/create/content.ascx.cs | 8 +- .../umbraco/create/media.ascx.cs | 94 ++++++++++--------- 6 files changed, 84 insertions(+), 47 deletions(-) diff --git a/src/Umbraco.Web.UI/umbraco/controls/ContentTypeControlNew.ascx b/src/Umbraco.Web.UI/umbraco/controls/ContentTypeControlNew.ascx index d0d0899bd7..a0588b4516 100644 --- a/src/Umbraco.Web.UI/umbraco/controls/ContentTypeControlNew.ascx +++ b/src/Umbraco.Web.UI/umbraco/controls/ContentTypeControlNew.ascx @@ -78,6 +78,10 @@ + +
+ Only Content Types with this checked can be created at the root level of Content and Media trees +
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx index d0d0899bd7..a0588b4516 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx @@ -78,6 +78,10 @@ + +
+ Only Content Types with this checked can be created at the root level of Content and Media trees +
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 5533eeb599..549ce2657c 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs @@ -296,6 +296,8 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }}); } dualAllowedContentTypes.Value = chosenContentTypeIDs; } + + allowAtRoot.Checked = cType.AllowAtRoot; } private void SaveAllowedChildTypes() @@ -309,6 +311,7 @@ jQuery(document).ready(function() {{ refreshDropDowns(); }}); int[] ids = new int[tmp.Count]; for (int i = 0; i < tmp.Count; i++) ids[i] = (int)tmp[i]; cType.AllowedChildContentTypeIDs = ids; + cType.AllowAtRoot = allowAtRoot.Checked; } #endregion diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.designer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.designer.cs index bc732a166a..465ea3bbca 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.designer.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.designer.cs @@ -255,6 +255,24 @@ namespace umbraco.controls { /// protected global::umbraco.uicontrols.Pane Pane5; + /// + /// pp_Root control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.PropertyPanel pp_Root; + + /// + /// allowAtRoot control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.CheckBox allowAtRoot; + /// /// pp_allowedChildren control. /// diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/content.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/content.ascx.cs index e39bef550f..14347b5c04 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/content.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/content.ascx.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; @@ -35,7 +36,8 @@ namespace umbraco.cms.presentation.create.controls int counter = 0; bool typeInited = false; StringBuilder js = new StringBuilder(); - foreach (DocumentType dt in DocumentType.GetAllAsList()) + var documentTypeList = DocumentType.GetAllAsList().ToList(); + foreach (DocumentType dt in documentTypeList) { string docDescription = "No description available..."; if (dt.Description != null && dt.Description != "") @@ -68,7 +70,9 @@ namespace umbraco.cms.presentation.create.controls counter++; } } - else { + // The Any check is here for backwards compatibility, if none are allowed at root, then all are allowed + else if (documentTypeList.Any(d => d.AllowAtRoot) == false || dt.AllowAtRoot) + { nodeType.Items.Add(li); js.Append("typeInfo[" + counter + "] = '

" + docDescription + "

'\n"); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/media.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/media.ascx.cs index d6b615316a..2149fb1d22 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/media.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/media.ascx.cs @@ -1,17 +1,19 @@ +using System.Linq; + namespace umbraco.cms.presentation.create.controls { - using System; - using System.Web.UI.WebControls; - using umbraco.BasePages; + using System; + using System.Web.UI.WebControls; + using umbraco.BasePages; - /// - /// Summary description for media. - /// - public partial class media : System.Web.UI.UserControl - { + /// + /// Summary description for media. + /// + public partial class media : System.Web.UI.UserControl + { - protected void Page_Load(object sender, System.EventArgs e) + protected void Page_Load(object sender, System.EventArgs e) { sbmt.Text = ui.Text("create"); int NodeId = int.Parse(Request["nodeID"]); @@ -23,7 +25,8 @@ namespace umbraco.cms.presentation.create.controls allowedIds = c.ContentType.AllowedChildContentTypeIDs; } - foreach (var dt in cms.businesslogic.media.MediaType.GetAllAsList()) + var documentTypeList = businesslogic.media.MediaType.GetAllAsList().ToList(); + foreach (var dt in documentTypeList) { ListItem li = new ListItem(); li.Text = dt.Text; @@ -32,47 +35,48 @@ namespace umbraco.cms.presentation.create.controls if (NodeId > 2) { foreach (int i in allowedIds) if (i == dt.Id) nodeType.Items.Add(li); - } - else + } + // The Any check is here for backwards compatibility, if none are allowed at root, then all are allowed + else if (documentTypeList.Any(d => d.AllowAtRoot) == false || dt.AllowAtRoot) nodeType.Items.Add(li); } } - #region Web Form Designer generated code - override protected void OnInit(EventArgs e) - { - // - // CODEGEN: This call is required by the ASP.NET Web Form Designer. - // - InitializeComponent(); - base.OnInit(e); - } - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { + #region Web Form Designer generated code + override protected void OnInit(EventArgs e) + { + // + // CODEGEN: This call is required by the ASP.NET Web Form Designer. + // + InitializeComponent(); + base.OnInit(e); + } - } - #endregion + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { - protected void sbmt_Click(object sender, System.EventArgs e) - { - if (Page.IsValid) - { - string returnUrl = umbraco.presentation.create.dialogHandler_temp.Create( - umbraco.helper.Request("nodeType"), - int.Parse(nodeType.SelectedValue), - int.Parse(Request["nodeID"]), - rename.Text); + } + #endregion - BasePage.Current.ClientTools - .ChangeContentFrameUrl(returnUrl) - .CloseModalWindow(); + protected void sbmt_Click(object sender, System.EventArgs e) + { + if (Page.IsValid) + { + string returnUrl = umbraco.presentation.create.dialogHandler_temp.Create( + umbraco.helper.Request("nodeType"), + int.Parse(nodeType.SelectedValue), + int.Parse(Request["nodeID"]), + rename.Text); - } - } - } + BasePage.Current.ClientTools + .ChangeContentFrameUrl(returnUrl) + .CloseModalWindow(); + + } + } + } }