protected void ShowConfirm(ClientPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (!args.IsPostBack)
            {
                SheerResponse.Confirm("Personalize component settings will be removed. Are you sure you want to continue?");
                args.WaitForPostBack();
                return;
            }
            if (!args.HasResult || !(args.Result != "no"))
            {
                this.ComponentPersonalization.Checked = true;
                return;
            }
            SheerResponse.Eval("scTogglePersonalizeComponentSection()");
            XElement rulesSet = this.RulesSet;

            foreach (XElement xElement in rulesSet.Elements("rule"))
            {
                XElement actionById = PersonalizationFormWithActions.GetActionById(xElement, this.SetRenderingActionId);
                if (actionById == null)
                {
                    continue;
                }
                actionById.Remove();
                HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new StringWriter());
                this.RenderSetRenderingAction(xElement, htmlTextWriter);
                ShortID shortID = ShortID.Parse(xElement.GetAttributeValue("uid"));
                Assert.IsNotNull(shortID, "ruleId");
                SheerResponse.SetInnerHtml(string.Concat(shortID, "_setrendering"), htmlTextWriter.InnerWriter.ToString().Replace("{ID}", shortID.ToString()));
            }
            this.RulesSet = rulesSet;
        }
 private bool IsComponentDisplayed(XElement rule)
 {
     Assert.ArgumentNotNull(rule, "rule");
     if (PersonalizationFormWithActions.GetActionById(rule, this.HideRenderingActionId) != null)
     {
         return(false);
     }
     return(true);
 }
        private bool IsComponentDisplayed(string id)
        {
            Assert.ArgumentNotNull(id, "id");
            XElement ruleById = PersonalizationFormWithActions.GetRuleById(this.RulesSet, id);

            if (ruleById != null && !this.IsComponentDisplayed(ruleById))
            {
                return(false);
            }
            return(true);
        }
        private static void RemoveAction(XElement rule, string id)
        {
            Assert.ArgumentNotNull(rule, "rule");
            Assert.ArgumentNotNull(id, "id");
            XElement actionById = PersonalizationFormWithActions.GetActionById(rule, id);

            if (actionById == null)
            {
                return;
            }
            actionById.Remove();
        }
        private void RenderSetRenderingAction(XElement rule, HtmlTextWriter writer)
        {
            Assert.ArgumentNotNull(rule, "rule");
            Assert.ArgumentNotNull(writer, "writer");
            string   itemID     = this.RenderingDefition.ItemID;
            XElement actionById = PersonalizationFormWithActions.GetActionById(rule, this.SetRenderingActionId);
            bool     flag       = true;

            if (actionById != null)
            {
                string attributeValue = actionById.GetAttributeValue("RenderingItem");
                if (!string.IsNullOrEmpty(attributeValue))
                {
                    itemID = attributeValue;
                    flag   = false;
                }
            }
            writer.Write(string.Concat("<div ", (!flag ? string.Empty : "class='default-values'"), ">"));
            if (string.IsNullOrEmpty(itemID))
            {
                writer.Write("</div>");
                return;
            }
            Item item = Client.ContentDatabase.GetItem(itemID);

            if (item == null)
            {
                writer.Write("</div>");
                return;
            }
            writer.Write("<span class='section-header' unselectable='on'>");
            writer.Write(Translate.Text("Presentation:"));
            writer.Write("</span>");
            string themedImageSource = Images.GetThemedImageSource(item.Appearance.Icon, ImageDimension.id48x48);

            if (!string.IsNullOrEmpty(item.Appearance.Thumbnail) && item.Appearance.Thumbnail != Settings.DefaultThumbnail)
            {
                string thumbnailSrc = UIUtil.GetThumbnailSrc(item, 128, 128);
                if (!string.IsNullOrEmpty(thumbnailSrc))
                {
                    themedImageSource = thumbnailSrc;
                }
            }
            writer.Write("<div style=\"background-image:url('{0}')\" class='thumbnail-container'>", HttpUtility.HtmlEncode(themedImageSource));
            writer.Write("</div>");
            writer.Write("<div class='picker-container'>");
            this.RenderPicker(writer, item, "SetRenderingClick", "ResetRendering", false, false);
            writer.Write("</div>");
            writer.Write("</div>");
        }
        private string GetRuleSectionHtml(XElement rule)
        {
            Assert.ArgumentNotNull(rule, "rule");
            HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new StringWriter());
            string         str            = ShortID.Parse(rule.GetAttributeValue("uid")).ToString();

            htmlTextWriter.Write("<table id='{ID}_body' cellspacing='0' cellpadding='0' class='rule-body'>");
            htmlTextWriter.Write("<tbody>");
            htmlTextWriter.Write("<tr>");
            htmlTextWriter.Write("<td class='left-column'>");
            this.RenderRuleConditions(rule, htmlTextWriter);
            htmlTextWriter.Write("</td>");
            htmlTextWriter.Write("<td class='right-column'>");
            this.RenderRuleActions(rule, htmlTextWriter);
            htmlTextWriter.Write("</td>");
            htmlTextWriter.Write(this.RenderRulePlaceholder("afterAction", rule));
            htmlTextWriter.Write("</tr>");
            htmlTextWriter.Write("</tbody>");
            htmlTextWriter.Write("</table>");
            string str1 = htmlTextWriter.InnerWriter.ToString().Replace("{ID}", str);
            bool   flag = PersonalizationFormWithActions.IsDefaultCondition(rule);

            CollapsiblePanelRenderer.ActionsContext actionsMenu = new CollapsiblePanelRenderer.ActionsContext()
            {
                IsVisible = !flag
            };
            if (!flag)
            {
                actionsMenu.OnActionClick = "javascript:return Sitecore.CollapsiblePanel.showActionsMenu(this,event)";
                actionsMenu.Menu          = this.GetActionsMenu(str);
            }
            string attributeValue = "Default";

            if (!flag || !string.IsNullOrEmpty(rule.GetAttributeValue("name")))
            {
                attributeValue = rule.GetAttributeValue("name");
            }
            CollapsiblePanelRenderer.NameContext nameContext = new CollapsiblePanelRenderer.NameContext(attributeValue)
            {
                Editable      = !flag,
                OnNameChanged = "javascript:return Sitecore.CollapsiblePanel.renameComplete(this,event)"
            };
            CollapsiblePanelRenderer.NameContext nameContext1             = nameContext;
            CollapsiblePanelRenderer             collapsiblePanelRenderer = new CollapsiblePanelRenderer()
            {
                CssClass = "rule-container"
            };

            return(collapsiblePanelRenderer.Render(str, str1, nameContext1, actionsMenu));
        }
        protected void SetRendering(ClientPipelineArgs args)
        {
            string result;

            Assert.ArgumentNotNull(args, "args");
            if (!args.IsPostBack)
            {
                string placeholder = this.RenderingDefition.Placeholder;
                Assert.IsNotNull(placeholder, "placeholder");
                string layout = this.Layout;
                GetPlaceholderRenderingsArgs getPlaceholderRenderingsArg = new GetPlaceholderRenderingsArgs(placeholder, layout, Client.ContentDatabase, ID.Parse(this.DeviceId))
                {
                    OmitNonEditableRenderings = true
                };
                getPlaceholderRenderingsArg.Options.ShowOpenProperties = false;
                CorePipeline.Run("getPlaceholderRenderings", getPlaceholderRenderingsArg);
                string dialogURL = getPlaceholderRenderingsArg.DialogURL;
                if (string.IsNullOrEmpty(dialogURL))
                {
                    SheerResponse.Alert("An error occurred.", new string[0]);
                    return;
                }
                SheerResponse.ShowModalDialog(dialogURL, "720px", "470px", string.Empty, true);
                args.WaitForPostBack();
                return;
            }
            if (args.HasResult)
            {
                if (args.Result.IndexOf(',') < 0)
                {
                    result = args.Result;
                }
                else
                {
                    string str      = args.Result;
                    char[] chrArray = new char[] { ',' };
                    result = str.Split(chrArray)[0];
                }
                XElement rulesSet = this.RulesSet;
                string   item     = args.Parameters["id"];
                XElement ruleById = PersonalizationFormWithActions.GetRuleById(rulesSet, item);
                Assert.IsNotNull(ruleById, "rule");
                (PersonalizationFormWithActions.GetActionById(ruleById, this.SetRenderingActionId) ?? PersonalizationFormWithActions.AddAction(ruleById, this.SetRenderingActionId)).SetAttributeValue("RenderingItem", ShortID.DecodeID(result));
                this.RulesSet = rulesSet;
                HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new StringWriter());
                this.RenderSetRenderingAction(ruleById, htmlTextWriter);
                SheerResponse.SetInnerHtml(string.Concat(item, "_setrendering"), htmlTextWriter.InnerWriter.ToString().Replace("{ID}", item));
            }
        }
        private void RenderRules()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("<div id='non-default-container'>");
            foreach (XElement xElement in this.RulesSet.Elements("rule"))
            {
                if (PersonalizationFormWithActions.IsDefaultCondition(xElement))
                {
                    stringBuilder.Append("</div>");
                }
                stringBuilder.Append(this.GetRuleSectionHtml(xElement));
            }
            this.RulesContainer.InnerHtml = stringBuilder.ToString();
        }
        protected void MoveConditionBefore(string id, string targetId)
        {
            Assert.ArgumentNotNull(id, "id");
            Assert.ArgumentNotNull(targetId, "targetId");
            XElement rulesSet = this.RulesSet;
            XElement ruleById = PersonalizationFormWithActions.GetRuleById(rulesSet, id);
            XElement xElement = PersonalizationFormWithActions.GetRuleById(rulesSet, targetId);

            if (ruleById != null && xElement != null)
            {
                ruleById.Remove();
                xElement.AddBeforeSelf(ruleById);
                this.RulesSet = rulesSet;
            }
        }
        protected void RenameRuleClick(Message message)
        {
            Assert.ArgumentNotNull(message, "message");
            string item = message.Arguments["ruleId"];
            string str  = message.Arguments["name"];

            Assert.IsNotNull(item, "id");
            if (!string.IsNullOrEmpty(str))
            {
                XElement rulesSet = this.RulesSet;
                XElement ruleById = PersonalizationFormWithActions.GetRuleById(rulesSet, item);
                if (ruleById != null)
                {
                    ruleById.SetAttributeValue("name", str);
                    this.RulesSet = rulesSet;
                }
            }
        }
        protected void ResetRendering(string id)
        {
            Assert.ArgumentNotNull(id, "id");
            if (!this.IsComponentDisplayed(id))
            {
                return;
            }
            XElement rulesSet = this.RulesSet;
            XElement ruleById = PersonalizationFormWithActions.GetRuleById(rulesSet, id);

            if (ruleById != null)
            {
                PersonalizationFormWithActions.RemoveAction(ruleById, this.SetRenderingActionId);
                this.RulesSet = rulesSet;
                HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new StringWriter());
                this.RenderSetRenderingAction(ruleById, htmlTextWriter);
                SheerResponse.SetInnerHtml(string.Concat(id, "_setrendering"), htmlTextWriter.InnerWriter.ToString().Replace("{ID}", id));
            }
        }
        private void RenderSetDatasourceAction(XElement rule, HtmlTextWriter writer)
        {
            Assert.ArgumentNotNull(rule, "rule");
            Assert.ArgumentNotNull(writer, "writer");
            string   datasource = this.RenderingDefition.Datasource;
            XElement actionById = PersonalizationFormWithActions.GetActionById(rule, this.SetDatasourceActionId);
            bool     flag       = true;

            if (actionById == null)
            {
                datasource = string.Empty;
            }
            else
            {
                datasource = actionById.GetAttributeValue("DataSource");
                flag       = false;
            }
            Item contextItem = null;
            bool flag1       = false;

            if (string.IsNullOrEmpty(datasource))
            {
                contextItem = this.ContextItem;
                flag1       = true;
            }
            else
            {
                contextItem = Client.ContentDatabase.GetItem(datasource);
            }
            writer.Write(string.Concat("<div ", (!flag ? string.Empty : "class='default-values'"), ">"));
            writer.Write("<span class='section-header' unselectable='on'>");
            writer.Write(Translate.Text("Content:"));
            writer.Write("</span>");
            if (contextItem != null)
            {
                this.RenderPicker(writer, contextItem, "SetDatasourceClick", "ResetDatasource", !flag1, flag1);
            }
            else
            {
                this.RenderPicker(writer, datasource, "SetDatasourceClick", "ResetDatasource", !flag1, flag1);
            }
            writer.Write("</div>");
        }
        protected void SwitchRenderingClick(string id)
        {
            Assert.ArgumentNotNull(id, "id");
            XElement rulesSet = this.RulesSet;
            XElement ruleById = PersonalizationFormWithActions.GetRuleById(rulesSet, id);

            if (ruleById != null)
            {
                if (this.IsComponentDisplayed(ruleById))
                {
                    PersonalizationFormWithActions.AddAction(ruleById, this.HideRenderingActionId);
                }
                else
                {
                    PersonalizationFormWithActions.RemoveAction(ruleById, this.HideRenderingActionId);
                }
                this.RulesSet = rulesSet;
            }
        }
        private void RenderRuleConditions(XElement rule, HtmlTextWriter writer)
        {
            Assert.ArgumentNotNull(rule, "rule");
            Assert.ArgumentNotNull(writer, "writer");
            bool flag = PersonalizationFormWithActions.IsDefaultCondition(rule);

            if (!flag)
            {
                Button button = new Button()
                {
                    Header  = Translate.Text("Edit rule"),
                    ToolTip = Translate.Text("Edit this rule"),
                    Class   = "scButton edit-button",
                    Click   = "EditConditionClick(\\\"{ID}\\\")"
                };
                writer.Write(HtmlUtil.RenderControl(button));
            }
            writer.Write(string.Concat("<div id='{ID}_rule' class='", (!flag ? "condition-container" : "condition-container default"), "'>"));
            writer.Write((flag ? this.ConditionDescriptionDefault : PersonalizationFormWithActions.GetRuleConditionsHtml(rule)));
            writer.Write("</div>");
        }
        protected void SetDatasource(ClientPipelineArgs args)
        {
            Language language;

            Assert.ArgumentNotNull(args, "args");
            string   item     = args.Parameters["id"];
            XElement rulesSet = this.RulesSet;
            XElement ruleById = PersonalizationFormWithActions.GetRuleById(rulesSet, item);

            Assert.IsNotNull(ruleById, "rule");
            if (args.IsPostBack)
            {
                if (args.HasResult)
                {
                    (PersonalizationFormWithActions.GetActionById(ruleById, this.SetDatasourceActionId) ?? PersonalizationFormWithActions.AddAction(ruleById, this.SetDatasourceActionId)).SetAttributeValue("DataSource", args.Result);
                    this.RulesSet = rulesSet;
                    HtmlTextWriter htmlTextWriter = new HtmlTextWriter(new StringWriter());
                    this.RenderSetDatasourceAction(ruleById, htmlTextWriter);
                    SheerResponse.SetInnerHtml(string.Concat(item, "_setdatasource"), htmlTextWriter.InnerWriter.ToString().Replace("{ID}", item));
                }
                return;
            }
            XElement actionById = PersonalizationFormWithActions.GetActionById(ruleById, this.SetRenderingActionId);
            Item     item1      = null;

            if (actionById != null && !string.IsNullOrEmpty(actionById.GetAttributeValue("RenderingItem")))
            {
                item1 = Client.ContentDatabase.GetItem(actionById.GetAttributeValue("RenderingItem"));
            }
            else if (!string.IsNullOrEmpty(this.RenderingDefition.ItemID))
            {
                item1 = Client.ContentDatabase.GetItem(this.RenderingDefition.ItemID);
            }
            if (item1 == null)
            {
                SheerResponse.Alert("Item not found.", new string[0]);
                return;
            }
            Item contextItem = this.ContextItem;
            GetRenderingDatasourceArgs getRenderingDatasourceArg = new GetRenderingDatasourceArgs(item1)
            {
                FallbackDatasourceRoots = new List <Item>()
                {
                    Client.ContentDatabase.GetRootItem()
                }
            };
            GetRenderingDatasourceArgs getRenderingDatasourceArg1 = getRenderingDatasourceArg;

            if (contextItem != null)
            {
                language = contextItem.Language;
            }
            else
            {
                language = null;
            }
            getRenderingDatasourceArg1.ContentLanguage = language;
            getRenderingDatasourceArg.ContextItemPath  = (contextItem != null ? contextItem.Paths.FullPath : string.Empty);
            getRenderingDatasourceArg.ShowDialogIfDatasourceSetOnRenderingItem = true;
            GetRenderingDatasourceArgs datasource = getRenderingDatasourceArg;
            XElement xElement = PersonalizationFormWithActions.GetActionById(ruleById, this.SetDatasourceActionId);

            if (xElement == null || string.IsNullOrEmpty(xElement.GetAttributeValue("DataSource")))
            {
                datasource.CurrentDatasource = this.RenderingDefition.Datasource;
            }
            else
            {
                datasource.CurrentDatasource = xElement.GetAttributeValue("DataSource");
            }
            if (string.IsNullOrEmpty(datasource.CurrentDatasource))
            {
                datasource.CurrentDatasource = contextItem.ID.ToString();
            }
            CorePipeline.Run("getRenderingDatasource", datasource);
            if (string.IsNullOrEmpty(datasource.DialogUrl))
            {
                SheerResponse.Alert("An error occurred.", new string[0]);
                return;
            }
            SheerResponse.ShowModalDialog(datasource.DialogUrl, "960px", "660px", string.Empty, true);
            args.WaitForPostBack();
        }
        private bool PersonalizeComponentActionExists()
        {
            XElement rulesSet = this.RulesSet;

            return(rulesSet.Elements("rule").Any <XElement>((XElement rule) => PersonalizationFormWithActions.GetActionById(rule, this.SetRenderingActionId) != null));
        }
        protected void EditCondition(ClientPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (string.IsNullOrEmpty(args.Parameters["id"]))
            {
                SheerResponse.Alert("Please select a rule", new string[0]);
                return;
            }
            string str = ID.Decode(args.Parameters["id"]).ToString();

            if (args.IsPostBack)
            {
                if (args.HasResult)
                {
                    string   result   = args.Result;
                    XElement xElement = XElement.Parse(result).Element("rule");
                    XElement rulesSet = this.RulesSet;
                    if (xElement != null)
                    {
                        XElement xElement1 = (
                            from node in rulesSet.Elements("rule")
                            where node.GetAttributeValue("uid") == str
                            select node).FirstOrDefault <XElement>();
                        if (xElement1 != null)
                        {
                            xElement1.ReplaceWith(xElement);
                            this.RulesSet = rulesSet;
                            SheerResponse.SetInnerHtml(string.Concat(args.Parameters["id"], "_rule"), PersonalizationFormWithActions.GetRuleConditionsHtml(xElement));
                        }
                    }
                }
                return;
            }
            RulesEditorOptions rulesEditorOption = new RulesEditorOptions()
            {
                IncludeCommon = true,
                RulesPath     = "/sitecore/system/settings/Rules/Conditional Renderings",
                AllowMultiple = false
            };
            RulesEditorOptions rulesEditorOption1 = rulesEditorOption;
            XElement           xElement2          = (
                from node in this.RulesSet.Elements("rule")
                where node.GetAttributeValue("uid") == str
                select node).FirstOrDefault <XElement>();

            if (xElement2 != null)
            {
                rulesEditorOption1.Value = string.Concat("<ruleset>", xElement2, "</ruleset>");
            }
            // rulesEditorOption1.HideActions = true;  // FIRST CHANGE
            SheerResponse.ShowModalDialog(rulesEditorOption1.ToUrlString().ToString(), "580px", "712px", string.Empty, true);
            args.WaitForPostBack();
        }