Example #1
0
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);


        ClassMetadata cm = new ClassMetadata();

        cm.Fields = MultiStepWizards.PlaceAnOrder.EditOrderLineItemProductDemographics;
        // setup the metadata
        CustomFieldSet1.Metadata = cm;

        DataEntryViewMetadata vm = new DataEntryViewMetadata();

        vm.Sections = new List <MemberSuite.SDK.Manifests.Command.ViewMetadata.ControlSection>();
        ViewMetadata.ControlSection cs = new ViewMetadata.ControlSection();

        foreach (var f in cm.Fields)
        {
            ControlMetadata cm2 = ControlMetadata.FromFieldMetadata(f);
            cm2.IsRequired = null;   // important, we don't want this overrideen
            cs.LeftControls.Add(cm2);
        }
        vm.Sections.Add(cs);
        CustomFieldSet1.PageLayout = vm;

        CustomFieldSet1.Render();
    }
    /// <summary>
    /// Applies a control metadata against the view metadata to find a value
    /// </summary>
    /// <param name="cMeta">The c meta.</param>
    /// <returns></returns>
    public object Resolve(ControlMetadata cMeta)
    {
        if (cMeta == null)
        {
            throw new ArgumentNullException("cMeta");
        }
        if (MemberSuiteObject == null || cMeta.DataSourceExpression == null)
        {
            return(null);
        }

        return(MemberSuiteObject.SafeGetValue(cMeta.DataSourceExpression));
    }
    /// <summary>
    /// Gets the field metadata associated with the specified control metadata
    /// </summary>
    /// <param name="meta">The meta.</param>
    /// <returns></returns>
    public FieldMetadata GetBoundFieldFor(ControlMetadata meta)
    {
        if (meta == null)
        {
            throw new ArgumentNullException("meta");
        }
        if (Metadata == null)
        {
            return(null);
        }

        // MS-6019 (Modified 1/9/2015) Sometimes the DataSourceExpression on the ControlMetadata does not match the name of any field.
        // It is worth checking whether the Name on the ControlMetadata matches any of the fields as well.
        return(Metadata.Fields.Find(x => x.Name == meta.DataSourceExpression) ?? Metadata.Fields.Find(x => x.Name == meta.Name));
    }
Example #4
0
    protected DataEntryViewMetadata createViewMetadataFromEntryQuestions()
    {
        var result      = new DataEntryViewMetadata();
        var baseSection = new ViewMetadata.ControlSection();

        baseSection.SubSections = new List <ViewMetadata.ControlSection>();

        var currentSection = new ViewMetadata.ControlSection();

        currentSection.LeftControls = new List <ControlMetadata>();
        baseSection.SubSections.Add(currentSection);
        foreach (var question in targetCompetitionQuestions)
        {
            var field = new ControlMetadata {
                DataSourceExpression = question.Name
            };

            // This isn't necessary - the field is aqequately described already
            ////ControlMetadata field = ControlMetadata.FromFieldMetadata(question.FieldDefinition);

            if (field.DisplayType == FieldDisplayType.Separator)
            {
                if (currentSection.LeftControls != null && currentSection.LeftControls.Count > 0)
                // we have to create a new section
                {
                    currentSection = new ViewMetadata.ControlSection();
                    currentSection.LeftControls = new List <ControlMetadata>();
                    baseSection.SubSections.Add(currentSection);
                }

                currentSection.Name  = Guid.NewGuid().ToString();
                currentSection.Label = field.PortalPrompt ?? field.Label; // set the section label
                continue;
            }

            currentSection.LeftControls.Add(field);
        }

        result.Sections = new List <ViewMetadata.ControlSection> {
            baseSection
        };
        return(result);
    }
    protected DataEntryViewMetadata createViewMetadataFromEntryQuestions()
    {
        var result      = new DataEntryViewMetadata();
        var baseSection = new ViewMetadata.ControlSection();

        baseSection.SubSections = new List <ViewMetadata.ControlSection>();

        var currentSection = new ViewMetadata.ControlSection();

        currentSection.LeftControls = new List <ControlMetadata>();
        baseSection.SubSections.Add(currentSection);
        foreach (var question in targetCompetitionQuestions.OrderBy(o => o.DisplayOrder))
        {
            var field = ControlMetadata.FromFieldMetadata(question.FieldDefinition);

            if (field.DisplayType == FieldDisplayType.Separator)
            {
                if (currentSection.LeftControls != null && currentSection.LeftControls.Count > 0)
                // we have to create a new section
                {
                    currentSection = new ViewMetadata.ControlSection();
                    currentSection.LeftControls = new List <ControlMetadata>();
                    baseSection.SubSections.Add(currentSection);
                }

                currentSection.Name  = Guid.NewGuid().ToString();
                currentSection.Label = field.PortalPrompt ?? field.Label; // set the section label
                continue;
            }

            if (currentSection.LeftControls != null)
            {
                currentSection.LeftControls.Add(field);
            }
        }

        result.Sections = new List <ViewMetadata.ControlSection> {
            baseSection
        };
        return(result);
    }
 /// <summary>
 /// Resolves the acceptable values.
 /// </summary>
 /// <param name="ControlMetadata">The control metadata.</param>
 /// <returns></returns>
 public object ResolveAcceptableValues(ControlMetadata ControlMetadata)
 {
     return(null);
 }
 /// <summary>
 /// Sets the value of the control in the model
 /// </summary>
 /// <param name="ControlMetadata">The control metadata.</param>
 /// <param name="valueToSet">The value to set.</param>
 public void SetModelValue(ControlMetadata ControlMetadata, object valueToSet, bool onlyIfMemberSuiteObject)
 {
     MemberSuiteObject[ControlMetadata.DataSourceExpression] = valueToSet;
 }
 /// <summary>
 /// Sets the value of the control in the model
 /// </summary>
 /// <param name="ControlMetadata">The control metadata.</param>
 /// <param name="valueToSet">The value to set.</param>
 public void SetModelValue(ControlMetadata ControlMetadata, object valueToSet)
 {
     SetModelValue(ControlMetadata, valueToSet, false);
 }
    private void renderControl(HtmlTableRow tableRow, ControlMetadata control)
    {
        ControlManager manager;

        if (control == null)
        {
            return;
        }

        var nameOfField = control.DataSourceExpression;

        FieldMetadata fieldMeta = null;

        if (Metadata != null && Metadata.Fields != null)
        {
            fieldMeta = Metadata.Fields.Find(x => x.Name == nameOfField);
        }

        // MS-4803. Make sure that DataSourceExpression is not empty.
        if (fieldMeta == null && !string.IsNullOrWhiteSpace(nameOfField)) // check to see if we're splitting
        {
            var splits = nameOfField.Split('|');
            nameOfField = splits[splits.Length - 1];

            if (Metadata != null && Metadata.Fields != null)
            {
                fieldMeta = Metadata.Fields.Find(x => x.Name == nameOfField);
            }
        }
        if (fieldMeta == null && control.DisplayType == null)
        {
            return;
        }

        if (fieldMeta != null && fieldMeta.PortalAccessibility == PortalAccessibility.None)
        {
            // Cannot display at all
            return;
        }

        if (fieldMeta == null)
        {
            manager = ControlManagerResolver.Resolve(control.DisplayType.Value);
        }
        else
        {
            manager = EditMode && fieldMeta.PortalAccessibility == PortalAccessibility.Full ? ControlManagerResolver.Resolve(fieldMeta.DisplayType) : new LabelControlManager(SuppressNullLabelReplacement);
        }

        manager.IsInPortal = true;
        manager.Initialize(this, control);
        registerControlManager(manager);

        tableRow.Attributes["style"] = "vertical-align: top";
        // add the form group
        var tdLabel   = new HtmlTableCell();
        var tdControl = new HtmlTableCell("td");

        if (control.UseEntireRow)
        {
            tdControl.Attributes["class"] = "columnHeader customFieldCell";
        }
        else
        {
            tdLabel.Attributes["class"] = "columnHeader customFieldCell";
        }

        //Commented out per MS-1995 When using address fields as custom fields, overlap occurs
        //if (manager.RowSpan > 1)
        //    tdLabel.Attributes["RowSpan"] = tdControl.Attributes["RowSpan"] = manager.RowSpan.ToString();

        // add the label (no labels for Seperators)
        if (!manager.CustomLabel)// MS-2675&& !control.UseEntireRow)
        {
            var label        = new HtmlGenericControl("label");
            var controlLabel = manager.GetLabel();

            if (fieldMeta != null && fieldMeta.PortalPrompt != null)
            {
                controlLabel = fieldMeta.PortalPrompt;
            }

            if (!SuppressValidation && manager.IsRequired() &&
                !(manager is CheckBoxControlManager) && !(manager is LabelControlManager))   // special exception - don't show required for checbkoxes/labels it makes no sense
            {
                controlLabel += " <span class=\"requiredField\">*</span>";
            }

            label.Controls.Add(new LiteralControl(controlLabel));

            // now, add the help text
            if (fieldMeta != null && fieldMeta.HelpText != null)
            {
                label.Controls.Add(new LiteralControl(string.Format("<BR/><span class='helpText'>{0}</span><BR/>&nbsp;",
                                                                    fieldMeta.HelpText.Replace("\n", "<BR/>"))));
            }

            tdLabel.Controls.Add(label);

            // only  add the label cell if we need to
            tableRow.Controls.Add(tdLabel);
            tdControl.Attributes["class"] = "controlCell";
        }
        else
        {
            if (control.UseEntireRow)
            {
                tdControl.Attributes["colspan"] = "4"; // of course, the control spans two controls
                tdControl.Attributes["Class"]   = "singleControlCell";
            }
            else
            {
                tdControl.Attributes["colspan"] = "2"; // of course, the control spans two controls
                tdControl.Attributes["Class"]   = "singleControlCell";
            }
        }

        // now, add the field


        tableRow.Controls.Add(tdControl);

        var controls = manager.InstantiateWithPostprocessing(
            ctls =>
        {
            if (manager.CustomLabel)
            {
                var labelBuilder = new StringBuilder();

                var label = manager.GetLabel();
                if (fieldMeta != null && !string.IsNullOrEmpty(fieldMeta.PortalPrompt))
                {
                    label = fieldMeta.PortalPrompt;
                }

                labelBuilder.Append(label);


                // now, add the help text
                if (fieldMeta != null && !string.IsNullOrEmpty(fieldMeta.HelpText))
                {
                    labelBuilder.Append(string.Format("<BR/><span class='helpText'>{0}</span><BR/>&nbsp;",
                                                      fieldMeta.HelpText.Replace("\n", "<BR/>")));
                }

                if (manager.IsRequired())
                {
                    labelBuilder.Append("<span class=\"requiredField\">*</span>");
                }
                labelBuilder.Append("<p/>");
                ctls.Insert(0, new LiteralControl(labelBuilder.ToString()));
            }
        }
            );

        if (manager.CustomLabel && controls.Count > 0 && controls[0] is LiteralControl)
        {
            controls.Insert(0, new LiteralControl("<span class=\"columnHeader customFieldCell\">"));
            controls.Add(new LiteralControl("</span>"));
        }

        if (controls != null)
        {
            foreach (var c in controls)
            {
                tdControl.Controls.Add(c);
            }
        }

        if (SuppressValidation)
        {
            return;
        }

        var validationContorls = manager.InstantiateValidationControls();

        if (validationContorls != null)
        {
            foreach (var c in validationContorls)
            {
                tdControl.Controls.Add(c);
            }
        }
    }
Example #10
0
        internal List<CompletionData> ReloadAllControls(RwHtmlCompletionContext context)
        {
            // get all possible control symbols
            var allClasses = ReloadAllClasses(context);
            var controlClasses = allClasses
                .Where(c => CompletionHelper.GetBaseTypes(c).Any(t => CheckType(t, typeof(RedwoodControl))))
                .ToList();

            var result = new List<CompletionData>();
            metadata = new ConcurrentDictionary<string, ControlMetadata>(StringComparer.CurrentCultureIgnoreCase);
            htmlGenericControlMetadata = null;

            foreach (var rule in context.Configuration.Markup.Controls)
            {
                string tagName;
                if (!string.IsNullOrEmpty(rule.Src))
                {
                    // markup control
                    tagName = rule.TagPrefix + ":" + rule.TagName;

                    // TODO: parse markup, find base type and extract metadata

                    result.Add(new CompletionData(tagName));
                }
                else
                {
                    // find all classes declared in the project
                    var controls = controlClasses.Where(c => c.ContainingAssembly.Name == rule.Assembly && c.ContainingNamespace.ToDisplayString() == rule.Namespace);
                    foreach (var control in controls)
                    {
                        tagName = rule.TagPrefix + ":" + control.Name;
                        var controlMetadata = GetControlMetadata(control, rule.TagPrefix, control.Name);
                        metadata[tagName] = controlMetadata;
                        result.Add(new CompletionData(tagName));

                        if (CheckType(control, typeof(HtmlGenericControl)))
                        {
                            htmlGenericControlMetadata = controlMetadata;
                        }
                    }
                }
            }

            return result;
        }
Example #11
0
        internal void GetElementContext(List<string> tagNameHierarchy, out ControlMetadata currentControl, out ControlPropertyMetadata currentProperty)
        {
            currentProperty = null;
            currentControl = null;

            for (int i = 0; i < tagNameHierarchy.Count; i++)
            {
                currentProperty = null;
                currentControl = null;

                var tagName = tagNameHierarchy[i];
                if (metadata.ContainsKey(tagName))
                {
                    // we have found a control
                    currentControl = metadata[tagName];

                    // the next element in the hierarchy might be a property
                    if (i + 1 < tagNameHierarchy.Count)
                    {
                        currentProperty = currentControl.Properties.FirstOrDefault(p => p.Name == tagNameHierarchy[i + 1] && p.IsElement);
                        if (currentProperty != null)
                        {
                            i++;
                        }
                    }
                }
                else
                {
                    // HTML or unknown element
                    currentControl = htmlGenericControlMetadata;
                }
            }
        }
Example #12
0
 public void SetModelValue(ControlMetadata ControlMetadata, object valueToSet, bool onlyIfMemberSuiteObject)
 {
 }
Example #13
0
 public void SetModelValue(ControlMetadata ControlMetadata, object valueToSet)
 {
 }
Example #14
0
 /// <summary>
 /// Gets the field metadata for the field that is bound
 /// to this control, if possible.
 /// </summary>
 /// <returns></returns>
 public FieldMetadata GetBoundFieldFor(ControlMetadata controlSpec)
 {
     return(null);
 }
Example #15
0
    // These methods are required for dynamic controls to render
    // properly

    public object Resolve(ControlMetadata cMeta)
    {
        return(null);
    }
Example #16
0
    protected DataEntryViewMetadata createViewMetadata(List <FieldMetadata> fields, bool isForSearch)
    {
        DataEntryViewMetadata result = new DataEntryViewMetadata();

        ViewMetadata.ControlSection baseSection = new ViewMetadata.ControlSection();
        baseSection.SubSections = new List <ViewMetadata.ControlSection>();

        var currentSection = new ViewMetadata.ControlSection();

        currentSection.LeftControls = new List <ControlMetadata>();
        baseSection.SubSections.Add(currentSection);
        foreach (var field in fields)
        {
            if (field.DisplayType == FieldDisplayType.Separator)
            {
                if (currentSection.LeftControls != null && currentSection.LeftControls.Count > 0)
                // we have to create a new section
                {
                    currentSection = new ViewMetadata.ControlSection();
                    currentSection.LeftControls = new List <ControlMetadata>();
                    baseSection.SubSections.Add(currentSection);
                }

                currentSection.Name = Guid.NewGuid().ToString();


                currentSection.Label = field.PortalPrompt ?? field.Label; // set the section label

                continue;
            }


            // // MS-1251 - REQUIREMENT to have to/from fields for numeric fields

            var control = ControlMetadata.FromFieldMetadata(field);

            if (isForSearch)
            {
                control.PortalPrompt = null;
            }
            switch (control.DataType)
            {
            case FieldDataType.Integer:
            case FieldDataType.Decimal:
            case FieldDataType.Date:
            case FieldDataType.DateTime:

                // we need to use a range
                var controlTo = control.Clone();
                control.Label += " - Range Start";
                control.Name  += "__from";
                control.DataSourceExpression += "__from";

                currentSection.LeftControls.Add(control);


                controlTo.Label += " - Range End";
                controlTo.Name  += "__to";
                controlTo.DataSourceExpression += "__to";


                currentSection.LeftControls.Add(controlTo);
                break;

            default:
                currentSection.LeftControls.Add(control);
                break;
            }
        }
        result.Sections = new List <ViewMetadata.ControlSection> {
            baseSection
        };
        return(result);
    }