Exemplo n.º 1
0
        internal static VxFormDefinition CreateFromModel(object model, VxFormLayoutOptions options)
        {
            // TODO: EXPANDO SWITCH
            var allProperties = VxHelpers.GetModelProperties(model.GetType());

            var rootFormDefinition = model.GetType().GetCustomAttribute <VxFormDefinition>();

            if (rootFormDefinition == null)
            {
                rootFormDefinition = VxFormDefinition.Create();
            }

            var defaultGroup = VxFormGroup.Create();


            foreach (var prop in allProperties)
            {
                if (VxFormGroup.IsFormGroup(prop))
                {
                    var nestedModel = prop.GetValue(model);
                    var formGroup   = VxFormGroup.CreateFromModel(nestedModel, options);
                    formGroup.Label = VxFormGroup.GetFormGroup(prop).Label;

                    rootFormDefinition.Groups.Add(formGroup);
                }
                else
                {
                    VxFormGroup.Add(prop.Name, defaultGroup, model, options);
                }
            }
            rootFormDefinition.Groups.Add(defaultGroup);

            return(rootFormDefinition);
        }
Exemplo n.º 2
0
        private void SetupFramework()
        {
            if (FormGeneratorOptions.FieldCssClassProvider != null)
            {
                var provider = FormGeneratorOptions.FieldCssClassProvider as VxFormCssClassProviderBase;
                // Set the options in the custom FieldCssClassProvider
                provider.FormLayoutOptions = FormLayoutOptions;

                CascadedEditContext.SetFieldCssClassProvider(provider);
            }
            if (FormLayoutOptions == null)
            {
                FormLayoutOptions = (VxFormLayoutOptions)ScopedServices.GetService(typeof(Layout.VxFormLayoutOptions));
            }
        }
Exemplo n.º 3
0
        internal static VxFormRow Create(VxFormElementLayoutAttribute layoutAttr,
                                         VxFormRowLayoutAttribute vxFormRowLayoutAttribute,
                                         VxFormLayoutOptions options)
        {
            // If no rowid is specified use the name instead
            var output = layoutAttr.RowId == 0 ? new VxFormRow(layoutAttr.FieldIdentifier) : new VxFormRow(layoutAttr.RowId);

            output.RowLayoutAttribute = vxFormRowLayoutAttribute;

            if (options.LabelOrientation == LabelOrientation.LEFT && output.RowLayoutAttribute?.Label != null)
            {
                output.Label = vxFormRowLayoutAttribute.Label;
            }

            return(output);
        }
Exemplo n.º 4
0
        internal static VxFormGroup CreateFromModel(object modelInstance, VxFormLayoutOptions options)
        {
            var typeToCheck = modelInstance.GetType();

            // check for generics
            if (typeToCheck.IsGenericType)
            {
                typeToCheck = typeToCheck.GetGenericTypeDefinition();
            }

            var allProperties = VxHelpers.GetModelProperties(typeToCheck);

            var rootGroup = VxFormGroup.Create();

            foreach (var prop in allProperties)
            {
                VxFormGroup.Add(prop.Name, rootGroup, modelInstance, options);
            }

            return(rootGroup);
        }
Exemplo n.º 5
0
        internal static void Add(string fieldIdentifier, VxFormGroup group, object modelInstance, VxFormLayoutOptions options)
        {
            // TODO: EXPANDO switch
            var prop                   = modelInstance.GetType().GetProperty(fieldIdentifier);
            var layoutAttr             = prop.GetCustomAttribute <VxFormElementLayoutAttribute>();
            var allRowLayoutAttributes = VxHelpers.GetAllAttributes <VxFormRowLayoutAttribute>(prop.DeclaringType);

            // If no attribute is found use the name of the property
            if (layoutAttr == null)
            {
                layoutAttr = new VxFormElementLayoutAttribute()
                {
                    Label = GetLabel(fieldIdentifier, modelInstance)
                }
            }
            ;

            PatchLayoutWithBuiltInAttributes(layoutAttr, prop);


            // Check if row already exists
            var foundRow = group.Rows.Find(value => value.Id == layoutAttr.RowId.ToString());

            if (foundRow == null)
            {
                foundRow = VxFormRow.Create(layoutAttr, allRowLayoutAttributes.Find(x => x.Id == layoutAttr.RowId), options);
                group.Rows.Add(foundRow);;
            }

            var formColumn = VxFormElementDefinition.Create(fieldIdentifier, layoutAttr, modelInstance, options);

            VxFormRow.AddColumn(foundRow, formColumn, options);

            // WHen there is a VxFormRowLayout found use the name if specified, this also sets the row to combined labels
            if (options.LabelOrientation == LabelOrientation.LEFT && foundRow.RowLayoutAttribute?.Label == null)
            {
                foundRow.Label = string.Join(", ", foundRow.Columns.ConvertAll(x => x.RenderOptions.Label));
            }
        }
 internal static VxFormElementDefinition Create(string fieldname, VxFormElementLayoutAttribute layoutAttr, object modelInstance, VxFormLayoutOptions options)
 {
     return(new VxFormElementDefinition(fieldname, layoutAttr, modelInstance));
 }
Exemplo n.º 7
0
        internal static void AddColumn(VxFormRow foundRow, VxFormElementDefinition formColumn, VxFormLayoutOptions options)
        {
            foundRow.Columns.Add(formColumn);

            var layoutAttr = formColumn.RenderOptions;

            // Turn off all Labels for the elements
            switch (options.LabelOrientation)
            {
            case LabelOrientation.LEFT: layoutAttr.ShowLabel = false; break;

            case LabelOrientation.NONE: layoutAttr.ShowLabel = false; break;

            case LabelOrientation.TOP: layoutAttr.ShowLabel = true; break;
            }


            if (options.ShowPlaceholder == PlaceholderPolicy.EXPLICIT_LABEL_FALLBACK)
            {
                layoutAttr.Placeholder = layoutAttr.Placeholder != null ? layoutAttr.Placeholder : layoutAttr.Label;
            }
            else if (
                (options.ShowPlaceholder == PlaceholderPolicy.IMPLICIT || options.ShowPlaceholder == PlaceholderPolicy.IMPLICIT_LABEL_FALLBACK) &&
                foundRow.Columns.Count > 1)
            {
                foundRow.Columns.ForEach(x =>
                {
                    x.RenderOptions.Placeholder = x.RenderOptions.Label;
                });
            }
            else if (options.ShowPlaceholder == PlaceholderPolicy.IMPLICIT_LABEL_FALLBACK && foundRow.Columns.Count == 1)
            {
                layoutAttr.Placeholder = layoutAttr.Label;
            }
            else if (options.ShowPlaceholder == PlaceholderPolicy.NONE)
            {
                layoutAttr.Placeholder = null;
            }
        }