public virtual void Render(TextWriter writer) { foreach (var child in PartsAdapter.GetItemsInZone(CurrentItem, ZoneName)) { RenderTemplate(writer, child); } }
protected virtual void AddChildItem(Control container, ContentItem item) { if (AddingChild != null) { AddingChild.Invoke(this, new ItemEventArgs(item)); } Control addedControl; if (GettingItemTemplate != null) { TemplateUrlEventArgs args = new TemplateUrlEventArgs(item); GettingItemTemplate(this, args); if (string.IsNullOrEmpty(args.TemplateUrl)) { addedControl = PartsAdapter.AddChildPart(item, container); } else { addedControl = PartsAdapter.AddUserControl(args.TemplateUrl, container, args.Item); } } else { addedControl = PartsAdapter.AddChildPart(item, container); } if (AddedItemTemplate != null) { AddedItemTemplate.Invoke(this, new ControlEventArgs(addedControl)); } }
public void CanResolve_PossibleChildren() { PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(pageItem); IEnumerable <ItemDefinition> items = controller.GetAllowedDefinitions(pageItem, "Zone1", null); Assert.That(items.Count(), Is.GreaterThan(0)); }
public void CanFilter_ItemsInZone() { PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(pageItem); IEnumerable <ContentItem> items = controller.GetParts(pageItem, "ZoneNone", Interfaces.Viewing); Assert.That(items.Count(), Is.EqualTo(0)); }
public void CanAddTo_ItemsInZone() { PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(pageItem); IEnumerable <ContentItem> items = controller.GetItemsInZone(pageItem, "ZoneAll"); Assert.That(items.Count(), Is.EqualTo(2)); }
public void Retrieves_ItemsInZone() { PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(customItem); IEnumerable <ContentItem> items = controller.GetParts(customItem, "Zone1", Interfaces.Viewing, ControlPanelState.Unknown); Assert.That(items.Count(), Is.EqualTo(1)); }
public void Retrieves_ItemsInZone() { PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(customItem); IEnumerable <ContentItem> items = controller.GetItemsInZone(customItem, "Zone1"); Assert.That(items.Count(), Is.EqualTo(1)); }
public void CanResolve_PossibleChildrenWithAuthorization() { PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(pageItem); IEnumerable <ItemDefinition> items = controller.GetAllowedDefinitions(pageItem, CreatePrincipal("admin")); Assert.That(items.Count(), Is.EqualTo(7)); items = controller.GetAllowedDefinitions(pageItem, CreatePrincipal("admin", "MyTestRole")); Assert.That(items.Count(), Is.EqualTo(8)); }
public virtual void Render(TextWriter writer) { if (N2.Web.Mvc.Html.RegistrationExtensions.GetRegistrationExpression(Html) != null) { return; } foreach (var child in PartsAdapter.GetParts(CurrentItem, ZoneName, GetInterface())) { RenderTemplate(writer, child); } }
private ItemList GetItems() { ItemListEventArgs args = new ItemListEventArgs(null); OnSelecting(args); if (CurrentItem != null && args.Items == null) { args.Items = new ItemList(PartsAdapter.GetParts(CurrentItem, ZoneName, GetInterface())); } OnSelected(args); OnFiltering(args); return(args.Items); }
/// <summary>Gets part definitions that can be added to the given page.</summary> /// <param name="adapter"></param> /// <param name="item"></param> /// <param name="pageZones"></param> /// <param name="user"></param> /// <returns></returns> public static IEnumerable <ItemDefinition> GetPartDefinitions(PartsAdapter adapter, ContentItem item, IEnumerable <Zone> pageZones, IPrincipal user) { IEnumerable <ItemDefinition> availableDefinitions; if (pageZones == null) { availableDefinitions = adapter.GetAllowedDefinitions(item, user); } else { availableDefinitions = GetPossibleDefinitions(adapter, pageZones, user); } return(availableDefinitions .OrderBy(d => d.SortOrder) .ThenBy(d => d.Title)); }
/// <summary>Gets part definitions that can be added to the given page.</summary> /// <param name="adapter"></param> /// <param name="item"></param> /// <param name="pageZones"></param> /// <param name="user"></param> /// <returns></returns> public static IEnumerable <ItemDefinition> GetPartDefinitions(PartsAdapter adapter, ContentItem item, IEnumerable <Zone> pageZones, IPrincipal user) { IEnumerable <ItemDefinition> availableDefinitions; if (pageZones == null) { availableDefinitions = adapter.GetAllowedDefinitions(item, user); } else { availableDefinitions = GetPossibleDefinitions(adapter, pageZones, user); } return(from x in availableDefinitions orderby x ascending, x.Title ascending select x); }
/// <summary>Gets part definitions that can be added to the given page.</summary> /// <param name="adapter"></param> /// <param name="item"></param> /// <param name="pageZones"></param> /// <param name="user"></param> /// <returns></returns> public static IEnumerable <ItemDefinition> GetPartDefinitions(PartsAdapter adapter, ContentItem item, IEnumerable <Zone> pageZones, IPrincipal user) { IEnumerable <ItemDefinition> availableDefinitions; if (pageZones == null) { availableDefinitions = adapter.GetAllowedDefinitions(item, user); } else { availableDefinitions = GetPossibleDefinitions(adapter, pageZones, user); } var sortedDefinitions = new List <ItemDefinition>(); sortedDefinitions.AddRange(availableDefinitions); sortedDefinitions.Sort(); return(sortedDefinitions); }
protected void RenderReplacingPreviewed(TextWriter writer, string preview) { int itemID; if (int.TryParse(preview, out itemID)) { ContentItem previewedItem = Html.ResolveService <IPersister>().Get(itemID); if (previewedItem != null && previewedItem.VersionOf.HasValue) { foreach (var child in PartsAdapter.GetParts(CurrentItem, ZoneName, GetInterface())) { if (previewedItem.VersionOf.Value == child) { RenderTemplate(writer, previewedItem); } else { RenderTemplate(writer, child); } } } } }
private static List <ItemDefinition> GetPossibleDefinitions(PartsAdapter adapter, IEnumerable <Zone> pageZones, IPrincipal user) { var availableDefinitions = new List <ItemDefinition>(); foreach (Zone z in pageZones) { ContentItem item = z.CurrentItem; string zoneName = z.ZoneName; if (item == null || string.IsNullOrEmpty(zoneName)) { continue; } foreach (ItemDefinition definition in adapter.GetAllowedDefinitions(item, zoneName, user)) { if (!availableDefinitions.Contains(definition)) { availableDefinitions.Add(definition); } } } return(availableDefinitions); }
protected override void CreateItems(Control container) { if (State.IsFlagSet(ControlPanelState.DragDrop) && (AllowExternalManipulation || CurrentItem == CurrentPage || Find.ClosestPage(CurrentItem) == CurrentPage)) { if (ZoneName.IndexOfAny(new[] { '.', ',', ' ', '\'', '"', '\t', '\r', '\n' }) >= 0) { throw new N2Exception("Zone '" + ZoneName + "' contains illegal characters."); } Panel zoneContainer = AddPanel(this, ZoneName + " dropZone"); if (CurrentItem.ID != 0 && !CurrentItem.VersionOf.HasValue) { zoneContainer.Attributes[PartUtilities.PathAttribute] = CurrentItem.Path; } else { zoneContainer.Attributes[PartUtilities.PathAttribute] = Find.ClosestPage(CurrentItem).Path; zoneContainer.Attributes["data-versionKey"] = CurrentItem.GetVersionKey(); zoneContainer.Attributes["data-versionIndex"] = CurrentItem.VersionIndex.ToString(); } zoneContainer.Attributes[PartUtilities.ZoneAttribute] = ZoneName; zoneContainer.Attributes[PartUtilities.AllowedAttribute] = PartUtilities.GetAllowedNames(ZoneName, PartsAdapter.GetAllowedDefinitions(CurrentItem, ZoneName, Page.User)); zoneContainer.ToolTip = GetToolTip(GetDefinition(CurrentItem), ZoneName); base.CreateItems(zoneContainer); } else { base.CreateItems(this); } }
public override void Render(TextWriter writer) { if (state == ControlPanelState.DragDrop) { if (ZoneName.IndexOfAny(new[] { '.', ',', ' ', '\'', '"', '\t', '\r', '\n' }) >= 0) { throw new N2Exception("Zone '" + ZoneName + "' contains illegal characters."); } writer.Write("<div class='" + ZoneName + " dropZone'"); writer.WriteAttribute(PartUtilities.PathAttribute, CurrentItem.Path) .WriteAttribute(PartUtilities.ZoneAttribute, ZoneName) .WriteAttribute(PartUtilities.AllowedAttribute, PartUtilities.GetAllowedNames(ZoneName, PartsAdapter.GetAllowedDefinitions(CurrentItem, ZoneName, Html.ViewContext.HttpContext.User))) .WriteAttribute("title", ZoneTitle ?? DroppableZone.GetToolTip(Html.ResolveService <IDefinitionManager>().GetDefinition(CurrentItem), ZoneName)) .Write(">"); RenderPreview(writer); writer.Write("</div>"); } else if (state == ControlPanelState.Previewing) { RenderPreview(writer); } else { base.Render(writer); } }
public void CanResolve_ZoneAdapter() { PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(pageItem); Assert.That(controller, Is.TypeOf(typeof(PageZoneAdapter))); }
public override void Render(TextWriter writer) { if (writer == null) { throw new NullReferenceException("writer cannot be null"); } if (state.IsFlagSet(ControlPanelState.DragDrop)) { if (String.IsNullOrWhiteSpace(ZoneName)) { throw new N2Exception("Zone name cannot be null, empty, or consist only of whitespace."); } if (ZoneName.IndexOfAny(new[] { '.', ',', ' ', '\'', '"', '\t', '\r', '\n' }) >= 0) { throw new N2Exception("Zone '" + ZoneName + "' contains illegal characters."); } if (CurrentItem == null) { throw new N2Exception("CurrentItem cannot be null"); } var dm = Html.ResolveService <IDefinitionManager>(); if (dm == null) { throw new N2Exception("Failed to resolve the definition manager."); } writer.Write("<div class=\"" + ZoneName + " dropZone\""); if (CurrentItem.ID != 0 && !CurrentItem.VersionOf.HasValue) { writer.WriteAttribute(PartUtilities.PathAttribute, CurrentItem.Path); } else { writer.WriteAttribute(PartUtilities.PathAttribute, (Find.ClosestPage(CurrentItem) ?? CurrentItem).Path); writer.WriteAttribute("data-versionKey", CurrentItem.GetVersionKey()); writer.WriteAttribute("data-versionIndex", CurrentItem.VersionIndex.ToString()); } writer.WriteAttribute(PartUtilities.ZoneAttribute, ZoneName) .WriteAttribute(PartUtilities.AllowedAttribute, PartUtilities.GetAllowedNames(ZoneName, PartsAdapter.GetAllowedDefinitions(CurrentItem, ZoneName, Html.ViewContext.HttpContext.User))) .WriteAttribute("title", ZoneTitle ?? DroppableZone.GetToolTip(dm.GetDefinition(CurrentItem), ZoneName)); writer.Write(">"); RenderPreview(writer); writer.Write("</div>"); } else if (state.IsFlagSet(ControlPanelState.Previewing)) { RenderPreview(writer); } else { base.Render(writer); } }
protected override void CreateItems(Control container) { state = ControlPanel.GetState(Page); if (state == ControlPanelState.DragDrop && (AllowExternalManipulation || CurrentItem == CurrentPage)) { if (ZoneName.IndexOfAny(new[] { '.', ',', ' ', '\'', '"', '\t', '\r', '\n' }) >= 0) { throw new N2Exception("Zone '" + ZoneName + "' contains illegal characters."); } Panel zoneContainer = AddPanel(this, ZoneName + " dropZone"); zoneContainer.Attributes[PartUtilities.PathAttribute] = CurrentItem.Path; zoneContainer.Attributes[PartUtilities.ZoneAttribute] = ZoneName; zoneContainer.Attributes[PartUtilities.AllowedAttribute] = PartUtilities.GetAllowedNames(ZoneName, PartsAdapter.GetAllowedDefinitions(CurrentItem, ZoneName, Page.User)); zoneContainer.ToolTip = GetToolTip(GetDefinition(CurrentItem), ZoneName); base.CreateItems(zoneContainer); } else { base.CreateItems(this); } }