Exemple #1
0
        private int CreateOptionSetPart(string name, OptionSetFieldSettings model)
        {
            var options = (!String.IsNullOrWhiteSpace(model.Options)) ?
                          model.Options.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) : null;

            if (options == null)
            {
                return(-1);
            }

            var optionSetPart = _contentManager.New <OptionSetPart>("OptionSet");

            optionSetPart.As <TitlePart>().Title = name;

            _contentManager.Create(optionSetPart, VersionOptions.Published);

            foreach (var option in options)
            {
                var term = _contentManager.New <OptionItemPart>("OptionItem");
                term.OptionSetId = optionSetPart.Id;
                term.Name        = option;
                _contentManager.Create(term, VersionOptions.Published);
            }
            return(optionSetPart.Id);
        }
 public override void UpdateFieldSettings(string fieldType, string fieldName, SettingsDictionary settingsDictionary, IUpdateModel updateModel) {
     if (fieldType != "OptionSetField") {
         return;
     }
     var model = new OptionSetFieldSettings();
     if (updateModel.TryUpdateModel(model, "OptionSetFieldSettings", null, null)) {
         UpdateSettings(model, settingsDictionary, "OptionSetFieldSettings");
         if (model.OptionSetId == 0) {
             model.OptionSetId = CreateOptionSetPart(fieldName, model);
             if (model.OptionSetId <= 0) {
                 updateModel.AddModelError("OptionSet", T("No items inputted"));
                 return;
             }
         }
         settingsDictionary["OptionSetFieldSettings.OptionSetId"] = model.OptionSetId.ToString("D");
         settingsDictionary["OptionSetFieldSettings.ListMode"] = model.ListMode.ToString();
     }
 }
        public override IEnumerable<TemplateViewModel> PartFieldEditorUpdate(ContentPartFieldDefinitionBuilder builder, IUpdateModel updateModel) {
            if (builder.FieldType != "OptionSetField") {
                yield break;
            }

            var model = new OptionSetFieldSettings();

            if (updateModel.TryUpdateModel(model, "OptionSetFieldSettings", null, null)) {
                UpdateSettings(model, builder, "OptionSetFieldSettings");

                if (model.OptionSetId == 0) {
                    string[] options = (!String.IsNullOrWhiteSpace(model.Options)) ?
                        model.Options.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) : null;

                    if (options == null) {
                        updateModel.AddModelError("OptionSet",T("No items inputted"));
                        yield break;
                    }

                    var optionSetPart = _contentManager.New<OptionSetPart>("OptionSet");
                    optionSetPart.As<TitlePart>().Title = builder.Name;

                    _contentManager.Create(optionSetPart, VersionOptions.Published);

                    foreach (var option in options) {
                        var term = _contentManager.New<OptionItemPart>("OptionItem");
                        term.OptionSetId = optionSetPart.Id;
                        term.Name = option;
                        _contentManager.Create(term, VersionOptions.Published);
                    }
                    model.OptionSetId = optionSetPart.Id;
                }

                builder
                    .WithSetting("OptionSetFieldSettings.OptionSetId", model.OptionSetId.ToString())
                    .WithSetting("OptionSetFieldSettings.ListMode", model.ListMode.ToString());
            }

            yield return DefinitionTemplate(model);
        }
Exemple #4
0
        public override void UpdateFieldSettings(string fieldType, string fieldName, SettingsDictionary settingsDictionary, IUpdateModel updateModel)
        {
            if (fieldType != "OptionSetField")
            {
                return;
            }
            var model = new OptionSetFieldSettings();

            if (updateModel.TryUpdateModel(model, "OptionSetFieldSettings", null, null))
            {
                UpdateSettings(model, settingsDictionary, "OptionSetFieldSettings");
                if (model.OptionSetId == 0)
                {
                    model.OptionSetId = CreateOptionSetPart(fieldName, model);
                    if (model.OptionSetId <= 0)
                    {
                        updateModel.AddModelError("OptionSet", T("No items inputted"));
                        return;
                    }
                }
                settingsDictionary["OptionSetFieldSettings.OptionSetId"] = model.OptionSetId.ToString("D");
                settingsDictionary["OptionSetFieldSettings.ListMode"]    = model.ListMode.ToString();
            }
        }
        private int CreateOptionSetPart(string name, OptionSetFieldSettings model) {
            var options = (!String.IsNullOrWhiteSpace(model.Options)) ?
                model.Options.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) : null;

            if (options == null) {
                return -1;
            }

            var optionSetPart = _contentManager.New<OptionSetPart>("OptionSet");
            optionSetPart.As<TitlePart>().Title = name;

            _contentManager.Create(optionSetPart, VersionOptions.Published);

            foreach (var option in options) {
                var term = _contentManager.New<OptionItemPart>("OptionItem");
                term.OptionSetId = optionSetPart.Id;
                term.Name = option;
                _contentManager.Create(term, VersionOptions.Published);
            }
            return optionSetPart.Id;
        }