Esempio n. 1
0
        protected void SetDefaultsInternal()
        {
            _allowMultiple   = false;
            _allowExtraValue = false;

            _options = new List <ChoiceOption>
            {
                new ChoiceOption(YesValue, SenseNetResourceManager.GetResourceKey("Ctd", "Enum-FieldSettingContent-YesNo-Yes")),
                new ChoiceOption(NoValue, SenseNetResourceManager.GetResourceKey("Ctd", "Enum-FieldSettingContent-YesNo-No"))
            };
        }
Esempio n. 2
0
        public static void ParseOptions(XPathNavigator node, List <ChoiceOption> options, ChoiceFieldSetting fieldSetting, out string enumTypeName)
        {
            options.Clear();
            enumTypeName = string.Empty;

            foreach (XPathNavigator optionElement in node.SelectChildren(XPathNodeType.Element))
            {
                if (optionElement.Name == "Enum")
                {
                    enumTypeName = optionElement.GetAttribute("type", "");
                    var enumType = TypeHandler.GetType(enumTypeName);
                    if (enumType == null)
                    {
                        throw new ContentRegistrationException("Enum");
                    }

                    var resClassName = optionElement.GetAttribute("resourceClass", "");
                    if (string.IsNullOrEmpty(resClassName))
                    {
                        resClassName = CtdResourceClassName;
                    }

                    var names  = Enum.GetNames(enumType);
                    var values = Enum.GetValues(enumType).Cast <int>().ToArray();
                    for (var i = 0; i < names.Length; i++)
                    {
                        var resKey = fieldSetting == null ? string.Empty : fieldSetting.GetResourceKey(names[i]);
                        var text   = string.IsNullOrEmpty(resKey) ? names[i] : SenseNetResourceManager.GetResourceKey(resClassName, resKey);
                        var c      = new ChoiceOption(values[i].ToString(), text);
                        options.Add(c);
                    }
                }
                else
                {
                    var text = optionElement.InnerXml;
                    var key  = optionElement.GetAttribute("value", "");

                    if (text.Length == 0 && key.Length == 0)
                    {
                        key = options.Count.ToString();
                    }
                    if (text.Length == 0)
                    {
                        text = key;
                    }
                    if (key.Length == 0)
                    {
                        key = text;
                    }

                    bool enabled;
                    if (!Boolean.TryParse(optionElement.GetAttribute("enabled", ""), out enabled))
                    {
                        enabled = true;
                    }

                    var selected = false;
                    Boolean.TryParse(optionElement.GetAttribute("selected", ""), out selected);

                    options.Add(new ChoiceOption(key, text, enabled, selected));
                }
            }
        }