/// <summary> /// Adds a field set to the region. /// </summary> /// <param name="fieldSet">The field set</param> public abstract void Add(PageEditFieldSet fieldSet);
/// <summary> /// Creates a new edit region model for the given region type and value. /// </summary> /// <param name="region">The region type</param> /// <param name="value">The region value</param> /// <returns>The edit model</returns> public PageEditRegionBase CreateRegion(Piranha.Models.RegionType region, object value) { PageEditRegionBase editRegion; if (region.Collection) { editRegion = new PageEditRegionCollection(); } else { editRegion = new PageEditRegion(); } editRegion.Id = region.Id; editRegion.Title = region.Title ?? region.Id; editRegion.CLRType = editRegion.GetType().FullName; IList items = new List <object>(); if (region.Collection) { items = (IList)value; } else { items.Add(value); } foreach (var item in items) { if (region.Fields.Count == 1) { var itemTitle = ""; // Get the item title if this is a collection region. if (region.Collection) { if (item != null) { itemTitle = ((Extend.IField)item).GetTitle(); } if (string.IsNullOrWhiteSpace(itemTitle) && !string.IsNullOrWhiteSpace(region.ListTitlePlaceholder)) { itemTitle = region.ListTitlePlaceholder; } else { itemTitle = "Item"; } } var set = new PageEditFieldSet() { new PageEditField() { Id = region.Fields[0].Id, Title = region.Fields[0].Title ?? region.Fields[0].Id, CLRType = item.GetType().FullName, Options = region.Fields[0].Options, Value = (Extend.IField)item } }; set.ListTitle = itemTitle; set.NoExpand = !region.ListExpand; editRegion.Add(set); } else { var fieldData = (IDictionary <string, object>)item; var fieldSet = new PageEditFieldSet(); foreach (var field in region.Fields) { if (fieldData.ContainsKey(field.Id)) { // Get the item title if this is a collection region. if (region.Collection) { if (!string.IsNullOrWhiteSpace(region.ListTitleField) && field.Id == region.ListTitleField) { var itemTitle = ""; if (fieldData[field.Id] != null) { itemTitle = ((Extend.IField)fieldData[field.Id]).GetTitle(); } if (string.IsNullOrWhiteSpace(itemTitle) && !string.IsNullOrWhiteSpace(region.ListTitlePlaceholder)) { itemTitle = region.ListTitlePlaceholder; } else if (string.IsNullOrWhiteSpace(itemTitle)) { itemTitle = "Item"; } fieldSet.ListTitle = itemTitle; fieldSet.NoExpand = !region.ListExpand; } } fieldSet.Add(new PageEditField() { Id = field.Id, Title = field.Title ?? field.Id, CLRType = fieldData[field.Id].GetType().FullName, Options = field.Options, Value = (Extend.IField)fieldData[field.Id] }); } } editRegion.Add(fieldSet); } } return(editRegion); }
/// <summary> /// Adds a field set to the region. /// </summary> /// <param name="fieldSet">The field set</param> public override void Add(PageEditFieldSet fieldSet) { FieldSet = fieldSet; }