Example #1
0
 /// <summary>Begins an editable wrapper that can be used to edit a single property in a view.</summary>
 /// <param name="html"></param>
 /// <param name="item"></param>
 /// <param name="displayableName"></param>
 /// <returns>A disposable object that must be called to close the editable wrapper element.</returns>
 public static IDisposable BeginEditableWrapper(this HtmlHelper html, ContentItem item, string displayableName)
 {
     if (ControlPanel.GetState(html.ContentEngine()) == ControlPanelState.DragDrop)
     {
         return(WebExtensions.GetEditableWrapper(item, true, displayableName, html.ContentEngine().Definitions.GetDefinition(item).Displayables[displayableName], html.ViewContext.Writer));
     }
     else
     {
         return(new EmptyDisposable());
     }
 }
            private static string Plugins(HtmlHelper html, ContentItem item, ControlPanelState state)
            {
                ContentItem start = html.StartPage();
                ContentItem root  = html.RootPage();

                Page p = new Page();

                foreach (IControlPanelPlugin plugin in html.ContentEngine().Resolve <IPluginFinder>().GetPlugins <IControlPanelPlugin>())
                {
                    var span = new System.Web.UI.HtmlControls.HtmlGenericControl("span");
                    span.Attributes["class"] = "control";
                    var pluginControl = plugin.AddTo(span, new PluginContext(new SelectionUtility(item, null), start, root, state, html.ContentEngine(), html.ViewContext.HttpContext));

                    if (pluginControl != null)
                    {
                        p.Controls.Add(span);
                    }
                }

                using (var sw = new StringWriter())
                    using (var htw = new HtmlTextWriter(sw))
                    {
                        p.RenderControl(htw);
                        return(sw.ToString());
                    }
            }
        /// <summary>Creates a navigation using unordered list elements.</summary>
        public static N2.Web.Tree Tree(this HtmlHelper html,
                                       ContentItem startsFrom = null,
                                       ContentItem current    = null,
                                       int takeLevels         = 2,
                                       bool parallelRoot      = true,
                                       bool appendCreatorNode = false,
                                       ItemFilter filter      = null,
                                       object htmlAttributes  = null)
        {
            if (startsFrom == null)
            {
                startsFrom = html.StartPage();
            }
            if (current == null)
            {
                current = html.CurrentPage();
            }
            if (filter == null)
            {
                filter = new NavigationFilter(html.ViewContext.HttpContext.User, html.ContentEngine().SecurityManager);
            }

            var builder = parallelRoot
                                ? (HierarchyBuilder) new ParallelRootHierarchyBuilder(startsFrom, takeLevels)
                                : (HierarchyBuilder) new TreeHierarchyBuilder(startsFrom, takeLevels);

            if (builder == null)
            {
                throw new ArgumentException("builder == null");
            }

            if (appendCreatorNode && ControlPanelExtensions.GetControlPanelState(html).IsFlagSet(ControlPanelState.DragDrop))
            {
                builder.GetChildren = (i) => i == null ? null : i.Children.FindNavigatablePages().Where(filter).AppendCreatorNode(html.ContentEngine(), i);
            }
            else
            {
                builder.GetChildren = (i) => i == null ? null : i.Children.FindNavigatablePages().Where(filter);
            }

            var tree = N2.Web.Tree.Using(builder);

            if (htmlAttributes != null)
            {
                tree.Tag(BootstrapTagAlterations(startsFrom, current, htmlAttributes));
            }

            ClassifyAnchors(startsFrom, current, parallelRoot, tree);

            return(tree);
        }
Example #4
0
        /// <summary>
        /// Build a tree that is bootstrap friendly
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="helper"></param>
        /// <param name="startFrom"></param>
        /// <param name="currentItem"></param>
        /// <param name="takeLevel"></param>
        /// <param name="filter"></param>
        /// <param name="appendCreatorNode"></param>
        /// <param name="includeRoot"></param>
        /// <param name="onHoverDropdowns"></param>
        /// <returns></returns>
        public static N2.Web.Tree BootstrapTree <TModel>(this HtmlHelper <TModel> helper,
                                                         ContentItem startFrom   = null,
                                                         ContentItem currentItem = null,
                                                         int takeLevel           = 2,
                                                         ItemFilter filter       = null,
                                                         bool appendCreatorNode  = false,
                                                         bool includeRoot        = true,
                                                         bool onHoverDropdowns   = false)
        {
            // prep
            if (startFrom == null)
            {
                startFrom = helper.StartPage();
            }
            if (currentItem == null)
            {
                currentItem = helper.CurrentPage();
            }
            if (filter == null)
            {
                filter = new NavigationFilter(helper.ViewContext.RequestContext.HttpContext.User, helper.ContentEngine().SecurityManager);
            }

            HierarchyBuilder builder = new ParallelRootHierarchyBuilder(startFrom, takeLevel);

            builder.GetChildren = (builder.GetChildren = (item) =>
            {
                var items = item.Children.Where(filter);
                if (appendCreatorNode && item.IsPage && helper.GetControlPanelState().IsFlagSet(ControlPanelState.DragDrop))
                {
                    items = items.AppendCreatorNode(helper.ContentEngine(), item);
                }
                return(items.ToList());
            });

            var node = builder.Build();

            if (!includeRoot)
            {
                node.Children.RemoveAt(0);
            }

            var tree = N2.Web.Tree.Using(node);

            tree.HtmlAttibutes(new { @class = "nav" });
            ClassifyAnchors(startFrom, currentItem, tree);

            return(tree);
        }
Example #5
0
        public static HelperResult OutputCache(this HtmlHelper html,
                                               Func <string, HelperResult> template,
                                               string cacheKey             = null,
                                               bool?perPage                = null,
                                               int?perAncestorAtLevel      = null,
                                               DateTime?absoluteExpiration = null,
                                               TimeSpan?slidingExpiration  = null)
        {
            if (html.ViewContext.RequestContext.HttpContext.Request.QueryString["edit"] != null)
            {
                return(template(""));
            }

            string composedKey = CreateCacheKey(html, template, cacheKey, perPage, perAncestorAtLevel);

            var cache = html.ContentEngine().Resolve <N2.Web.CacheWrapper>();

            var cachedResults = cache.Get <string>(composedKey);

            if (cachedResults != null)
            {
                return(new HelperResult(tw => tw.Write(cachedResults)));
            }

            return(new HelperResult(tw =>
            {
                using (var sw = new StringWriter())
                {
                    var originalWriter = html.ViewContext.Writer;
                    try
                    {
                        html.ViewContext.Writer = sw;     // in case something renders directly to the stream

                        template(composedKey).WriteTo(sw);
                        var results = sw.ToString();

                        cache.Add(composedKey, results, new CacheOptions {
                            AbsoluteExpiration = absoluteExpiration ?? System.Web.Caching.Cache.NoAbsoluteExpiration, SlidingExpiration = slidingExpiration ?? System.Web.Caching.Cache.NoSlidingExpiration
                        });

                        tw.Write(results);
                    }
                    finally
                    {
                        html.ViewContext.Writer = originalWriter;
                    }
                }
            }));
        }
Example #6
0
            private static string Plugins(HtmlHelper html, ContentItem item, ControlPanelState state)
            {
                ContentItem start = html.StartPage();
                ContentItem root  = html.RootPage();

                Page p = new Page();

                foreach (IControlPanelPlugin plugin in html.ContentEngine().Resolve <IPluginFinder>().GetPlugins <IControlPanelPlugin>())
                {
                    plugin.AddTo(p, new PluginContext(new SelectionUtility(item, null), start, root, state, html.ContentEngine(), html.ViewContext.HttpContext));
                }

                using (var sw = new StringWriter())
                    using (var htw = new HtmlTextWriter(sw))
                    {
                        p.RenderControl(htw);
                        return(sw.ToString());
                    }
            }
Example #7
0
        public static void RenderControlPanel(this HtmlHelper html)
        {
            var engine = html.ContentEngine();
            var item   = html.CurrentItem() ?? html.StartPage();

            if (!engine.SecurityManager.IsEditor(html.ViewContext.HttpContext.User))
            {
                return;
            }
            if (RegistrationExtensions.GetRegistrationExpression(html) != null)
            {
                return;
            }

            var state    = ControlPanel.GetState(html.ViewContext.HttpContext.User, html.ViewContext.HttpContext.Request.QueryString);
            var settings = new
            {
                NavigationUrl = engine.ManagementPaths.GetNavigationUrl(item),
                ManagementUrl = engine.ManagementPaths.GetManagementInterfaceUrl(),
                Path          = item.Path,
                Plugins       = Plugins(html, item, state),
                Definitions   = Definitions(html, engine, item, state),
                Version       = typeof(ContentItem).Assembly.GetName().Version.ToString(),
                Permission    = engine.GetContentAdapter <NodeAdapter>(item).GetMaximumPermission(item)
            };

            html.Resources().JQuery()
            .JQueryPlugins()
            .JQueryUi()
            .JavaScript("{ManagementUrl}/Resources/Js/parts.js").StyleSheet("{ManagementUrl}/Resources/Css/parts.css");

            string controlPanelHtml = format.Replace(settings);

            html.ViewContext.Writer.Write(controlPanelHtml);

            if (state == ControlPanelState.DragDrop)
            {
                html.Resources().JavaScript(@"window.n2ddcp = new n2DragDrop();", ScriptOptions.DocumentReady);
            }
        }
 /// <summary>Gets the curent state of the control panel.</summary>
 /// <param name="html"></param>
 /// <returns></returns>
 public static ControlPanelState GetControlPanelState(this HtmlHelper html)
 {
     return(UI.WebControls.ControlPanel.GetState(html.ContentEngine()));
 }
			private static string Plugins(HtmlHelper html, ContentItem item, ControlPanelState state)
			{
				ContentItem start = html.StartPage();
				ContentItem root = html.RootPage();

				Page p = new Page();
				foreach (IControlPanelPlugin plugin in html.ContentEngine().Resolve<IPluginFinder>().GetPlugins<IControlPanelPlugin>())
				{
					plugin.AddTo(p, new PluginContext(new SelectionUtility(item, null), start, root, state, html.ContentEngine(), html.ViewContext.HttpContext));
				}

				using (var sw = new StringWriter())
				using (var htw = new HtmlTextWriter(sw))
				{
					p.RenderControl(htw);
					return sw.ToString();
				}
			}
Example #10
0
 public ViewContentHelper(HtmlHelper html)
     : base(html.ContentEngine(), () => html.CurrentPath())
 {
     this.html = html;
 }
Example #11
0
 public LegacyControlPanelHelper(HtmlHelper html)
     : base(html.ContentEngine(), html.CurrentItem(), html.ViewContext.Writer, html.ViewContext.GetResourceStateCollection())
 {
     this.Html = html;
 }
            private static string Plugins(HtmlHelper html, ContentItem item, ControlPanelState state)
            {
                ContentItem start = html.StartPage();
                ContentItem root = html.RootPage();

                Page p = new Page();
                foreach (IControlPanelPlugin plugin in html.ContentEngine().Resolve<IPluginFinder>().GetPlugins<IControlPanelPlugin>())
                {
                    var span = new System.Web.UI.HtmlControls.HtmlGenericControl("span");
                    span.Attributes["class"] = "control";
                    var pluginControl = plugin.AddTo(span, new PluginContext(new SelectionUtility(item, null), start, root, state, html.ContentEngine(), html.ViewContext.HttpContext));

                    if (pluginControl != null)
                        p.Controls.Add(span);
                }

                using (var sw = new StringWriter())
                using (var htw = new HtmlTextWriter(sw))
                {
                    p.RenderControl(htw);
                    return sw.ToString();
                }
            }
Example #13
0
 public static ItemDefinition Definition(this HtmlHelper html, ContentItem item)
 {
     return(html.ContentEngine().Definitions.GetDefinition(item));
 }
 /// <summary>
 /// determines if user is actively managing (administering) the site vs. using the site
 /// </summary>
 /// <param name="html"></param>
 /// <returns>true if managing</returns>
 public static bool IsManaging(this HtmlHelper html)
 {
     return(IsManaging(html.ContentEngine()));
 }
        /// <summary>
        /// determines if user is actively organizing parts / editing the page interactively via drag & drop
        /// </summary>
        /// <param name="html"></param>
        /// <returns>true if managing</returns>
        public static bool IsOrganizing(this HtmlHelper html)
        {
            var engine = html.ContentEngine();

            return(engine != null && ControlPanel.GetState(engine).IsFlagSet(ControlPanelState.DragDrop));
        }
Example #16
0
 /// <summary>Begins an editable wrapper that can be used to edit a single property in a view.</summary>
 /// <param name="html"></param>
 /// <param name="item"></param>
 /// <param name="displayableName"></param>
 /// <returns>A disposable object that must be called to close the editable wrapper element.</returns>
 public static IDisposable BeginEditableWrapper(this HtmlHelper html, ContentItem item, string displayableName)
 {
     return(WebExtensions.GetEditableWrapper(item, true, displayableName, html.ContentEngine().Definitions.GetDefinition(item).Displayables[displayableName], html.ViewContext.Writer));
 }
 /// <summary>Gets the curent state of the control panel.</summary>
 /// <param name="html"></param>
 /// <returns></returns>
 public static ControlPanelState GetControlPanelState(HtmlHelper html)
 {
     return(UI.WebControls.ControlPanel.GetState(html.ContentEngine().SecurityManager, html.ViewContext.HttpContext.User, html.ViewContext.HttpContext.Request.QueryString));
 }
Example #18
0
 public ViewContentHelper(HtmlHelper html)
     : base(html.ContentEngine(), () => html.CurrentPath())
 {
     this.html = html;
 }
 /// <summary>Gets the curent state of the control panel.</summary>
 /// <param name="html"></param>
 /// <returns></returns>
 public static ControlPanelState GetControlPanelState(HtmlHelper html)
 {
     return UI.WebControls.ControlPanel.GetState(html.ContentEngine().SecurityManager, html.ViewContext.HttpContext.User, html.ViewContext.HttpContext.Request.QueryString);
 }
			public LegacyControlPanelHelper(HtmlHelper html)
				: base(html.ContentEngine(), html.CurrentItem(), html.ViewContext.Writer, html.ViewContext.GetResourceStateCollection())
			{
				this.Html = html;
			}