Exemple #1
0
        /// <summary>
        /// Builds content for internal fields
        /// </summary>
        /// <param name="subitem"></param>
        /// <param name="resultText"></param>
        private void InternalFieldContentBuilder(Item subitem, StringBuilder resultText)
        {
            //Get all the fields for an item
            var fields = subitem.Fields;

            fields.ReadAll();
            fields.Sort();

            foreach (Field field in fields)
            {
                if (!field.Name.StartsWith("__"))
                {
                    string fieldSource = DetermineFieldSource(field);

                    switch (field.Type)
                    {
                    case "Droptree":
                        var treeCtrl = new Tree();

                        treeCtrl.ItemID   = subitem.ID.ToString();
                        treeCtrl.ID       = string.Format("ExpressSubitem_{0:N}{1:N}", field.ID.Guid, subitem.ID.Guid);
                        treeCtrl.Source   = field.Source;
                        treeCtrl.Disabled = Disabled;

                        var sources  = GetSources(subitem, field);
                        var sourceId = Guid.Empty;

                        if (sources.Any())
                        {
                            sourceId = sources[0].ID.Guid;
                        }

                        Sitecore.Context.ClientPage.AddControl(this, treeCtrl);
                        treeCtrl.Value = field.Value;

                        resultText.AppendFormat(Prototypes.Tree, field.DisplayName, treeCtrl.RenderAsText(), treeCtrl.ID, field.ID, sourceId, fieldSource);

                        break;

                    case "File":
                        var fileCtrl = new File();

                        fileCtrl.ID = string.Format("ExpressSubitem_{0:N}{1:N}", field.ID.Guid, subitem.ID.Guid);

                        Sitecore.Context.ClientPage.AddControl(this, fileCtrl);
                        fileCtrl.SetValue(field.Value);
                        fileCtrl.Disabled = Disabled;

                        resultText.AppendFormat(Prototypes.StandardWrapper,
                                                field.DisplayName,
                                                fileCtrl.RenderAsText(),
                                                fileCtrl.ID,
                                                field.ID,
                                                RenderMenuButtons(fileCtrl.ID, field, ReadOnly),
                                                "file",
                                                fieldSource);

                        break;

                    case "Image":
                        var imageCtrl = new Sitecore.Shell.Applications.ContentEditor.Image();

                        imageCtrl.ID = string.Format("ExpressSubitem_{0:N}{1:N}", field.ID.Guid, subitem.ID.Guid);

                        Sitecore.Context.ClientPage.AddControl(this, imageCtrl);
                        imageCtrl.ItemLanguage = ItemLanguage;
                        imageCtrl.ItemVersion  = ItemVersion;
                        imageCtrl.SetValue(field.Value);
                        imageCtrl.Disabled = Disabled;

                        resultText.AppendFormat(Prototypes.StandardWrapper,
                                                field.DisplayName,
                                                imageCtrl.RenderAsText(),
                                                imageCtrl.ID,
                                                field.ID,
                                                RenderMenuButtons(imageCtrl.ID, field, ReadOnly),
                                                "image",
                                                fieldSource);

                        break;

                    case "Multilist":
                        var multiListCtrl = new MultilistEx();

                        multiListCtrl.ItemID = subitem.ID.ToString();
                        multiListCtrl.ID     = string.Format("ExpressSubitem_{0:N}{1:N}", field.ID.Guid, subitem.ID.Guid);
                        multiListCtrl.SetValue(field.Value);
                        multiListCtrl.Source = field.Source;
                        Sitecore.Context.ClientPage.AddControl(this, multiListCtrl);
                        multiListCtrl.Disabled     = Disabled;
                        multiListCtrl.ItemLanguage = subitem.Language.Name;

                        resultText.AppendFormat(Prototypes.StandardWrapper,
                                                field.DisplayName,
                                                multiListCtrl.RenderAsText(),
                                                multiListCtrl.ID,
                                                field.ID,
                                                RenderMenuButtons(multiListCtrl.ID, field, ReadOnly),
                                                "multilist",
                                                fieldSource);

                        break;

                    case "Treelist":
                        var treelistCtrl = new TreeList();

                        treelistCtrl.ItemID       = subitem.ID.ToString();
                        treelistCtrl.ID           = string.Format("ExpressSubitem_{0:N}{1:N}", field.ID.Guid, subitem.ID.Guid);
                        treelistCtrl.ItemLanguage = ItemLanguage;
                        treelistCtrl.SetValue(field.Value);
                        treelistCtrl.Source   = field.Source;
                        treelistCtrl.Disabled = Disabled;

                        Sitecore.Context.ClientPage.AddControl(this, treelistCtrl);

                        resultText.AppendFormat(Prototypes.StandardWrapper,
                                                field.DisplayName,
                                                treelistCtrl.RenderAsText(),
                                                treelistCtrl.ID,
                                                field.ID,
                                                RenderMenuButtons(treelistCtrl.ID, field, ReadOnly),
                                                "treelist",
                                                fieldSource);

                        break;

                    case "Datetime":
                    case "Date":
                        var dateCtrl = field.Type == "Date" ? new Date() : new Sitecore.Shell.Applications.ContentEditor.DateTime();

                        dateCtrl.ItemID   = subitem.ID.ToString();
                        dateCtrl.ID       = string.Format("ExpressSubitem_{0:N}{1:N}", field.ID.Guid, subitem.ID.Guid);
                        dateCtrl.Disabled = Disabled;

                        Sitecore.Context.ClientPage.AddControl(this, dateCtrl);
                        dateCtrl.SetValue(field.Value);

                        resultText.AppendFormat(Prototypes.Date,
                                                field.DisplayName,
                                                dateCtrl.RenderAsText(),
                                                dateCtrl.ID,
                                                field.ID,
                                                RenderMenuButtons(dateCtrl.ID, field, ReadOnly),
                                                fieldSource);

                        break;

                    case "Rich Text":
                        var richTextCtrl = new RichText();
                        richTextCtrl.ItemID       = subitem.ID.ToString();
                        richTextCtrl.ItemLanguage = ItemLanguage;
                        richTextCtrl.ItemVersion  = subitem.Version.ToString();
                        richTextCtrl.FieldID      = field.ID.ToString();
                        richTextCtrl.ID           = string.Format("ExpressSubitem_{0:N}{1:N}", field.ID.Guid, subitem.ID.Guid);
                        richTextCtrl.Disabled     = Disabled;

                        Sitecore.Context.ClientPage.AddControl(this, richTextCtrl);
                        // Fixing Sitecore bug for no value field
                        if (field.Value == "__#!$No value$!#__")
                        {
                            using (new SecurityDisabler())
                            {
                                using (new EditContext(subitem))
                                {
                                    field.Value = "";
                                }
                            }
                        }
                        richTextCtrl.Value = field.Value;

                        resultText.AppendFormat(Prototypes.RichText,
                                                field.DisplayName,
                                                richTextCtrl.RenderAsText(),
                                                richTextCtrl.ID,
                                                field.ID,
                                                RenderMenuButtons(richTextCtrl.ID, field, ReadOnly),
                                                fieldSource);

                        break;

                    case "Single-Line Text":
                    case "Integer":
                        resultText.AppendFormat(Prototypes.TextBox, field.DisplayName, field.ID, field.Value, Disabled ? "disabled='disabled'" : "", fieldSource);

                        break;

                    case "Droplink":
                        bool   selectionInList;
                        string options      = BuildDropdownOptions(subitem, field, out selectionInList);
                        string errorMessage = "";

                        if (!selectionInList)
                        {
                            errorMessage = @"<DIV style=""PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; COLOR: #999999; PADDING-TOP: 2px"">The field contains a value that is not in the selection list.</DIV>";
                        }

                        resultText.AppendFormat(Prototypes.Dropdown, field.DisplayName, field.ID, options, Disabled ? "disabled='disabled'" : "", errorMessage, fieldSource);

                        break;

                    case "Checkbox":
                        var @checked = ((CheckboxField)field).Checked;
                        resultText.AppendFormat(Prototypes.Checkbox, field.DisplayName, field.ID, @checked ? "checked" : "", Disabled ? "disabled='disabled'" : "", fieldSource);

                        break;

                    default:
                        resultText.AppendFormat("<div class=\"unknown-field\">Unknown field type of \"{0}\" for field \"{1}\"</div>", field.Type, field.Name);

                        break;
                    }
                }
            }
        }