public override async Task <IDisplayResult> UpdateAsync(ContentPartFieldDefinition model, UpdatePartFieldEditorContext context) { var viewModel = new UpdateResponsiveMediaFieldSettingsViewModel(); await context.Updater.TryUpdateModelAsync(viewModel, Prefix); var settings = new ResponsiveMediaFieldSettings { AllowMediaText = viewModel.AllowMediaText, Hint = viewModel.Hint, Multiple = viewModel.Multiple, Required = viewModel.Required, FallbackData = JsonConvert.SerializeObject(ResponsiveMediaUtils.ParseMedia(_mediaFileStore, viewModel.FallbackData)) }; try { settings.Breakpoints = viewModel.Breakpoints; settings.GetBreakpoints(); } catch { context.Updater.ModelState.AddModelError(Prefix, T["Failed to parse breakpoints, make sure it only contains numeric values."]); } context.Builder.WithSettings(settings); return(Edit(model)); }
public IList <ResponsiveMediaItem> ParseMedia(string data, int[] breakpoints) { var media = ResponsiveMediaUtils.ParseMedia(_mediaFileStore, data); foreach (var mediaItem in media) { mediaItem.Sources = mediaItem.GetSourceSets(breakpoints); } return(media); }
public override IDisplayResult Edit(ResponsiveMediaField field, BuildFieldEditorContext context) { var settings = context.PartFieldDefinition.GetSettings <ResponsiveMediaFieldSettings>(); if (!settings.IsConfigured) { return(Initialize <EditResponsiveMediaFieldViewModel>("ResponsiveMediaField_Unconfigured", model => { model.Field = field; model.Part = context.ContentPart; model.PartFieldDefinition = context.PartFieldDefinition; })); } return(Initialize <EditResponsiveMediaFieldViewModel>(GetEditorShapeType(context), model => { model.Field = field; model.Part = context.ContentPart; model.PartFieldDefinition = context.PartFieldDefinition; model.Data = JsonConvert.SerializeObject(ResponsiveMediaUtils.ParseMedia(_mediaFileStore, field.Data)); })); }