public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition) {
     if (definition.FieldDefinition.Name == "TaxonomyField") {
         var model = definition.Settings.GetModel<TaxonomyFieldSettings>();
         model.Taxonomies = _taxonomyService.GetTaxonomies();
         yield return DefinitionTemplate(model);
     }
 }
示例#2
0
        public dynamic Render(PropertyContext context, ContentItem contentItem, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) {
            var p = contentItem.Parts.FirstOrDefault( x => x.PartDefinition.Name == part.Name);

            if(p == null) {
                return String.Empty;
            }

            var f = p.Fields.FirstOrDefault(x => x.Name == field.Name);

            if(f == null) {
                return String.Empty;
            }

            object value = null;

            _contentFieldValueProviders.Invoke(provider => {
                var result = provider.GetValue(contentItem, f);
                if (result != null) {
                    value = result;
                }
            }, Logger);

            if (value == null) {
                value = f.Storage.Get<object>(storageName);
            }

            if (value == null) {
                return null;
            }

            // call specific formatter rendering
            return _propertyFormater.Format(storageType, value, context.State);
        }
 public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition)
 {
     if (definition.FieldDefinition.Name == "BlogPostPickerField") {
         var model = definition.Settings.GetModel<BlogPostPickerFieldSettings>();
         yield return DefinitionTemplate(model);
     }
 }
 public override void ApplyFilter(FilterContext context, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) {
     var op = (OptionSetOperator) Enum.Parse(typeof (OptionSetOperator), (string) context.State.Operator);
     string value = context.State.Value;
     var valueArr = value != null
         ? value.Split('&').Select(int.Parse).ToArray()
         : new[] {0};
     switch (op) {
         case OptionSetOperator.MatchesAny:
             Action<IAliasFactory> selectorAny = alias => alias.ContentPartRecord<OptionItemContainerPartRecord>().Property("OptionItems", "opits").Property("OptionItemRecord", "opcpr");
             Action<IHqlExpressionFactory> filterAny = x => x.InG("Id", valueArr);
             context.Query.Where(selectorAny, filterAny);
             break;
         case OptionSetOperator.MatchesAll:
             foreach (var id in valueArr) {
                 var optionId = id;
                 Action<IAliasFactory> selectorAll =
                     alias => alias.ContentPartRecord<OptionItemContainerPartRecord>().Property("OptionItems", "opit" + optionId);
                 Action<IHqlExpressionFactory> filterAll = x => x.Eq("OptionItemRecord.Id", optionId);
                 context.Query.Where(selectorAll, filterAll);
             }
             break;
         case OptionSetOperator.NotMatchesAny:
             Action<IAliasFactory> selectorNotAny = alias => alias.ContentPartRecord<OptionItemContainerPartRecord>().Property("OptionItems", "opits").Property("OptionItemRecord", "opcpr");
             Action<IHqlExpressionFactory> filterNotAny = x => x.Not(y => y.InG("Id", valueArr));
             context.Query.Where(selectorNotAny, filterNotAny);
             break;
     }
 }
示例#5
0
 public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition) {
     if (definition.FieldDefinition.Name == "PhoneField"
         || definition.FieldDefinition.Name == "PhoneFieldCreate") {
         var model = definition.Settings.GetModel<PhoneFieldSettings>();
         yield return DefinitionTemplate(model);
     }
 }
 public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition)
 {
     if (definition.FieldDefinition.Name.Equals(typeof(MoneyField).Name))
     {
         yield return DefinitionTemplate(definition.Settings.GetModel<MoneyFieldSettings>());
     }
 }
        public IFieldStorage BindStorage(ContentPart contentPart, ContentPartFieldDefinition partFieldDefinition) {
            var partName = XmlConvert.EncodeLocalName(contentPart.PartDefinition.Name);
            var fieldName = XmlConvert.EncodeLocalName(partFieldDefinition.Name);
            var infosetPart = contentPart.As<InfosetPart>();

            return new SimpleFieldStorage(
                (name, valueType) => Get(infosetPart.Infoset.Element, partName, fieldName, name),
                (name, valueType, value) => {
                        Set(infosetPart.Infoset.Element, partName, fieldName, name, value);

                        var context = new FieldStorageEventContext {
                                        FieldName = partFieldDefinition.Name,
                                        PartName = contentPart.PartDefinition.Name,
                                        Value = value,
                                        ValueName = name,
                                        ValueType = valueType,
                                        Content = infosetPart
                                    };

                        foreach(var fieldEvent in _events) {
                            fieldEvent.SetCalled(context);
                        }
                    }
                );
        }
 public EditPartFieldViewModel(int index, ContentPartFieldDefinition field) {
     Index = index;
     Name = field.Name;
     FieldDefinition = new EditFieldViewModel(field.FieldDefinition);
     Settings = field.Settings;
     _Definition = field;
 }
        public LocalizedString DisplaySortCriterion(SortCriterionContext context, ContentPartDefinition part, ContentPartFieldDefinition fieldDefinition) {
            bool ascending = (bool)context.State.Sort;

            return ascending
                       ? T("Ordered by field {0}, ascending", fieldDefinition.Name)
                       : T("Ordered by field {0}, descending", fieldDefinition.Name);

        }
 public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition)
 {
     if (definition.FieldDefinition.Name == typeof(HintField).Name)
     {
         var model = definition.Settings.GetModel<HintFieldSettings>();
         yield return DefinitionTemplate(model);
     }
 }
 public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition)
 {
     if (definition.FieldDefinition.Name.Equals(typeof(MediaLibraryUploadField).Name))
     {
         var model = definition.Settings.GetModel<MediaLibraryUploadFieldSettings>();
         yield return DefinitionTemplate(model);
     }
 }
   PartFieldEditor(ContentPartFieldDefinition definition)
 {
     if (definition.FieldDefinition.Name == "DateTimeField")
     {
         var model = definition.Settings.GetModel<DateTimeFieldSettings>();
         yield return DefinitionTemplate(model);
     }
 }
 public Task BuildPartFieldEditorAsync(ContentPartFieldDefinition model, BuildEditorContext context)
 {
     return _partFieldDisplayDrivers.InvokeAsync(async contentDisplay =>
     {
         var result = await contentDisplay.BuildEditorAsync(model, context);
         if (result != null)
             result.Apply(context);
     }, Logger);
 }
 public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition) {
     if (definition.FieldDefinition.Name == "TextField") {
         var model = new TextFieldSettingsEventsViewModel {
             Settings = definition.Settings.GetModel<TextFieldSettings>(),
         };
             
         yield return DefinitionTemplate(model);
     }
 }
示例#15
0
        public IFieldStorage BindStorage(ContentPart contentPart, ContentPartFieldDefinition partFieldDefinition) {
            var partName = XmlConvert.EncodeLocalName(contentPart.PartDefinition.Name);
            var fieldName = XmlConvert.EncodeLocalName(partFieldDefinition.Name);
            var infosetPart = contentPart.As<InfosetPart>();

            return new SimpleFieldStorage(
                (name, valueType) => Get(infosetPart.ContentItem.VersionRecord == null ? infosetPart.Infoset.Element : infosetPart.VersionInfoset.Element, partName, fieldName, name),
                (name, valueType, value) => Set(infosetPart.ContentItem.VersionRecord == null ? infosetPart.Infoset.Element : infosetPart.VersionInfoset.Element, partName, fieldName, name, value));
        }
        public IFieldStorageProvider GetProvider(ContentPartFieldDefinition partFieldDefinition)
        {
            IFieldStorageProvider provider = null;

            string storage;
            if (partFieldDefinition.Settings.TryGetValue(Storage, out storage))
                provider = Locate(storage);

            return provider ?? Locate(DefaultProviderName);
        }
示例#17
0
        public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition)
        {
            if (!String.Equals("TextField", partFieldDefinition.FieldDefinition.Name, StringComparison.Ordinal))
            {
                return null;
            }

            return Shape<TextFieldSettings>("TextFieldSettings_Edit", model => partFieldDefinition.Settings.Populate(model))
                .Location("Content");
        }
示例#18
0
 public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition) {
     if (definition.FieldDefinition.Name == "DateTimeField") {
         var model = definition.Settings.GetModel<DateTimeFieldSettings>();
         model.Editor = new DateTimeEditor() {
             ShowDate = true,
             ShowTime = true,
             Date = _dateLocalizationServices.ConvertToLocalizedDateString(model.DefaultValue),
             Time = _dateLocalizationServices.ConvertToLocalizedTimeString(model.DefaultValue),
         };
         yield return DefinitionTemplate(model);
     }
 }
 public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition) {
     if (definition.FieldDefinition.Name == "ReferenceField" ||
         definition.FieldDefinition.Name == "ReferenceFieldCreate") {
         var metadataTypes = _contentDefinitionService.GetUserDefinedTypes();
         var model = definition.Settings.GetModel<ReferenceFieldSettings>();
         model.ContentTypeList = metadataTypes.Select(item => new SelectListItem {
             Text = item.Name,
             Value = item.Name,
             Selected = item.Name == model.ContentTypeName
         }).ToList();
         yield return DefinitionTemplate(model);
     }
 }
 public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition)
 {
     if (definition.FieldDefinition.Name == "ContentReferenceField") {
         var model = definition.Settings.GetModel<ContentReferenceFieldSettings>();
         model.QueryList = _contentManager.Query("Query").List()
             .Select(c => new SelectListItem {
                 Text = _contentManager.GetItemMetadata(c).DisplayText,
                 Value = c.Id.ToString(CultureInfo.InvariantCulture),
                 Selected = c.Id == model.QueryId
             }).ToList();
         yield return DefinitionTemplate(model);
     }
 }
示例#21
0
        public override async Task<IDisplayResult> UpdateAsync(ContentPartFieldDefinition partFieldDefinition, UpdatePartFieldEditorContext context)
        {
            if (!String.Equals("TextField", partFieldDefinition.FieldDefinition.Name, StringComparison.Ordinal))
            {
                return null;
            }

            var model = new TextFieldSettings();

            await context.Updater.TryUpdateModelAsync(model, Prefix);

            context.Builder.Hint(model.Hint);

            return Edit(partFieldDefinition);
        }
示例#22
0
        public void ApplyFilter(FilterContext context, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) {
            var propertyName = String.Join(".", part.Name, field.Name, storageName ?? "");

            // use an alias with the join so that two filters on the same Field Type wont collide
            var relationship = fieldTypeEditor.GetFilterRelationship(propertyName.ToSafeName());

            // generate the predicate based on the editor which has been used
            Action<IHqlExpressionFactory> predicate = fieldTypeEditor.GetFilterPredicate(context.State);

            // combines the predicate with a filter on the specific property name of the storage, as implemented in FieldIndexService
            Action<IHqlExpressionFactory> andPredicate = x => x.And(y => y.Eq("PropertyName", propertyName), predicate);

            // apply where clause
            context.Query = context.Query.Where(relationship, andPredicate);
        }
        public ContentPartDefinitionBuilder WithField(string fieldName, Action<ContentPartFieldDefinitionBuilder> configuration) {

            var existingField = _fields.FirstOrDefault(x => x.Name == fieldName);
            if (existingField != null) {
                var toRemove = _fields.Where(x => x.Name == fieldName).ToArray();
                foreach (var remove in toRemove) {
                    _fields.Remove(remove);
                }
            }
            else {
                existingField = new ContentPartFieldDefinition(fieldName);
            }
            var configurer = new FieldConfigurerImpl(existingField);
            configuration(configurer);
            _fields.Add(configurer.Build());
            return this;
        }
 public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition) {
     if (definition.FieldDefinition.Name == "OptionSetField") {
         var model = definition.Settings.GetModel<OptionSetFieldSettings>();
         if (model.OptionSetId == 0) {
             yield return DefinitionTemplate(model);
         }
         else {
             var optionItems = _contentManager.Query<OptionItemPart, OptionItemPartRecord>()
                 .Where(x => x.OptionSetId == model.OptionSetId)
                 .WithQueryHints(new QueryHints().ExpandRecords<TitlePartRecord, CommonPartRecord>())
                 .List();
             var options = optionItems.Aggregate(string.Empty, (current, next) =>
                 string.IsNullOrEmpty(current) ? next.Name : current + Environment.NewLine + next.Name);
             model.Options = options;
             var templateName = model.GetType().Name + ".Edit";
             yield return DefinitionTemplate(model, templateName, model.GetType().Name);
         }
     }
 }
示例#25
0
        public override IEnumerable<TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition) {
            if (definition.FieldDefinition.Name == "TextField") {
                var shapeTable = _shapeTableLocator().Lookup(_orchardServices.WorkContext.CurrentTheme.Id);
                var flavors = shapeTable.Bindings.Keys
                    .Where(x => x.StartsWith("Body_Editor__", StringComparison.OrdinalIgnoreCase))
                    .Select(x => x.Substring("Body_Editor__".Length))
                    .Where(x => !String.IsNullOrWhiteSpace(x))
                    .Select(x => x[0].ToString(CultureInfo.InvariantCulture).ToUpper() + x.Substring(1) )
                    .Select(x => x.CamelFriendly())
                    ;


                var model = new TextFieldSettingsEventsViewModel {
                    Settings = definition.Settings.GetModel<TextFieldSettings>(),
                    Flavors = flavors.ToArray()
                };
                    
                yield return DefinitionTemplate(model);
            }
        }
        public void ApplySortCriterion(SortCriterionContext context, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) {
            bool ascending = Convert.ToBoolean(context.State.Sort);
            var propertyName = String.Join(".", part.Name, field.Name, storageName ?? "");

            // use an alias with the join so that two filters on the same Field Type wont collide
            var relationship = fieldTypeEditor.GetFilterRelationship(propertyName.ToSafeName());

            // generate the predicate based on the editor which has been used
            Action<IHqlExpressionFactory> predicate = y => y.Eq("PropertyName", propertyName);

            // combines the predicate with a filter on the specific property name of the storage, as implemented in FieldIndexService

            // apply where clause
            context.Query = context.Query.Where(relationship, predicate);
            
            // apply sort
            context.Query = ascending 
                ? context.Query.OrderBy(relationship, x => x.Asc("Value")) 
                : context.Query.OrderBy(relationship, x => x.Desc("Value"));
        }
 protected ContentPartFieldDefinitionBuilder(ContentPartFieldDefinition field) {
     _settings = new SettingsDictionary(field.Settings.ToDictionary(kv => kv.Key, kv => kv.Value));
 }
 public FieldConfigurerImpl(ContentPartFieldDefinition field)
     : base(field) {
     _fieldDefinition = field.FieldDefinition;
     _fieldName = field.Name;
 }
 public IFieldStorage BindStorage(ContentPart contentPart, ContentPartFieldDefinition partFieldDefinition) {
     return new DefaultCotentPartFieldStorage(contentPart, partFieldDefinition);
 }
 private void Apply(ContentPartFieldDefinition model, ContentPartFieldDefinitionRecord record)
 {
     record.Settings = model.Settings;
 }