N2.Web.UI.WebControls.ItemEditorList.CreateChildControls C# (CSharp) Method

CreateChildControls() protected method

protected CreateChildControls ( ) : void
return void
        protected override void CreateChildControls()
        {
            if (!string.IsNullOrEmpty(Label))
            {
                Controls.AddAt(0, new Label { Text = Label, CssClass = "editorLabel" });
            }

            foreach (ContentItem item in GetItems())
            {
                CreateItemEditor(item);
            }
			itemEditorsContainer.Attributes["class"] = "item-editor-list-items items-count-" + itemEditorsContainer.Controls.Count;

			var allowedDefinitions = Parts.GetAllowedDefinitions(ParentItem, ZoneName, Page.User);
			allowedDefinitions = allowedDefinitions.Where(d => MinimumType.IsAssignableFrom(d.ItemType));
			allowedDefinitions = allowedDefinitions.WhereAuthorized(Engine.SecurityManager, Engine.RequestContext.User, ParentItem);
            var allowedChildren = allowedDefinitions.SelectMany(d => Parts.GetTemplates(ParentItem, d))
				.WhereAllowed(ParentItem, ZoneName, Engine.RequestContext.User, Engine.Definitions, Engine.SecurityManager)
                .ToList();
			if (AllowedTemplateKeys != null)
				allowedChildren = allowedChildren.Where(td => AllowedTemplateKeys.Contains(td.Name)).ToList();
            if (allowedChildren.Count == 0)
            {
                var alert = CreateControl(addPanel, "div", "alert");
                alert.InnerHtml = "Cannot add any parts due to zone/user/type restrictions";
            }
            else if (allowedChildren.Count == 1)
            {
                var btn = CreateButton(addPanel, allowedChildren[0]);
                btn.CssClass = "btn";
            }
            else
            {
                var btnGroup = CreateControl(addPanel, "div", "btn-group");
                var toggle = CreateControl(btnGroup, "a", "btn dropdown-toggle");
                toggle.Attributes["data-toggle"] = "dropdown";
                toggle.Attributes["href"] = "#";
                toggle.InnerHtml = "<b class='fa fa-plus-circle'></b> " + (Utility.GetLocalResourceString("Add") ?? "Add") + " <b class='caret'></b>";

                var dropdownMenu = CreateControl(btnGroup, "ul", "dropdown-menu");

				foreach (var template in allowedChildren)
                {
					var li = CreateControl(dropdownMenu, "li", "");
					CreateButton(li, template);
                }
            }

            base.CreateChildControls();
        }