Beispiel #1
0
        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 (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);
            }
        }
Beispiel #3
0
        private bool TryAddItemReference(WebControl control)
        {
            if (control == null)
            {
                return(false);
            }
            control.Attributes["data-item"]             = CurrentItem.ID.ToString();
            control.Attributes["data-item-version-key"] = CurrentItem.GetVersionKey();
            control.Attributes["data-page"]             = CurrentItem.IsPage
                                ? currentItem.ID.ToString()
                                : Find.ClosestPage(CurrentItem) != null
                                        ? Find.ClosestPage(CurrentItem).ID.ToString()
                                        : "";

            control.Attributes["data-item-zone"]      = CurrentItem.ZoneName;
            control.Attributes["data-item-reference"] = ClientID + "_autosaved_item_id";
            return(true);
        }
Beispiel #4
0
        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);
            }
        }