コード例 #1
0
        public static HtmlString RenderMortarItem(
            this HtmlHelper helper,
            MortarRow row,
            MortarItem item,
            string viewPath   = "",
            string actionName = "",
            object model      = null)
        {
            if (item == null || item.Value == null)
            {
                return(new HtmlString(string.Empty));
            }

            if (!string.IsNullOrWhiteSpace(viewPath))
            {
                viewPath = viewPath.TrimEnd('/') + "/";
            }

            if (string.IsNullOrWhiteSpace(actionName))
            {
                actionName = item.Value.DocumentTypeAlias;
            }

            var controllerName = string.Concat(item.Value.DocumentTypeAlias, "Surface");

            if (SurfaceControllerHelper.SurfaceControllerExists(controllerName, actionName, true))
            {
                return(helper.Action(actionName,
                                     controllerName,
                                     new
                {
                    mortarModel = model ?? item.Value,
                    mortarRow = row,
                    mortarViewPath = viewPath
                }));
            }

            return(helper.Partial(viewPath + item.Value.DocumentTypeAlias, model ?? item.Value));
        }
コード例 #2
0
        public static HtmlString RenderDocTypeGridEditorItem(
            this HtmlHelper helper,
            IPublishedContent content,
            string editorAlias     = "",
            string viewPath        = "",
            string previewViewPath = "",
            bool isPreview         = false)
        {
            if (content == null)
            {
                return(new HtmlString(string.Empty));
            }

            var controllerName = $"{content.DocumentTypeAlias}Surface";

            if (string.IsNullOrWhiteSpace(viewPath) == false)
            {
                viewPath = viewPath.EnsureEndsWith('/');
            }

            if (string.IsNullOrWhiteSpace(previewViewPath) == false)
            {
                previewViewPath = previewViewPath.EnsureEndsWith('/');
            }

            var routeValues = new
            {
                dtgeModel           = content,
                dtgeViewPath        = viewPath,
                dtgePreviewViewPath = previewViewPath,
                dtgePreview         = isPreview
            };

            // Try looking for surface controller with action named after the editor alias
            if (string.IsNullOrWhiteSpace(editorAlias) == false && SurfaceControllerHelper.SurfaceControllerExists(controllerName, editorAlias, true))
            {
                return(helper.Action(editorAlias, controllerName, routeValues));
            }

            // Try looking for surface controller with action named after the doc type alias alias
            if (SurfaceControllerHelper.SurfaceControllerExists(controllerName, content.DocumentTypeAlias, true))
            {
                return(helper.Action(content.DocumentTypeAlias, controllerName, routeValues));
            }

            // See if a default surface controller has been registered
            var defaultController = DefaultDocTypeGridEditorSurfaceControllerResolver.Current.GetDefaultControllerType();

            if (defaultController != null)
            {
                var defaultControllerName = defaultController.Name.Substring(0, defaultController.Name.LastIndexOf("Controller"));

                // Try looking for an action named after the editor alias
                if (string.IsNullOrWhiteSpace(editorAlias) == false && SurfaceControllerHelper.SurfaceControllerExists(defaultControllerName, editorAlias, true))
                {
                    return(helper.Action(editorAlias, defaultControllerName, routeValues));
                }

                // Try looking for a doc type alias action
                if (SurfaceControllerHelper.SurfaceControllerExists(defaultControllerName, content.DocumentTypeAlias, true))
                {
                    return(helper.Action(content.DocumentTypeAlias, defaultControllerName, routeValues));
                }

                // Just go with a default action name
                return(helper.Action("Index", defaultControllerName, routeValues));
            }

            // Check for preview view
            if (string.IsNullOrWhiteSpace(previewViewPath) == false &&
                isPreview)
            {
                var fullPreviewViewPath = $"{previewViewPath}{editorAlias}.cshtml";
                if (ViewHelper.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
                {
                    return(helper.Partial(fullPreviewViewPath, content));
                }

                fullPreviewViewPath = $"{previewViewPath}{content.DocumentTypeAlias}.cshtml";
                if (ViewHelper.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
                {
                    return(helper.Partial(fullPreviewViewPath, content));
                }

                fullPreviewViewPath = $"{previewViewPath}Default.cshtml";
                if (ViewHelper.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
                {
                    return(helper.Partial(fullPreviewViewPath, content));
                }
            }

            // Check for view path view
            if (string.IsNullOrWhiteSpace(viewPath) == false)
            {
                var fullViewPath = $"{viewPath}{editorAlias}.cshtml";
                if (ViewHelper.ViewExists(helper.ViewContext, fullViewPath, true))
                {
                    return(helper.Partial(fullViewPath, content));
                }

                fullViewPath = $"{viewPath}{content.DocumentTypeAlias}.cshtml";
                if (ViewHelper.ViewExists(helper.ViewContext, fullViewPath, true))
                {
                    return(helper.Partial(fullViewPath, content));
                }

                fullViewPath = $"{viewPath}Default.cshtml";
                if (ViewHelper.ViewExists(helper.ViewContext, fullViewPath, true))
                {
                    return(helper.Partial(fullViewPath, content));
                }
            }

            // Resort to standard partial views
            if (ViewHelper.ViewExists(helper.ViewContext, editorAlias, true))
            {
                return(helper.Partial(editorAlias, content));
            }

            return(helper.Partial(content.DocumentTypeAlias, content));
        }
コード例 #3
0
        public static HtmlString RenderDocTypeGridEditorItem(
            this HtmlHelper helper,
            IPublishedContent content,
            string editorAlias     = "",
            string viewPath        = "",
            string previewViewPath = "")
        {
            if (content == null)
            {
                return(new HtmlString(string.Empty));
            }

            var controllerName = content.DocumentTypeAlias + "Surface";

            if (!string.IsNullOrWhiteSpace(viewPath))
            {
                viewPath = viewPath.TrimEnd('/') + "/";
            }

            if (!string.IsNullOrWhiteSpace(previewViewPath))
            {
                previewViewPath = previewViewPath.TrimEnd('/') + "/";
            }

            // Try looking for surface controller with action named after the editor alias
            if (!editorAlias.IsNullOrWhiteSpace() && SurfaceControllerHelper.SurfaceControllerExists(controllerName, editorAlias, true))
            {
                return(helper.Action(editorAlias, controllerName, new
                {
                    dtgeModel = content,
                    dtgeViewPath = viewPath,
                    dtgePreviewViewPath = previewViewPath
                }));
            }

            // Try looking for surface controller with action named after the doc type alias alias
            if (SurfaceControllerHelper.SurfaceControllerExists(controllerName, content.DocumentTypeAlias, true))
            {
                return(helper.Action(content.DocumentTypeAlias, controllerName, new
                {
                    dtgeModel = content,
                    dtgeViewPath = viewPath,
                    dtgePreviewViewPath = previewViewPath
                }));
            }

            // See if a default surface controller has been registered
            var defaultController = DefaultDocTypeGridEditorSurfaceControllerResolver.Current.GetDefaultControllerType();

            if (defaultController != null)
            {
                var defaultControllerName = defaultController.Name.Substring(0, defaultController.Name.LastIndexOf("Controller"));

                // Try looking for an action named after the editor alias
                if (!editorAlias.IsNullOrWhiteSpace() && SurfaceControllerHelper.SurfaceControllerExists(defaultControllerName, editorAlias, true))
                {
                    return(helper.Action(editorAlias, defaultControllerName, new
                    {
                        dtgeModel = content,
                        dtgeViewPath = viewPath,
                        dtgePreviewViewPath = previewViewPath
                    }));
                }

                // Try looking for a doc type alias action
                if (SurfaceControllerHelper.SurfaceControllerExists(defaultControllerName, content.DocumentTypeAlias, true))
                {
                    return(helper.Action(content.DocumentTypeAlias, defaultControllerName, new
                    {
                        dtgeModel = content,
                        dtgeViewPath = viewPath,
                        dtgePreviewViewPath = previewViewPath
                    }));
                }

                // Just go with a default action name
                return(helper.Action("Index", defaultControllerName, new
                {
                    dtgeModel = content,
                    dtgeViewPath = viewPath,
                    dtgePreviewViewPath = previewViewPath
                }));
            }

            // Check for preview view
            if (!string.IsNullOrWhiteSpace(previewViewPath) &&
                helper.ViewContext.RequestContext.HttpContext.Request.QueryString["dtgePreview"] == "1")
            {
                var fullPreviewViewPath = previewViewPath + editorAlias + ".cshtml";
                if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
                {
                    return(helper.Partial(fullPreviewViewPath, content));
                }

                fullPreviewViewPath = previewViewPath + content.DocumentTypeAlias + ".cshtml";
                if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
                {
                    return(helper.Partial(fullPreviewViewPath, content));
                }

                fullPreviewViewPath = previewViewPath + "Default.cshtml";
                if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullPreviewViewPath, true))
                {
                    return(helper.Partial(fullPreviewViewPath, content));
                }
            }

            // Check for view path view
            if (!string.IsNullOrWhiteSpace(viewPath))
            {
                var fullViewPath = viewPath + editorAlias + ".cshtml";
                if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullViewPath, true))
                {
                    return(helper.Partial(fullViewPath, content));
                }

                fullViewPath = viewPath + content.DocumentTypeAlias + ".cshtml";
                if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullViewPath, true))
                {
                    return(helper.Partial(fullViewPath, content));
                }

                fullViewPath = viewPath + "Default.cshtml";
                if (ViewEngines.Engines.ViewExists(helper.ViewContext, fullViewPath, true))
                {
                    return(helper.Partial(fullViewPath, content));
                }
            }

            // Resort to standard partial views
            if (ViewEngines.Engines.ViewExists(helper.ViewContext, editorAlias, true))
            {
                return(helper.Partial(editorAlias, content));
            }

            return(helper.Partial(content.DocumentTypeAlias, content));
        }