Created
December 14, 2014 22:06
-
-
Save fredrikhaglund/e2212a59306779b37862 to your computer and use it in GitHub Desktop.
EPiServer Developer Fundamentals - Demo of different editors and UI Extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel.DataAnnotations; | |
using System.Linq; | |
using System.Web; | |
using EPiServer; | |
using EPiServer.Cms.Shell.UI.ObjectEditing.EditorDescriptors.SelectionFactories; | |
using EPiServer.Core; | |
using EPiServer.DataAbstraction; | |
using EPiServer.DataAnnotations; | |
using EPiServer.ServiceLocation; | |
using EPiServer.Shell; | |
using EPiServer.Shell.ObjectEditing; | |
using EPiServer.SpecializedProperties; | |
using EPiServer.UI.Admin; | |
using EPiServer.Web; | |
using EPiServer.XForms; | |
using Validator = EPiServer.Framework.Validator; | |
namespace AlloyTraining.Models.Pages | |
{ | |
[UIDescriptorRegistration] | |
public class TestPageUIDescriptor : UIDescriptor<TestPage> | |
{ | |
public TestPageUIDescriptor() | |
{ | |
IconClass = ContentTypeCssClassNames.Container; | |
DefaultView = "sampleView"; //CmsViewNames.AllPropertiesView; | |
} | |
} | |
[ServiceConfiguration(typeof(EPiServer.Shell.ViewConfiguration))] | |
public class SampleView : ViewConfiguration<TestPage> | |
{ | |
public SampleView() | |
{ | |
Key = "sampleView"; | |
Name = "Sample View"; | |
Description = "A simple demo view"; | |
ControllerType = "epi-cms/widget/IFrameController"; | |
ViewType = VirtualPathUtility.ToAbsolute("~/UIExtensions/CustomView.aspx"); | |
IconClass = "customview"; | |
} | |
} | |
[ContentType(DisplayName = "TestPage", GUID = "77309042-6cb8-45d3-8cb8-2a00917dbc5e", Description = "")] | |
public class TestPage : PageData | |
{ | |
public virtual bool ShowTeaser { get; set; } | |
public virtual int Votes { get; set; } | |
public virtual double Price { get; set; } | |
public virtual DateTime EventStartTime { get; set; } | |
//public virtual TimeSpan EventDuration { get; set; } - NOT SUPPORTED | |
public virtual string Heading { get; set; } | |
[UIHint(UIHint.Textarea)] | |
public virtual string MetaDescription { get; set; } | |
public virtual XhtmlString MainBody { get; set; } | |
public virtual Url Link { get; set; } | |
[UIHint(UIHint.Image)] //Legacy - Use ContentReference as type for images | |
public virtual Url ImageUrl { get; set; } | |
[UIHint(UIHint.Document)] //Obsolete - Use ContentReference as type | |
public virtual Url FileUrl { get; set; } | |
public virtual LinkItemCollection Links { get; set; } | |
public virtual CategoryList SelectedCategories { get; set; } | |
public virtual XForm Form { get; set; } | |
public virtual PageType FilterOnPageType { get; set; } | |
public virtual ContentArea RightBlockArea { get; set; } | |
[AllowedTypes(typeof(ProductPage))] | |
public virtual ContentArea RelatedContentArea { get; set; } | |
public virtual ContentReference TeaserContentLink { get; set; } | |
public virtual PageReference SitemapPageLink { get; set; } | |
[UIHint(UIHint.Block)] | |
public virtual ContentReference BlockReference { get; set; } | |
[UIHint(UIHint.BlockFolder)] //BlockFolder and MediaFolder gives the same result since the folder structure is the same | |
public virtual ContentReference Folder { get; set; } | |
[UIHint(UIHint.Image)] //Anything that implements IContentImage | |
public virtual ContentReference MainImage { get; set; } | |
[UIHint(UIHint.Video)] //Anything that implements IContentVideo | |
public virtual ContentReference Video { get; set; } | |
[UIHint(UIHint.MediaFile)] | |
public virtual ContentReference MediaFileOfAnyType { get; set; } | |
[AllowedTypes(new[] { typeof(ProductPage) })] | |
public virtual ContentReference SettingsPageReference { get; set; } | |
[SelectOne(SelectionFactoryType = typeof(MyLanguageSelectionFactory))] // Implements ISelectionFactory | |
public virtual string SingleLanguage { get; set; } | |
[SelectMany(SelectionFactoryType = typeof(MyLanguageSelectionFactory))] // Implements ISelectionFactory | |
public virtual string MultipleLanguage { get; set; } | |
[AutoSuggestSelection(typeof(CitySelectionQuery))] // Implements ISelectionQuery | |
public virtual string MeetingRoom { get; set; } | |
[AutoSuggestSelection(typeof(CitySelectionQuery), AllowCustomValues = true)] // Implements ISelectionQuery | |
public virtual string EventLocation { get; set; } | |
} | |
[SelectionFactoryRegistration] | |
public class MyLanguageSelectionFactory : ISelectionFactory | |
{ | |
private readonly SelectItem[] _items; | |
public MyLanguageSelectionFactory() | |
{ | |
_items = new SelectItem[] | |
{ | |
new SelectItem() {Text = String.Empty, Value = String.Empty}, | |
new SelectItem() {Text = "Swedish", Value = "1"}, | |
new SelectItem() {Text = "English", Value = "2"} | |
}; | |
} | |
public virtual IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata) | |
{ | |
return _items; | |
} | |
} | |
// Example of a Selection Query for auto complet. | |
[ServiceConfiguration(typeof (ISelectionQuery))] | |
public class CitySelectionQuery : ISelectionQuery | |
{ | |
private readonly SelectItem[] _items; | |
public CitySelectionQuery() | |
{ | |
_items = new SelectItem[] | |
{ | |
new SelectItem() {Text = String.Empty, Value = String.Empty}, | |
new SelectItem() {Text = "Stockholm", Value = "1"}, | |
new SelectItem() {Text = "Copenhagen", Value = "2"} | |
}; | |
} | |
//Will be called when the editor types something in the selection editor. | |
public IEnumerable<ISelectItem> GetItems(string query) | |
{ | |
return _items.Where(i => i.Text.StartsWith(query, StringComparison.OrdinalIgnoreCase)); | |
} | |
//Will be called when initializing an editor with an existing value to get the corresponding text representation. | |
public ISelectItem GetItemByValue(string value) | |
{ | |
return _items.FirstOrDefault(i => i.Value.Equals(value)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment