protected override void Define(DynamicFormBuilder builder) { builder.Entity <Customer>(e => { e.Property(p => p.CustomerId).IsReadOnly(); e.Property(p => p.FirstName).IsRequired(); e.Property(p => p.LastName).IsRequired().Rule(CheckCompanyRequired); e.Property(p => p.Phone); e.Property(p => p.EmailAddress).Rule(CheckEmail); e.Property(p => p.CompanyName); e //.DialogButton("QueryResult", ButtonActionTypes.Custom, "Back") .DialogButton("CustAddrCountList", ButtonActionTypes.Cancel) //.DialogButton(ButtonActionTypes.Close) .DialogButton(ButtonActionTypes.Validate) .DialogButton(ButtonActionTypes.Submit, "Update", "Save to database"); e.DialogButtonNavigation("CustAddrCountList", ButtonActionTypes.Delete, ButtonActionTypes.Submit); e.DialogButtonNavigation("/", ButtonActionTypes.Close); }); }
protected override void Define(DynamicFormBuilder builder) { builder.Entity <Address>(e => { e.Property(p => p.AddressId).IsReadOnly(); e.Property(p => p.AddressLine1).IsRequired(); e.Property(p => p.AddressLine2); e.Property(p => p.City).IsRequired(); e.Property(p => p.CountryRegion).IsRequired(); e.Property(p => p.PostalCode).IsRequired(); e.Property(p => p.ModifiedDate).IsReadOnly().Rule(DefaultModifiedDate, FormRuleTriggers.Create); e.DialogButton(ButtonActionTypes.Cancel).DialogButton(ButtonActionTypes.Validate).DialogButton(ButtonActionTypes.Submit); e.DialogButtonNavigation("CustAddrList/{1}", ButtonActionTypes.Delete, ButtonActionTypes.Cancel, ButtonActionTypes.Submit); e.AfterSave(SaveToCustomerAddress); }); }
/// <summary> /// 获取模块的编辑表单 /// </summary> /// <param name="widgetInfo">模块信息</param> /// <returns></returns> public virtual FormBuilder GetWidgetEditForm(TemplateWidgetInfo widgetInfo) { var dynamicFormBuilder = new DynamicFormBuilder(); // 添加模块中的参数 dynamicFormBuilder.AddFields(widgetInfo.Arguments); // 生成表单 var form = dynamicFormBuilder.ToForm<TabFormBuilder>(); form.Attribute = new FormAttribute( "WidgetEditForm", "/api/visual_editor/submit_widget_edit_form?path=" + HttpUtils.UrlEncode(widgetInfo.WidgetPath)); // 添加无参数的提醒 if (!widgetInfo.Arguments.Any()) { form.Fields.Add(new FormField(new TemplateHtmlFieldAttribute( "NoArguments", "theme.visualeditor/no_arguments_alert.html"))); } // 添加内嵌css, 前置html, 后置html var noLint = JsonConvert.SerializeObject(new { lint = false }); form.Fields.Add(new FormField(new TextBoxFieldAttribute( VisualWidgetRenderer.CssClassKey, "example: col-md-3 my-class") { Group = "AdditionalStyle" })); form.Fields.Add(new FormField(new CodeEditorAttribute( VisualWidgetRenderer.InlineCssKey, 5, "css", noLint) { Group = "AdditionalStyle" })); form.Fields.Add(new FormField(new CodeEditorAttribute( VisualWidgetRenderer.BeforeHtmlKey, 8, "html", noLint) { Group = "AdditionalStyle" })); form.Fields.Add(new FormField(new CodeEditorAttribute( VisualWidgetRenderer.AfterHtmlKey, 8, "html", noLint) { Group = "AdditionalStyle" })); return form; }
public void BuildDynamicFormData_ThrowsArgumentExceptionIfTypeInfoDoesNotHaveADynamicFormAttribute() { // Arrange DynamicFormBuilder dynamicFormsBuilder = new DynamicFormBuilder(); // Act and Assert Assert.Throws <ArgumentException>(() => dynamicFormsBuilder.BuildDynamicFormData(typeof(DummyRequestModel_NoDynamicFormAttribute).GetTypeInfo())); }
protected override void Define(DynamicFormBuilder builder) { builder.Entity <Order>(e => { e.Property(p => p.Id).IsReadOnly(); e.Property(p => p.ClientName).IsReadOnly(); e.Property(p => p.Created).IsReadOnly(); }); }
protected override void Define(DynamicFormBuilder builder) { builder.Entity <Order>(e => { e.Property(e => e.Id).IsRequired().IsHidden().IsReadOnly().Label("PK").Format("d").IsFilter() .Control(typeof(DefaultTextEditControl)).ControlReadOnly(typeof(DefaultReadonlyCheckboxControl)); e.Property(e => e.ClientName).Rule(CheckName); }); }
protected override void Define(DynamicFormBuilder builder) { builder.Entity <Product>(e => { e.Property(p => p.Id).IsReadOnly(); e.Property(p => p.Name).IsRequired(); e.Property(p => p.Price).IsRequired(); e.DialogButton(ButtonActionTypes.Cancel).DialogButton(ButtonActionTypes.Validate).DialogButton(ButtonActionTypes.Submit); e.DialogButtonNavigation("ProductList", ButtonActionTypes.Delete, ButtonActionTypes.Cancel, ButtonActionTypes.Submit); }); }
public void BuildDynamicControlData_ReturnsNullForPropertyInfoWithNoDynamicControlAttribute() { // Arrange DynamicFormBuilder dynamicFormsBuilder = new DynamicFormBuilder(); PropertyInfo propertyInfo = typeof(DummyRequestModel).GetProperty(nameof(DummyRequestModel.Password)); // Act DynamicControlData result = dynamicFormsBuilder.BuildDynamicControlData(propertyInfo); // Assert Assert.Null(result); }
protected override void Define(DynamicFormBuilder builder) { builder.Entity <Student>(e => { e.ExcludeAll(); e.Property(p => p.ID).IsReadOnly(); e.Property(p => p.FirstMidName).IsReadOnly(); e.Property(p => p.LastName).IsReadOnly(); }); }
protected override void Define(DynamicFormBuilder builder) { builder.Entity <OrderItem>(e => { e.ExcludeAll(); e.Property(p => p.Id).IsReadOnly(); e.Property(p => p.OrderId).IsFilter().IsHidden(); e.Property(p => p.ProductId).Dropdown <Product>().Set(c => c.Id, c => c.Name).IsRequired(); e.Property(p => p.Qty).IsRequired(); e.DialogButton(ButtonActionTypes.Cancel).DialogButton(ButtonActionTypes.Validate).DialogButton(ButtonActionTypes.Submit); e.DialogButtonNavigation("OrderItemList/{1}", ButtonActionTypes.Delete, ButtonActionTypes.Cancel, ButtonActionTypes.Submit); }); }
protected override void Define(DynamicFormBuilder builder) { builder.Entity <Course>(e => { e.Property(p => p.CourseID).IsPrimaryKey().IsUnique(); e.Property(p => p.Title).IsRequired(); e.Property(p => p.Credits).IsRequired(); e.DialogButton(ButtonActionTypes.Cancel).DialogButton(ButtonActionTypes.Submit); e.DialogButtonNavigation("CourseList", ButtonActionTypes.Cancel, ButtonActionTypes.Delete, ButtonActionTypes.Submit); }); }
public void BuildDynamicControlValidatorData_CreatesDynamicControlValidatorDataFromAsyncValidationAttribute() { // Arrange DynamicFormBuilder dynamicFormsBuilder = new DynamicFormBuilder(); AsyncValidateAttribute dummyValidationAttribute = new AsyncValidateAttribute(nameof(DummyStrings.Dummy), typeof(DummyStrings), "testController", "testAction"); // Act ValidatorData result = dynamicFormsBuilder.BuildDynamicControlValidatorData(dummyValidationAttribute); // Assert Assert.Equal("asyncValidate", result.Name); Assert.Equal(DummyStrings.Dummy, result.ErrorMessage); Assert.Equal(1, result.Options.Count); Assert.Equal(result.Options[nameof(AsyncValidateAttribute.RelativeUrl)], "test/testAction"); }
protected override void Define(DynamicFormBuilder builder) { builder.Entity <Customer>(e => { e.ExcludeAll(); e.Property(p => p.CustomerId).IsReadOnly(); e.Property(p => p.FirstName).IsReadOnly(); e.Property(p => p.MiddleName).IsReadOnly(); e.Property(p => p.LastName).IsReadOnly(); }); }
public void BuildDynamicControlValidatorData_CreatesDynamicControlValidatorDataFromValidationAttribute() { // Arrange DynamicFormBuilder dynamicFormsBuilder = new DynamicFormBuilder(); DummyValidationAttribute dummyValidationAttribute = new DummyValidationAttribute("dummyString", 0, nameof(DummyStrings.Dummy), typeof(DummyStrings)); // Act ValidatorData result = dynamicFormsBuilder.BuildDynamicControlValidatorData(dummyValidationAttribute); // Assert Assert.Equal("dummyValidation", result.Name); Assert.Equal(DummyStrings.Dummy, result.ErrorMessage); Assert.Equal(2, result.Options.Count); Assert.Equal(result.Options["DummyStringProperty"], "dummyString"); Assert.Equal(result.Options["DummyIntProperty"], "0"); }
protected override void Define(DynamicFormBuilder builder) { builder.Entity <ClientModel>(e => { e.Context(p => p.Client).Load().Save(); e.Context(p => p.ClientContact).Load().Save().SavingMapping(p => p.Client.Id, p => p.PersonId); e.ContextPropertyList(p => p.ClientAddressList).Load().Save().SavingMapping(p => p.Client.Id, p => p.PersonId); e.Property(p => p.Client.Id).IsReadOnly(); e.Property(p => p.Client.FirstName).IsRequired(); e.Property(p => p.Client.LastName).IsRequired(); //e.DialogButton(ButtonActionTypes.Cancel).DialogButton(ButtonActionTypes.Validate).DialogButton(ButtonActionTypes.Submit); //e.DialogButtonNavigation("OrderList", ButtonActionTypes.Delete, ButtonActionTypes.Cancel, ButtonActionTypes.Submit); }); }
protected override void Define(DynamicFormBuilder builder) { builder.Entity <Student>(e => { e.Property(p => p.ID).IsReadOnly(); e.Property(p => p.FirstMidName).IsRequired(); e.Property(p => p.LastName).IsRequired(); e.Property(p => p.EnrollmentDate).Rule(DefaultDate, FormRuleTriggers.Create).Rule(CheckDate); e.DialogButton(ButtonActionTypes.Cancel).DialogButton(ButtonActionTypes.Validate).DialogButton(ButtonActionTypes.Submit); e.DialogButtonNavigation("StudentList", ButtonActionTypes.Cancel, ButtonActionTypes.Delete, ButtonActionTypes.Submit); }); }
protected override void Define(DynamicFormBuilder builder) { builder.Entity <Enrollment>(e => { e.Property(p => p.EnrollmentID).IsPrimaryKey().IsReadOnly(); e.Property(p => p.StudentID).IsFilter().IsHidden(); e.Property(p => p.CourseID).IsRequired().Dropdown <Course>().Set(c => c.CourseID, c => c.Title); e.Property(p => p.Grade).IsRequired().Rule(DefaultGrade, FormRuleTriggers.Create).Dropdown <Grade>().Set(g => g, g => g); e.DialogButton(ButtonActionTypes.Cancel).DialogButton(ButtonActionTypes.Submit); // {0} always reserved for Primary Key (EnrollmentID in this case) but EnrollmentList accepts StudentId as parameter e.DialogButtonNavigation("EnrollmentList/{1}", ButtonActionTypes.Cancel, ButtonActionTypes.Delete, ButtonActionTypes.Submit); }); }
public void BuildDynamicFormData_CreatesDynamicFormDataFromTypeInfo() { // Arrange DynamicFormBuilder dynamicFormsBuilder = new DynamicFormBuilder(); Mock <DynamicFormBuilder> mockBuilder = new Mock <DynamicFormBuilder>(); mockBuilder.Setup(b => b.BuildDynamicControlData(It.IsAny <PropertyInfo>())).Returns(new DynamicControlData()); mockBuilder.CallBase = true; // Act DynamicFormData result = mockBuilder.Object.BuildDynamicFormData(typeof(DummyRequestModel).GetTypeInfo()); // Assert Assert.NotNull(result); mockBuilder.VerifyAll(); Assert.Equal(3, result.DynamicControlData.Count); Assert.Equal(DummyStrings.Dummy, result.ErrorMessage); Assert.Equal(DummyStrings.Dummy, result.ButtonText); }
protected override void Define(DynamicFormBuilder builder) { //(new AdventureWorksContext()).Find(); builder.Entity <CustomerModel>(e => { // Load/Save //e.Property(p => p.Customer).Get(db => db.Find).Set(); e.Context(p => p.Customer).Load().Save(); // mapping CustomerId => r.AddressId just example, how to map model property to property in the list e.ContextPropertyList(p => p.Addresses).Load(GetAddressList).Save(SaveAddressList).SavingMapping(m => m.Customer.CustomerId, r => r.AddressId);; e.Context(p => p.OrderHeader).Load().Save().SavingMapping(m => m.Customer.CustomerId, r => r.CustomerId); // UI e.Property(p => p.Customer.CustomerId).IsReadOnly(); e.Property(p => p.Customer.FirstName).IsRequired(); e.Property(p => p.Customer.LastName).IsRequired(); e.Property(p => p.Customer.Phone); e.Property(p => p.Customer.EmailAddress); e.Property(p => p.Customer.CompanyName); // Buttons e //.DialogButton("QueryResult", ButtonActionTypes.Custom, "Back") .DialogButton("CustAddrCountList", ButtonActionTypes.Cancel) //.DialogButton(ButtonActionTypes.Close) .DialogButton(ButtonActionTypes.Validate) .DialogButton(ButtonActionTypes.Submit, "Update", "Save to database"); e.DialogButtonNavigation("CustAddrCountList", ButtonActionTypes.Delete, ButtonActionTypes.Submit); e.DialogButtonNavigation("/", ButtonActionTypes.Close); }); }
protected override void Define(DynamicFormBuilder builder) { builder.Entity <Person>(e => { e.Property(p => p.Id).IsReadOnly(); e.Property(p => p.Name).IsRequired(); e.Property(p => p.Surname).IsRequired(); e.Property(p => p.Dob); e.Property(p => p.Phone).IsRequired(); e.Property(p => p.PrimaryAddressId).Dropdown <Address>().Set(c => c.Id, c => c.Line1).IsRequired(); e.DialogButton(ButtonActionTypes.Cancel).DialogButton(ButtonActionTypes.Validate).DialogButton(ButtonActionTypes.Submit); e.DialogButtonNavigation("PersonStoreList/{0}", ButtonActionTypes.Delete, ButtonActionTypes.Cancel, ButtonActionTypes.Submit); }); }
public void BuildDynamicControlData_CreatesDynamicControlDataFromPropertyInfo() { // Arrange PropertyInfo propertyInfo = typeof(DummyRequestModel).GetProperty(nameof(DummyRequestModel.Email)); DynamicFormBuilder dynamicFormsBuilder = new DynamicFormBuilder(); // Act DynamicControlData result = dynamicFormsBuilder.BuildDynamicControlData(propertyInfo); // Assert Assert.Equal("email", result.Name); Assert.Equal(0, result.Order); Assert.Equal("input", result.TagName); Assert.NotNull(result.ValidatorData); Assert.Equal(result.ValidatorData.Count, 1); Assert.Equal("validateMatches", result.ValidatorData[0].Name); Assert.NotNull(result.AsyncValidatorData); Assert.Equal("asyncValidate", result.AsyncValidatorData.Name); Assert.Equal(DummyStrings.Dummy, result.DisplayName); Assert.NotNull(result.Properties); Assert.Equal(result.Properties["type"], "email"); Assert.Equal(result.Properties["placeholder"], DummyStrings.Dummy); }
public DynamicEditFormBase() { _dataFieldProcessor = new DefaultDataFieldProcessor(); _builder = new DynamicFormBuilder(); Define(_builder); }
protected virtual void Define(DynamicFormBuilder builder) { }