/// <summary>
        /// Initializes a new instance based on the specified <paramref name="control"/>.
        /// </summary>
        /// <param name="control">An instance of <see cref="GridControl"/> representing the control.</param>
        protected GridControlDtgeValue(GridControl control) : base(control, control.JObject)
        {
            JObject value = control.JObject.GetObject("value");

            string docTypeAlias = value.GetString("dtgeContentTypeAlias");

            string contentValue = value.GetObject("value").ToString();

            string controlId = GetControlId(contentValue);

            Content = DocTypeGridEditorHelper.ConvertValueToContent(controlId, docTypeAlias, contentValue);
        }
        /// <summary>
        /// Initializes a new instance based on the specified <paramref name="control"/>.
        /// </summary>
        /// <param name="control">An instance of <see cref="GridControl"/> representing the control.</param>
        protected GridControlDtgeValue(GridControl control) : base(control, control.JObject)
        {
            JObject value = control.JObject.GetObject("value");

            Id = value.GetGuid("id");

            DtgeContentTypeAlias = value.GetString("dtgeContentTypeAlias");

            string contentValue = value.GetObject("value").ToString();

            Element = DocTypeGridEditorHelper.ConvertValueToContent(Id.ToString(), DtgeContentTypeAlias, contentValue);
        }
Esempio n. 3
0
        public static HtmlString RenderDocTypeGridEditorItem(this HtmlHelper helper,
                                                             string id,
                                                             string docType,
                                                             string value,
                                                             string viewPath   = "",
                                                             string actionName = "",
                                                             object model      = null)
        {
            var content = DocTypeGridEditorHelper.ConvertValueToContent(id, docType, value);

            return(helper.RenderDocTypeGridEditorItem(content, viewPath, actionName, model));
        }
        public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, [FromUri] int pageId)
        {
            var page = default(IPublishedContent);

            // If the page is new, then the ID will be zero
            if (pageId > 0)
            {
                // Get page container node
                page = UmbracoContext.ContentCache.GetById(pageId);
                if (page == null)
                {
                    // If unpublished, then fake PublishedContent (with IContent object)
                    page = new UnpublishedContent(pageId, Services);
                }
            }

            // NOTE: The previous previewer had a content node associated with the request,
            // meaning that an implementation may have used this to traverse the content-tree.
            // In order to maintain backward-compatibility, we must ensure the PublishedContentRequest context.
            if (UmbracoContext.PublishedContentRequest == null)
            {
                UmbracoContext.PublishedContentRequest = new PublishedContentRequest(
                    Request.RequestUri,
                    UmbracoContext.RoutingContext,
                    UmbracoConfig.For.UmbracoSettings().WebRouting,
                    null)
                {
                    PublishedContent = page
                };
            }

            // Set the culture for the preview
            if (page != null)
            {
                var culture = page.GetCulture();
                System.Threading.Thread.CurrentThread.CurrentCulture   = culture;
                System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
            }

            // Get content node object
            var content = DocTypeGridEditorHelper.ConvertValueToContent(data.Id, data.ContentTypeAlias, data.Value);

            // Construct preview model
            var model = new PreviewModel
            {
                Page            = page,
                Item            = content,
                EditorAlias     = data.EditorAlias,
                PreviewViewPath = data.PreviewViewPath,
                ViewPath        = data.ViewPath
            };

            // Render view
            var partialName = "~/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditorPreviewer.cshtml";
            var markup      = Helpers.ViewHelper.RenderPartial(partialName, model, UmbracoContext.HttpContext);

            // Return response
            var response = new HttpResponseMessage
            {
                Content = new StringContent(markup ?? string.Empty)
            };

            response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeNames.Text.Html);

            return(response);
        }
Esempio n. 5
0
        public PartialViewResult GetPreviewMarkup([FromForm] PreviewData data, [FromQuery] int pageId)
        {
            var page = default(IPublishedContent);

            // If the page is new, then the ID will be zero
            if (pageId > 0)
            {
                // Get page container node
                page = _contentQuery.Content(pageId);
                if (page == null)
                {
                    // If unpublished, then fake PublishedContent
                    page = new UnpublishedContent(pageId, _contentService, _contentTypeService, _dataTypeService, _propertyEditorCollection, _publishedContentTypeFactory);
                }
            }


            if (_umbracoContext.UmbracoContext.PublishedRequest == null)
            {
                var request = _router.CreateRequestAsync(new Uri(Request.GetDisplayUrl())).Result;
                request.SetPublishedContent(page);
                _umbracoContext.UmbracoContext.PublishedRequest = request.Build();
            }

            // Set the culture for the preview
            if (page != null && page.Cultures != null)
            {
                var currentCulture = string.IsNullOrWhiteSpace(data.Culture) ? page.GetCultureFromDomains() : data.Culture;
                if (currentCulture != null && page.Cultures.ContainsKey(currentCulture))
                {
                    var culture = new CultureInfo(page.Cultures[currentCulture].Culture);
                    // _umbracoContext.UmbracoContext.PublishedRequest.Culture = culture; // TODO: Not sure if this is needed?
                    System.Threading.Thread.CurrentThread.CurrentCulture   = culture;
                    System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
                    _umbracoContext.UmbracoContext.VariationContextAccessor.VariationContext = new VariationContext(culture.Name);
                }
            }

            // Get content node object
            var content = _dtgeHelper.ConvertValueToContent(data.Id, data.ContentTypeAlias, data.Value);

            // Construct preview model
            var model = new PreviewModel
            {
                Page            = page,
                Item            = content,
                EditorAlias     = data.EditorAlias,
                PreviewViewPath = data.PreviewViewPath,
                ViewPath        = data.ViewPath
            };


            // Render view

            var partialName = "~/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditorPreviewer.cshtml";

            var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary());

            viewData.Model = model;
            return(new PartialViewResult()
            {
                ViewName = partialName,
                ViewData = viewData
            });
        }
        public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, [FromUri] int pageId)
        {
            var page = default(IPublishedContent);

            // If the page is new, then the ID will be zero
            if (pageId > 0)
            {
                // Get page container node
                page = Umbraco.Content(pageId);
                if (page == null)
                {
                    // If unpublished, then fake PublishedContent
                    page = new UnpublishedContent(pageId, Services);
                }
            }

            if (UmbracoContext.PublishedRequest == null)
            {
                var router = Current.Factory.GetInstance(typeof(IPublishedRouter)) as IPublishedRouter;
                UmbracoContext.PublishedRequest = router.CreateRequest(UmbracoContext, Request.RequestUri);
                UmbracoContext.PublishedRequest.PublishedContent = page;
            }

            // Set the culture for the preview
            if (page != null && page.Cultures != null)
            {
                var currentCulture = string.IsNullOrWhiteSpace(data.Culture) ? page.GetCultureFromDomains() : data.Culture;
                if (currentCulture != null && page.Cultures.ContainsKey(currentCulture))
                {
                    var culture = new CultureInfo(page.Cultures[currentCulture].Culture);
                    UmbracoContext.PublishedRequest.Culture = culture;
                    System.Threading.Thread.CurrentThread.CurrentCulture   = culture;
                    System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
                }
            }

            // Get content node object
            var content = DocTypeGridEditorHelper.ConvertValueToContent(data.Id, data.ContentTypeAlias, data.Value);

            // Construct preview model
            var model = new PreviewModel
            {
                Page            = page,
                Item            = content,
                EditorAlias     = data.EditorAlias,
                PreviewViewPath = data.PreviewViewPath,
                ViewPath        = data.ViewPath
            };

            // Render view
            var partialName = "~/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditorPreviewer.cshtml";
            var markup      = Helpers.ViewHelper.RenderPartial(partialName, model, UmbracoContext.HttpContext, UmbracoContext);

            // Return response
            var response = new HttpResponseMessage
            {
                Content = new StringContent(markup ?? string.Empty)
            };

            response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeNames.Text.Html);

            return(response);
        }