public virtual void WriteTo(TextWriter writer)
            {
                var engine = Html.ContentEngine();

                if (!Html.ViewContext.HttpContext.User.Identity.IsAuthenticated || !engine.SecurityManager.IsEditor(Html.ViewContext.HttpContext.User))
                {
                    return;
                }
                if (RegistrationExtensions.GetRegistrationExpression(Html) != null)
                {
                    return;
                }

                var item = currentItem ?? Html.CurrentItem() ?? Html.StartPage();

                var state    = ControlPanelExtensions.GetControlPanelState(Html);
                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)
                };

                var resources = Html.Resources(writer);

                if (includeJQuery)
                {
                    resources.JQuery();
                }
                if (includeJQueryPlugins)
                {
                    resources.JQueryPlugins().JQueryUi();
                }
                if (includePartScripts)
                {
                    resources.Constnats().JavaScript("{ManagementUrl}/Resources/Js/parts.js");
                }
                if (includePartStyles)
                {
                    resources.StyleSheet("{ManagementUrl}/Resources/Css/parts.css");
                }

                if (refreshNavigation)
                {
                    writer.Write(formatWithRefresh.Replace(settings));
                }
                else
                {
                    writer.Write(formatWithoutRefresh.Replace(settings));
                }

                if (state == ControlPanelState.DragDrop)
                {
                    Html.Resources().JavaScript(UI.WebControls.ControlPanel.DragDropScriptInitialization(), ScriptOptions.DocumentReady);
                }
            }
Esempio n. 2
0
        public static ContentRegistration Define(this ViewContentHelper content, Action <ContentRegistration> registration)
        {
            var re = RegistrationExtensions.GetRegistrationExpression(content.Html);

            if (re != null)
            {
                FakeModel(content, re);

                re.Context.GlobalSortOffset = 0;
                if (content.Html.GetType().IsGenericType)
                {
                    var contentType = content.Html.GetType().GetGenericArguments().First();
                    if (typeof(ContentItem).IsAssignableFrom(contentType) && re.ContentType == null)
                    {
                        re.ContentType = contentType;
                        re.Title       = contentType.Name;
                    }
                }
                re.IsDefined = true;
                if (registration != null)
                {
                    registration(re);
                }
            }
            return(re);
        }
Esempio n. 3
0
        public static ContentRegistration PrependDefinition(this ViewContentHelper content, Action <ContentRegistration> registration = null)
        {
            var re = RegistrationExtensions.GetRegistrationExpression(content.Html);

            if (re != null)
            {
                re.Context.GlobalSortOffset = -1000;
                registration(re);
            }
            return(re);
        }
Esempio n. 4
0
        /// <summary>Renders the openable control panel displayed in the upper left corner on N2 sites.</summary>
        /// <param name="html"></param>
        public static ControlPanelHelper ControlPanel(this HtmlHelper html)
        {
            var cp = ControlPanelFactory(html);

            if (RegistrationExtensions.GetRegistrationExpression(html) != null)
            {
                return(new EmptyControlPanelHelper());
            }
            if (html.ViewContext.HttpContext.Request["refresh"] == "true")
            {
                cp = cp.ForceRefreshNavigation();
            }
            return(cp);
        }
Esempio n. 5
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);
            }
        }
Esempio n. 6
0
            public virtual void WriteTo(TextWriter writer)
            {
                var engine = Html.ContentEngine();

                // NBS-205 - enforce SSL
                ISecureRequestCheck check = null;

                try
                {
                    check = engine.Container.Resolve <ISecureRequestCheck>();
                }
                catch (Exception)
                {
                    check = null;
                }
                if (check != null && !check.IsSecure(Html.ViewContext.HttpContext.Request))
                {
                    return;
                }

                if (!Html.ViewContext.HttpContext.User.Identity.IsAuthenticated || !engine.SecurityManager.IsEditor(Html.ViewContext.HttpContext.User))
                {
                    return;
                }
                if (RegistrationExtensions.GetRegistrationExpression(Html) != null)
                {
                    return;
                }

                var item = CurrentItem ?? Html.CurrentItem() ?? Html.StartPage();

                var state    = GetControlPanelState(Html);
                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),
                    VersionIndex                = item.VersionIndex,
                    VersionKey                  = item.GetVersionKey(),
                    Force                       = ForceRefreshNavigationOnLoad ? "true" : "false",
                    State                       = item != null?item.State.ToString() : "NonContent",
                                           Mode = GetControlPanelState(Html).ToString()
                };

                var resources = Html.Resources(writer).Constants();

                if (IncludeJQuery)
                {
                    resources.JQuery();
                }
                if (IncludeJQueryPlugins)
                {
                    resources.JQueryPlugins(IncludeJQuery);
                }
                if (IncludeJQueryUi)
                {
                    resources.JQueryUi(IncludeJQuery);
                }
                if (IncludeCkEditor)
                {
                    resources.CKEditor();
                }
                if (IncludePartScripts)
                {
                    resources.PartsJs();
                }
                if (IncludePartStyles)
                {
                    resources.PartsCss(); resources.IconsCss();
                }

                if (RefreshNavigationOnLoad)
                {
                    writer.Write(formatWithRefresh.Replace(settings));
                }
                else
                {
                    writer.Write(formatWithoutRefresh.Replace(settings));
                }

                if (state.IsFlagSet(ControlPanelState.DragDrop))
                {
                    Html.Resources().JavaScript(UI.WebControls.ControlPanel.DragDropScriptInitialization(item), ScriptOptions.DocumentReady);
                }
            }