private LayoutDefinition GetLayoutDefinition() { var xml = WebEditUtil.ConvertJSONLayoutToXML(WebUtil.GetFormValue("scLayout")); var layoutDefinition = LayoutDefinition.Parse(xml); return(layoutDefinition); }
/// <summary> /// Get Rendering /// </summary> /// <param name="renderingId"> /// The rendering Id. /// </param> /// <returns> /// returns Rendering as RenderingDefinition /// </returns> private static RenderingDefinition GetRendering(string renderingId) { var formValue = WebUtil.GetFormValue("scLayout"); var id = ShortID.Decode(WebUtil.GetFormValue("scDeviceID")); var layoutDefinition = WebEditUtil.ConvertJSONLayoutToXML(formValue); var parsedLayout = LayoutDefinition.Parse(layoutDefinition); var device = parsedLayout.GetDevice(id); var index = device.GetIndex(renderingId); return((RenderingDefinition)device.Renderings[index]); }
public override void Execute(CommandContext context) { string formValue = WebUtil.GetFormValue("scLayout"); string xml = WebEditUtil.ConvertJSONLayoutToXML(formValue); string id = ShortID.Decode(WebUtil.GetFormValue("scDeviceID")); LayoutDefinition layoutDefinition = LayoutDefinition.Parse(xml); if (layoutDefinition == null) { ReturnLayout(); return; } DeviceDefinition device = layoutDefinition.GetDevice(id); if (device == null) { ReturnLayout(); return; } string uniqueId = Guid.Parse(context.Parameters["renderingUid"]).ToString("B").ToUpperInvariant(); RenderingDefinition renderingByUniqueId = device.GetRenderingByUniqueId(uniqueId); if (renderingByUniqueId == null) { ReturnLayout(); return; } if (string.IsNullOrEmpty(renderingByUniqueId.Parameters)) { if (!string.IsNullOrEmpty(renderingByUniqueId.ItemID)) { RenderingItem renderingItem = Client.ContentDatabase.GetItem(renderingByUniqueId.ItemID); renderingByUniqueId.Parameters = ((renderingItem != null) ? renderingItem.Parameters : string.Empty); } else { renderingByUniqueId.Parameters = string.Empty; } } NameValueCollection nameValueCollection = WebUtil.ParseUrlParameters(renderingByUniqueId.Parameters); string input = nameValueCollection["FieldNames"]; string text = context.Parameters["variant"]; if (Guid.TryParse(input, out Guid result) && result == Guid.Parse(text)) { ReturnLayout(); return; } nameValueCollection["FieldNames"] = text; renderingByUniqueId.Parameters = new UrlString(nameValueCollection.EscapeDataValues()).GetUrl(); formValue = WebEditUtil.ConvertXMLLayoutToJSON(layoutDefinition.ToXml()); ReturnLayout(formValue); }
protected virtual LayoutDefinition GetCurrentLayoutDefinition() { string formValue = WebUtil.GetFormValue("scLayout"); if (string.IsNullOrEmpty(formValue)) { return(null); } string xML = WebEditUtil.ConvertJSONLayoutToXML(formValue); if (string.IsNullOrEmpty(xML)) { return(null); } return(LayoutDefinition.Parse(xML)); }
private Item GetDatasourceItem(string referenceId, Item item) { Assert.ArgumentNotNull(referenceId, "referenceId"); Assert.ArgumentNotNull(item, "item"); string str2 = WebEditUtil.ConvertJSONLayoutToXML(WebUtil.GetFormValue("scLayout")); Assert.IsNotNull(str2, "xmlLayout"); LayoutDefinition definition = LayoutDefinition.Parse(str2); ID clientDeviceId = WebEditUtil.GetClientDeviceId(); Assert.IsNotNull(clientDeviceId, "deviceId"); RenderingDefinition renderingByUniqueId = definition.GetDevice(clientDeviceId.ToString()).GetRenderingByUniqueId(referenceId); Assert.IsNotNull(renderingByUniqueId, "rendering"); RenderingReference reference = new RenderingReference(renderingByUniqueId, item.Language, item.Database); if (!string.IsNullOrEmpty(reference.Settings.DataSource)) { return(item.Database.GetItem(reference.Settings.DataSource)); } return(null); }
/// <summary> /// Run Form /// </summary> /// <param name="args"> /// The args. /// </param> protected void Run(ClientPipelineArgs args) { if (!args.IsPostBack) { var rendering = GetRendering(ShortID.Decode(args.Parameters["uniqueid"])); if (rendering == null) { return; } var urlString = new UrlString(UIUtil.GetUri("control:MediaFramework.EmbedMedia")); urlString["mo"] = "webedit"; if (!string.IsNullOrEmpty(rendering.Parameters)) { var collection = StringUtil.GetNameValues(rendering.Parameters, '=', '&'); foreach (string key in collection) { urlString[key] = collection[key]; } } if (ID.IsID(rendering.Datasource)) { urlString[Constants.PlayerParameters.ItemId] = rendering.Datasource; } string activePage = args.Parameters[Constants.PlayerParameters.ActivePage]; if (!string.IsNullOrEmpty(activePage)) { urlString[Constants.PlayerParameters.ActivePage] = activePage; } Context.ClientPage.ClientResponse.ShowModalDialog(urlString.ToString(), "1100", "600", string.Empty, true); args.WaitForPostBack(); } else { Assert.ArgumentNotNull(args, "args"); if (args.HasResult) { var formValue = WebUtil.GetFormValue("scLayout"); var id = ShortID.Decode(WebUtil.GetFormValue("scDeviceID")); var uniqueId = ShortID.Decode(args.Parameters["uniqueid"]); var layoutDefinition = WebEditUtil.ConvertJSONLayoutToXML(formValue); var parsedLayout = LayoutDefinition.Parse(layoutDefinition); var device = parsedLayout.GetDevice(id); var deviceIndex = parsedLayout.Devices.IndexOf(device); var index = device.GetIndex(uniqueId); var rendering = (RenderingDefinition)device.Renderings[index]; UrlString url = new UrlString(this.GetParameters(args.Result)); string itemId = url[Constants.PlayerParameters.ItemId]; url.Remove(Constants.PlayerParameters.ItemId); rendering.Datasource = new ID(itemId).ToString(); rendering.Parameters = url.ToString(); parsedLayout.Devices[deviceIndex] = device; var updatedLayout = parsedLayout.ToXml(); var layout = GetLayout(updatedLayout); SheerResponse.SetAttribute("scLayoutDefinition", "value", layout); SheerResponse.Eval("window.parent.Sitecore.PageModes.ChromeManager.handleMessage('chrome:rendering:propertiescompleted');"); } } }