private void RenderContentControls(HtmlTextWriter output, VariableValueItemStub value) { bool flag; Assert.ArgumentNotNull(output, "output"); Assert.ArgumentNotNull(value, "value"); ShortID tid = value.Id.ToShortID(); Item currentContent = null; currentContent = GetCurrentContent(value, out flag); string str = flag ? "default-values" : string.Empty; if (value.HideComponent) { str = str + " display-off"; } output.Write("<div {0} id='{1}_content'>", (str == string.Empty) ? str : ("class='" + str + "'"), tid); string click = value.HideComponent ? "javascript:void(0);" : ("variation:setcontent(variationid=" + tid + ")"); string reset = value.HideComponent ? "javascript:void(0);" : "ResetVariationContent(\\\"{0}\\\")".FormatWith(new object[] { tid }); RenderPicker(output, currentContent, click, reset, true); output.Write("</div>"); }
private string RenderVariableValueDetails(VariableValueItemStub value) { var output = new HtmlTextWriter(new StringWriter()); output.Write("<table class='top-row'>"); output.Write("<tr>"); output.Write("<td class='left test-title'>"); output.Write(Translate.Text("Test Content Item:")); output.Write("</td>"); output.Write("<td class='right'>"); output.Write("</td>"); output.Write("</tr>"); output.Write("<tr>"); output.Write("<td class='left test-content'>"); RenderContentControls(output, value); output.Write("</td>"); output.Write("<td class='right display-component'>"); RenderDisplayControls(output, value); output.Write("</td>"); output.Write("</tr>"); output.Write("<tr class='component-row'>"); output.Write("<td class='left test-title'>"); output.Write(Translate.Text("Test Component Design:")); output.Write("</td>"); output.Write("<td rowspan='2' class='right'>"); output.Write("</td>"); output.Write("</tr>"); output.Write("<tr class='component-row'>"); output.Write("<td class='left test-component'>"); RenderComponentControls(output, value); output.Write("</td>"); output.Write("</tr>"); output.Write("</table>"); return(output.InnerWriter.ToString()); }
private void RenderComponentControls(HtmlTextWriter output, VariableValueItemStub value) { bool flag; ShortID tid = value.Id.ToShortID(); Item currentRenderingItem = GetCurrentRenderingItem(value, out flag); string thumbnailSrc = GetThumbnailSrc(currentRenderingItem); string str2 = flag ? "default-values" : string.Empty; if (value.HideComponent) { str2 = str2 + " display-off"; } output.Write("<div id='{0}_component' {1}>", tid, string.IsNullOrEmpty(str2) ? string.Empty : ("class='" + str2 + "'")); output.Write("<div style=\"background-image:url('{0}')\" class='thumbnail-container'>", thumbnailSrc); output.Write("</div>"); output.Write("<div class='picker-container'>"); string click = value.HideComponent ? "javascript:void(0);" : ("variation:setcomponent(variationid=" + tid + ")"); string reset = value.HideComponent ? "javascript:void(0);" : "ResetVariationComponent(\\\"{0}\\\")".FormatWith(new object[] { tid }); RenderPicker(output, currentRenderingItem, click, reset, false); output.Write("</div>"); output.Write("</div>"); }
protected void SetComponent(ClientPipelineArgs args) { string str = args.Parameters["variationid"]; if (string.IsNullOrEmpty(str)) { SheerResponse.Alert("Item not found.", new string[0]); } else if ((Rendering == null) || (Layout == null)) { SheerResponse.Alert("An error ocurred.", new string[0]); } else if (!args.IsPostBack) { string placeholder = Rendering.Placeholder; Assert.IsNotNull(placeholder, "placeholder"); string str3 = Layout.ToXml(); var args2 = new GetPlaceholderRenderingsArgs(placeholder, str3, Client.ContentDatabase, ID.Parse(DeviceId)); args2.OmitNonEditableRenderings = true; args2.CustomData["showOpenProperties"] = false; CorePipeline.Run("getPlaceholderRenderings", args2); string dialogURL = args2.DialogURL; if (string.IsNullOrEmpty(dialogURL)) { SheerResponse.Alert("An error ocurred.", new string[0]); } else { SheerResponse.ShowModalDialog(dialogURL, "720px", "470px", string.Empty, true); args.WaitForPostBack(); } } else if (args.HasResult) { ID id = ShortID.DecodeID(str); List <VariableValueItemStub> variableValues = VariableValues; VariableValueItemStub stub = variableValues.Find(v => v.Id == id); if (stub != null) { string result; if (args.Result.IndexOf(',') >= 0) { result = args.Result.Split(new[] { ',' })[0]; } else { result = args.Result; } stub.ReplacementComponent = result; var output = new HtmlTextWriter(new StringWriter()); RenderComponentControls(output, stub); SheerResponse.SetOuterHtml(str + "_component", output.InnerWriter.ToString()); VariableValues = variableValues; } } }
private static void UpdateVariableValueItem(MultivariateTestValueItem variableValue, VariableValueItemStub variableStub, int sortOrder) { Assert.ArgumentNotNull(variableValue, "variableValue"); using (new EditContext(variableValue)) { variableValue["Name"] = variableStub.Name; variableValue.Datasource.Path = variableStub.Datasource; variableValue.HideComponent = variableStub.HideComponent; variableValue.ReplacementComponent.Path = variableStub.ReplacementComponent; variableValue.InnerItem.Appearance.Sortorder = sortOrder; } }
protected void AddVariation() { ID newID = ID.NewID; var item = new VariableValueItemStub(newID, NewVariationDefaultName); List <VariableValueItemStub> variableValues = VariableValues; variableValues.Insert(0, item); VariableValues = variableValues; string str = RenderVariableValue(item); SetControlsState(); SheerResponse.Insert(Variations.ClientID, "afterBegin", str); SheerResponse.Eval("Sitecore.CollapsiblePanel.newAdded('{0}')".FormatWith(new object[] { newID.ToShortID() })); }
protected void ResetVariationContent(string variationId) { Assert.ArgumentNotNull(variationId, "variationId"); ID id = ShortID.DecodeID(variationId); List <VariableValueItemStub> variableValues = VariableValues; VariableValueItemStub stub = variableValues.Find(v => v.Id == id); if (stub != null) { stub.Datasource = string.Empty; var output = new HtmlTextWriter(new StringWriter()); RenderContentControls(output, stub); SheerResponse.SetOuterHtml(variationId + "_content", output.InnerWriter.ToString()); VariableValues = variableValues; } }
private Item GetCurrentRenderingItem(VariableValueItemStub value, out bool isFallback) { isFallback = false; if (!string.IsNullOrEmpty(value.ReplacementComponent)) { return(Client.ContentDatabase.GetItem(value.ReplacementComponent)); } RenderingDefinition rendering = Rendering; if ((rendering != null) && !string.IsNullOrEmpty(rendering.ItemID)) { isFallback = true; return(Client.ContentDatabase.GetItem(rendering.ItemID)); } return(null); }
private Item GetCurrentContent(VariableValueItemStub value, out bool isFallback) { Assert.ArgumentNotNull(value, "value"); isFallback = false; Item item = null; if (!string.IsNullOrEmpty(value.Datasource)) { return(Client.ContentDatabase.GetItem(value.Datasource)); } if ((Rendering != null) && !string.IsNullOrEmpty(Rendering.Datasource)) { item = Client.ContentDatabase.GetItem(Rendering.Datasource); isFallback = true; } return(item); }
private void RenderDisplayControls(HtmlTextWriter output, VariableValueItemStub value) { Assert.ArgumentNotNull(output, "output"); Assert.ArgumentNotNull(value, "value"); ShortID tid = value.Id.ToShortID(); output.Write( "<input type='checkbox' onfocus='this.blur();' onclick=\"javascript:return scSwitchRendering(this, event, '{0}')\" ", tid); if (value.HideComponent) { output.Write(" checked='checked' "); } output.Write("/>"); output.Write("<span class='display-component-title'>"); output.Write(Translate.Text("Hide Component")); output.Write("</span>"); }
private string RenderVariableValue(VariableValueItemStub value) { var renderer = new CollapsiblePanelRenderer(); var context3 = new CollapsiblePanelRenderer.ActionsContext { IsVisible = true }; CollapsiblePanelRenderer.ActionsContext actionsContext = context3; string id = value.Id.ToShortID().ToString(); actionsContext.Menu = GetActionsMenu(id); var context4 = new CollapsiblePanelRenderer.NameContext(value.Name) { OnNameChanged = "javascript:Sitecore.CollapsiblePanel.nameChanged(this, event)" }; CollapsiblePanelRenderer.NameContext nameContext = context4; string panelHtml = RenderVariableValueDetails(value); return(renderer.Render(id, panelHtml, false, nameContext, actionsContext)); }
protected virtual void InitVariableValues() { if (Rendering != null) { IEnumerable <MultivariateTestValueItem> variableValues = TestingUtil.MultiVariateTesting.GetVariableValues( Rendering, Client.ContentDatabase); var list = new List <VariableValueItemStub>(); foreach (MultivariateTestValueItem item in variableValues) { var stub2 = new VariableValueItemStub(item.ID, item["Name"]) { Datasource = item.Datasource.Path, HideComponent = item.HideComponent }; VariableValueItemStub stub = stub2; ID targetID = item.ReplacementComponent.TargetID; stub.ReplacementComponent = ID.IsNullOrEmpty(targetID) ? string.Empty : targetID.ToString(); list.Add(stub); } VariableValues = list; } }
protected void ChangeDisplayComponent(string variationId) { Assert.ArgumentNotNull(variationId, "variationId"); ID id = ShortID.DecodeID(variationId); List <VariableValueItemStub> variableValues = VariableValues; VariableValueItemStub stub = variableValues.Find(v => v.Id == id); if (stub != null) { stub.HideComponent = !stub.HideComponent; using (var writer = new HtmlTextWriter(new StringWriter())) { RenderContentControls(writer, stub); SheerResponse.SetOuterHtml(variationId + "_content", writer.InnerWriter.ToString()); } using (var writer2 = new HtmlTextWriter(new StringWriter())) { RenderComponentControls(writer2, stub); SheerResponse.SetOuterHtml(variationId + "_component", writer2.InnerWriter.ToString()); } VariableValues = variableValues; } }
private Item GetCurrentContent(VariableValueItemStub value, out bool isFallback) { Assert.ArgumentNotNull(value, "value"); isFallback = false; Item item = null; if (!string.IsNullOrEmpty(value.Datasource)) { return Client.ContentDatabase.GetItem(value.Datasource); } if ((Rendering != null) && !string.IsNullOrEmpty(Rendering.Datasource)) { item = Client.ContentDatabase.GetItem(Rendering.Datasource); isFallback = true; } return item; }
private static void UpdateVariableValueItem(MultivariateTestValueItem variableValue, VariableValueItemStub variableStub) { Assert.ArgumentNotNull(variableValue, "variableValue"); UpdateVariableValueItem(variableValue, variableStub, variableValue.InnerItem.Appearance.Sortorder); }
protected virtual void InitVariableValues() { if (Rendering != null) { IEnumerable<MultivariateTestValueItem> variableValues = TestingUtil.MultiVariateTesting.GetVariableValues( Rendering, Client.ContentDatabase); var list = new List<VariableValueItemStub>(); foreach (MultivariateTestValueItem item in variableValues) { var stub2 = new VariableValueItemStub(item.ID, item["Name"]) { Datasource = item.Datasource.Path, HideComponent = item.HideComponent }; VariableValueItemStub stub = stub2; ID targetID = item.ReplacementComponent.TargetID; stub.ReplacementComponent = ID.IsNullOrEmpty(targetID) ? string.Empty : targetID.ToString(); list.Add(stub); } VariableValues = list; } }
private static bool IsVariableValueChanged(MultivariateTestValueItem variableItem, VariableValueItemStub variableStub) { Assert.ArgumentNotNull(variableItem, "variableItem"); return ((variableItem["Name"] != variableStub.Name) || ((variableItem.Datasource.Path != variableStub.Datasource) || ((variableItem.ReplacementComponent.Path != variableStub.ReplacementComponent) || (variableItem.HideComponent != variableStub.HideComponent)))); }
protected void AddVariation() { ID newID = ID.NewID; var item = new VariableValueItemStub(newID, NewVariationDefaultName); List<VariableValueItemStub> variableValues = VariableValues; variableValues.Insert(0, item); VariableValues = variableValues; string str = RenderVariableValue(item); SetControlsState(); SheerResponse.Insert(Variations.ClientID, "afterBegin", str); SheerResponse.Eval("Sitecore.CollapsiblePanel.newAdded('{0}')".FormatWith(new object[] {newID.ToShortID()})); }
protected virtual bool UpdateVariableValues(MultivariateTestVariableItem variableItem, out List <ID> modifiedVariations) { Assert.ArgumentNotNull(variableItem, "variableItem"); modifiedVariations = new List <ID>(); List <VariableValueItemStub> variableValues = VariableValues; var list2 = new List <MultivariateTestValueItem>(TestingUtil.MultiVariateTesting.GetVariableValues(variableItem)); var comparer = new DefaultComparer(); list2.Sort((lhs, rhs) => comparer.Compare(lhs, rhs)); int num = (list2.Count > 0) ? (list2[0].InnerItem.Appearance.Sortorder - 1) : Settings.DefaultSortOrder; var templateID = new TemplateID(MultivariateTestValueItem.TemplateID); var list3 = new List <KeyValuePair <MultivariateTestValueItem, VariableValueItemStub> >(); var list4 = new List <KeyValuePair <int, VariableValueItemStub> >(); for (int i = variableValues.Count - 1; i >= 0; i--) { VariableValueItemStub stub = variableValues[i]; ID currentId = stub.Id; int index = list2.FindIndex(item => item.ID == currentId); if (index < 0) { var pair = new KeyValuePair <int, VariableValueItemStub>(num--, stub); list4.Add(pair); } else { MultivariateTestValueItem item = list2[index]; if (IsVariableValueChanged(item, stub)) { list3.Add(new KeyValuePair <MultivariateTestValueItem, VariableValueItemStub>(item, stub)); } list2.RemoveAt(index); } } if (list2.Count != 0) { } foreach (Item item2 in list2) { modifiedVariations.Add(item2.ID); item2.Delete(); } foreach (var pair2 in list4) { VariableValueItemStub variableStub = pair2.Value; int key = pair2.Key; string name = variableStub.Name; if (ContainsNonASCIISymbols(name)) { Item item3 = variableItem.Database.GetItem(templateID.ID); name = (item3 != null) ? item3.Name : "Unnamed item"; } if (!ItemUtil.IsItemNameValid(name)) { try { name = ItemUtil.ProposeValidItemName(name); } catch (Exception) { return(false); } } name = ItemUtil.GetUniqueName(variableItem, name); Item item4 = variableItem.InnerItem.Add(name, templateID); Assert.IsNotNull(item4, "newVariableValue"); UpdateVariableValueItem((MultivariateTestValueItem)item4, variableStub, key); } foreach (var pair3 in list3) { MultivariateTestValueItem variableValue = pair3.Key; VariableValueItemStub stub3 = pair3.Value; modifiedVariations.Add(variableValue.ID); UpdateVariableValueItem(variableValue, stub3); } return(true); }
private void RenderContentControls(HtmlTextWriter output, VariableValueItemStub value) { bool flag; Assert.ArgumentNotNull(output, "output"); Assert.ArgumentNotNull(value, "value"); ShortID tid = value.Id.ToShortID(); Item currentContent = null; currentContent = GetCurrentContent(value, out flag); string str = flag ? "default-values" : string.Empty; if (value.HideComponent) { str = str + " display-off"; } output.Write("<div {0} id='{1}_content'>", (str == string.Empty) ? str : ("class='" + str + "'"), tid); string click = value.HideComponent ? "javascript:void(0);" : ("variation:setcontent(variationid=" + tid + ")"); string reset = value.HideComponent ? "javascript:void(0);" : "ResetVariationContent(\\\"{0}\\\")".FormatWith(new object[] {tid}); RenderPicker(output, currentContent, click, reset, true); output.Write("</div>"); }
private Item GetCurrentRenderingItem(VariableValueItemStub value, out bool isFallback) { isFallback = false; if (!string.IsNullOrEmpty(value.ReplacementComponent)) { return Client.ContentDatabase.GetItem(value.ReplacementComponent); } RenderingDefinition rendering = Rendering; if ((rendering != null) && !string.IsNullOrEmpty(rendering.ItemID)) { isFallback = true; return Client.ContentDatabase.GetItem(rendering.ItemID); } return null; }
private string RenderVariableValue(VariableValueItemStub value) { var renderer = new CollapsiblePanelRenderer(); var context3 = new CollapsiblePanelRenderer.ActionsContext { IsVisible = true }; CollapsiblePanelRenderer.ActionsContext actionsContext = context3; string id = value.Id.ToShortID().ToString(); actionsContext.Menu = GetActionsMenu(id); var context4 = new CollapsiblePanelRenderer.NameContext(value.Name) { OnNameChanged = "javascript:Sitecore.CollapsiblePanel.nameChanged(this, event)" }; CollapsiblePanelRenderer.NameContext nameContext = context4; string panelHtml = RenderVariableValueDetails(value); return renderer.Render(id, panelHtml, false, nameContext, actionsContext); }
private void RenderComponentControls(HtmlTextWriter output, VariableValueItemStub value) { bool flag; ShortID tid = value.Id.ToShortID(); Item currentRenderingItem = GetCurrentRenderingItem(value, out flag); string thumbnailSrc = GetThumbnailSrc(currentRenderingItem); string str2 = flag ? "default-values" : string.Empty; if (value.HideComponent) { str2 = str2 + " display-off"; } output.Write("<div id='{0}_component' {1}>", tid, string.IsNullOrEmpty(str2) ? string.Empty : ("class='" + str2 + "'")); output.Write("<div style=\"background-image:url('{0}')\" class='thumbnail-container'>", thumbnailSrc); output.Write("</div>"); output.Write("<div class='picker-container'>"); string click = value.HideComponent ? "javascript:void(0);" : ("variation:setcomponent(variationid=" + tid + ")"); string reset = value.HideComponent ? "javascript:void(0);" : "ResetVariationComponent(\\\"{0}\\\")".FormatWith(new object[] {tid}); RenderPicker(output, currentRenderingItem, click, reset, false); output.Write("</div>"); output.Write("</div>"); }
private static bool IsVariableValueChanged(MultivariateTestValueItem variableItem, VariableValueItemStub variableStub) { Assert.ArgumentNotNull(variableItem, "variableItem"); return((variableItem["Name"] != variableStub.Name) || ((variableItem.Datasource.Path != variableStub.Datasource) || ((variableItem.ReplacementComponent.Path != variableStub.ReplacementComponent) || (variableItem.HideComponent != variableStub.HideComponent)))); }
protected void SetContent(ClientPipelineArgs args) { Predicate <VariableValueItemStub> match = null; Predicate <VariableValueItemStub> predicate2 = null; ID id; string str = args.Parameters["variationid"]; if (string.IsNullOrEmpty(str)) { SheerResponse.Alert("Item not found.", new string[0]); } else { id = ShortID.DecodeID(str); if (args.IsPostBack) { if (args.HasResult) { List <VariableValueItemStub> variableValues = VariableValues; if (match == null) { match = v => v.Id == id; } VariableValueItemStub stub = variableValues.Find(match); if (stub != null) { stub.Datasource = args.Result; var output = new HtmlTextWriter(new StringWriter()); RenderContentControls(output, stub); SheerResponse.SetOuterHtml(str + "_content", output.InnerWriter.ToString()); VariableValues = variableValues; } } } else { if (predicate2 == null) { predicate2 = v => v.Id == id; } VariableValueItemStub stub2 = VariableValues.Find(predicate2); if ((stub2 != null) && ((Rendering != null) && !string.IsNullOrEmpty(Rendering.ItemID))) { Item renderingItem = Client.ContentDatabase.GetItem(Rendering.ItemID); if (renderingItem == null) { SheerResponse.Alert("Item not found.", new string[0]); } else { //get current content item Item variantSourceItem = (ContextItemUri == null) ? null : Client.ContentDatabase.GetItem(ContextItemUri.ToDataUri()); if (variantSourceItem.IsNotNull()) { //use variant mapping functionality to find proper source MultiVariantProcessor processor = new MultiVariantProcessor(); IMultiVariantMapping mapping = processor.GetMapping(variantSourceItem.TemplateID.ToString(), Client.ContentDatabase); if (mapping != null) { //set mapping variantSourceItem = mapping.VariantSource(variantSourceItem); } } var args3 = new GetRenderingDatasourceArgs(renderingItem); args3.FallbackDatasourceRoots = new List <Item> { variantSourceItem }; args3.ContentLanguage = ((variantSourceItem != null) ? variantSourceItem.Language : null); args3.ContextItemPath = (variantSourceItem != null) ? variantSourceItem.Paths.FullPath : string.Empty; args3.ShowDialogIfDatasourceSetOnRenderingItem = true; args3.CurrentDatasource = (string.IsNullOrEmpty(stub2.Datasource) ? Rendering.Datasource : stub2.Datasource); GetRenderingDatasourceArgs args2 = args3; CorePipeline.Run("getRenderingDatasource", args2); if (string.IsNullOrEmpty(args2.DialogUrl)) { SheerResponse.Alert("An error ocurred.", new string[0]); } else { SheerResponse.ShowModalDialog(args2.DialogUrl, "460px", "460px", string.Empty, true); args.WaitForPostBack(); } } } } } }
private string RenderVariableValueDetails(VariableValueItemStub value) { var output = new HtmlTextWriter(new StringWriter()); output.Write("<table class='top-row'>"); output.Write("<tr>"); output.Write("<td class='left test-title'>"); output.Write(Translate.Text("Test Content Item:")); output.Write("</td>"); output.Write("<td class='right'>"); output.Write("</td>"); output.Write("</tr>"); output.Write("<tr>"); output.Write("<td class='left test-content'>"); RenderContentControls(output, value); output.Write("</td>"); output.Write("<td class='right display-component'>"); RenderDisplayControls(output, value); output.Write("</td>"); output.Write("</tr>"); output.Write("<tr class='component-row'>"); output.Write("<td class='left test-title'>"); output.Write(Translate.Text("Test Component Design:")); output.Write("</td>"); output.Write("<td rowspan='2' class='right'>"); output.Write("</td>"); output.Write("</tr>"); output.Write("<tr class='component-row'>"); output.Write("<td class='left test-component'>"); RenderComponentControls(output, value); output.Write("</td>"); output.Write("</tr>"); output.Write("</table>"); return output.InnerWriter.ToString(); }