17 using System.Collections.Generic;
18 using System.Collections.ObjectModel;
21 using erminas.SmartAPI.CMS.Converter;
22 using erminas.SmartAPI.Utils;
24 namespace erminas.SmartAPI.CMS.Project.ContentClasses.Elements
35 ILanguageDependentValue<string> DefaultValueString {
get; }
36 string DescriptionInCurrentDisplayLanguage {
get;
set; }
38 IEnumerable<IOptionListSelection> Entries {
get; }
42 bool HasLanguageDependendNames {
get;
set; }
43 bool HasLanguageDependendValues {
get;
set; }
44 bool IsAllowingOtherValues {
get;
set; }
45 ILanguageDependentValue<string> SampleText {
get; }
56 internal class OptionListEntry : IOptionListEntry
59 public string Name {
get;
internal set; }
60 public string Value {
get;
internal set; }
65 IEnumerable<IOptionListEntry> Entries {
get; }
70 internal sealed
class OptionListSelection : IOptionListSelection
72 private readonly IOptionList _optionList;
74 public OptionListSelection(IOptionList optionList, XmlElement element)
76 _optionList = optionList;
77 Guid = element.GetGuid();
78 Entries = GetEntries(element);
81 public IEnumerable<IOptionListEntry> Entries {
get;
private set; }
82 public Guid Guid {
get;
private set; }
84 public IOptionList OptionList
86 get {
return _optionList; }
89 public IProject Project
91 get {
return OptionList.Project; }
94 public ISession Session
96 get {
return OptionList.Session; }
99 private ReadOnlyCollection<OptionListEntry> GetEntries(XmlElement element)
101 return (from XmlElement curEntry in element.GetElementsByTagName(
"ITEM")
105 LanguageVariant = Project.LanguageVariants[curEntry.GetAttributeValue(
"languageid")],
106 Name = curEntry.GetName(),
107 Value = curEntry.InnerText
108 }).ToList().AsReadOnly();
112 internal class OptionList : ContentClassContentElement, IOptionList
114 private const string ELTDEFAULTVALUE =
"eltdefaultvalue";
116 internal OptionList(IContentClass contentClass, XmlElement xmlElement) : base(contentClass, xmlElement)
118 if (xmlElement.SelectSingleNode(
@"//SELECTIONS") == null)
120 IsInitialized =
false;
128 [RedDot(
"eltparentelementguid", ConverterType = typeof (ContentClassElementConverter))]
129 public IContentClassElement ChildElementOf
131 get {
return GetAttributeValue<IContentClassElement>(); }
132 set { SetAttributeValue(value); }
135 [RedDot(ELTDEFAULTVALUE)]
136 public ILanguageDependentValue<string> DefaultValueString
138 get {
return GetAttributeValue<ILanguageDependentValue<string>>(); }
141 [RedDot(
"eltrddescription")]
142 public string DescriptionInCurrentDisplayLanguage
144 get {
return GetAttributeValue<string>(); }
145 set { SetAttributeValue(value); }
148 public IEnumerable<IOptionListSelection> Entries
152 EnsureInitialization();
153 return (from XmlElement curEntry in _xmlElement.GetElementsByTagName(
"SELECTION")
154 select (IOptionListSelection) new OptionListSelection(this, curEntry)).ToList().AsReadOnly();
165 [RedDot("eltlanguagedependentname")]
166 public
bool HasLanguageDependendNames
168 get {
return GetAttributeValue<bool>(); }
169 set { SetAttributeValue(value); }
172 [RedDot(
"eltlanguagedependentvalue")]
173 public bool HasLanguageDependendValues
175 get {
return GetAttributeValue<bool>(); }
176 set { SetAttributeValue(value); }
179 [RedDot(
"eltuserdefinedallowed")]
180 public bool IsAllowingOtherValues
182 get {
return GetAttributeValue<bool>(); }
183 set { SetAttributeValue(value); }
186 [RedDot(
"eltrdexample")]
187 public ILanguageDependentValue<string> SampleText
189 get {
return GetAttributeValue<ILanguageDependentValue<string>>(); }
192 [RedDot(
"eltorderby", ConverterType = typeof (EnumConverter<SortMode>))]
195 get {
return GetAttributeValue<SortMode>(); }
196 set { SetAttributeValue(value); }
199 protected override XmlElement RetrieveWholeObject()
201 const string LOAD_OBJECT =
202 @"<TEMPLATE><ELEMENT action=""load"" guid=""{0}""><SELECTIONS action=""load"" guid=""{0}""/></ELEMENT></TEMPLATE>";
205 Project.ExecuteRQL(LOAD_OBJECT.RQLFormat(
this),
RqlType.SessionKeyInProject).GetSingleElement(
"ELEMENT");