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("data-id", CurrentItem.ID.ToString()); 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); } }
private static string Definitions(HtmlHelper html, IEngine engine, ContentItem item, ControlPanelState state) { if (state.IsFlagSet(ControlPanelState.DragDrop)) { StringBuilder sb = new StringBuilder(); var a = engine.ResolveAdapter <PartsAdapter>(item); foreach (var d in UI.WebControls.ControlPanel.GetPartDefinitions(a, item, null, html.ViewContext.HttpContext.User)) { foreach (var t in a.GetTemplates(item, d)) { sb.AppendFormat( "<div id='{0}' title='{1}' data-type='{2}' data-template='{3}' class='{4}'>{5}</div>", /*{0}*/ t.Definition.ToString().Replace('/', '-'), /*{1}*/ t.Description, /*{2}*/ t.Definition.Discriminator, /*{3}*/ t.Name, /*{4}*/ "definition " + t.Definition.Discriminator, /*{5}*/ UI.WebControls.ControlPanel.FormatImageAndText(t.Definition.IconUrl, t.Title)); } } if (sb.Length > 0) { return("<div class='definitions'>" + sb + "</div>"); } } return(""); }
protected override void OnInit(System.EventArgs e) { ControlPanelState state = ControlPanel.GetState(Page.GetEngine()); Visible = !state.IsFlagSet(ControlPanelState.Hidden); base.OnInit(e); }
protected override void OnInit(EventArgs e) { State = ControlPanel.GetState(Page.GetEngine()); if (State.IsFlagSet(ControlPanelState.Editing)) { AddEditable(); } else { AddDisplayable(); } }
protected override void OnInit(EventArgs e) { State = ControlPanel.GetState(Page.GetEngine()); if (State.IsFlagSet(ControlPanelState.Editing)) { AddEditable(); } else { AddDisplayable(); } }
public override void Render(TextWriter writer) { if (state.IsFlagSet(ControlPanelState.DragDrop)) { if (ZoneName.IndexOfAny(new[] { '.', ',', ' ', '\'', '"', '\t', '\r', '\n' }) >= 0) { throw new N2Exception("Zone '" + ZoneName + "' contains illegal characters."); } 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).Path) .WriteAttribute("data-versionKey", CurrentItem.GetVersionKey()) .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(Html.ResolveService <IDefinitionManager>().GetDefinition(CurrentItem), ZoneName)); writer.Write(">"); RenderPreview(writer); writer.Write("</div>"); } else if (state.IsFlagSet(ControlPanelState.Previewing)) { RenderPreview(writer); } else { base.Render(writer); } }
/// <summary>Retrieves content items added to a zone of the parnet item.</summary> /// <param name="belowParentItem">The item whose items to get.</param> /// <param name="inZoneNamed">The zone in which the items should be contained.</param> /// <param name="filteredForInterface">Interface where the parts are displayed.</param> /// <param name="state">The control panel state to consider.</param> /// <returns>A list of items in the zone.</returns> public virtual IEnumerable <ContentItem> GetParts(ContentItem belowParentItem, string inZoneNamed, string filteredForInterface, ControlPanelState state) { if (belowParentItem == null) { return(new ItemList()); } var items = belowParentItem.Children.FindParts(inZoneNamed) .Where(new AccessFilter(WebContext.User, Security)); if (filteredForInterface == Interfaces.Viewing && !state.IsFlagSet(ControlPanelState.Previewing) && !belowParentItem.VersionOf.HasValue) { items = items.Where(new PublishedFilter()); } return(items); }
/// <summary>Retrieves content items added to a zone of the parnet item.</summary> /// <param name="belowParentItem">The item whose items to get.</param> /// <param name="inZoneNamed">The zone in which the items should be contained.</param> /// <param name="filteredForInterface">Interface where the parts are displayed.</param> /// <param name="state">The control panel state to consider.</param> /// <returns>A list of items in the zone.</returns> public virtual IEnumerable<ContentItem> GetParts(ContentItem belowParentItem, string inZoneNamed, string filteredForInterface, ControlPanelState state) { if(belowParentItem == null) return new ItemList(); var items = belowParentItem.Children.FindParts(inZoneNamed) .Where(new AccessFilter(WebContext.User, Security)); if(filteredForInterface == Interfaces.Viewing && !state.IsFlagSet(ControlPanelState.Previewing) && !belowParentItem.VersionOf.HasValue) items = items.Where(new PublishedFilter()); return items; }
private static string Definitions(HtmlHelper html, IEngine engine, ContentItem item, ControlPanelState state) { if (state.IsFlagSet(ControlPanelState.DragDrop)) { StringBuilder sb = new StringBuilder(); var a = engine.ResolveAdapter<PartsAdapter>(item); foreach (var d in UI.WebControls.ControlPanel.GetPartDefinitions(a, item, null, html.ViewContext.HttpContext.User)) { foreach (var t in a.GetTemplates(item, d)) { sb.AppendFormat( "<div id='{0}' title='{1}' data-type='{2}' data-template='{3}' class='{4}'>{5}</div>", /*{0}*/ t.Definition.ToString().Replace('/', '-'), /*{1}*/ t.Description, /*{2}*/ t.Definition.Discriminator, /*{3}*/ t.Name, /*{4}*/ "definition " + t.Definition.Discriminator, /*{5}*/ UI.WebControls.ControlPanel.FormatImageAndText(t.Definition.IconUrl, t.Title)); } } if (sb.Length > 0) return "<div class='definitions'>" + sb + "</div>"; } return ""; }
protected virtual bool ActiveFor(Control container, ControlPanelState state) { return state.IsFlagSet(ShowDuring); }
protected override void CreateChildControls() { ControlPanelState state = GetState(Page.GetEngine()); if (state.IsFlagSet(ControlPanelState.Hidden)) { AppendDefinedTemplate(HiddenTemplate, this); return; } Register.StyleSheet(Page, Register.DefaultIconsCssPath); if (state.IsFlagSet(ControlPanelState.Visible)) { AppendDefinedTemplate(VisibleHeaderTemplate, this); } if (state.IsFlagSet(ControlPanelState.DragDrop)) { AppendDefinedTemplate(DragDropHeaderTemplate, this); } if (state.IsFlagSet(ControlPanelState.Editing)) { AppendDefinedTemplate(EditingHeaderTemplate, this); } if (state.IsFlagSet(ControlPanelState.Previewing)) { AppendDefinedTemplate(PreviewingHeaderTemplate, this); } AddPlugins(state); if (state.IsFlagSet(ControlPanelState.DragDrop)) { AddDefinitions(this); RegisterDragDropStyles(); RegisterDragDropScripts(); } if (state.IsFlagSet(ControlPanelState.Editing)) { Register.JQuery(Page); Register.StyleSheet(Page, Url.ToAbsolute(StyleSheetUrl), Media.All); } if (state.IsFlagSet(ControlPanelState.Previewing)) { AppendDefinedTemplate(PreviewingFooterTemplate, this); } if (state.IsFlagSet(ControlPanelState.Editing)) { AppendDefinedTemplate(EditingFooterTemplate, this); } if (state.IsFlagSet(ControlPanelState.DragDrop)) { AppendDefinedTemplate(DragDropFooterTemplate, this); } if (state.IsFlagSet(ControlPanelState.Visible)) { AppendDefinedTemplate(VisibleFooterTemplate, this); } base.CreateChildControls(); }
protected virtual bool ActiveFor(Control container, ControlPanelState state) { return(state.IsFlagSet(ShowDuring)); }
public static bool IsManaging(this ControlPanelState state) { return(state.IsFlagSet(ControlPanelState.DragDrop) || state.IsFlagSet(ControlPanelState.Editing) || state.IsFlagSet(ControlPanelState.Previewing)); }