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(); }
protected override void CreateChildControls() { if (!string.IsNullOrEmpty(Label)) { Controls.AddAt(0, new Label { Text = Label, CssClass = "editorLabel" }); } foreach (ContentItem item in GetItems()) { CreateItemEditor(item); } var allowedChildren = Parts.GetAllowedDefinitions(ParentItem, ZoneName, Page.User) .Where(d => MinimumType.IsAssignableFrom(d.ItemType)) .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 (ItemDefinition definition in allowedChildren) { var li = CreateControl(dropdownMenu, "li", ""); CreateButton(li, definition); } } base.CreateChildControls(); }
protected override void CreateChildControls() { if (!string.IsNullOrEmpty(Label)) { Controls.AddAt(0, new Label { Text = Label, CssClass = "editorLabel" }); } foreach (ContentItem item in GetItems()) { CreateItemEditor(item); } addPanel.Controls.Add(new Label { Text = Utility.GetLocalResourceString("Add") ?? "Add", CssClass = "addLabel" }); var allowedChildren = Parts.GetAllowedDefinitions(ParentItem, ZoneName, Page.User).ToList(); foreach (ItemDefinition definition in allowedChildren) { if (!MinimumType.IsAssignableFrom(definition.ItemType)) { continue; } var button = new LinkButton { ID = "iel" + ID + "_" + definition.GetDiscriminatorWithTemplateKey().Replace('/', '_'), Text = string.Format("<img src='{0}' alt='ico'/>{1}", definition.IconUrl, definition.Title), ToolTip = definition.ToolTip, CausesValidation = false }; var closureDefinition = definition; button.Command += (s, a) => { ContentItem item = CreateItem(closureDefinition); item.ZoneName = ZoneName; AddedDefinitions.Add(closureDefinition.GetDiscriminatorWithTemplateKey()); CreateItemEditor(item); }; addPanel.Controls.Add(button); } base.CreateChildControls(); }