private void BuildPlaceholder(Border border, DeviceDefinition deviceDefinition, PlaceholderDefinition placeholderDefinition)
        {
            string str3;

            Assert.ArgumentNotNull(border, "border");
            Assert.ArgumentNotNull(deviceDefinition, "deviceDefinition");
            Assert.ArgumentNotNull(placeholderDefinition, "placeholderDefinition");
            string metaDataItemId = placeholderDefinition.MetaDataItemId;
            Border child          = new Border();

            border.Controls.Add(child);
            string str2 = StringUtil.GetString(new string[] { this.EditPlaceholderClick }).Replace("$Device", deviceDefinition.ID).Replace("$UniqueID", placeholderDefinition.UniqueId);

            Assert.IsNotNull(metaDataItemId, "placeholder id");
            Item item = Client.ContentDatabase.GetItem(metaDataItemId);

            if (item != null)
            {
                string displayName = item.DisplayName;
                str3 = Images.GetImage(item.Appearance.Icon, 0x10, 0x10, "absmiddle", "0px 4px 0px 0px") + displayName;
            }
            else
            {
                str3 = Images.GetImage("Imaging/16x16/layer_blend.png", 0x10, 0x10, "absmiddle", "0px 4px 0px 0px") + placeholderDefinition.Key;
            }
            if (!string.IsNullOrEmpty(str2))
            {
                child.RollOver = true;
                child.Class    = "scRollOver";
                child.Click    = str2;
            }
            Sitecore.Web.UI.HtmlControls.Literal literal = new Sitecore.Web.UI.HtmlControls.Literal("<div style=\"padding:2\">" + str3 + "</div>");
            child.Controls.Add(literal);
        }
        private void CreateControls(int id, string email)
        {
            var editRecipient = new Edit
            {
                Width = new Unit("100%"),
                ID    = "editRecipient" + id,
                Value = email
            };

            for (var i = 1; i < id; i++)
            {
                var edit = gpConfigurations.FindControl("editRecipient" + i) as Edit;
                if (edit != null)
                {
                    edit.Width = new Unit("100%");
                }
            }
            var lRecipient = new Literal
            {
                Text  = "E-mail №" + id,
                ID    = "lRecipient" + id,
                Value = Recipients.ToString(CultureInfo.InvariantCulture)
            };

            gpConfigurations.Controls.Add(lRecipient);
            gpConfigurations.Controls.Add(editRecipient);
        }
Ejemplo n.º 3
0
        protected void SetStatus(int step, StatusType t, string message)
        {
            int         pos = (step > 0) ? step - 1 : 0;
            HtmlLiteral i   = StatusImages[pos];
            HtmlLiteral m   = MessageFields[pos];
            ImageSet    p   = StatusTypes[t];

            i.Text = ThemeManager.GetImage(p.Src, p.Width, p.Height);
            m.Text = message;
        }
        private void AddDelSection(string idPostfix)
        {
            ImageBuilder builder = new ImageBuilder
            {
                Src    = "Applications/16x16/delete2.png",
                Width  = 0x10,
                Height = 0x10,
                Style  = "cursor: pointer"
            };

            Sitecore.Web.UI.HtmlControls.Literal child = new Sitecore.Web.UI.HtmlControls.Literal
            {
                Text = builder.ToString()
            };
            Border border = new Border
            {
                ID    = "DelSection" + idPostfix,
                Click = "DelSection_Click"
            };

            border.Controls.Add(child);
            this.ParentControl.Controls.Add(border);
        }
        protected override void OnLoad(EventArgs args)
        {
            if (!Sitecore.Context.ClientPage.IsEvent)
             {
            SetProperties();
            GridPanel gridPanel = new GridPanel();
            Controls.Add(gridPanel);
            gridPanel.Columns = 4;
            GetControlAttributes();

            foreach (string text2 in base.Attributes.Keys)
            {
               gridPanel.Attributes.Add(text2, base.Attributes[text2]);
            }

            gridPanel.Style["margin"] = "0px 0px 4px 0px";
            SetViewStateString("ID", ID);
            Sitecore.Web.UI.HtmlControls.Literal literal = new Sitecore.Web.UI.HtmlControls.Literal("All");
            literal.Class = ("scContentControlMultilistCaption");

            gridPanel.Controls.Add(literal);
            gridPanel.SetExtensibleProperty(literal, "Width", "50%");
            gridPanel.SetExtensibleProperty(literal, "Row.Height", "20px");

            LiteralControl spacer = new LiteralControl(Images.GetSpacer(24, 1));
            gridPanel.Controls.Add(spacer);
            gridPanel.SetExtensibleProperty(spacer, "Width", "24px");

            literal = new Sitecore.Web.UI.HtmlControls.Literal("Selected");
            literal.Class = "scContentControlMultilistCaption";

            gridPanel.Controls.Add(literal);
            gridPanel.SetExtensibleProperty(literal, "Width", "50%");

            spacer = new LiteralControl(Images.GetSpacer(24, 1));
            gridPanel.Controls.Add(spacer);
            gridPanel.SetExtensibleProperty(spacer, "Width", "24px");

            Scrollbox scrollbox = new Scrollbox();
            scrollbox.ID = GetUniqueID("S");

            gridPanel.Controls.Add(scrollbox);
            scrollbox.Style["border"] = "3px window-inset";
            gridPanel.SetExtensibleProperty(scrollbox, "rowspan", "2");

            DataTreeview dataTreeView = new DataTreeview();
            dataTreeView.ID = ID + "_all";
            scrollbox.Controls.Add(dataTreeView);
            dataTreeView.DblClick = ID + ".Add";

            ImageBuilder builderRight = new ImageBuilder();
            builderRight.Src = "Applications/16x16/nav_right_blue.png";
            builderRight.ID = ID + "_right";
            builderRight.Width = 0x10;
            builderRight.Height = 0x10;
            builderRight.Margin = "2";
            builderRight.OnClick = Sitecore.Context.ClientPage.GetClientEvent(ID + ".Add");

            ImageBuilder builderLeft = new ImageBuilder();
            builderLeft.Src = "Applications/16x16/nav_left_blue.png";
            builderLeft.ID = ID + "_left";
            builderLeft.Width = 0x10;
            builderLeft.Height = 0x10;
            builderLeft.Margin = "2";
            builderLeft.OnClick = Sitecore.Context.ClientPage.GetClientEvent(ID + ".Remove");

            LiteralControl literalControl = new LiteralControl(builderRight.ToString() + "<br/>" + builderLeft.ToString());
            gridPanel.Controls.Add(literalControl);
            gridPanel.SetExtensibleProperty(literalControl, "Width", "30");
            gridPanel.SetExtensibleProperty(literalControl, "Align", "center");
            gridPanel.SetExtensibleProperty(literalControl, "VAlign", "top");
            gridPanel.SetExtensibleProperty(literalControl, "rowspan", "2");

            Sitecore.Web.UI.HtmlControls.Listbox listbox = new Listbox();
                listBox = listbox;
            gridPanel.SetExtensibleProperty(listbox, "VAlign", "top");
            gridPanel.SetExtensibleProperty(listbox, "Height", "100%");

            gridPanel.Controls.Add(listbox);
            listbox.ID = ID + "_selected";
            listbox.DblClick = ID + ".Remove";
            listbox.Style["width"] = "100%";
            listbox.Size = "10";
            listbox.Attributes["onchange"] = "javascript:document.getElementById('" + this.ID + "_help').innerHTML=this.selectedIndex>=0?this.options[this.selectedIndex].innerHTML:''";
            listbox.Attributes["class"] = "scContentControlMultilistBox";

            dataTreeView.Disabled = ReadOnly;
            listbox.Disabled = ReadOnly;

            ImageBuilder builderUp = new ImageBuilder();
            builderUp.Src = "Applications/16x16/nav_up_blue.png";
            builderUp.ID = ID + "_up";
            builderUp.Width = 0x10;
            builderUp.Height = 0x10;
            builderUp.Margin = "2px";
            builderUp.OnClick = Sitecore.Context.ClientPage.GetClientEvent(ID + ".Up");

            ImageBuilder builderDown = new ImageBuilder();
            builderDown.Src = "Applications/16x16/nav_down_blue.png";
            builderDown.ID = ID + "_down";
            builderDown.Width = 0x10;
            builderDown.Height = 0x10;
            builderDown.Margin = "2";
            builderDown.OnClick = Sitecore.Context.ClientPage.GetClientEvent(ID + ".Down");

            literalControl = new LiteralControl(builderUp.ToString() + "<br/>" + builderDown.ToString());
            gridPanel.Controls.Add(literalControl);
            gridPanel.SetExtensibleProperty(literalControl, "Width", "30");
            gridPanel.SetExtensibleProperty(literalControl, "Align", "center");
            gridPanel.SetExtensibleProperty(literalControl, "VAlign", "top");
            gridPanel.SetExtensibleProperty(literalControl, "rowspan", "2");
            gridPanel.Controls.Add(new LiteralControl("<div style=\"border:1px solid #999999;font:8pt tahoma;padding:2px;margin:4px 0px 4px 0px;height:14px\" id=\"" + this.ID + "_help\"></div>"));

            DataContext treeContext = new DataContext();
            gridPanel.Controls.Add(treeContext);
            treeContext.ID = GetUniqueID("D");
            treeContext.Filter = FormTemplateFilterForDisplay();
            dataTreeView.DataContext = treeContext.ID;
            treeContext.DataViewName = "Master";
            if (!string.IsNullOrEmpty(this.SourceDatabaseName))
            {
               treeContext.Parameters = "databasename=" + this.SourceDatabaseName;
            }
            treeContext.Root = DataSource;
            dataTreeView.EnableEvents();

            listbox.Size = "10";
            gridPanel.Fixed = true;
            dataTreeView.AutoUpdateDataContext = true;
            dataTreeView.ShowRoot = true;
            listbox.Attributes["class"] = "scContentControlMultilistBox";

            gridPanel.SetExtensibleProperty(scrollbox, "Height", "100%");
            RestoreState();
             }
             base.OnLoad(args);
        }
 private void CreateControls(int id, string email)
 {
     var editRecipient = new Edit
       {
     Width = new Unit("100%"),
     ID = "editRecipient" + id,
     Value = email
       };
       for (var i = 1; i < id; i++)
       {
     var edit = gpConfigurations.FindControl("editRecipient" + i) as Edit;
     if (edit != null) edit.Width = new Unit("100%");
       }
       var lRecipient = new Literal
       {
     Text = "E-mail №" + id,
     ID = "lRecipient" + id,
     Value = Recipients.ToString(CultureInfo.InvariantCulture)
       };
       gpConfigurations.Controls.Add(lRecipient);
       gpConfigurations.Controls.Add(editRecipient);
 }
Ejemplo n.º 7
0
        private Control GetVariableEditor(IDictionary variable)
        {
            var value = variable["Value"];
            var name = (string) variable["Name"];
            var editor = variable["Editor"] as string;
            var type = value.GetType();

            if (type == typeof (DateTime) ||
                (!string.IsNullOrEmpty(editor) &&
                 (editor.IndexOf("date", StringComparison.OrdinalIgnoreCase) > -1 ||
                  editor.IndexOf("time", StringComparison.OrdinalIgnoreCase) > -1)))
            {
                var dateTimePicker = new DateTimePicker
                {
                    ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                    ShowTime = (variable["ShowTime"] != null && (bool) variable["ShowTime"]) ||
                               (!string.IsNullOrEmpty(editor) &&
                                editor.IndexOf("time", StringComparison.OrdinalIgnoreCase) > -1)
                };
                if (value is DateTime)
                {
                    var date = (DateTime) value;
                    if (date != DateTime.MinValue && date != DateTime.MaxValue)
                    {
                        dateTimePicker.Value = (date.Kind != DateTimeKind.Utc)
                            ? DateUtil.ToIsoDate(TypeResolver.Resolve<IDateConverter>("IDateConverter").ToServerTime(date))
                            : DateUtil.ToIsoDate(date);
                    }
                }
                else
                {
                    dateTimePicker.Value = value as string ?? string.Empty;
                }
                return dateTimePicker;
            }

            if (!string.IsNullOrEmpty(editor) && editor.IndexOf("rule", StringComparison.OrdinalIgnoreCase) > -1)
            {
                string editorId = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name+"_");
                Sitecore.Context.ClientPage.ServerProperties[editorId] = value;

                var rulesBorder = new Border
                {
                    Class = "rulesWrapper",
                    ID = editorId
                };

                Button rulesEditButton = new Button
                {
                    Header = "Edit rule",
                    Class = "scButton edit-button rules-edit-button",
                    Click = "EditConditionClick(\\\"" + editorId + "\\\")"
                };

                rulesBorder.Controls.Add(rulesEditButton);
                var rulesRender = new Literal
                {
                    ID = editorId + "_renderer",
                    Text = GetRuleConditionsHtml(
                        string.IsNullOrEmpty(value as string) ? "<ruleset />" : value as string)
                };
                rulesRender.Class = rulesRender.Class + " varRule";
                rulesBorder.Controls.Add(rulesRender);
                return rulesBorder;
            }

            if (!string.IsNullOrEmpty(editor) &&
                (editor.IndexOf("treelist", StringComparison.OrdinalIgnoreCase) > -1 ||
                 (editor.IndexOf("multilist", StringComparison.OrdinalIgnoreCase) > -1) ||
                 (editor.IndexOf("droplist", StringComparison.OrdinalIgnoreCase) > -1)))
            {
                Item item = null;
                var strValue = string.Empty;
                if (value is Item)
                {
                    item = (Item) value;
                    strValue = item.ID.ToString();
                }
                else if (value is IEnumerable<object>)
                {
                    List<Item> items = (value as IEnumerable<object>).Cast<Item>().ToList();
                    item = items.FirstOrDefault();
                    strValue = string.Join("|", items.Select(i => i.ID.ToString()).ToArray());
                }

                var dbName = item == null ? Sitecore.Context.ContentDatabase.Name : item.Database.Name;
                if (editor.IndexOf("multilist", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    var multiList = new MultilistExtended
                    {
                        ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                        Value = strValue,
                        Database = dbName,
                        ItemID = "{11111111-1111-1111-1111-111111111111}",
                        Source = variable["Source"] as string ?? "/sitecore",
                    };
                    multiList.SetLanguage(Sitecore.Context.Language.Name);

                    multiList.Class += "  treePicker";
                    return multiList;
                }

                if (editor.IndexOf("droplist", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    var lookup = new LookupEx
                    {
                        ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                        Database = dbName,
                        ItemID = (item != null ? item.ID.ToString() : "{11111111-1111-1111-1111-111111111111}"),
                        Source = variable["Source"] as string ?? "/sitecore",
                        ItemLanguage = Sitecore.Context.Language.Name,
                        Value = (item != null ? item.ID.ToString() : "{11111111-1111-1111-1111-111111111111}")
                    };
                    lookup.Class += " textEdit";
                    return lookup;
                }
                var treeList = new TreeList
                {
                    ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                    Value = strValue,
                    AllowMultipleSelection = true,
                    DatabaseName = dbName,
                    Database = dbName,
                    Source = variable["Source"] as string ?? "/sitecore",
                    DisplayFieldName = variable["DisplayFieldName"] as string ?? "__DisplayName"
                };
                treeList.Class += " treePicker";
                return treeList;
            }
            if (type == typeof (Item) ||
                (!string.IsNullOrEmpty(editor) && (editor.IndexOf("item", StringComparison.OrdinalIgnoreCase) > -1)))
            {
                var item = value as Item;
                var source = variable["Source"] as string;
                var root = variable["Root"] as string;
                var sourceRoot = string.IsNullOrEmpty(source)
                    ? "/sitecore"
                    : StringUtil.ExtractParameter("DataSource", source);
                var dataContext = item != null
                    ? new DataContext
                    {
                        DefaultItem = item.Paths.Path,
                        ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("dataContext"),
                        Parameters = string.IsNullOrEmpty(source) ? "databasename=" + item.Database.Name : source,
                        DataViewName = "Master",
                        Root = string.IsNullOrEmpty(root) ? sourceRoot : root,
                        Database = item.Database.Name,
                        Selected = new[] {new DataUri(item.ID, item.Language, item.Version)},
                        Folder = item.ID.ToString(),
                        Language = item.Language,
                        Version = item.Version
                    }
                    : new DataContext
                    {
                        ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("dataContext"),
                        Parameters = string.IsNullOrEmpty(source) ? "databasename=master" : source,
                        DataViewName = "Master",
                        Root = string.IsNullOrEmpty(root) ? sourceRoot : root
                    };

                DataContextPanel.Controls.Add(dataContext);

                var treePicker = new TreePicker
                {
                    ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                    Value = item != null ? item.ID.ToString() : string.Empty,
                    DataContext = dataContext.ID,
                    AllowNone = !string.IsNullOrEmpty(editor) && (editor.IndexOf("allownone", StringComparison.OrdinalIgnoreCase) > -1)
                };
                treePicker.Class += " treePicker";
                return treePicker;
            }

            if (type == typeof (bool) ||
                (!string.IsNullOrEmpty(editor) && (editor.IndexOf("bool", StringComparison.OrdinalIgnoreCase) > -1)))
            {
                var checkboxBorder = new Border
                {
                    Class = "checkBoxWrapper",
                    ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_")
                };
                var checkBox = new Checkbox
                {
                    ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                    Header = (string) variable["Title"],
                    HeaderStyle = "display:inline-block;",
                    Checked = (bool) value,
                    Class = "varCheckbox"
                };
                checkboxBorder.Controls.Add(checkBox);
                return checkboxBorder;
            }

            if (!string.IsNullOrEmpty(editor))
            {
                var showRoles = editor.IndexOf("role", StringComparison.OrdinalIgnoreCase) > -1;
                var showUsers = editor.IndexOf("user", StringComparison.OrdinalIgnoreCase) > -1;
                var multiple = editor.IndexOf("multiple", StringComparison.OrdinalIgnoreCase) > -1;
                if (showRoles || showUsers)
                {
                    var picker = new UserPicker();
                    picker.Style.Add("float", "left");
                    picker.ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_");
                    picker.Class += " scContentControl textEdit clr" + value.GetType().Name;
                    picker.Value = (value is IEnumerable<object>) ? String.Join("|", ((IEnumerable<object>)value).Select(x => x.ToString()).ToArray()) : value.ToString();
                    picker.ExcludeRoles = !showRoles;
                    picker.ExcludeUsers = !showUsers;
                    picker.DomainName = variable["Domain"] as string ?? variable["DomainName"] as string;
                    picker.Multiple = multiple;
                    picker.Click = "UserPickerClick(" + picker.ID + ")";
                    return picker;
                }
            }

            Sitecore.Web.UI.HtmlControls.Control edit;
            if (!string.IsNullOrEmpty(editor) && editor.IndexOf("info", StringComparison.OrdinalIgnoreCase) > -1)
            {
                return new Literal {Text = value.ToString(), Class = "varHint"};
            }

            if (variable["lines"] != null && ((int) variable["lines"] > 1))
            {
                edit = new Memo();
                edit.Attributes.Add("rows", variable["lines"].ToString());
            }
            else if (variable["Options"] != null)
            {
                var psOptions = variable["Options"].BaseObject();
                var options = new OrderedDictionary();
                if (psOptions is OrderedDictionary)
                {
                    options = psOptions as OrderedDictionary;
                }
                else if (psOptions is string)
                {
                    var strOptions = ((string) variable["Options"]).Split('|');
                    var i = 0;
                    while (i < strOptions.Length)
                    {
                        options.Add(strOptions[i++], strOptions[i++]);
                    }
                }
                else if (psOptions is Hashtable)
                {
                    var hashOptions = variable["Options"] as Hashtable;
                    foreach (var key in hashOptions.Keys)
                    {
                        options.Add(key, hashOptions[key]);
                    }
                }
                else
                {
                    throw new Exception("Checklist options format unrecognized.");
                }

                if (!string.IsNullOrEmpty(editor))
                {
                    if (editor.IndexOf("radio", StringComparison.OrdinalIgnoreCase) > -1)
                    {
                        var radioList = new Groupbox
                        {
                            ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                            // Header = (string) variable["Title"],
                            Class = "scRadioGroup"
                        };

                        foreach (var option in options.Keys)
                        {
                            var optionName = option.ToString();
                            var optionValue = options[optionName].ToString();
                            var item = new Radiobutton
                            {
                                Header = optionName,
                                Value = optionValue,
                                ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID(radioList.ID),
                                Name = radioList.ID,
                                Checked = optionValue == value.ToString()
                            };
                            radioList.Controls.Add(item);
                            radioList.Controls.Add(new Literal("<br/>"));
                        }

                        return radioList;
                    }

                    if (editor.IndexOf("check", StringComparison.OrdinalIgnoreCase) > -1)
                    {
                        var checkList = new PSCheckList
                        {
                            ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                            HeaderStyle = "margin-top:20px; display:inline-block;",
                            ItemID = "{11111111-1111-1111-1111-111111111111}"
                        };
                        checkList.SetItemLanguage(Sitecore.Context.Language.Name);
                        string[] values;
                        if (value is string)
                        {
                            values = value.ToString().Split('|');
                        }
                        else if (value is IEnumerable)
                        {
                            values = ((value as IEnumerable).Cast<object>().Select(s => s == null ? "" : s.ToString())).ToArray();
                        }
                        else
                        {
                            values = new[] {value.ToString()};
                        }
                        foreach (var item in from object option in options.Keys
                            select option.ToString()
                            into optionName
                            let optionValue = options[optionName].ToString()
                            select new ChecklistItem
                            {
                                ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID(checkList.ID),
                                Header = optionName,
                                Value = optionValue,
                                Checked = values.Contains(optionValue, StringComparer.OrdinalIgnoreCase)
                            })
                        {
                            checkList.Controls.Add(item);
                        }

                        checkList.TrackModified = false;
                        checkList.Disabled = false;
                        return checkList;
                    }
                }

                edit = new Combobox();
                var placeholder = variable["Placeholder"];
                if (placeholder is string)
                {
                    var option = new ListItem
                    {
                        Header = placeholder.ToString(),
                        Value = "",
                        Selected = true
                    };
                    edit.Controls.Add(option);
                }

                foreach (var option in options.Keys)
                {
                    var optionName = option.ToString();
                    var optionValue = options[optionName].ToString();
                    var item = new ListItem
                    {
                        Header = optionName,
                        Value = optionValue
                    };
                    edit.Controls.Add(item);
                }
            }
            else
            {
                var placeholder = variable["Placeholder"];
                if (!string.IsNullOrEmpty(editor) && editor.IndexOf("pass", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    edit = new PasswordExtended();
                    if (placeholder is string)
                    {
                        ((PasswordExtended)edit).PlaceholderText = placeholder.ToString();
                    }
                }
                else
                {
                    edit = new EditExtended();
                    if (placeholder is string)
                    {
                        ((EditExtended)edit).PlaceholderText = placeholder.ToString();
                    }
                }
            }
            var tip = (variable["Tooltip"] as string);
            if (!String.IsNullOrEmpty(tip))
            {
                edit.ToolTip = tip.RemoveHtmlTags();
            }
            edit.Style.Add("float", "left");
            edit.ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_");
            edit.Class += " scContentControl textEdit clr" + value.GetType().Name;
            edit.Value = value.ToString();

            return edit;
        }
Ejemplo n.º 8
0
        private void AddControls(object[] variables)
        {
            var tabs = new Dictionary<string, Border>(StringComparer.OrdinalIgnoreCase);
            Tabstrip.Visible = variables.Cast<Hashtable>().Select(variable => variable["Tab"] as string).Any(tabName => !string.IsNullOrEmpty(tabName));

            foreach (Hashtable variable in variables)
            {
                var tabName = (variable["Tab"] as string) ?? "Other";
                var name = (variable["Title"] as string) ?? (variable["Name"] as string);
                var hint = (variable["Tip"] as string) ??
                           (variable["Hint"] as string) ?? (variable["Tooltip"] as string);
                var columns =  12;
                bool clearfix = false;
                if (variable["Columns"] != null)
                {
                    var strColumns = variable["Columns"].ToString().Split(' ');
                    foreach (var columnValue in strColumns)
                    {
                        if (int.TryParse(columnValue, out columns))
                        {
                            if (columns > 12 && columns < 0)
                            {
                                columns = 12;
                            }
                        }
                        break;
                    }
                    clearfix = strColumns.Contains("first", StringComparer.OrdinalIgnoreCase);
                }
                var container = GetContainer(tabs, tabName);
                var input = GetVariableEditor(variable);

                var variableBorder = new Border();

                if (variable["Value"] == null || variable["Value"].GetType() != typeof(bool))
                {
                    var label = new Literal { Text = name, Class = "varTitle" };
                    variableBorder.Controls.Add(label);
                    if (ShowHints && !string.IsNullOrEmpty(hint))
                    {
                        label = new Literal { Text = hint, Class = "varHint" };
                        variableBorder.Controls.Add(label);
                    }
                }

                name = (string)variable["Name"];
                variableBorder.ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_");

                variableBorder.Controls.Add(input);
                var height = variable["Height"] as string;
                if (!string.IsNullOrEmpty(height))
                {
                    variableBorder.Height = new Unit(height);
                    variableBorder.Class = "variableWrapper variableWrapperFixedHeight";
                }
                else
                {
                    variableBorder.Class = "variableWrapper";
                }
                variableBorder.Class += " grid-" + columns;
                if (clearfix)
                {
                    variableBorder.Class += " clearfix";
                }
                container.Controls.Add(variableBorder);
            }

            TabOffsetValue.Text = string.Format("<script type='text/javascript'>var tabsOffset={0};</script>",
                tabs.Count > 0 ? 24 : 0);
        }
Ejemplo n.º 9
0
        private Control GetVariableEditor(IDictionary variable)
        {
            var value  = variable["Value"];
            var name   = (string)variable["Name"];
            var editor = variable["Editor"] as string;
            var type   = value.GetType();

            if (type == typeof(DateTime) ||
                (!string.IsNullOrEmpty(editor) &&
                 (editor.IndexOf("date", StringComparison.OrdinalIgnoreCase) > -1 ||
                  editor.IndexOf("time", StringComparison.OrdinalIgnoreCase) > -1)))
            {
                var dateTimePicker = new DateTimePicker
                {
                    ID       = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                    ShowTime = (variable["ShowTime"] != null && (bool)variable["ShowTime"]) ||
                               (!string.IsNullOrEmpty(editor) &&
                                editor.IndexOf("time", StringComparison.OrdinalIgnoreCase) > -1)
                };
                if (value is DateTime)
                {
                    var date = (DateTime)value;
                    if (date != DateTime.MinValue && date != DateTime.MaxValue)
                    {
                        dateTimePicker.Value = date.Kind != DateTimeKind.Utc
                            ? DateUtil.ToIsoDate(TypeResolver.Resolve <IDateConverter>().ToServerTime(date))
                            : DateUtil.ToIsoDate(date);
                    }
                }
                else
                {
                    dateTimePicker.Value = value as string ?? string.Empty;
                }
                return(dateTimePicker);
            }

            if (!string.IsNullOrEmpty(editor) && editor.IndexOf("rule", StringComparison.OrdinalIgnoreCase) > -1)
            {
                var editorId = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_");
                Sitecore.Context.ClientPage.ServerProperties[editorId] = value;

                var rulesBorder = new Border
                {
                    Class = "rulesWrapper",
                    ID    = editorId
                };

                var rulesEditButton = new Button
                {
                    Header = Texts.PowerShellMultiValuePrompt_GetVariableEditor_Edit_rule,
                    Class  = "scButton edit-button rules-edit-button",
                    Click  = "EditConditionClick(\\\"" + editorId + "\\\")"
                };

                rulesBorder.Controls.Add(rulesEditButton);
                var rulesRender = new Literal
                {
                    ID   = editorId + "_renderer",
                    Text = GetRuleConditionsHtml(
                        string.IsNullOrEmpty(value as string) ? "<ruleset />" : value as string)
                };
                rulesRender.Class = rulesRender.Class + " varRule";
                rulesBorder.Controls.Add(rulesRender);
                return(rulesBorder);
            }

            if (!string.IsNullOrEmpty(editor) &&
                (editor.IndexOf("treelist", StringComparison.OrdinalIgnoreCase) > -1 ||
                 (editor.IndexOf("multilist", StringComparison.OrdinalIgnoreCase) > -1) ||
                 (editor.IndexOf("droplist", StringComparison.OrdinalIgnoreCase) > -1) ||
                 (editor.IndexOf("droptree", StringComparison.OrdinalIgnoreCase) > -1)))
            {
                Item item     = null;
                var  strValue = string.Empty;
                if (value is Item)
                {
                    item     = (Item)value;
                    strValue = item.ID.ToString();
                }
                else if (value is IEnumerable <object> )
                {
                    var items = (value as IEnumerable <object>).Cast <Item>().ToList();
                    item     = items.FirstOrDefault();
                    strValue = string.Join("|", items.Select(i => i.ID.ToString()).ToArray());
                }

                var dbName = item == null ? Sitecore.Context.ContentDatabase.Name : item.Database.Name;
                if (editor.IndexOf("multilist", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    var multiList = new MultilistExtended
                    {
                        ID       = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                        Value    = strValue,
                        Database = dbName,
                        ItemID   = ItemIDs.RootID.ToString(),
                        Source   = variable["Source"] as string ?? "/sitecore",
                    };
                    multiList.SetLanguage(Sitecore.Context.Language.Name);

                    multiList.Class += "  treePicker";
                    return(multiList);
                }

                if (editor.IndexOf("droplist", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    if (Sitecore.Context.ContentDatabase?.Name != dbName)
                    {
                        // this control will crash if if content database is different than the items fed to it.
                        return(new Literal
                        {
                            Text = "<span style='color: red'>" +
                                   Translate.Text(
                                Texts
                                .PowerShellMultiValuePrompt_GetVariableEditor_DropList_control_cannot_render_items_from_the_database___0___because_it_its_not_the_same_as___1___which_is_the_current_content_database__,
                                dbName, Sitecore.Context.ContentDatabase?.Name) + "</span>",
                            Class = "varHint"
                        });
                    }
                    var lookup = new LookupEx
                    {
                        ID           = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                        Database     = dbName,
                        ItemID       = item?.ID.ToString() ?? ItemIDs.RootID.ToString(),
                        Source       = variable["Source"] as string ?? "/sitecore",
                        ItemLanguage = Sitecore.Context.Language.Name,
                        Value        = item?.ID.ToString() ?? ItemIDs.RootID.ToString()
                    };
                    lookup.Class += " textEdit";
                    return(lookup);
                }

                if (editor.IndexOf("droptree", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    var tree = new Tree
                    {
                        ID           = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                        Database     = dbName,
                        ItemID       = item?.ID.ToString() ?? ItemIDs.Null.ToString(),
                        Source       = variable["Source"] as string ?? "",
                        ItemLanguage = Sitecore.Context.Language.Name,
                        Value        = item?.ID.ToString() ?? ""
                    };
                    tree.Class += " textEdit";
                    return(tree);
                }
                var treeList = new TreeList
                {
                    ID    = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                    Value = strValue,
                    AllowMultipleSelection = true,
                    DatabaseName           = dbName,
                    Database         = dbName,
                    Source           = variable["Source"] as string ?? "/sitecore",
                    DisplayFieldName = variable["DisplayFieldName"] as string ?? "__DisplayName"
                };
                treeList.Class += " treePicker";
                return(treeList);
            }
            if (type == typeof(Item) ||
                (!string.IsNullOrEmpty(editor) && (editor.IndexOf("item", StringComparison.OrdinalIgnoreCase) > -1)))
            {
                var item       = value as Item;
                var source     = variable["Source"] as string;
                var root       = variable["Root"] as string;
                var sourceRoot = string.IsNullOrEmpty(source)
                    ? "/sitecore"
                    : StringUtil.ExtractParameter("DataSource", source);
                var dataContext = item != null
                    ? new DataContext
                {
                    DefaultItem  = item.Paths.Path,
                    ID           = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("dataContext"),
                    Parameters   = string.IsNullOrEmpty(source) ? "databasename=" + item.Database.Name : source,
                    DataViewName = "Master",
                    Root         = string.IsNullOrEmpty(root) ? sourceRoot : root,
                    Database     = item.Database.Name,
                    Selected     = new[] { new DataUri(item.ID, item.Language, item.Version) },
                    Folder       = item.ID.ToString(),
                    Language     = item.Language,
                    Version      = item.Version
                }
                    : new DataContext
                {
                    ID           = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("dataContext"),
                    Parameters   = string.IsNullOrEmpty(source) ? "databasename=master" : source,
                    DataViewName = "Master",
                    Root         = string.IsNullOrEmpty(root) ? sourceRoot : root
                };

                DataContextPanel.Controls.Add(dataContext);

                var treePicker = new TreePicker
                {
                    ID    = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                    Value = item != null?item.ID.ToString() : string.Empty,
                                DataContext = dataContext.ID,
                                AllowNone   =
                                    !string.IsNullOrEmpty(editor) &&
                                    (editor.IndexOf("allownone", StringComparison.OrdinalIgnoreCase) > -1)
                };
                treePicker.Class += " treePicker";
                return(treePicker);
            }

            if (type == typeof(bool) ||
                (!string.IsNullOrEmpty(editor) && (editor.IndexOf("bool", StringComparison.OrdinalIgnoreCase) > -1)))
            {
                var checkboxBorder = new Border
                {
                    Class = "checkBoxWrapper",
                    ID    = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_")
                };
                var checkBox = new Checkbox
                {
                    ID          = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                    Header      = (string)variable["Title"],
                    HeaderStyle = "display:inline-block;",
                    Checked     = (bool)value,
                    Class       = "varCheckbox"
                };
                checkboxBorder.Controls.Add(checkBox);
                return(checkboxBorder);
            }

            if (!string.IsNullOrEmpty(editor))
            {
                var showRoles = editor.IndexOf("role", StringComparison.OrdinalIgnoreCase) > -1;
                var showUsers = editor.IndexOf("user", StringComparison.OrdinalIgnoreCase) > -1;
                var multiple  = editor.IndexOf("multiple", StringComparison.OrdinalIgnoreCase) > -1;
                if (showRoles || showUsers)
                {
                    var picker = new UserPicker();
                    picker.Style.Add("float", "left");
                    picker.ID     = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_");
                    picker.Class += " scContentControl textEdit clr" + value.GetType().Name;
                    picker.Value  = value is IEnumerable <object>
                                    ?string.Join("|", ((IEnumerable <object>)value).Select(x => x.ToString()).ToArray())
                                        : value.ToString();

                    picker.ExcludeRoles = !showRoles;
                    picker.ExcludeUsers = !showUsers;
                    picker.DomainName   = variable["Domain"] as string ?? variable["DomainName"] as string;
                    picker.Multiple     = multiple;
                    picker.Click        = "UserPickerClick(" + picker.ID + ")";
                    return(picker);
                }
            }

            Sitecore.Web.UI.HtmlControls.Control edit;
            if (!string.IsNullOrEmpty(editor) && editor.IndexOf("info", StringComparison.OrdinalIgnoreCase) > -1)
            {
                return(new Literal {
                    Text = value.ToString(), Class = "varHint"
                });
            }

            if (variable["lines"] != null && ((int)variable["lines"] > 1))
            {
                edit = new Memo();
                edit.Attributes.Add("rows", variable["lines"].ToString());
                var placeholder = variable["Placeholder"];
                if (placeholder is string)
                {
                    edit.Attributes.Add("Placeholder", placeholder.ToString());
                }
            }
            else if (variable["Options"] != null)
            {
                var psOptions = variable["Options"].BaseObject();
                var options   = new OrderedDictionary();
                if (psOptions is OrderedDictionary)
                {
                    options = psOptions as OrderedDictionary;
                }
                else if (psOptions is string)
                {
                    var strOptions = ((string)variable["Options"]).Split('|');
                    var i          = 0;
                    while (i < strOptions.Length)
                    {
                        options.Add(strOptions[i++], strOptions[i++]);
                    }
                }
                else if (psOptions is Hashtable)
                {
                    var hashOptions = variable["Options"] as Hashtable;
                    foreach (var key in hashOptions.Keys)
                    {
                        options.Add(key, hashOptions[key]);
                    }
                }
                else
                {
                    throw new Exception("Checklist options format unrecognized.");
                }

                if (!string.IsNullOrEmpty(editor))
                {
                    if (editor.IndexOf("radio", StringComparison.OrdinalIgnoreCase) > -1)
                    {
                        var radioList = new Groupbox
                        {
                            ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_"),
                            // Header = (string) variable["Title"],
                            Class = "scRadioGroup"
                        };

                        foreach (var option in options.Keys)
                        {
                            var optionName  = option.ToString();
                            var optionValue = options[optionName].ToString();
                            var item        = new Radiobutton
                            {
                                Header  = optionName,
                                Value   = optionValue,
                                ID      = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID(radioList.ID),
                                Name    = radioList.ID,
                                Checked = optionValue == value.ToString()
                            };
                            radioList.Controls.Add(item);
                            radioList.Controls.Add(new Literal("<br/>"));
                        }

                        return(radioList);
                    }

                    if (editor.IndexOf("check", StringComparison.OrdinalIgnoreCase) > -1)
                    {
                        var checkBorder = new Border
                        {
                            Class = "checkListWrapper",
                            ID    = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_")
                        };
                        var editorId = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_");
                        var link     =
                            new Literal(
                                @"<div class='checkListActions'>" +
                                @"<a href='#' class='scContentButton' onclick=""javascript:return scForm.postEvent(this,event,'checklist:checkall(id=" +
                                editorId + @")')"">" + Translate.Text("Select all") + "</a> &nbsp;|&nbsp; " +
                                @"<a href='#' class='scContentButton' onclick=""javascript:return scForm.postEvent(this,event,'checklist:uncheckall(id=" +
                                editorId + @")')"">" + Translate.Text("Unselect all") + "</a> &nbsp;|&nbsp;" +
                                @"<a href='#' class='scContentButton' onclick=""javascript:return scForm.postEvent(this,event,'checklist:invert(id=" +
                                editorId + @")')"">" + Translate.Text("Invert selection") + "</a>" +
                                @"</div>");
                        checkBorder.Controls.Add(link);
                        var checkList = new PSCheckList
                        {
                            ID          = editorId,
                            HeaderStyle = "margin-top:20px; display:inline-block;",
                            ItemID      = ItemIDs.RootID.ToString()
                        };
                        checkList.SetItemLanguage(Sitecore.Context.Language.Name);
                        string[] values;
                        if (value is string)
                        {
                            values = value.ToString().Split('|');
                        }
                        else if (value is IEnumerable)
                        {
                            values =
                                (value as IEnumerable).Cast <object>()
                                .Select(s => s == null ? "" : s.ToString())
                                .ToArray();
                        }
                        else
                        {
                            values = new[] { value.ToString() };
                        }
                        foreach (var item in from object option in options.Keys
                                 select option.ToString()
                                 into optionName
                                 let optionValue = options[optionName].ToString()
                                                   select new ChecklistItem
                        {
                            ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID(checkList.ID),
                            Header = optionName,
                            Value = optionValue,
                            Checked = values.Contains(optionValue, StringComparer.OrdinalIgnoreCase)
                        })
                        {
                            checkList.Controls.Add(item);
                        }

                        checkList.TrackModified = false;
                        checkList.Disabled      = false;
                        checkBorder.Controls.Add(checkList);
                        return(checkBorder);
                    }
                }

                edit = new Combobox();
                var placeholder = variable["Placeholder"];
                if (placeholder is string)
                {
                    var option = new ListItem
                    {
                        Header   = placeholder.ToString(),
                        Value    = "",
                        Selected = true
                    };
                    edit.Controls.Add(option);
                }

                foreach (var option in options.Keys)
                {
                    var optionName  = option.ToString();
                    var optionValue = options[optionName].ToString();
                    var item        = new ListItem
                    {
                        Header = optionName,
                        Value  = optionValue
                    };
                    edit.Controls.Add(item);
                }
            }
            else
            {
                var placeholder = variable["Placeholder"];
                if (!string.IsNullOrEmpty(editor) && editor.IndexOf("pass", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    edit = new PasswordExtended();
                    if (placeholder is string)
                    {
                        ((PasswordExtended)edit).PlaceholderText = placeholder.ToString();
                    }
                }
                else
                {
                    edit = new EditExtended();
                    if (placeholder is string)
                    {
                        ((EditExtended)edit).PlaceholderText = placeholder.ToString();
                    }
                }
            }
            var tip = variable["Tooltip"] as string;

            if (!string.IsNullOrEmpty(tip))
            {
                edit.ToolTip = tip.RemoveHtmlTags();
            }
            edit.Style.Add("float", "left");
            edit.ID     = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_");
            edit.Class += " scContentControl textEdit clr" + value.GetType().Name;
            edit.Value  = value.ToString();

            return(edit);
        }
Ejemplo n.º 10
0
        private void AddControls(object[] variables)
        {
            var tabs = new Dictionary <string, Border>(StringComparer.OrdinalIgnoreCase);

            Tabstrip.Visible =
                variables.Cast <Hashtable>()
                .Select(variable => variable["Tab"] as string)
                .Any(tabName => !string.IsNullOrEmpty(tabName));
            var fieldValidators = FieldValidators;

            foreach (Hashtable variable in variables)
            {
                var tabName = variable["Tab"] as string ?? "Other";
                var name    = variable["Name"] as string ?? string.Empty;
                var title   = variable["Title"] as string ?? name;
                var hint    = variable["Tip"] as string ??
                              variable["Hint"] as string ?? variable["Tooltip"] as string;
                var variableValue = variable["Value"];
                var columns       = 12;
                var clearfix      = false;
                var height        = variable["Height"] as string;
                var validator     = variable["Validator"] as ScriptBlock;

                if (validator != null)
                {
                    fieldValidators.Add(name, validator.ToString());
                }

                if (variable["Columns"] != null)
                {
                    var strColumns = variable["Columns"].ToString().Split(' ');
                    foreach (var columnValue in strColumns)
                    {
                        if (int.TryParse(columnValue, out columns))
                        {
                            if (columns > 12 && columns < 0)
                            {
                                columns = 12;
                            }
                        }
                        break;
                    }
                    clearfix = strColumns.Contains("first", StringComparer.OrdinalIgnoreCase);
                }

                // get the control in which the variable should be placed.
                var container = GetContainer(tabs, tabName);

                // retrieve the variable editor control.
                Control variableEditor;
                try
                {
                    variableEditor = GetVariableEditor(variable);
                }
                catch (Exception ex)
                {
                    PowerShellLog.Error($"Error while rendering editor in Read-Variable cmdlet for variable {title}", ex);
                    variableEditor = new Literal
                    {
                        Text  = Texts.PowerShellMultiValuePrompt_AddControls_Error_while_rendering_this_editor,
                        Class = "varHint"
                    };
                }

                // create and set up the variable wrapper
                var variableWrapper = new Border
                {
                    ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_")
                };

                // add variable title and tooltip if it's not a checkbox
                if (variableValue == null || variableValue.GetType() != typeof(bool))
                {
                    var label = new Literal {
                        Text = title, Class = "varTitle"
                    };
                    variableWrapper.Controls.Add(label);
                    if (ShowHints && !string.IsNullOrEmpty(hint))
                    {
                        label = new Literal {
                            Text = hint, Class = "varHint"
                        };
                        variableWrapper.Controls.Add(label);
                    }
                }

                if (!string.IsNullOrEmpty(height))
                {
                    variableWrapper.Height = new Unit(height);
                    variableWrapper.Class  = "variableWrapper variableWrapperFixedHeight";
                }
                else
                {
                    variableWrapper.Class = "variableWrapper";
                }

                variableWrapper.Class += " grid-" + columns;
                if (clearfix)
                {
                    variableWrapper.Class += " clearfix";
                }

                // add editor to the wrapper
                variableWrapper.Controls.Add(variableEditor);

                // add validator indicator
                var variableValidator = new Border
                {
                    ID        = $"var_{name}_validator",
                    InnerHtml = "",
                    Class     = "validator"
                };
                variableWrapper.Controls.Add(variableValidator);

                // add wrapper to the container
                container.Controls.Add(variableWrapper);
            }

            FieldValidators     = fieldValidators;
            TabOffsetValue.Text = $"<script type='text/javascript'>var tabsOffset={(tabs.Count > 0 ? 24 : 0)};</script>";
        }
Ejemplo n.º 11
0
 private void AddControls(object[] variables)
 {
     foreach (Hashtable variable in variables)
     {
         var name = variable["Title"] as string;
         if (variable["Value"] == null || variable["Value"].GetType() != typeof (bool))
         {
             var label = new Literal {Text = name + ":"};
             label.Class = "varTitle";
             ValuePanel.Controls.Add(label);
         }
         var input = GetVariableEditor(variable);
         ValuePanel.Controls.Add(input);
     }
 }
        private void BuildRendering(Border border, DeviceDefinition deviceDefinition, RenderingDefinition renderingDefinition, int index, int conditionsCount)
        {
            Assert.ArgumentNotNull(border, "border");
            Assert.ArgumentNotNull(deviceDefinition, "deviceDefinition");
            Assert.ArgumentNotNull(renderingDefinition, "renderingDefinition");
            string itemID = renderingDefinition.ItemID;

            if (itemID != null)
            {
                Item item = Client.ContentDatabase.GetItem(itemID);
                if (item != null)
                {
                    string displayName   = item.DisplayName;
                    string icon          = item.Appearance.Icon;
                    string str4          = string.Empty;
                    string initialMarkup = Images.GetImage(icon, 0x10, 0x10, "absmiddle", "0px 4px 0px 0px") + displayName;
                    if ((str4.Length > 0) && (str4 != "content"))
                    {
                        string str7 = initialMarkup;
                        initialMarkup = str7 + " " + Translate.Text("in") + " " + str4 + ".";
                    }
                    if (conditionsCount > 1)
                    {
                        initialMarkup = initialMarkup + @"<span class=""{((conditionsCount > 9) ? ""scConditionContainer scLongConditionContainer"" : ""scConditionContainer"")}"">{conditionsCount}</span>";
                    }
                    initialMarkup = RenderLayoutGridRenderingPipeline.Run(renderingDefinition, initialMarkup);
                    Border child = new Border();
                    border.Controls.Add(child);
                    string str6 = StringUtil.GetString(new string[] { this.EditRenderingClick }).Replace("$Device", deviceDefinition.ID).Replace("$Index", index.ToString());
                    if (!string.IsNullOrEmpty(str6))
                    {
                        child.RollOver = true;
                        child.Class    = "scRollOver";
                        child.Click    = str6;
                    }

                    if (!string.IsNullOrEmpty(renderingDefinition.Datasource))
                    {
                        var ds = Client.ContentDatabase.GetItem(renderingDefinition.Datasource);
                        if (ds != null)
                        {
                            initialMarkup += " - " + ds.Name;
                        }
                    }
                    else
                    {
                        initialMarkup += " - No Data Source";
                    }

                    if (!string.IsNullOrEmpty(renderingDefinition.Placeholder))
                    {
                        var           nesting = renderingDefinition.Placeholder.Split('/');
                        StringBuilder sb      = new StringBuilder();
                        foreach (var nest in nesting)
                        {
                            if (nest.IndexOf('_') > -1)
                            {
                                var keys = nest.Split('_');
                                sb.Append(keys[0]);
                            }
                            else
                            {
                                sb.Append(nest);
                            }

                            sb.Append(" > ");
                        }
                        var friendlyPlaceholders = sb.ToString();
                        if (friendlyPlaceholders.IndexOf(" > ") > -1)
                        {
                            friendlyPlaceholders = friendlyPlaceholders.Substring(0, friendlyPlaceholders.Length - 2);
                        }

                        initialMarkup += string.Format(@"<br /><span class=""friendlyPlaceholder"">{0}</a>", friendlyPlaceholders);
                    }


                    Sitecore.Web.UI.HtmlControls.Literal literal = new Sitecore.Web.UI.HtmlControls.Literal("<div class='scRendering' style='padding:2px;position:relative'>" + initialMarkup + "</div>");
                    child.Controls.Add(literal);
                }
            }
        }
 private void AddDelSection(string idPostfix)
 {
     ImageBuilder builder = new ImageBuilder
     {
         Src = "Applications/16x16/delete2.png",
         Width = 0x10,
         Height = 0x10,
         Style = "cursor: pointer"
     };
     Sitecore.Web.UI.HtmlControls.Literal child = new Sitecore.Web.UI.HtmlControls.Literal
     {
         Text = builder.ToString()
     };
     Border border = new Border
     {
         ID = "DelSection" + idPostfix,
         Click = "DelSection_Click"
     };
     border.Controls.Add(child);
     this.ParentControl.Controls.Add(border);
 }
Ejemplo n.º 14
0
        private void AddControls(object[] variables)
        {
            var tabs = new Dictionary <string, Border>(StringComparer.OrdinalIgnoreCase);

            Tabstrip.Visible = variables.Cast <Hashtable>().Select(variable => variable["Tab"] as string).Any(tabName => !string.IsNullOrEmpty(tabName));

            foreach (Hashtable variable in variables)
            {
                var tabName = (variable["Tab"] as string) ?? "Other";
                var name    = (variable["Title"] as string) ?? (variable["Name"] as string);
                var hint    = (variable["Tip"] as string) ??
                              (variable["Hint"] as string) ?? (variable["Tooltip"] as string);
                var  columns  = 12;
                bool clearfix = false;
                if (variable["Columns"] != null)
                {
                    var strColumns = variable["Columns"].ToString().Split(' ');
                    foreach (var columnValue in strColumns)
                    {
                        if (int.TryParse(columnValue, out columns))
                        {
                            if (columns > 12 && columns < 0)
                            {
                                columns = 12;
                            }
                        }
                        break;
                    }
                    clearfix = strColumns.Contains("first", StringComparer.OrdinalIgnoreCase);
                }
                var container = GetContainer(tabs, tabName);
                var input     = GetVariableEditor(variable);

                var variableBorder = new Border();

                if (variable["Value"] == null || variable["Value"].GetType() != typeof(bool))
                {
                    var label = new Literal {
                        Text = name, Class = "varTitle"
                    };
                    variableBorder.Controls.Add(label);
                    if (ShowHints && !string.IsNullOrEmpty(hint))
                    {
                        label = new Literal {
                            Text = hint, Class = "varHint"
                        };
                        variableBorder.Controls.Add(label);
                    }
                }

                name = (string)variable["Name"];
                variableBorder.ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("variable_" + name + "_");

                variableBorder.Controls.Add(input);
                var height = variable["Height"] as string;
                if (!string.IsNullOrEmpty(height))
                {
                    variableBorder.Height = new Unit(height);
                    variableBorder.Class  = "variableWrapper variableWrapperFixedHeight";
                }
                else
                {
                    variableBorder.Class = "variableWrapper";
                }
                variableBorder.Class += " grid-" + columns;
                if (clearfix)
                {
                    variableBorder.Class += " clearfix";
                }
                container.Controls.Add(variableBorder);
            }

            TabOffsetValue.Text = string.Format("<script type='text/javascript'>var tabsOffset={0};</script>",
                                                tabs.Count > 0 ? 24 : 0);
        }
        private void BuildRendering(Border border, DeviceDefinition deviceDefinition, RenderingDefinition renderingDefinition, int index, int conditionsCount)
        {
            Assert.ArgumentNotNull(border, "border");
            Assert.ArgumentNotNull(deviceDefinition, "deviceDefinition");
            Assert.ArgumentNotNull(renderingDefinition, "renderingDefinition");

            string itemId = renderingDefinition.ItemID;
            if (itemId == null)
            {
                return;
            }

            Item obj = Client.ContentDatabase.GetItem(itemId);
            if (obj == null)
            {
                return;
            }

            string displayName = obj.DisplayName;
            string icon = obj.Appearance.Icon;
            string str1 = string.Empty;
            string str2 = displayName;

            if (str1.Length > 0 && str1 != "content")
            {
                str2 = string.Format("{0} {1} {2}.", str2, Translate.Text("in"), str1);
            }

            if (Settings.Analytics.Enabled && conditionsCount > 1)
            {
                str2 += string.Format("<span class=\"{0}\">{1}</span>", conditionsCount > 9
                        ? "scConditionContainer scLongConditionContainer"
                        : "scConditionContainer",
                    conditionsCount);
            }

            Border border1 = new Border();
            border1.Style.Add("float", "left");

            Border borderX = new Border();

            var renderingIconAnchor = new HtmlGenericControl
            {
                InnerHtml = "<a onclick='window.open(\"/sitecore/shell/Applications/Content%20Editor.aspx?fo=" +
                    itemId + "\",\"myWin\",\"width=800,height=600\"); return false;' taget='_blank' class='linkIcon'>" +
                    Images.GetImage(icon, 16, 16, "absmiddle", "0px 4px 0px 0px") + "</a>",
            };
            renderingIconAnchor.Style.Add("float", "left");

            borderX.Controls.Add(renderingIconAnchor);
            borderX.Controls.Add(border1);

            var clearBoth = new HtmlGenericControl("div");
            clearBoth.Style.Add("clear","both");
            borderX.Controls.Add(clearBoth);

            border.Controls.Add(borderX);

            string str3 = StringUtil.GetString(EditRenderingClick).Replace("$Device", deviceDefinition.ID).Replace("$Index", index.ToString());

            if (!string.IsNullOrEmpty(str3))
            {
                border1.RollOver = true;
                border1.Class = "scRollOver";
                border1.Click = str3;
            }

            var literal = new Sitecore.Web.UI.HtmlControls.Literal(
                string.Format("<div class='scRendering' style='padding:2px;position:relative'>{0}</div>", str2)
                );

            border1.Controls.Add(literal);
        }
        /// <summary>
        /// Copy from Sitecore as as, just to make compile.
        /// </summary>
        private void BuildPlaceholder(Border border, DeviceDefinition deviceDefinition, PlaceholderDefinition placeholderDefinition)
        {
            Assert.ArgumentNotNull(border, "border");
            Assert.ArgumentNotNull(deviceDefinition, "deviceDefinition");
            Assert.ArgumentNotNull(placeholderDefinition, "placeholderDefinition");

            string metaDataItemId = placeholderDefinition.MetaDataItemId;

            Border border1 = new Border();
            border.Controls.Add(border1);

            string str1 = StringUtil.GetString(EditPlaceholderClick)
                .Replace("$Device", deviceDefinition.ID)
                .Replace("$UniqueID", placeholderDefinition.UniqueId);

            Assert.IsNotNull(metaDataItemId, "placeholder id");

            Item obj = Client.ContentDatabase.GetItem(metaDataItemId);

            string str2;
            if (obj != null)
            {
                string displayName = obj.DisplayName;
                str2 = Images.GetImage(obj.Appearance.Icon, 16, 16, "absmiddle", "0px 4px 0px 0px") + displayName;
            }
            else
            {
                str2 = Images.GetImage("Imaging/16x16/layer_blend.png", 16, 16, "absmiddle", "0px 4px 0px 0px") + placeholderDefinition.Key;
            }

            if (!string.IsNullOrEmpty(str1))
            {
                border1.RollOver = true;
                border1.Class = "scRollOver";
                border1.Click = str1;
            }

            var literal = new Sitecore.Web.UI.HtmlControls.Literal(string.Format("<div style=\"padding:2\">{0}</div>", str2));
            border1.Controls.Add(literal);
        }