/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { // Get all help attributes List <FormHelpAttribute> helps = context.Property.GetCustomAttributes <FormHelpAttribute>().ToList(); // If the current property has no helps this module has nothing to to if (!helps.Any()) { return; } foreach (FormHelpAttribute help in helps) { string helpCssClases = DetermineHelpCssClasses(help.HelpType); string helpText = GetTextForKey(help.HelpText, context); // Create the help JSON object JObject helpObject = new JObject(); helpObject["type"] = new JValue("help"); helpObject["helpvalue"] = new JValue("<div class=\"" + helpCssClases + "\" >" + helpText + "</div>"); if (!string.IsNullOrEmpty(help.Condition)) { helpObject["condition"] = ConvertConditionToAbsolutePath(context.DtoType.Name, context.FullPropertyPath, help.Condition); } context.CurrentFormElementParent.Add(helpObject); } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { // Get all help attributes List<FormHelpAttribute> helps = context.Property.GetCustomAttributes<FormHelpAttribute>().ToList(); // If the current property has no helps this module has nothing to to if (!helps.Any()) { return; } foreach (FormHelpAttribute help in helps) { string helpCssClases = DetermineHelpCssClasses(help.HelpType); string helpText = GetTextForKey(help.HelpText, context); // Create the help JSON object JObject helpObject = new JObject(); helpObject["type"] = new JValue("help"); helpObject["helpvalue"] = new JValue("<div class=\"" + helpCssClases + "\" >" + helpText + "</div>"); if (!string.IsNullOrEmpty(help.Condition)) { helpObject["condition"] = ConvertConditionToAbsolutePath(context.DtoType.Name, context.FullPropertyPath, help.Condition); } context.CurrentFormElementParent.Add(helpObject); } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { if (context.Property.GetCustomAttribute<FormDisplayAttribute>() != null) { FormDisplayAttribute formDisplayAttribute = context.Property.GetCustomAttribute<FormDisplayAttribute>(); // Build a new hierarchy object for the element JObject hierachyObject = new JObject(); JArray hierarcyItems = new JArray(); hierachyObject["type"] = new JValue("section"); hierachyObject["items"] = hierarcyItems; if (context.CurrentFormElement != null) { // Move the current element into the form hierarcy hierarcyItems.Add(context.CurrentFormElement); context.CurrentFormElementParent.Remove(context.CurrentFormElement); context.CurrentFormElementParent.Add(hierachyObject); } // Set the new parent element to the current hierarchy context.CurrentFormElementParent = hierarcyItems; string cssClasses = ConvertDisplayWidthToCssClass(formDisplayAttribute.DisplayWidth); if (!string.IsNullOrEmpty(cssClasses)) { hierachyObject["htmlClass"] = new JValue(cssClasses); } } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { FormArrayAttribute arrayAttribute = context.Property.GetCustomAttribute <FormArrayAttribute>(); // Test to the form subobject attribute if (arrayAttribute != null) { if (context.Property.PropertyType.GetInterfaces() .Where(i => i.GetTypeInfo().IsGenericType) .Select(i => i.GetGenericTypeDefinition()).Any(i => i == typeof(IEnumerable <>))) { // Get the subtype from a generic type argument Type subType = context.Property.PropertyType.GetGenericArguments()[0]; // Create the subform JContainer properties = context.FormBuilder.BuildForm(subType, context.OriginDtoType, context.TargetCulture, context.FullPropertyPath + "[]"); // Merge the properties of the sub object into the current context JObject currentFormElement = context.GetOrCreateCurrentFormElement(); currentFormElement["key"] = context.FullPropertyPath; currentFormElement["items"] = properties; if (!string.IsNullOrEmpty(arrayAttribute.AddButtonTitle)) { string addText = GetTextForKey(arrayAttribute.AddButtonTitle, context); currentFormElement["add"] = new JValue(addText); } } else { throw new InvalidOperationException("An " + nameof(FormArrayAttribute) + " must always be on a property with a type derived from IEnumerable<>"); } } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public void Process(FormBuilderContext context) { if(context.Property.GetCustomAttribute<FormTitleAttribute>() != null) { context.GetOrCreateCurrentFormElement()["key"] = context.FullPropertyPath; } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { // Get all form hierarchy attributes List<FormSectionAttribute> formHierarchies = context.Property.GetCustomAttributes<FormSectionAttribute>().ToList(); // If the current property has no form hierarchy elements this module has nothing to to if (!formHierarchies.Any()) { return; } JObject hierachyObject = null; foreach (FormSectionAttribute formHierarchy in formHierarchies) { // Is the hierarchy already in the form? hierachyObject = FindFormHierarchyObject(context.CompleteForm, formHierarchy.HierarchyPath, true); UpdateFormHierarchyObject(hierachyObject, formHierarchy, context); } // ReSharper disable once PossibleNullReferenceException because we make sure to have at least one object in the hierarcy JArray hierarcyItems = (JArray)hierachyObject["items"]; if (context.CurrentFormElement != null) { // Move the current element into the form hierarcy hierarcyItems.Add(context.CurrentFormElement); context.CurrentFormElementParent.Remove(context.CurrentFormElement); } // Set the new parent element to the current hierarchy context.CurrentFormElementParent = hierarcyItems; }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { if (context.Property.GetCustomAttribute <FormDisplayAttribute>() != null) { FormDisplayAttribute formDisplayAttribute = context.Property.GetCustomAttribute <FormDisplayAttribute>(); // Build a new hierarchy object for the element JObject hierachyObject = new JObject(); JArray hierarcyItems = new JArray(); hierachyObject["type"] = new JValue("section"); hierachyObject["items"] = hierarcyItems; if (context.CurrentFormElement != null) { // Move the current element into the form hierarcy hierarcyItems.Add(context.CurrentFormElement); context.CurrentFormElementParent.Remove(context.CurrentFormElement); context.CurrentFormElementParent.Add(hierachyObject); } // Set the new parent element to the current hierarchy context.CurrentFormElementParent = hierarcyItems; string cssClasses = ConvertDisplayWidthToCssClass(formDisplayAttribute.DisplayWidth); if (!string.IsNullOrEmpty(cssClasses)) { hierachyObject["htmlClass"] = new JValue(cssClasses); } } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public void Process(FormBuilderContext context) { if (context.Property.GetCustomAttribute <FormTitleAttribute>() != null) { context.GetOrCreateCurrentFormElement()["key"] = context.FullPropertyPath; } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { FormArrayAttribute arrayAttribute = context.Property.GetCustomAttribute<FormArrayAttribute>(); // Test to the form subobject attribute if (arrayAttribute != null) { if (context.Property.PropertyType.GetInterfaces() .Where(i => i.GetTypeInfo().IsGenericType) .Select(i => i.GetGenericTypeDefinition()).Any(i => i == typeof (IEnumerable<>))) { // Get the subtype from a generic type argument Type subType = context.Property.PropertyType.GetGenericArguments()[0]; // Create the subform JContainer properties = context.FormBuilder.BuildForm(subType, context.OriginDtoType, context.TargetCulture, context.FullPropertyPath + "[]"); // Merge the properties of the sub object into the current context JObject currentFormElement = context.GetOrCreateCurrentFormElement(); currentFormElement["key"] = context.FullPropertyPath; currentFormElement["items"] = properties; if (!string.IsNullOrEmpty(arrayAttribute.AddButtonTitle)) { string addText = GetTextForKey(arrayAttribute.AddButtonTitle, context); currentFormElement["add"] = new JValue(addText); } } else { throw new InvalidOperationException("An FormArrayAttribute must always be on a property with a type derived from IEnumerable<>"); } } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { // Get all form hierarchy attributes List <FormSectionAttribute> formHierarchies = context.Property.GetCustomAttributes <FormSectionAttribute>().ToList(); // If the current property has no form hierarchy elements this module has nothing to to if (!formHierarchies.Any()) { return; } JObject hierachyObject = null; foreach (FormSectionAttribute formHierarchy in formHierarchies) { // Is the hierarchy already in the form? hierachyObject = FindFormHierarchyObject(context.CompleteForm, formHierarchy.HierarchyPath, true); UpdateFormHierarchyObject(hierachyObject, formHierarchy, context); } // ReSharper disable once PossibleNullReferenceException because we make sure to have at least one object in the hierarcy JArray hierarcyItems = (JArray)hierachyObject["items"]; if (context.CurrentFormElement != null) { // Move the current element into the form hierarcy hierarcyItems.Add(context.CurrentFormElement); context.CurrentFormElementParent.Remove(context.CurrentFormElement); } // Set the new parent element to the current hierarchy context.CurrentFormElementParent = hierarcyItems; }
protected virtual void RenderFormGroupContents(HtmlTextWriter writer, FormGroupDisplay display) { writer.Write(Config.RenderLabel()); bool shouldRenderControlSizeDiv = !string.IsNullOrWhiteSpace(Config.ControlSize); if (shouldRenderControlSizeDiv) { writer.AddAttribute("class", Config.ControlSize); writer.RenderBeginTag("div"); } writer.Write(Config.RenderControl(display)); FormBuilderContext builderContext = Html.GetFormBuilderContext(); if (builderContext.RenderValidationMessages) { writer.Write(Config.RenderValidationMessage()); } if (shouldRenderControlSizeDiv) { writer.RenderEndTag(); // div } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { // Get the attribute FormConditionAttribute conditionAttribute = context.Property.GetCustomAttribute<FormConditionAttribute>(); // If the current property has a condition add it if (conditionAttribute != null) { string condition = FormModuleHelper.ConvertConditionToAbsolutePath(context.DtoType.Name, context.FullPropertyPath, conditionAttribute.Condition); context.GetOrCreateCurrentFormElement()["condition"] = new JValue(condition); } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { // Get the attribute FormConditionAttribute conditionAttribute = context.Property.GetCustomAttribute <FormConditionAttribute>(); // If the current property has a condition add it if (conditionAttribute != null) { string condition = FormModuleHelper.ConvertConditionToAbsolutePath(context.DtoType.Name, context.FullPropertyPath, conditionAttribute.Condition); context.GetOrCreateCurrentFormElement()["condition"] = new JValue(condition); } }
/// <summary> /// Gets the text for key. /// </summary> /// <param name="key">The key.</param> /// <param name="formBuilderContext">The form builder context.</param> /// <returns> /// The string for the requested key. /// </returns> protected string GetTextForKey(string key, FormBuilderContext formBuilderContext) { if (_languageProvider != null) { // If a language provider is availabe call it to get the text return _languageProvider.GetTextForKey(key, formBuilderContext.GetLanguageContext()); } else { // If no language provider is available return the key as text return key; } }
/// <summary> /// Gets the text for key. /// </summary> /// <param name="key">The key.</param> /// <param name="formBuilderContext">The form builder context.</param> /// <returns> /// The string for the requested key. /// </returns> protected string GetTextForKey(string key, FormBuilderContext formBuilderContext) { if (_languageProvider != null) { // If a language provider is availabe call it to get the text return(_languageProvider.GetTextForKey(key, formBuilderContext.GetLanguageContext())); } else { // If no language provider is available return the key as text return(key); } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { // Test to the form subobject attribute if (context.Property.GetCustomAttribute <FormSubObjectAttribute>() != null) { // Get the type from the property directly Type subType = context.Property.PropertyType; // Create the subform JContainer properties = context.FormBuilder.BuildForm(subType, context.OriginDtoType, context.TargetCulture, context.FullPropertyPath); // Merge the properties of the sub object into the current context context.CurrentFormElementParent.Merge(properties); } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { // Test to the form subobject attribute if (context.Property.GetCustomAttribute<FormSubObjectAttribute>() != null) { // Get the type from the property directly Type subType = context.Property.PropertyType; // Create the subform JContainer properties = context.FormBuilder.BuildForm(subType, context.OriginDtoType, context.TargetCulture, context.FullPropertyPath); // Merge the properties of the sub object into the current context context.CurrentFormElementParent.Merge(properties); } }
/// <summary> /// Updates a form hierarchy object. /// </summary> /// <param name="hierarchyObject">The hierarchy object.</param> /// <param name="formSection">The form section.</param> public void UpdateFormHierarchyObject(JObject hierarchyObject, FormSectionAttribute formSection, FormBuilderContext context) { hierarchyObject["type"] = ConvertSectionType(formSection.SectionType); if (!string.IsNullOrEmpty(formSection.Title)) { hierarchyObject["title"] = GetTextForKey(formSection.Title, context); } if(!string.IsNullOrEmpty(formSection.Condition)) { string condition = FormModuleHelper.ConvertConditionToAbsolutePath(context.DtoType.Name, context.FullPropertyPath, formSection.Condition); hierarchyObject["condition"] = new JValue(condition); } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { Type propertyType = context.Property.PropertyType; // Support enums and nullable enums if (propertyType.GetTypeInfo().IsEnum || (propertyType.GetTypeInfo().IsGenericType&& propertyType.GetGenericTypeDefinition() == typeof(Nullable <>) && Nullable.GetUnderlyingType(propertyType).GetTypeInfo().IsEnum)) { FieldInfo[] enumMembers; // Read the enum members if (propertyType.GetTypeInfo().IsEnum) { enumMembers = propertyType.GetFields(BindingFlags.Public | BindingFlags.Static); } else { enumMembers = Nullable.GetUnderlyingType(propertyType).GetFields(BindingFlags.Public | BindingFlags.Static); } JArray titleMap = new JArray(); // Create the title map objects foreach (FieldInfo enumMember in enumMembers) { JObject title = new JObject(); title["value"] = new JValue(Convert.ChangeType(enumMember.GetValue(null), typeof(int))); if (enumMember.GetCustomAttribute <FormTitleAttribute>() != null) { string titleKey = enumMember.GetCustomAttribute <FormTitleAttribute>().Title; title["name"] = GetTextForKey(titleKey, context); titleMap.Add(title); } } // Add the title map to the element context.GetOrCreateCurrentFormElement()["titleMap"] = titleMap; context.GetOrCreateCurrentFormElement()["type"] = new JValue("radios"); } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { FormSimpleChoiceAttribute simpleChoiceAttribute = context.Property.GetCustomAttribute<FormSimpleChoiceAttribute>(); if (simpleChoiceAttribute != null) { StringBuilder choices = new StringBuilder(); JObject titleMap = new JObject(); foreach (string value in simpleChoiceAttribute.Values) { titleMap[value] = GetTextForKey(value, context); } context.GetOrCreateCurrentFormElement()["type"] = new JValue("select"); context.GetOrCreateCurrentFormElement()["titleMap"] = JObject.Parse(choices.ToString()); } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { FormSimpleChoiceAttribute simpleChoiceAttribute = context.Property.GetCustomAttribute <FormSimpleChoiceAttribute>(); if (simpleChoiceAttribute != null) { StringBuilder choices = new StringBuilder(); JObject titleMap = new JObject(); foreach (string value in simpleChoiceAttribute.Values) { titleMap[value] = GetTextForKey(value, context); } context.GetOrCreateCurrentFormElement()["type"] = new JValue("select"); context.GetOrCreateCurrentFormElement()["titleMap"] = JObject.Parse(choices.ToString()); } }
public ApplicationUnit(IGenericRepository <User> userRepository, IGenericRepository <Role> roleRepository, IGenericRepository <Group> groupRepository, IGenericRepository <Event> eventRepository, IGenericRepository <Sponsor> sponsorRepository, IGenericRepository <JoinGroupRequest> joinGroupRequestRepository, IGenericRepository <GroupPhoto> groupPhotoRepository, IGenericRepository <PersonalMessage> personalMessageRepository, FormBuilderContext formBuilderContext) { _userRepository = userRepository; _roleRepository = roleRepository; _groupRepository = groupRepository; _eventRepository = eventRepository; _sponsorRepository = sponsorRepository; _joinGroupRequestRepository = joinGroupRequestRepository; _groupPhotoRepository = groupPhotoRepository; _personalMessageRepository = personalMessageRepository; _context = formBuilderContext; }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { // Get all help attributes List <FormTextAttribute> texts = context.Property.GetCustomAttributes <FormTextAttribute>().ToList(); // If the current property has no helps this module has nothing to to if (!texts.Any()) { return; } foreach (FormTextAttribute textAttribute in texts) { string text = GetTextForKey(textAttribute.Text, context); // Create the help JSON object JObject textObject = new JObject(); textObject["type"] = new JValue("help"); textObject["helpvalue"] = new JValue("<p>" + text + "</p>"); context.CurrentFormElementParent.Add(textObject); } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { if ((context.Property.PropertyType == typeof(bool) || context.Property.PropertyType == typeof(bool?)) && context.Property.GetCustomAttribute <FormBoolAsRadioAttribute>() != null) { FormBoolAsRadioAttribute boolAsRadioAttribute = context.Property.GetCustomAttribute <FormBoolAsRadioAttribute>(); JArray titleMap = new JArray(); // Add yes title JObject yesMap = new JObject(); yesMap["value"] = new JValue(true); yesMap["name"] = new JValue(GetTextForKey(boolAsRadioAttribute.YesTitle, context)); titleMap.Add(yesMap); JObject noMap = new JObject(); noMap["value"] = new JValue(false); noMap["name"] = new JValue(GetTextForKey(boolAsRadioAttribute.NoTitle, context)); titleMap.Add(noMap); context.GetOrCreateCurrentFormElement()["type"] = new JValue("radios"); context.GetOrCreateCurrentFormElement()["titleMap"] = titleMap; } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { // Get all help attributes List<FormTextAttribute> texts = context.Property.GetCustomAttributes<FormTextAttribute>().ToList(); // If the current property has no helps this module has nothing to to if (!texts.Any()) { return; } foreach (FormTextAttribute textAttribute in texts) { string text = GetTextForKey(textAttribute.Text, context); // Create the help JSON object JObject textObject = new JObject(); textObject["type"] = new JValue("help"); textObject["helpvalue"] = new JValue("<p>" + text + "</p>"); context.CurrentFormElementParent.Add(textObject); } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public override void Process(FormBuilderContext context) { if ((context.Property.PropertyType == typeof(bool) || context.Property.PropertyType == typeof(bool?)) && context.Property.GetCustomAttribute<FormBoolAsRadioAttribute>() != null) { FormBoolAsRadioAttribute boolAsRadioAttribute = context.Property.GetCustomAttribute<FormBoolAsRadioAttribute>(); JArray titleMap = new JArray(); // Add yes title JObject yesMap = new JObject(); yesMap["value"] = new JValue(true); yesMap["name"] = new JValue(GetTextForKey(boolAsRadioAttribute.YesTitle, context)); titleMap.Add(yesMap); JObject noMap = new JObject(); noMap["value"] = new JValue(false); noMap["name"] = new JValue(GetTextForKey(boolAsRadioAttribute.NoTitle, context)); titleMap.Add(noMap); context.GetOrCreateCurrentFormElement()["type"] = new JValue("radios"); context.GetOrCreateCurrentFormElement()["titleMap"] = titleMap; } }
/// <summary> /// Updates a form hierarchy object. /// </summary> /// <param name="hierarchyObject">The hierarchy object.</param> /// <param name="formSection">The form section.</param> public void UpdateFormHierarchyObject(JObject hierarchyObject, FormSectionAttribute formSection, FormBuilderContext context) { hierarchyObject["type"] = ConvertSectionType(formSection.SectionType); if (!string.IsNullOrEmpty(formSection.Title)) { hierarchyObject["title"] = GetTextForKey(formSection.Title, context); } if (!string.IsNullOrEmpty(formSection.Condition)) { string condition = FormModuleHelper.ConvertConditionToAbsolutePath(context.DtoType.Name, context.FullPropertyPath, formSection.Condition); hierarchyObject["condition"] = new JValue(condition); } }
/// <summary> /// Processes the specified context. /// </summary> /// <param name="context">The context to process.</param> public abstract void Process(FormBuilderContext context);