Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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));
            }
        }