示例#1
0
 public static XcstDelegate <object>?MemberTemplate(HtmlHelper html, ModelMetadata propertyMetadata) =>
 EditorInstructions.MemberTemplate(html, propertyMetadata);
示例#2
0
        internal static void ObjectTemplate(HtmlHelper html, IXcstPackage package, ISequenceWriter <object> seqOutput, TemplateHelpers.TemplateHelperDelegate templateHelper)
        {
            ViewDataDictionary viewData      = html.ViewData;
            ModelMetadata      modelMetadata = viewData.ModelMetadata;

            if (viewData.TemplateInfo.TemplateDepth > 1)
            {
                MetadataInstructions.DisplayTextHelper(html, seqOutput, modelMetadata);
                return;
            }

            var filteredProperties = EditorInstructions.EditorProperties(html);
            var groupedProperties  = filteredProperties.GroupBy(p => p.GroupName());

            bool createFieldset = groupedProperties.Any(g => g.Key != null);

            foreach (var group in groupedProperties)
            {
                XcstWriter?fieldsetWriter = null;

                if (createFieldset)
                {
                    fieldsetWriter = DocumentWriter.CastElement(package, seqOutput);

                    fieldsetWriter.WriteStartElement("fieldset");
                    fieldsetWriter.WriteStartElement("legend");
                    fieldsetWriter.WriteString(group.Key);
                    fieldsetWriter.WriteEndElement();
                }

                foreach (ModelMetadata propertyMeta in group)
                {
                    XcstWriter?fieldWriter = null;

                    if (!propertyMeta.HideSurroundingHtml)
                    {
                        XcstDelegate <object>?memberTemplate =
                            EditorInstructions.MemberTemplate(html, propertyMeta);

                        if (memberTemplate != null)
                        {
                            memberTemplate(null !/* argument is not used */, fieldsetWriter ?? seqOutput);
                            continue;
                        }

                        XcstWriter labelWriter = fieldsetWriter
                                                 ?? DocumentWriter.CastElement(package, seqOutput);

                        labelWriter.WriteStartElement("div");
                        labelWriter.WriteAttributeString("class", "editor-label");
                        LabelInstructions.LabelHelper(html, labelWriter, propertyMeta, propertyMeta.PropertyName);
                        labelWriter.WriteEndElement();

                        fieldWriter = fieldsetWriter
                                      ?? DocumentWriter.CastElement(package, seqOutput);

                        fieldWriter.WriteStartElement("div");
                        fieldWriter.WriteAttributeString("class", "editor-field");
                    }

                    templateHelper(
                        html,
                        package,
                        fieldWriter ?? fieldsetWriter ?? seqOutput,
                        propertyMeta,
                        htmlFieldName: propertyMeta.PropertyName,
                        templateName: null,
                        membersNames: null,
                        DataBoundControlMode.Edit,
                        additionalViewData: null
                        );

                    if (!propertyMeta.HideSurroundingHtml)
                    {
                        fieldWriter !.WriteString(" ");
                        ValidationInstructions.ValidationMessageHelper(html, fieldWriter, propertyMeta, propertyMeta.PropertyName, null, null, null);
                        fieldWriter.WriteEndElement(); // </div>
                    }
                }

                if (createFieldset)
                {
                    fieldsetWriter !.WriteEndElement(); // </fieldset>
                }
            }
        }