Exemple #1
0
        public TControl Begin()
        {
            if (_begun)
            {
                throw new Exception("Already called Begin");
            }

            string name = Context.Name;
            string id   = Context.Id;

            var div = new HtmlTagBuilder("div");

            if (!string.IsNullOrWhiteSpace(name))
            {
                div.Attributes.Add("data-container-for", name);
            }
            if (!string.IsNullOrWhiteSpace(id))
            {
                div.Attributes.Add("data-group", id);
            }
            if (Context.IsHidden)
            {
                div.Attributes.Add("style", "display: none;");
            }
            if (Context.IsInvisible)
            {
                div.AddCssClass("invisible");
            }

            div.AddCssClass("form-group");
            div.AddCssClass("has-feedback");

            var context = HtmlHelper.ViewContext;

            context.Writer.Write(div.ToString(TagRenderMode.StartTag));

            string header = Context.Header;

            if (header != null)
            {
                if (string.IsNullOrWhiteSpace(name))
                {
                    context.Writer.Write("<label>");
                }
                else
                {
                    context.Writer.Write("<label for='" + name + "'>");
                }
                context.Writer.Write(header + "</label>");
                if (!string.IsNullOrWhiteSpace(name))
                {
                    context.Writer.Write("<span class='field-validation-valid' data-valmsg-for='" + name + "' data-valmsg-replace='true'></span>");
                }
            }
            string description = Context.Description;

            if (!string.IsNullOrWhiteSpace(description))
            {
                context.Writer.Write("<div class='help-block'>" + description + "</div>");
            }

            var tag = new HtmlTagBuilder(TagType);

            tag.MergeAttributes(Context.HtmlAttributes);
            tag.MergeIfAttribute("readonly", "readonly", Context.IsReadOnly);
            tag.MergeIfAttribute("disabled", "disabled", Context.IsDisabled);
            context.Writer.Write(tag.ToString(TagRenderMode.StartTag));
            _begun = true;
            return((TControl)this);
        }
Exemple #2
0
        public virtual bool CreateCell(StringBuilder cells, object cellData, string columnClassPrefix, bool isHeader, bool isTotal, GridColumnContext <TRow> context, object htmlAttributes)
        {
            var cell = new HtmlTagBuilder("div");

            int width = AddColClass(cell, columnClassPrefix, "xs", Position.Width(0), -1);

            width = AddColClass(cell, columnClassPrefix, "sm", Position.Width(1), width);
            width = AddColClass(cell, columnClassPrefix, "md", Position.Width(2), width);
            width = AddColClass(cell, columnClassPrefix, "lg", Position.Width(3), width);

            int offset = AddOffsetClass(cell, columnClassPrefix, "xs", Position.Offset(0), 0);

            offset = AddOffsetClass(cell, columnClassPrefix, "sm", Position.Offset(1), offset);
            offset = AddOffsetClass(cell, columnClassPrefix, "md", Position.Offset(2), offset);
            offset = AddOffsetClass(cell, columnClassPrefix, "lg", Position.Offset(3), offset);

            string style = Context.Style.ToString().ToLowerInvariant();

            if (Context.Style != GridColumnStyle.Text)
            {
                cell.AddCssClass(columnClassPrefix + "-" + style);
            }
            if (isHeader)
            {
                if (context.WrapHeader)
                {
                    cell.AddCssClass("wrap");
                }
                string valueId  = context.Index.ToString(CultureInfo.InvariantCulture);
                var    sortable = context.IsSortable;
                if (sortable != GridBooleanPlus.False)
                {
                    cell.MergeAttribute("data-sortable", valueId);
                    if (sortable != GridBooleanPlus.True)
                    {
                        cell.MergeAttribute("data-sortable-type", sortable.ToString().ToLowerInvariant());
                    }
                }
                var filterable = context.IsFilterable;
                if (filterable != GridBooleanPlus.False)
                {
                    cell.MergeAttribute("data-filterable", valueId);
                    if (filterable != GridBooleanPlus.True)
                    {
                        cell.MergeAttribute("data-filterable-type", filterable.ToString().ToLowerInvariant());
                    }
                }
                var groupable = context.IsGroupable;
                if (groupable != GridBooleanPlus.False)
                {
                    cell.MergeAttribute("data-groupable", valueId);
                    if (groupable != GridBooleanPlus.True)
                    {
                        cell.MergeAttribute("data-groupable-type", groupable.ToString().ToLowerInvariant());
                    }
                    var groupsExpanded = context.GroupsExpanded;
                    if (groupsExpanded != GridGroupsExpanded.First)
                    {
                        cell.MergeAttribute("data-groupable-expanded", groupsExpanded.ToString().ToLowerInvariant());
                    }
                }
            }
            else if (isTotal && context.Total > GridColumnTotal.Title) // Skip total titles
            {
                cell.MergeAttribute("data-total", context.Index.ToString(CultureInfo.InvariantCulture));
                cell.MergeAttribute("data-total-type", context.Total.ToString().ToLowerInvariant());
                switch (context.Subtotal)
                {
                case GridColumnSubtotal.Prefix:
                    if (context.Prefix != null)
                    {
                        cell.MergeAttribute("data-total-sub", "true");
                    }
                    break;

                case GridColumnSubtotal.Suffix:
                    if (context.Suffix != null)
                    {
                        cell.MergeAttribute("data-total-sub", "true");
                    }
                    break;
                }
                cell.MergeAttribute("data-total-style", context.Style.ToString().ToLowerInvariant());
            }
            bool hasData;

            if (cellData == null)
            {
                hasData = false;
            }
            else
            {
                string cellString = cellData.ToString();
                if (string.IsNullOrWhiteSpace(cellString))
                {
                    hasData = false;
                }
                else
                {
                    cell.InnerHtml = cellString;
                    hasData        = true;
                }
            }

            cell.MergeAttributes(htmlAttributes);
            AddCell(cells, cell);

            AddClearFix(cells, "visible-xs", Position.EndOfRow(0));
            AddClearFix(cells, "visible-sm", Position.EndOfRow(1));
            AddClearFix(cells, "visible-md", Position.EndOfRow(2));
            AddClearFix(cells, "visible-lg", Position.EndOfRow(3));

            return(hasData);
        }