/// <summary> /// Creates a standalone label to be output in a form for a field. /// </summary> /// <typeparam name="TModel">The view model type for the current view</typeparam> /// <typeparam name="TTemplate">The type of HTML template renderer the form is using</typeparam> /// <typeparam name="T">The type of the field being generated</typeparam> /// <param name="form">The form the label is being created in</param> /// <param name="property">A lamdba expression to identify the field to render the label for</param> /// <returns>The HTML for the label</returns> public static IFieldConfiguration LabelFor <TModel, TTemplate, T>(this IForm <TModel, TTemplate> form, Expression <Func <TModel, T> > property) where TTemplate : IFormTemplate { var config = new FieldConfiguration(); config.SetField(() => form.GetFieldGenerator(property).GetLabelHtml(config)); return(config); }
// POST: odata/FieldConfigurations public async Task <IHttpActionResult> Post(FieldConfiguration fieldConfiguration) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } fieldConfiguration.Id = Guid.NewGuid(); db.FieldConfigurations.Add(fieldConfiguration); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (FieldConfigurationExists(fieldConfiguration.Id)) { return(Conflict()); } else { throw; } } return(Created(fieldConfiguration)); }
/// <summary> /// Registers a field configuration for a controller type so it can be represented as an appropriate backend field. /// </summary> /// <param name="controllerType">Type of the controller.</param> /// <param name="configuration">The configuration.</param> public static void RegisterFieldConfiguration(Type controllerType, FieldConfiguration configuration) { lock (BackendFieldFallbackConfigurator.FieldMap) { BackendFieldFallbackConfigurator.FieldMap[controllerType] = configuration; } }
/// <summary> /// Outputs a field with passed in HTML. /// </summary> /// <param name="labelHtml">The HTML for the label part of the field</param> /// <param name="elementHtml">The HTML for the field element part of the field</param> /// <param name="validationHtml">The HTML for the validation markup part of the field</param> /// <param name="metadata">Any field metadata</param> /// <param name="isValid">Whether or not the field is valid</param> /// <returns>A field configuration that can be used to output the field as well as configure it fluently</returns> public IFieldConfiguration Field(IHtmlString labelHtml, IHtmlString elementHtml, IHtmlString validationHtml = null, ModelMetadata metadata = null, bool isValid = true) { var fc = new FieldConfiguration(); fc.SetField(() => Form.Template.Field(labelHtml, elementHtml, validationHtml, metadata, new ReadonlyFieldConfiguration(fc), isValid)); return(fc); }
/// <summary> /// Prepares a Form control for display in the backend. /// </summary> /// <param name="formControl">The form control.</param> /// <param name="formId">Id of the form that hosts the field.</param> /// <returns>The configured form control.</returns> public Control ConfigureFormControl(Control formControl, Guid formId) { if (formControl != null) { var actionInvoker = ObjectFactory.Resolve <IControllerActionInvoker>() as Telerik.Sitefinity.Mvc.ControllerActionInvoker; if (actionInvoker != null) { actionInvoker.DeserializeControllerProperties((Telerik.Sitefinity.Mvc.Proxy.MvcProxyBase)formControl); } var behaviorObject = ObjectFactory.Resolve <IControlBehaviorResolver>().GetBehaviorObject(formControl); var behaviorType = behaviorObject.GetType(); FieldConfiguration fieldConfiguration = null; foreach (var pair in BackendFieldFallbackConfigurator.FieldMap) { if (pair.Key.IsAssignableFrom(behaviorType)) { fieldConfiguration = pair.Value; if (pair.Value == null) { return(null); } break; } } if (fieldConfiguration == null) { fieldConfiguration = BackendFieldFallbackConfigurator.FieldMap[typeof(TextFieldController)]; } var formField = behaviorObject as IFormFieldControl; if (formField != null) { var newControl = (IFormFieldControl)Activator.CreateInstance(fieldConfiguration.BackendFieldType); newControl.MetaField = formField.MetaField; if (newControl is FieldControl) { ((FieldControl)newControl).Title = formField.MetaField.Title; var fieldController = formField as IFormFieldController <IFormFieldModel>; if (fieldController != null) { ((FieldControl)newControl).ValidatorDefinition = fieldController.Model.ValidatorDefinition; if (fieldConfiguration.FieldConfigurator != null) { fieldConfiguration.FieldConfigurator.FormId = formId; fieldConfiguration.FieldConfigurator.Configure((FieldControl)newControl, fieldController); } } } return((Control)newControl); } } return(formControl); }
/// <summary> /// Creates a standalone validation message to be output in a form for a field. /// </summary> /// <example> /// @using (var f = Html.BeginChameleonForm()) { /// @f.ValidationMessageFor(m => m.PositionTitle) /// } /// </example> /// <typeparam name="TModel">The view model type for the current view</typeparam> /// <typeparam name="T">The type of the field being generated</typeparam> /// <param name="form">The form the label is being created in</param> /// <param name="property">A lamdba expression to identify the field to render the validation message for</param> /// <returns>The HTML for the validation message</returns> public static IFieldConfiguration ValidationMessageFor <TModel, T>(this IForm <TModel> form, Expression <Func <TModel, T> > property) { var config = new FieldConfiguration(); config.SetField(() => form.GetFieldGenerator(property).GetValidationHtml(config)); return(config); }
public virtual void SetUp() { DynamoDbRootEntityConfiguration = new DynamoDbRootEntityConfiguration(); DynamoDbMappingConfigurationFake = new Mock <DynamoDbEntityConfiguration>(); DynamoDbMappingConfigurationFake.Setup(c => c.AddFieldConfiguration(It.IsAny <FieldConfiguration>())) .Callback <FieldConfiguration>(fieldConfiguration => { CurrentFieldConfiguration = fieldConfiguration; }); }
/// <summary> /// Creates a single form field as a child of another form field. /// </summary> /// <example> /// @using (var f = s.BeginFieldFor(m => m.Company)) { /// @f.FieldFor(m => m.PositionTitle) /// } /// </example> /// <typeparam name="TModel">The view model type for the current view</typeparam> /// <typeparam name="T">The type of the field being generated</typeparam> /// <param name="field">The parent field the field is being created in</param> /// <param name="property">A lamdba expression to identify the field to render the field for</param> /// <returns>A field configuration object that allows you to configure the field</returns> public static IFieldConfiguration FieldFor <TModel, T>(this Field <TModel> field, Expression <Func <TModel, T> > property) { var config = new FieldConfiguration(); // ReSharper disable ObjectCreationAsStatement new Field <TModel>(field.Form, false, field.Form.GetFieldGenerator(property), config); // ReSharper restore ObjectCreationAsStatement return(config); }
/// <summary> /// Creates a single form field as a child of a form section. /// </summary> /// <example> /// @s.FieldFor(m => m.FirstName) /// </example> /// <typeparam name="TModel">The view model type for the current view</typeparam> /// <typeparam name="T">The type of the field being generated</typeparam> /// <param name="section">The section the field is being created in</param> /// <param name="property">A lamdba expression to identify the field to render the field for</param> /// <returns>A field configuration object that allows you to configure the field</returns> public static IFieldConfiguration FieldFor <TModel, T>(this ISection <TModel> section, Expression <Func <TModel, T> > property) { var fc = new FieldConfiguration(); // ReSharper disable ObjectCreationAsStatement new Field <TModel>(section.Form, false, section.Form.GetFieldGenerator(property), fc); // ReSharper restore ObjectCreationAsStatement return(fc); }
public void GetLabelHtml_should_return_display_attribute_if_WithoutLabelElement_used_and_DisplayAttribute_present() { var generator = Arrange(x => x.StringWithDisplayAttribute); var fieldConfig = new FieldConfiguration(); fieldConfig.WithoutLabelElement(); var config = generator.PrepareFieldConfiguration(fieldConfig, FieldParent.Section); var actual = generator.GetLabelHtml(config).ToString(); Assert.That(actual, Is.EqualTo("Use this display name")); }
public void Use_correct_html_for_without_inline_label_for_boolean_checkbox() { var g = Arrange(x => x.RequiredBoolean); IFieldConfiguration config = new FieldConfiguration(); config = config.WithoutInlineLabel(); var result = g.GetFieldHtml(config); HtmlApprovals.VerifyHtml(result.ToHtmlString()); }
void OnClosed(object sender, System.Windows.Forms.FormClosedEventArgs e) { if (DialogResult == System.Windows.Forms.DialogResult.OK) { SelectedConfig = FieldConfiguration.GetConfigurationByName(this.presetSelectionComboBox.SelectedItem.ToString()); if (SelectedConfig == null) { SelectedConfig = new FieldConfiguration(this.widthSelectionTextBox.Text, this.heightSelectionTextBox.Text, this.minesSelectionTextBox.Text); } ConfigurationManager.MostRecentFieldConfiguration = SelectedConfig; } }
protected FieldConfiguration Map <TType>(Expression <Func <TEntity, TType> > propertyExpression, IPropertyConverter propertyConverter = null) { var propertyInfo = GetPropertyInfo(propertyExpression); if (propertyInfo != null) { var fieldConfiguration = new FieldConfiguration(propertyInfo.Name, propertyInfo.PropertyType, false, propertyConverter: propertyConverter); _dynamoDbEntityConfiguration.AddFieldConfiguration(fieldConfiguration); return(fieldConfiguration); } return(null); //TODO: Throws exception }
// DELETE: odata/FieldConfigurations(5) public async Task <IHttpActionResult> Delete([FromODataUri] Guid key) { FieldConfiguration fieldConfiguration = await db.FieldConfigurations.FindAsync(key); if (fieldConfiguration == null) { return(NotFound()); } db.FieldConfigurations.Remove(fieldConfiguration); await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
public FieldConfiguration Clone() { var fieldConfiguration = new FieldConfiguration(); fieldConfiguration.Name = this.Name; fieldConfiguration.Position = this.Position; fieldConfiguration.Length = this.Length; fieldConfiguration.Type = this.Type; fieldConfiguration.IsBasic = this.IsBasic; fieldConfiguration.IsKey = this.IsKey; fieldConfiguration.IsForList = this.IsForList; fieldConfiguration.IsAttachment = this.IsAttachment; return(fieldConfiguration); }
public void Configure_DefaultValues_ConfigSetWithDefaults() { //Act var attr = new StubFieldAttribute(); var config = new FieldConfiguration(); var propertyInfo = typeof(StubItem).GetProperty("X"); //Act attr.Configure(propertyInfo, config); //Assert Assert.AreEqual(propertyInfo, config.PropertyInfo); // Assert.IsNullOrEmpty(config.Name); Assert.IsFalse(config.ReadOnly); }
private FieldConfiguration CreateComplexFieldConfiguration <TType>(PropertyInfo propertyInfo) { var classMap = _classMapLoader.Load <TType>(); var fieldConfiguration = new FieldConfiguration(propertyInfo.Name, propertyInfo.PropertyType, true); foreach (var innerFieldConfiguration in classMap.GetMappingConfigurationFields()) { fieldConfiguration.FieldConfigurations.Add(innerFieldConfiguration); } _dynamoDbEntityConfiguration.AddFieldConfiguration(fieldConfiguration); return(fieldConfiguration); }
public void Configure_FieldNameSet_FieldNameSetOnConfig() { //Act var attr = new StubFieldAttribute(); var config = new FieldConfiguration(); var propertyInfo = typeof(StubItem).GetProperty("X"); // attr.Name = "test field name"; //Act attr.Configure(propertyInfo, config); //Assert Assert.AreEqual(propertyInfo, config.PropertyInfo); // Assert.AreEqual(attr.Name, config.Name); Assert.IsFalse(config.ReadOnly); }
public void Configure_ReadOnlySet_ReadOnlySetOnConfig() { //Act var attr = new StubFieldAttribute(); var config = new FieldConfiguration(); var propertyInfo = typeof(StubItem).GetProperty("X"); attr.ReadOnly = true; //Act attr.Configure(propertyInfo, config); //Assert Assert.AreEqual(propertyInfo, config.PropertyInfo); //Assert.IsNullOrEmpty(config.Name); Assert.True(config.ReadOnly); }
public void Output_radio_list_field_with_prepended_and_appended_html_when_required() { var t = new TwitterBootstrap3FormTemplate(); var fc = new FieldConfiguration(); fc.Bag.IsRadioOrCheckboxList = true; var result = t.Field(new HtmlString("labelhtml"), new HtmlString("elementhtml"), new HtmlString("validationhtml"), GetRequiredMetadata(), fc .Prepend(new HtmlString("<1>")) .Prepend(new HtmlString("<2>")) .Append(new HtmlString("<3>")) .Append(new HtmlString("<4>")) .WithHint(new HtmlString("<hint>")), false); HtmlApprovals.VerifyHtml(result.ToHtmlString()); }
public void Output_field_with_prepended_and_appended_html_when_allowed_input_group() { var t = new TwitterBootstrap3FormTemplate(); var fc = new FieldConfiguration(); fc.Bag.CanBeInputGroup = true; var result = t.Field(new HtmlString("labelhtml"), new HtmlString("elementhtml"), new HtmlString("validationhtml"), GetRequiredMetadata(), fc .Prepend(new HtmlString("<1>")) .Prepend(new HtmlString("<2>")) .Append(new HtmlString("<3>")) .Append(new HtmlString("<4>")) .WithHint(new HtmlString("<hint>")) .AsInputGroup(), // This shouldn't take effect since we haven't specified this field can be an input group false); HtmlApprovals.VerifyHtml(result.ToHtmlString()); }
private DataTable GetGridFormatSettings() { var dtGridFormat = new FieldConfiguration.Data(); dtGridFormat.SystemEntityTypeId = GetSystemEntityTypeId(); DataTable gridFormatdt = null; if (Session[CoreTableName + "_GridFormatSettings"] != null) { gridFormatdt = (DataTable)Session[CoreTableName + "_GridFormatSettings"]; } else { gridFormatdt = FieldConfiguration.Search(dtGridFormat, SessionVariables.AuditId); Session[CoreTableName + "_GridFormatSettings"] = gridFormatdt; } return(gridFormatdt); }
public void Output_radio_list_field_with_prepended_and_appended_html_when_required() { var t = new TwitterBootstrapFormTemplate(); var fc = new FieldConfiguration(); fc.Bag.IsRadioOrCheckboxList = true; var metadata = new ModelMetadata(new EmptyModelMetadataProvider(), typeof(object), () => null, typeof(object), ""); metadata.IsRequired = true; var result = t.Field(new HtmlString("labelhtml"), new HtmlString("elementhtml"), new HtmlString("validationhtml"), metadata, fc .Prepend(new HtmlString("<1>")).Prepend(new HtmlString("<2>")) .Append(new HtmlString("<3>")).Append(new HtmlString("<4>")) .WithHint(new HtmlString("<hint>")), false ); HtmlApprovals.VerifyHtml(result.ToHtmlString()); }
private void StartNewGame(FieldConfiguration config) { this.SuspendLayout(); this.Controls.Remove(field); field = new MineField(config); this.field.Location = new System.Drawing.Point(0, menuStripMain.Height); this.field.Name = "field"; this.field.Size = new System.Drawing.Size(152, 159); this.field.TabIndex = 0; this.field.NewGameStarted += new System.EventHandler(this.OnNewGameStarted); this.field.RemainingBombsCountChanged += new System.EventHandler(this.OnBombsCountChanged); this.field.GameEnded += new EventHandler(OnGameEnded); this.field.DrawCells(); this.Controls.Add(field); this.mineLabelBombsCount.Value = config.MinesCount; this.mineLabelTime.Value = 0; this.buttonSmileyFace.ParentField = field; NormalizeLayoutAndValues(); this.ResumeLayout(); }
public void Output_field_with_prepended_and_appended_html_when_allowed_input_group() { var t = new TwitterBootstrapFormTemplate(); var metadata = new ModelMetadata(new EmptyModelMetadataProvider(), typeof(object), () => null, typeof(object), ""); metadata.IsRequired = true; var fc = new FieldConfiguration(); fc.Bag.CanBeInputGroup = true; var result = t.Field(new HtmlString("labelhtml"), new HtmlString("elementhtml"), new HtmlString("validationhtml"), metadata, fc .Prepend(new HtmlString("<1>")).Prepend(new HtmlString("<2>")) .Append(new HtmlString("<3>")).Append(new HtmlString("<4>")) .WithHint(new HtmlString("<hint>")) .AsInputGroup() // This shouldn't take effect since we haven't specified this field can be an input group .ToReadonly(), false ); HtmlApprovals.VerifyHtml(result.ToHtmlString()); }
/// <summary> /// Idempotently gets a <see cref="IFieldConfiguration"/> from <see cref="TagHelperContext"/> Items. /// </summary> /// <param name="context">The tag helper context</param> /// <returns>The field configuration</returns> public static IFieldConfiguration GetFieldConfiguration(this TagHelperContext context) { var key = $"{FieldConfigurationItemsKey}:{context.UniqueId}"; if (context.Items.ContainsKey(key)) { var fc = context.Items[key] as IFieldConfiguration; if (fc == null) { throw new InvalidOperationException($"Found object in context.Items.{key} that wasn't of type IFieldConfiguration, but instead was {context.Items[key]?.GetType()}"); } return(fc); } else { var fc = new FieldConfiguration(); context.Items[key] = fc; return(fc); } }
// PUT: odata/FieldConfigurations(5) public async Task <IHttpActionResult> Put([FromODataUri] Guid key, Delta <FieldConfiguration> patch) { Validate(patch.GetEntity()); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } FieldConfiguration fieldConfiguration = await db.FieldConfigurations.FindAsync(key); if (fieldConfiguration == null) { return(NotFound()); } patch.Put(fieldConfiguration); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FieldConfigurationExists(key)) { return(NotFound()); } else { throw; } } return(Updated(fieldConfiguration)); }
private static object GetValue <T>(List <DataElement> detailData, FieldConfiguration fieldConfiguration, ExtractorBase <T> extractor) { object retVal; // The scope type memo is special in that text can be spread over multiple fields in 4000 char chunks. Thus we use the simple GetValue method // that stiches the data together in one field. if (detailData.First().ElementType == DataElementElementType.memo) { retVal = extractor.GetValue(detailData, fieldConfiguration.ElementId); } else { retVal = fieldConfiguration.IsRepeatable ? (object)extractor.GetListValues(detailData, fieldConfiguration.ElementId) : extractor.GetValue(detailData, fieldConfiguration.ElementId); } if (fieldConfiguration.IsDefaultField && retVal is List <string> ) { retVal = string.Join(Environment.NewLine, (List <string>)retVal); } return(retVal); }
/// <summary> /// Configures the specified property info. /// </summary> /// <param name="propertyInfo">The property info.</param> /// <param name="config">The config.</param> public void Configure(PropertyInfo propertyInfo, FieldConfiguration config) { config.ReadOnly = this.ReadOnly; base.Configure(propertyInfo, config); }
private object GetValue(List <DataElement> detailData, FieldConfiguration fieldConfiguration) { object retVal = null; try { switch (fieldConfiguration.Type) { case ElasticFieldTypes.TypeString: var textExtractor = new TextExtractor(); retVal = GetValue(detailData, fieldConfiguration, textExtractor); break; case ElasticFieldTypes.TypeTimePeriod: var timePeriodExtractor = new TimePeriodExtractor(); retVal = GetValue(detailData, fieldConfiguration, timePeriodExtractor); break; case ElasticFieldTypes.TypeDateWithYear: var dateWithYearExtractor = new DateWithYearExtractor(); retVal = GetValue(detailData, fieldConfiguration, dateWithYearExtractor); break; case ElasticFieldTypes.TypeBase64: var elasticBase64Extractor = new Base64Extractor(); retVal = GetValue(detailData, fieldConfiguration, elasticBase64Extractor); break; case ElasticFieldTypes.TypeInt + "?": case ElasticFieldTypes.TypeInt: var intExtractor = new IntExtractor(); retVal = GetValue(detailData, fieldConfiguration, intExtractor); break; case ElasticFieldTypes.TypeBool + "?": case ElasticFieldTypes.TypeBool: var boolExtractor = new BoolExtractor(); retVal = GetValue(detailData, fieldConfiguration, boolExtractor); break; case ElasticFieldTypes.TypeFloat + "?": case ElasticFieldTypes.TypeFloat: var floatExtractor = new FloatExtractor(); retVal = GetValue(detailData, fieldConfiguration, floatExtractor); break; case ElasticFieldTypes.TypeHyperlink: var hyperlinkExtractor = new HyperlinkExtractor(); retVal = GetValue(detailData, fieldConfiguration, hyperlinkExtractor); break; case ElasticFieldTypes.TypeEntityLink: var entityLinkExtractor = new EntityLinkExtractor(); retVal = GetValue(detailData, fieldConfiguration, entityLinkExtractor); break; } } catch (Exception ex) { Log.Error(ex.Message); throw; } return(retVal); }
/// <summary> /// Configures the specified property info. /// </summary> /// <param name="propertyInfo">The property info.</param> /// <param name="config">The config.</param> public void Configure(PropertyInfo propertyInfo, FieldConfiguration config) { config.ReadOnly = ReadOnly; base.Configure(propertyInfo, config); }
public FieldAccessibilityOptions(FieldConfiguration config) { this.config = config; }