Ejemplo n.º 1
0
        public CommentFilteredJsonResult IceUpdate()
        {
            CommentFilteredJsonResult result = new CommentFilteredJsonResult();

            disableClientSideCaching();

            try
            {
                //XDocument contentDoc = null;
                //if (_CMSPageRoutingRequest != null)
                //{
                //	//initialize method already processed the request and had a content document already, use it
                //	CMSPageDocumentDynamicPreviewRequest dynamicPreviewRequest = _CMSPageRoutingRequest.CMSRequest as CMSPageDocumentDynamicPreviewRequest;
                //	contentDoc = dynamicPreviewRequest.ContentDocument;
                //}
                //ice update needs to consider content units scenario, so it will look into presentations folder.
                ContentUnitControllerContext controllerContext = new ContentUnitControllerContext(ControllerContext);

                DocumentPreviewIceFieldMarkupUpdateRequest iceUpdateRequest = _PageFactory.GetIceFieldMarkupUpdater(Request, null) as DocumentPreviewIceFieldMarkupUpdateRequest;

                string fieldViewName = ControllerContext.Controller.GetAvailableView(iceUpdateRequest, controllerContext);

                string contentStr;

                //when not able to locate the template in both editable and normal path, try to use the default fallback templates for text and html
                if (ControllerContext.Controller.ViewExists(fieldViewName, controllerContext))
                {
                    using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
                    {
                        HtmlHelper html = new HtmlHelper(new ViewContext(controllerContext, new WebFormView(ControllerContext, "Shared/Title"), new ViewDataDictionary()
                        {
                        },
                                                                         new TempDataDictionary()
                        {
                        }, sw), new ViewPage());

                        contentStr = Server.HtmlDecode(html.Partial(fieldViewName, iceUpdateRequest).ToHtmlString());
                    }
                }
                else
                {
                    DynamicPreviewICEProcessor iceUpdateProc = new DynamicPreviewICEProcessor(_SitePath);
                    InContextEditUpdateInfo    iceInfo       = iceUpdateProc.IceUpdatePreparation(iceUpdateRequest);

                    if (iceInfo == null)
                    {
                        throw new ArgumentException("Cannot locate either MVC view or Xslt template for element \"" + iceUpdateRequest.FieldName + "\". This field cannot be edited. This is an error of site implementation.");
                    }

                    //use classic transformation engine, even though slower, make sure work with all preview cases
                    LegacyTransformationEngine transformer = new LegacyTransformationEngine(_SitePath, string.Empty, true, _UseTempStylesheetsLocation);

                    //during ice update preparation, updated xslts werer already processed, we don't need to process it again.
                    bool ssUpdated = false;
                    contentStr = transformer.Transform(iceInfo.Field, iceInfo.MainStylesheet.FilePath, iceInfo.MainStylesheet.Doc, ssUpdated);
                }

                //only process pretentation if instructed
                if (iceUpdateRequest.PresentationFragTemplate != null)
                {
                    contentStr = processComponentUnitInstance(iceUpdateRequest, contentStr);
                }
                else if (iceUpdateRequest.PresentationInformation != null)
                {
                    //process templates. this is a tricky scenario. we will need to locate a content unit place holder that has "ElementId" value matching the field unique id
                    //only take that part of the presentation and apply to the expanded string's id
                    contentStr = processContentUnit(iceUpdateRequest, contentStr);
                }

                result.Data = new XHRResponse(
                    new Dictionary <string, object>()
                {
                    { "newMarkup", contentStr },
                    //{"fieldXml", iceUpdateRequest.Content.ToString(SaveOptions.DisableFormatting)}
                    { "fieldXml", iceUpdateRequest.ExpandedXml }
                });
            }
            catch (Exception e)
            {
                result.Data = new XHRResponse(
                    e.Message, XHRResponseType.PROCESSING_ERROR);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public CommentFilteredJsonResult IceUpdate()
        {
            CommentFilteredJsonResult result = new CommentFilteredJsonResult();

            disableClientSideCaching();

            try
            {
                CMSIceFieldMarkupUpdateRequest iceUpdateRequest = _PageFactory.GetIceFieldMarkupUpdater(Request);

                string fieldViewName = ControllerContext.Controller.GetAvailableView(iceUpdateRequest);

                string contentStr;

                //when not able to locate the template in both editable and normal path, try to use the default fallback templates for text and html
                if (ControllerContext.Controller.ViewExists(fieldViewName))
                {
                    using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
                    {
                        HtmlHelper html = new HtmlHelper(new ViewContext(ControllerContext, new WebFormView(ControllerContext, "Shared/Title"), new ViewDataDictionary()
                        {
                        },
                                                                         new TempDataDictionary()
                        {
                        }, sw), new ViewPage());

                        contentStr = Server.HtmlDecode(html.Partial(fieldViewName, iceUpdateRequest).ToHtmlString());
                    }
                }
                else
                {
                    DynamicPreviewICEProcessor iceUpdateProc = new DynamicPreviewICEProcessor(_SitePath);
                    InContextEditUpdateInfo    iceInfo       = iceUpdateProc.IceUpdatePreparation(iceUpdateRequest);

                    if (iceInfo == null)
                    {
                        throw new ArgumentException("Cannot locate either MVC view or Xslt template for element \"" + iceUpdateRequest.FieldName + "\". This field cannot be edited. This is an error of site implementation.");
                    }

                    //use classic transformation engine, even though slower, make sure work with all preview cases
                    LegacyTransformationEngine transformer = new LegacyTransformationEngine(_SitePath, string.Empty, true, _UseTempStylesheetsLocation);

                    //during ice update preparation, updated xslts werer already processed, we don't need to process it again.
                    bool ssUpdated = false;
                    contentStr = transformer.Transform(iceInfo.Field, iceInfo.MainStylesheet.FilePath, iceInfo.MainStylesheet.Doc, ssUpdated);
                }

                result.Data = new XHRResponse(
                    new Dictionary <string, object>()
                {
                    { "newMarkup", contentStr }
                });
            }
            catch (Exception e)
            {
                result.Data = new XHRResponse(
                    e.Message, XHRResponseType.PROCESSING_ERROR);
            }

            return(result);
        }