private static MvcHtmlString InternalListDetailElement <T>(this HtmlHelper helper, HtmlStringBuilder sbOptions, TypeElementContext <T> itemTC, EntityListDetail listDetail)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            sb.AddLine(EntityBaseHelper.WriteIndex(helper, itemTC));
            sb.AddLine(helper.HiddenRuntimeInfo(itemTC));

            if (EntityBaseHelper.EmbeddedOrNew((Modifiable)(object)itemTC.Value))
            {
                sb.AddLine(EntityBaseHelper.RenderContent(helper, itemTC, RenderContentMode.ContentInInvisibleDiv, listDetail));
            }
            else if (itemTC.Value != null)
            {
                sb.Add(helper.Div(itemTC.Compose(EntityBaseKeys.Entity), null, "", new Dictionary <string, object> {
                    { "style", "display:none" }
                }));
            }

            sbOptions.Add(new HtmlTag("option")
                          .Id(itemTC.Compose(EntityBaseKeys.ToStr))
                          .Class("sf-entity-list-option")
                          .Let(a => itemTC.Index > 0 ? a : a.Attr("selected", "selected"))
                          .SetInnerText(itemTC.Value?.ToString())
                          .ToHtml(TagRenderMode.Normal));

            return(sb.ToHtml());
        }
        private static MvcHtmlString InternalTabRepeaterHeader<T>(this HtmlHelper helper, TypeElementContext<T> itemTC, EntityTabRepeater repeater)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("li", itemTC.Compose(EntityRepeaterKeys.RepeaterElement)).Let(h => itemTC.Index == 0 ? h.Class("active") : h)
                .Class("sf-repeater-element")))
            {
                using (sb.SurroundLine(new HtmlTag("a")
                    .Attr("href", "#" + itemTC.Compose(EntityBaseKeys.Entity))
                    .Attr("data-toggle", "tab")))
                {
                    sb.Add(new HtmlTag("span").SetInnerText(itemTC.Value.ToString()));

                    sb.AddLine(EntityBaseHelper.WriteIndex(helper, itemTC));
                    sb.AddLine(helper.HiddenRuntimeInfo(itemTC));

                    if (repeater.Move)
                    {
                        sb.AddLine(EntityButtonHelper.MoveUpItem(helper, itemTC, repeater, btn: false, elementType: "span", isVertical: false));
                        sb.AddLine(EntityButtonHelper.MoveDownItem(helper, itemTC, repeater, btn: false, elementType: "span", isVertical: false));
                    }

                    if (repeater.Remove)
                        sb.AddLine(EntityButtonHelper.RemoveItem(helper, itemTC, repeater, btn: false, elementType: "span"));
                }

            }

            return sb.ToHtml();
        }
Exemple #3
0
        public static MvcHtmlString RenderWidgets(this HtmlHelper helper, WidgetContext ctx)
        {
            if (GetWidget == null)
            {
                return(MvcHtmlString.Empty);
            }

            List <IWidget> widgets = GetWidget.GetInvocationListTyped()
                                     .Select(d => d(ctx))
                                     .NotNull()
                                     .ToList();

            if (widgets.IsNullOrEmpty())
            {
                return(MvcHtmlString.Empty);
            }

            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("ul").Class("sf-widgets")))
            {
                foreach (IWidget widget in widgets)
                {
                    sb.AddLine(widget.ToHtml(helper));
                }
            }
            return(sb.ToHtml());
        }
Exemple #4
0
        public static MvcHtmlString TimePicker(this HtmlHelper helper, string name, bool formGroup, string value, string dateFormat, IDictionary <string, object> htmlProps = null)
        {
            if (dateFormat.Contains("f") || dateFormat.Contains("F"))
            {
                htmlProps["class"] += " form-control";
                return(helper.TextBox(TypeContextUtilities.Compose(name, "Time"), value, htmlProps));
            }

            var input = new HtmlTag("input")
                        .IdName(name)
                        .Attr("type", "text")
                        .Class("form-control")
                        .Attrs(htmlProps)
                        .Attr("value", value);

            if (!formGroup)
            {
                return(AttachTimePiceker(input, dateFormat));
            }

            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(AttachTimePiceker(new HtmlTag("div").Class("input-group time"), dateFormat)))
            {
                sb.Add(input);

                using (sb.SurroundLine(new HtmlTag("span").Class("input-group-addon")))
                    sb.Add(new HtmlTag("span").Class("glyphicon glyphicon-time"));
            }

            return(sb.ToHtml());
        }
Exemple #5
0
        public override MvcHtmlString ToHtml(HtmlHelper helper)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();
            using (sb.SurroundLine(new HtmlTag("div").Class("btn-group")))
            {
                var a = new HtmlTag("a")
                    .Id(Id)
                    .Class("btn")
                    .Class("btn-" + Style.ToString().ToLower())
                    .Class(CssClass)
                    .Class("dropdown-toggle")
                    .Attr("data-toggle", "dropdown")
                    .Attr("alt", Tooltip)
                    .Attrs(HtmlProps);

                if (!Enabled)
                    a.Attr("disabled", "disabled");

                using (sb.SurroundLine(a))
                {
                    sb.AddLine(new MvcHtmlString(Text));
                    sb.AddLine(new HtmlTag("span").Class("caret"));
                }


                using (sb.SurroundLine(new HtmlTag("ul").Class("dropdown-menu")))
                {
                    if (Items != null)
                        foreach (var ci in Items)
                            sb.Add(ci.ToHtml());
                }
            }

            return sb.ToHtml();
        }
Exemple #6
0
        public static MvcHtmlString DatePicker(this HtmlHelper helper, string name, bool inputGroup, string value, string jsFormat, CultureInfo culture = null, IDictionary <string, object> htmlProps = null)
        {
            if (culture == null)
            {
                culture = CultureInfo.CurrentCulture;
            }

            var input = new HtmlTag("input")
                        .IdName(name)
                        .Attr("type", "text")
                        .Class("form-control")
                        .Attrs(htmlProps)
                        .Attr("value", value);

            if (!inputGroup)
            {
                return(AttachDatePicker(input, culture, jsFormat));
            }

            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(AttachDatePicker(new HtmlTag("div").Class("input-group date"), culture, jsFormat)))
            {
                sb.Add(input);

                using (sb.SurroundLine(new HtmlTag("span").Class("input-group-addon")))
                    sb.Add(new HtmlTag("span").Class("glyphicon glyphicon-calendar"));
            }

            return(sb.ToHtml());
        }
        public static MvcHtmlString ToStringButton(this List <ToolBarButton> elements, HtmlHelper helper)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder(elements.Select(tb => tb.ToHtml(helper)));

            sb.Add(new MvcHtmlString(@"<script>$(function(){ $('[data-toggle=""tooltip""]').tooltip({}); });</script>"));

            return(sb.ToHtml());
        }
        static MvcHtmlString QueryTokenCombo(this HtmlHelper helper, QueryToken previous, QueryToken selected, int index, Context context, QueryTokenBuilderSettings settings)
        {
            if (previous != null && AllowSubTokens != null && !AllowSubTokens(previous))
            {
                return(MvcHtmlString.Create(""));
            }

            var queryTokens = previous.SubTokens(settings.QueryDescription, settings.Options);

            if (queryTokens.IsEmpty())
            {
                return(new HtmlTag("input")
                       .Attr("type", "hidden")
                       .IdName(context.Compose("ddlTokensEnd_" + index))
                       .Attr("disabled", "disabled")
                       .Attr("data-parenttoken", previous == null ? "" : previous.FullKey()));
            }

            var options = new HtmlStringBuilder();

            options.AddLine(new HtmlTag("option").Attr("value", "").SetInnerText("-").ToHtml());
            foreach (var qt in queryTokens)
            {
                var option = new HtmlTag("option")
                             .Attr("value", previous == null ? qt.FullKey() : qt.Key)
                             .SetInnerText((previous == null && qt.Parent != null ? " - " : "") + qt.ToString());

                if (selected != null && qt.Key == selected.Key)
                {
                    option.Attr("selected", "selected");
                }

                option.Attr("title", qt.NiceTypeName);
                option.Attr("style", "color:" + qt.TypeColor);

                if (settings.Decorators != null)
                {
                    settings.Decorators(qt, option);
                }

                options.AddLine(option.ToHtml());
            }

            HtmlTag dropdown = new HtmlTag("select")
                               .Class("form-control")
                               .IdName(context.Compose("ddlTokens_" + index))
                               .InnerHtml(options.ToHtml())
                               .Attr("data-parenttoken", previous == null ? "" : previous.FullKey());

            if (selected != null)
            {
                dropdown.Attr("title", selected.NiceTypeName);
                dropdown.Attr("style", "color:" + selected.TypeColor);
            }

            return(dropdown.ToHtml());
        }
        private static MvcHtmlString InternalEntityRepeater<T>(this HtmlHelper helper, EntityTabRepeater repeater)
        {
            if (!repeater.Visible || repeater.HideIfNull && repeater.UntypedValue == null)
                return MvcHtmlString.Empty;

            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("fieldset").Id(repeater.Prefix).Class("sf-tab-repeater-field SF-control-container SF-avoid-child-errors")))
            {
                using (sb.SurroundLine(new HtmlTag("legend")))
                using (sb.SurroundLine(new HtmlTag("div", repeater.Compose("header"))))
                {
                    sb.AddLine(new HtmlTag("span").InnerHtml(repeater.LabelHtml ?? repeater.LabelText.FormatHtml()).ToHtml());

                    using (sb.SurroundLine(new HtmlTag("span", repeater.Compose("shownButton")).Class("pull-right")))
                    {
                        sb.AddLine(EntityButtonHelper.Create(helper, repeater, btn: false));
                        sb.AddLine(EntityButtonHelper.Find(helper, repeater, btn: false));
                    }
                }

                sb.AddLine(helper.Hidden(repeater.Compose(EntityListBaseKeys.ListPresent), ""));

                using (sb.SurroundLine(new HtmlTag("div")))
                {
                    using (sb.SurroundLine(new HtmlTag("ul", repeater.Compose(EntityRepeaterKeys.ItemsContainer)).Class("nav nav-tabs")))
                    {
                        if (repeater.UntypedValue != null)
                        {
                            foreach (var itemTC in TypeContextUtilities.TypeElementContext((TypeContext<MList<T>>)repeater.Parent))
                                sb.Add(InternalTabRepeaterHeader(helper, itemTC, repeater));
                        }
                    }

                    using (sb.SurroundLine(new HtmlTag("div", repeater.Compose(EntityRepeaterKeys.TabsContainer)).Class("tab-content")))
                        if (repeater.UntypedValue != null)
                        {
                            foreach (var itemTC in TypeContextUtilities.TypeElementContext((TypeContext<MList<T>>)repeater.Parent))
                                using (sb.SurroundLine(new HtmlTag("div", itemTC.Compose(EntityBaseKeys.Entity)).Class("tab-pane")
                                    .Let(h => itemTC.Index == 0 ? h.Class("active") : h)))
                                    sb.Add(EntityBaseHelper.RenderContent(helper, itemTC, RenderContentMode.Content, repeater));
                        }
                }

                if (repeater.ElementType.IsEmbeddedEntity() && repeater.Create)
                {
                    T embedded = (T)(object)new ConstructorContext(helper.ViewContext.Controller).ConstructUntyped(typeof(T));
                    TypeElementContext<T> templateTC = new TypeElementContext<T>(embedded, (TypeContext)repeater.Parent, 0, null);
                    sb.AddLine(EntityBaseHelper.EmbeddedTemplate(repeater, EntityBaseHelper.RenderContent(helper, templateTC, RenderContentMode.Content, repeater), templateTC.Value.ToString()));
                }

                sb.AddLine(repeater.ConstructorScript(JsModule.Lines, "EntityTabRepeater"));
            }

            return sb.ToHtml();
        }
Exemple #10
0
        public virtual MvcHtmlString CombinedScript(HtmlHelper html, string[] files, ScriptType scriptType)
        {
            string scriptElement = scriptType == ScriptType.Css ? cssElement : jsElement;

            HtmlStringBuilder sb = new HtmlStringBuilder();
            foreach (var f in files)
                sb.AddLine(MvcHtmlString.Create(scriptElement.Formato(Subdomain(f + "?v=" + Version))));

            return sb.ToHtml();
        }
Exemple #11
0
 public static MvcHtmlString WebMenu(this HtmlHelper helper, IEnumerable<WebMenuItem> menuITems)
 {
     var currentUrl = helper.ViewContext.RequestContext.HttpContext.Request.RawUrl; 
     HtmlStringBuilder sb = new HtmlStringBuilder();
     foreach (WebMenuItem menu in menuITems)
     {
         if (menu.Visible)
             menu.Write(sb, currentUrl, 0);
     }
     return sb.ToHtml();
 }
Exemple #12
0
        public virtual MvcHtmlString CombinedScript(HtmlHelper html, string[] files, ScriptType scriptType)
        {
            string scriptElement = scriptType == ScriptType.Css ? cssElement : jsElement;

            HtmlStringBuilder sb = new HtmlStringBuilder();

            foreach (var f in files)
            {
                sb.AddLine(MvcHtmlString.Create(scriptElement.FormatWith(Subdomain(f + "?v=" + Version))));
            }

            return(sb.ToHtml());
        }
Exemple #13
0
        public static MvcHtmlString WebMenu(this HtmlHelper helper, IEnumerable <WebMenuItem> menuITems)
        {
            var currentUrl       = helper.ViewContext.RequestContext.HttpContext.Request.RawUrl;
            HtmlStringBuilder sb = new HtmlStringBuilder();

            foreach (WebMenuItem menu in menuITems)
            {
                if (menu.Visible)
                {
                    menu.Write(sb, currentUrl, 0);
                }
            }
            return(sb.ToHtml());
        }
        static MvcHtmlString InternalListElement <T>(this HtmlHelper helper, HtmlStringBuilder sbOptions, TypeElementContext <T> itemTC, EntityList entityList)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();


            sb.AddLine(EntityBaseHelper.WriteIndex(helper, itemTC));
            sb.AddLine(helper.HiddenRuntimeInfo(itemTC));

            if (entityList.IsVisible == null || entityList.IsVisible(itemTC))
            {
                if (EntityBaseHelper.EmbeddedOrNew((Modifiable)(object)itemTC.Value))
                {
                    sb.AddLine(EntityBaseHelper.RenderPopup(helper, itemTC, RenderPopupMode.PopupInDiv, entityList));
                }
                else if (itemTC.Value != null)
                {
                    sb.Add(helper.Div(itemTC.Compose(EntityBaseKeys.Entity), null, "",
                                      new Dictionary <string, object> {
                        { "style", "display:none" }, { "class", "sf-entity-list" }
                    }));
                }

                var optionTag = new HtmlTag("option")
                                .Id(itemTC.Compose(EntityBaseKeys.ToStr))
                                .Class("sf-entity-list-option")
                                .Let(a => itemTC.Index > 0 ? a : a.Attr("selected", "selected"))
                                .SetInnerText(itemTC.Value?.ToString());

                if (!EntityBaseHelper.EmbeddedOrNew((Modifiable)(object)itemTC.Value))
                {
                    PrimaryKey?idOrNull = null;
                    Type       type     = itemTC.Value.GetType();
                    if (type.IsLite())
                    {
                        idOrNull = ((Lite <IEntity>)itemTC.Value).IdOrNull;
                    }

                    if (type.IsEntity())
                    {
                        idOrNull = ((Entity)(object)itemTC.Value).IdOrNull;
                    }

                    optionTag.Attr("title", " ".CombineIfNotEmpty(itemTC.Value.GetType().CleanType().NiceName(), idOrNull));
                }

                sbOptions.Add(optionTag.ToHtml(TagRenderMode.Normal));
            }

            return(sb.ToHtml());
        }
Exemple #15
0
        public static MvcHtmlString QueryTokenBuilder(this HtmlHelper helper, QueryToken queryToken, Context context, QueryTokenBuilderSettings settings)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();
            using (sb.Surround(new HtmlTag("span").Id(context.Prefix).Class("token-builder")))
            {
                sb.Add(QueryTokenBuilderOptions(helper, queryToken, context, settings));
            }

            sb.Add(MvcHtmlString.Create("<script>" + new JsFunction(JsFunction.FinderModule, "QueryTokenBuilder.init", context.Prefix,
                Navigator.ResolveWebQueryName(settings.QueryDescription.QueryName), settings.ControllerUrl, settings.RequestExtraJSonData).ToString()
                + "</script>")); 
        
            return sb.ToHtml();     
        }
        public static MvcHtmlString QueryTokenBuilderOptions(this HtmlHelper helper, QueryToken queryToken, Context context, QueryTokenBuilderSettings settings)
        {
            var tokenPath = queryToken.Follow(qt => qt.Parent).Reverse().NotNull().ToList();

            HtmlStringBuilder sb = new HtmlStringBuilder();

            for (int i = 0; i < tokenPath.Count; i++)
            {
                sb.AddLine(helper.QueryTokenCombo(i == 0 ? null : tokenPath[i - 1], tokenPath[i], i, context, settings));
            }

            sb.AddLine(helper.QueryTokenCombo(queryToken, null, tokenPath.Count, context, settings));

            return(sb.ToHtml());
        }
Exemple #17
0
        public static MvcHtmlString QueryTokenBuilderOptions(this HtmlHelper helper, QueryToken queryToken, Context context, QueryTokenBuilderSettings settings)
        {
            var tokenPath = queryToken.Follow(qt => qt.Parent).Reverse().NotNull().ToList();

            HtmlStringBuilder sb = new HtmlStringBuilder();

            for (int i = 0; i < tokenPath.Count; i++)
            {
                sb.AddLine(helper.QueryTokenCombo(i == 0 ? null : tokenPath[i - 1], tokenPath[i], i, context, settings));
            }

            sb.AddLine(helper.QueryTokenCombo(queryToken, null, tokenPath.Count, context, settings));

            return sb.ToHtml();
        }
Exemple #18
0
        static MvcHtmlString QueryTokenCombo(this HtmlHelper helper, QueryToken previous, QueryToken selected, int index, Context context, QueryTokenBuilderSettings settings)
        {
            if (previous != null && AllowSubTokens != null && !AllowSubTokens(previous))
                return MvcHtmlString.Create("");

            var queryTokens = previous.SubTokens(settings.QueryDescription, settings.CanAggregate);

            if (queryTokens.IsEmpty())
                return new HtmlTag("input")
                .Attr("type", "hidden")
                .IdName(context.Compose("ddlTokensEnd_" + index))
                .Attr("disabled", "disabled")
                .Attr("data-parenttoken", previous == null ? "" : previous.FullKey());

            var options = new HtmlStringBuilder();
            options.AddLine(new HtmlTag("option").Attr("value", "").SetInnerText("-").ToHtml());
            foreach (var qt in queryTokens)
            {
                var option = new HtmlTag("option")
                    .Attr("value", previous == null ? qt.FullKey() : qt.Key)
                    .SetInnerText((previous == null && qt.Parent != null ? " - " : "") + qt.ToString());

                if (selected != null && qt.Key == selected.Key)
                    option.Attr("selected", "selected");

                option.Attr("title", qt.NiceTypeName);
                option.Attr("style", "color:" + qt.TypeColor);

                if (settings.Decorators != null)
                    settings.Decorators(qt, option); 

                options.AddLine(option.ToHtml());
            }

            HtmlTag dropdown = new HtmlTag("select")
                .Class("form-control")
                .IdName(context.Compose("ddlTokens_" + index))
                .InnerHtml(options.ToHtml()) 
                .Attr("data-parenttoken", previous == null ? "" : previous.FullKey());

            if (selected != null)
            {
                dropdown.Attr("title", selected.NiceTypeName);
                dropdown.Attr("style", "color:" + selected.TypeColor);
            }

            return dropdown.ToHtml();
        }
Exemple #19
0
        public static MvcHtmlString Header(Column col, OrderType?orderType)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("th")
                                   .Attr("draggable", "true")
                                   .Attr("data-column-name", col.Name)
                                   .Attr("data-nice-name", col.Token.NiceName())))
            {
                sb.Add(new HtmlTag("span").Class("sf-header-sort")
                       .Class(orderType == null ? null :
                              orderType == OrderType.Ascending ? "asc" : "desc"));

                sb.Add(new HtmlTag("span").SetInnerText(col.DisplayName));
            }
            return(sb.ToHtml());
        }
        public static MvcHtmlString FormGroup(this HtmlHelper html, Context context, string controlId, MvcHtmlString label, MvcHtmlString value)
        {
            if (context.FormGroupStyle == FormGroupStyle.None)
            {
                return(value);
            }

            var form = context is LineBase ? ((LineBase)context).FormGroupHtmlProps : null;

            var formSize = context.FormGroupSizeCss;

            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("div").Class("form-group").Class(formSize).Attrs(form)))
            {
                var lbl = new HtmlTag("label").Attr("for", controlId).InnerHtml(label);

                if (context.FormGroupStyle == FormGroupStyle.SrOnly)
                {
                    lbl.Class("sr-only");
                }
                else if (context.FormGroupStyle == FormGroupStyle.LabelColumns)
                {
                    lbl.Class("control-label").Class(context.LabelColumns.ToString());
                }

                lbl.Attrs(context is LineBase ? ((LineBase)context).LabelHtmlProps : null);

                if (context.FormGroupStyle != FormGroupStyle.BasicDown)
                {
                    sb.AddLine(lbl);
                }

                using (context.FormGroupStyle == FormGroupStyle.LabelColumns ? sb.SurroundLine(new HtmlTag("div").Class(context.ValueColumns.ToString())) : null)
                {
                    sb.AddLine(value);
                }

                if (context.FormGroupStyle == FormGroupStyle.BasicDown)
                {
                    sb.AddLine(lbl);
                }
            }

            return(sb.ToHtml());
        }
Exemple #21
0
        public static MvcHtmlString QueryTokenBuilder(this HtmlHelper helper, QueryToken queryToken, Context context, QueryTokenBuilderSettings settings)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();
            using (sb.SurroundLine(new HtmlTag("span").Id(context.Prefix).Class("token-builder")))
            {
                sb.Add(QueryTokenBuilderOptions(helper, queryToken, context, settings));
            }

            if (settings.ControllerUrl.HasText())
            {
                sb.Add(MvcHtmlString.Create("<script>" + JsModule.Finder["QueryTokenBuilder.init"](context.Prefix,
                    Finder.ResolveWebQueryName(settings.QueryDescription.QueryName), settings.ControllerUrl, (int)settings.Options, settings.RequestExtraJSonData).ToString()
                    + "</script>"));
            }
        
            return sb.ToHtml();     
        }
Exemple #22
0
        private static MvcHtmlString InternalValue(HtmlHelper helper, ValueLine valueLine)
        {
            HtmlStringBuilder sb     = new HtmlStringBuilder();
            ValueLineType     vltype = valueLine.ValueLineType ?? Configurator.GetDefaultValueLineType(valueLine.Type);

            using (valueLine.UnitText == null ? null : sb.SurroundLine(new HtmlTag("div").Class("input-group")))
            {
                sb.AddLine(Configurator.Helper[vltype](helper, valueLine));

                if (valueLine.UnitText.HasText())
                {
                    sb.AddLine(helper.Span(null, valueLine.UnitText, "input-group-addon"));
                }
            }

            return(sb.ToHtml());
        }
        public static MvcHtmlString QueryTokenBuilder(this HtmlHelper helper, QueryToken queryToken, Context context, QueryTokenBuilderSettings settings)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("span").Id(context.Prefix).Class("token-builder")))
            {
                sb.Add(QueryTokenBuilderOptions(helper, queryToken, context, settings));
            }

            if (settings.ControllerUrl.HasText())
            {
                sb.Add(MvcHtmlString.Create("<script>" + JsModule.Finder["QueryTokenBuilder.init"](context.Prefix,
                                                                                                   Finder.ResolveWebQueryName(settings.QueryDescription.QueryName), settings.ControllerUrl, (int)settings.Options, settings.RequestExtraJSonData).ToString()
                                            + "</script>"));
            }

            return(sb.ToHtml());
        }
        public virtual MvcHtmlString CombinedScript(HtmlHelper html, string[] files, ScriptType scriptType)
        {
            string scriptElement = scriptType == ScriptType.Css ? cssElement : jsElement;

            HtmlStringBuilder sb = new HtmlStringBuilder();

            foreach (var f in files)
            {
                if (f.StartsWith("http", StringComparison.InvariantCultureIgnoreCase))
                {
                    sb.AddLine(MvcHtmlString.Create(scriptElement.FormatWith(f + "?v=" + Version)));
                }
                else
                {
                    sb.AddLine(MvcHtmlString.Create(scriptElement.FormatWith(Subdomain(f + "?v=" + Version))));
                }
            }
            return(sb.ToHtml());
        }
Exemple #25
0
        public MvcHtmlString ToHtml(HtmlHelper helper)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine("li"))
            {
                using (sb.SurroundLine(new HtmlTag("a", Id)
                                       .Class("badge").Class(Class).Class(Active? "sf-widget-active" : null)
                                       .Attr("title", Title)
                                       .Attr("role", "button")
                                       .Attr("href", "#")
                                       .Attr("data-toggle", "dropdown")))
                {
                    if (IconClass.HasText())
                    {
                        sb.AddLine(new HtmlTag("span").Class(IconClass));
                    }

                    if (Text.HasText())
                    {
                        sb.AddLine(new HtmlTag("span").SetInnerText(Text));
                    }

                    if (Html != null)
                    {
                        sb.AddLine(Html);
                    }
                }

                using (sb.SurroundLine(new HtmlTag("ul")
                                       .Class("dropdown-menu dropdown-menu-right")
                                       .Attr("role", "menu")
                                       .Attr("aria-labelledby", Id)))
                {
                    foreach (var mi in Items)
                    {
                        sb.AddLine(mi.ToHtml());
                    }
                }
            }

            return(sb.ToHtml());
        }
        public static MvcHtmlString ValudationSummaryStatic(this HtmlHelper html)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("div", "sfGlobalValidationSummary")))
            {
                if (html.ViewData.ModelState.Any(x => x.Value.Errors.Any()))
                {
                    using (sb.SurroundLine(new HtmlTag("ul").Class("validaton-summary alert alert-danger")))
                    {
                        foreach (var str in html.ViewData.ModelState.SelectMany(a => a.Value.Errors))
                        {
                            sb.Add(new HtmlTag("li").SetInnerText(str.ErrorMessage));
                        }
                    }
                }
            }
            return(sb.ToHtml());
        }
        public override MvcHtmlString ToHtml(HtmlHelper helper)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("div").Class("btn-group")))
            {
                var a = new HtmlTag("a")
                        .Id(Id)
                        .Class("btn")
                        .Class("btn-" + Style.ToString().ToLower())
                        .Class(CssClass)
                        .Class("dropdown-toggle")
                        .Attr("data-toggle", "dropdown")
                        .Attr("alt", Tooltip)
                        .Attrs(HtmlProps);

                if (!Enabled)
                {
                    a.Attr("disabled", "disabled");
                }

                using (sb.SurroundLine(a))
                {
                    sb.AddLine(new MvcHtmlString(Text));
                    sb.AddLine(new HtmlTag("span").Class("caret"));
                }


                using (sb.SurroundLine(new HtmlTag("ul").Class("dropdown-menu")))
                {
                    if (Items != null)
                    {
                        foreach (var ci in Items)
                        {
                            sb.Add(ci.ToHtml());
                        }
                    }
                }
            }

            return(sb.ToHtml());
        }
Exemple #28
0
        private static MvcHtmlString CountSearchControlInternal(FindOptions findOptions, Web.CountSearchControl options, Context context)
        {
            findOptions.SearchOnLoad = true;



            HtmlStringBuilder sb = new HtmlStringBuilder();

            if (options.Navigate)
            {
                sb.Add(new HtmlTag("a").Id(context.Prefix)
                       .Class("count-search")
                       .Attr("href", options.Href.HasText() ? options.Href : findOptions.ToString())
                       .SetInnerText("..."));
            }
            else
            {
                sb.Add(new HtmlTag("span").Id(context.Prefix)
                       .Class("count-search")
                       .SetInnerText("..."));
            }

            if (options.View)
            {
                sb.Add(new HtmlTag("a", context.Compose("csbtnView"))
                       .Class("sf-line-button sf-view")
                       .Attr("title", EntityControlMessage.View.NiceToString())
                       .Attr("onclick", JsModule.Finder["explore"](findOptions.ToJS(context.Compose("New"))).ToString())
                       .InnerHtml(new HtmlTag("span").Class("glyphicon glyphicon-arrow-right")));
            }

            var function = new JsFunction(JsModule.Finder, "count",
                                          findOptions.ToJS(context.Prefix),
                                          new JRaw("'" + context.Prefix + "'.get()"));

            sb.Add(MvcHtmlString.Create("<script>" + function.ToHtmlString() + "</script>"));

            return(sb.ToHtml());
        }
        //http://stackoverflow.com/questions/979095/asp-net-mvc-dropdownlist-pre-selected-item-ignored
        public static MvcHtmlString SafeDropDownList(this HtmlHelper html, string idAndName, IEnumerable <SelectListItem> elements, IDictionary <string, object> htmlAttributes = null)
        {
            var select = new HtmlTag("select").IdName(idAndName).Attrs(htmlAttributes);

            HtmlStringBuilder sb = new HtmlStringBuilder();

            foreach (var se in elements)
            {
                var option = new HtmlTag("option").Attr("value", se.Value).SetInnerText(se.Text);

                if (se.Selected)
                {
                    option.Attr("selected", "selected");
                }

                sb.Add(option.ToHtml());
            }

            select.InnerHtml(sb.ToHtml());

            return(select.ToHtml());
        }
Exemple #30
0
        private static MvcHtmlString InternalRepeaterElement <T>(this HtmlHelper helper, TypeElementContext <T> itemTC, EntityRepeater repeater)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            if (repeater.IsVisible == null || repeater.IsVisible(itemTC))
            {
                using (sb.SurroundLine(new HtmlTag("fieldset", itemTC.Compose(EntityRepeaterKeys.RepeaterElement)).Class("sf-repeater-element")))
                {
                    using (sb.SurroundLine(new HtmlTag("legend")))
                    {
                        if (repeater.Remove)
                        {
                            sb.AddLine(EntityButtonHelper.RemoveItem(helper, itemTC, repeater, btn: false, elementType: "a"));
                        }

                        if (repeater.Move)
                        {
                            sb.AddLine(EntityButtonHelper.MoveUpItem(helper, itemTC, repeater, btn: false, elementType: "a", isVertical: true));
                            sb.AddLine(EntityButtonHelper.MoveDownItem(helper, itemTC, repeater, btn: false, elementType: "a", isVertical: true));
                        }
                    }

                    sb.AddLine(EntityBaseHelper.WriteIndex(helper, itemTC));
                    sb.AddLine(helper.HiddenRuntimeInfo(itemTC));

                    sb.AddLine(EntityBaseHelper.RenderContent(helper, itemTC, RenderContentMode.ContentInVisibleDiv, repeater));
                }
            }
            else
            {
                using (sb.SurroundLine(new HtmlTag("fieldset", itemTC.Compose(EntityRepeaterKeys.RepeaterElement)).Class("sf-repeater-element hidden")))
                {
                    sb.AddLine(EntityBaseHelper.WriteIndex(helper, itemTC));
                    sb.AddLine(helper.HiddenRuntimeInfo(itemTC));
                }
            }

            return(sb.ToHtml());
        }
Exemple #31
0
        public static MvcHtmlString ColorTextbox(this HtmlHelper helper, ValueLine valueLine)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("div").Class("input-group")))
            {
                valueLine.ValueHtmlProps.AddCssClass("form-control");

                ColorEmbedded color = (ColorEmbedded)valueLine.UntypedValue;

                sb.AddLine(helper.TextBox(valueLine.Prefix, color == null ? "" : color.RGBHex(), valueLine.ValueHtmlProps));

                sb.AddLine(new HtmlTag("span").Class("input-group-addon").InnerHtml(new HtmlTag("i")));
            }

            sb.AddLine(new HtmlTag("script").InnerHtml(MvcHtmlString.Create(
                                                           @" $(function(){
        $('#" + valueLine.Prefix + @"').parent().colorpicker()" + (valueLine.ReadOnly ? ".colorpicker('disable')" : null) + @";
   });")));

            return(sb.ToHtml());
        }
Exemple #32
0
        public static MvcHtmlString DateTimePicker(this HtmlHelper helper, string name, bool formGroup, DateTime?value, string dateTimeFormat, CultureInfo culture = null, IDictionary <string, object> htmlProps = null)
        {
            var dateFormat = SplitDateTimeFormat(dateTimeFormat, culture);

            if (dateFormat.TimeFormat == null)
            {
                return(helper.DatePicker(name, formGroup, value?.ToString(dateFormat.DateFormat, culture), ToJsDateFormat(dateFormat.DateFormat), culture, htmlProps));
            }

            if (dateFormat.DateFormat == null)
            {
                return(helper.TimePicker(name, formGroup, value?.ToString(dateFormat.TimeFormat, culture), dateFormat.TimeFormat, htmlProps));
            }

            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("div", name).Class("date-time")))
            {
                sb.Add(helper.DatePicker(TypeContextUtilities.Compose(name, "Date"), formGroup, value?.ToString(dateFormat.DateFormat, culture), ToJsDateFormat(dateFormat.DateFormat), culture, htmlProps));
                sb.Add(helper.TimePicker(TypeContextUtilities.Compose(name, "Time"), formGroup, value?.ToString(dateFormat.TimeFormat, culture), dateFormat.TimeFormat, htmlProps));
            }
            return(sb.ToHtml());
        }
Exemple #33
0
        public MvcHtmlString ToHTml(HtmlHelper helper)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();
            using (sb.Surround("li"))
            {
                using (sb.Surround(new HtmlTag("a", Id)
                    .Class("badge").Class(Class).Class(Active? "sf-widget-active" : null)
                    .Attr("title", Title)
                    .Attr("role", "button")
                    .Attr("href", "#")
                    .Attr("data-toggle", "dropdown")))
                {

                    if (IconClass.HasText())
                        sb.AddLine(new HtmlTag("span").Class(IconClass));

                    if (Text.HasText())
                        sb.AddLine(new HtmlTag("span").SetInnerText(Text));

                    if (Html != null)
                        sb.AddLine(Html);
                }

                using (sb.Surround(new HtmlTag("ul")
                    .Class("dropdown-menu dropdown-menu-right")
                    .Attr("role", "menu")
                    .Attr("aria-labelledby", Id)))
                {
                    foreach (var mi in Items)
                    {
                        sb.AddLine(mi.ToHtml());
                    }
                }
            }

            return sb.ToHtml();
        }
        private static MvcHtmlString CountSearchControlInternal(FindOptions findOptions, Web.CountSearchControl options)
        {
            findOptions.SearchOnLoad = true;

            int count = Navigator.QueryCount(new CountOptions(findOptions.QueryName)
            {
                FilterOptions = findOptions.FilterOptions
            });

            HtmlStringBuilder sb = new HtmlStringBuilder();

            if (options.Navigate)
            {
                sb.Add(new HtmlTag("a")
                    .Class("count-search").Class(count > 0 ? "count-with-results badge" : "count-no-results")
                    .Attr("href", options.Href.HasText() ? options.Href : findOptions.ToString())
                    .SetInnerText(count.ToString()));
            }
            else
            {
                sb.Add(new HtmlTag("span")
                    .Class("count-search").Class(count > 0 ? "count-with-results badge" : "count-no-results")
                    .SetInnerText(count.ToString()));
            }

            if (options.PopupViewPrefix != null)
            {
                sb.Add(new HtmlTag("a", options.PopupViewPrefix + "csbtnView")
                  .Class("sf-line-button sf-view")
                  .Attr("title", EntityControlMessage.View.NiceToString())
                  .Attr("onclick", new JsFunction(JsFunction.FinderModule, "explore", findOptions.ToJS(options.PopupViewPrefix)).ToString())
                  .InnerHtml(new HtmlTag("span").Class("glyphicon glyphicon-arrow-right")));
            }

            return sb.ToHtml();
        }
Exemple #35
0
        public static MvcHtmlString TimePicker(this HtmlHelper helper, string name, bool formGroup, string value, string dateFormat, IDictionary<string, object> htmlProps = null)
        {
            if (dateFormat.Contains("f") || dateFormat.Contains("F"))
            {
                htmlProps["class"] += " form-control";
                return helper.TextBox(TypeContextUtilities.Compose(name, "Time"), value, htmlProps);
            }

            var input = new HtmlTag("input")
                .IdName(name)
                .Attr("type", "text")
                .Class("form-control")
                .Attrs(htmlProps)
                .Attr("value", value);

            if (!formGroup)
                return AttachTimePiceker(input, dateFormat);

            HtmlStringBuilder sb = new HtmlStringBuilder();
            using (sb.Surround(AttachTimePiceker(new HtmlTag("div").Class("input-group time"), dateFormat)))
            {
                sb.Add(input);

                using (sb.Surround(new HtmlTag("span").Class("input-group-addon")))
                    sb.Add(new HtmlTag("span").Class("glyphicon glyphicon-time"));
            }

            return sb.ToHtml();
        }
Exemple #36
0
        public static MvcHtmlString DatePicker(this HtmlHelper helper, string name, bool formGroup, string value, string jsFormat, CultureInfo culture = null, IDictionary<string, object> htmlProps = null)
        {
            if (culture == null)
                culture = CultureInfo.CurrentCulture;

            var input = new HtmlTag("input")
                .IdName(name)
                .Attr("type", "text")
                .Class("form-control")               
                .Attrs(htmlProps)
                .Attr("value", value);
               
            if(!formGroup)
                return AttachDatePicker(input, culture, jsFormat);
            
            HtmlStringBuilder sb = new HtmlStringBuilder();
            using (sb.Surround(AttachDatePicker(new HtmlTag("div").Class("input-group date"), culture, jsFormat)))
            {
                sb.Add(input);

                using (sb.Surround(new HtmlTag("span").Class("input-group-addon")))
                    sb.Add(new HtmlTag("span").Class("glyphicon glyphicon-calendar"));
            }

            return sb.ToHtml();
        }
Exemple #37
0
        public static MvcHtmlString DateTimePicker(this HtmlHelper helper, string name, bool formGroup, DateTime? value, string dateTimeFormat, CultureInfo culture = null, IDictionary<string, object> htmlProps = null)
        {
            var dateFormat = SplitDateTimeFormat(dateTimeFormat, culture);

            if (dateFormat.TimeFormat == null)
                return helper.DatePicker(name, formGroup, value.TryToString(dateFormat.DateFormat, culture), ToJsDateFormat(dateFormat.DateFormat), culture, htmlProps);

            if(dateFormat.DateFormat == null)
                return helper.TimePicker(name, formGroup, value.TryToString(dateFormat.TimeFormat, culture), dateFormat.TimeFormat, htmlProps);

            HtmlStringBuilder sb = new HtmlStringBuilder();
            using (sb.Surround(new HtmlTag("div", name).Class("date-time")))
            {
                sb.Add(helper.DatePicker(TypeContextUtilities.Compose(name, "Date"), formGroup, value.TryToString(dateFormat.DateFormat, culture), ToJsDateFormat(dateFormat.DateFormat), culture, htmlProps));
                sb.Add(helper.TimePicker(TypeContextUtilities.Compose(name, "Time"), formGroup, value.TryToString(dateFormat.TimeFormat, culture), dateFormat.TimeFormat, htmlProps));
            }
            return sb.ToHtml();
        }
Exemple #38
0
        public static MvcHtmlString RenderWidgetsForEntity(this HtmlHelper helper, WidgetContext ctx)
        {
            if (GetWidget == null)
                return MvcHtmlString.Empty;

            List<IWidget> widgets = GetWidget.GetInvocationList()
                .Cast<Func<WidgetContext, IWidget>>()
                .Select(d => d(ctx))
                .NotNull()
                .ToList();

            if (widgets.IsNullOrEmpty())
                return MvcHtmlString.Empty;

            HtmlStringBuilder sb = new HtmlStringBuilder();
            using (sb.Surround(new HtmlTag("ul").Class("sf-widgets")))
            {
                foreach (Widget widget in widgets)
                {
                    sb.AddLine(widget.ToHTml(helper));
                }
            }
            return sb.ToHtml();
        }
        public static MvcHtmlString Header(Column col, OrderType? orderType)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();
            using (sb.Surround(new HtmlTag("th")
                .Attr("draggable", "true")
                .Attr("data-column-name", col.Name)
                .Attr("data-nice-name", col.Token.NiceName())))
            {
                sb.Add(new HtmlTag("span").Class("sf-header-sort")
                    .Class(orderType == null ? null :
                    orderType == OrderType.Ascending ? "asc" : "desc"));

                sb.Add(new HtmlTag("span").SetInnerText(col.DisplayName));
            }
            return sb.ToHtml();
        }
Exemple #40
0
        }                                 //is applied to link


        public void Write(HtmlStringBuilder sb, string currentUrl, int depth)
        {
            if (!this.Visible)
            {
                throw new InvalidOperationException("Invisible menu");
            }

            bool isActive = this.Link != null && this.Link.ToString() == currentUrl ||
                            children.HasItems() && children.Any(a => a.Link != null && a.Link.ToString() == currentUrl);

            bool isHeader = IsHeader(depth);

            using (sb.SurroundLine(new HtmlTag("li").Class(isActive ? "active" : null).Class(isHeader ? "dropdown-header" : this.children.HasItems() ? "dropdown" : null)))
            {
                if (Link != null)
                {
                    string link = Link.ToString();

                    if (ManualA != null)
                    {
                        sb.AddLine(ManualA(link, title, " ".CombineIfNotEmpty(Class, "selected")));
                    }
                    else
                    {
                        HtmlTag tbA = new HtmlTag("a")
                                      .Attrs(new { href = link, title = Title, id = Id })
                                      .Class(Class);

                        if (Html != null)
                        {
                            tbA.InnerHtml(Html);
                        }
                        else
                        {
                            tbA.SetInnerText(Text);
                        }

                        sb.AddLine(tbA.ToHtml());
                    }
                }
                else if (this.children.HasItems() && !isHeader)
                {
                    using (sb.SurroundLine(new HtmlTag("a").Attr("href", "#")
                                           .Class("dropdown-toggle")
                                           .Class(Class)
                                           .Attr("data-toggle", "dropdown")))
                    {
                        if (Html != null)
                        {
                            sb.Add(Html);
                        }
                        else
                        {
                            sb.Add(new HtmlTag("span").SetInnerText(Text));
                        }

                        sb.Add(new HtmlTag("b").Class("caret"));
                    }
                }
                else if (Html != null)
                {
                    sb.AddLine(Html);
                }
                else
                {
                    sb.AddLine(new HtmlTag("span").SetInnerText(Text));
                }

                if (this.children.HasItems() && !isHeader)
                {
                    using (sb.SurroundLine(new HtmlTag("ul").Class("dropdown-menu")))
                    {
                        bool lastHeader = false;
                        foreach (WebMenuItem menu in this.children)
                        {
                            if (menu.Visible)
                            {
                                if (lastHeader)
                                {
                                    sb.AddLine(new HtmlTag("li").Class("divider"));
                                }

                                menu.Write(sb, currentUrl, depth + 1);

                                lastHeader = menu.IsHeader(depth + 1);
                            }
                        }
                    }
                }
            }

            if (isHeader)
            {
                foreach (WebMenuItem menu in this.children)
                {
                    if (menu.Visible)
                    {
                        menu.Write(sb, currentUrl, depth + 1);
                    }
                }
            }
        }
Exemple #41
0
        private static MvcHtmlString InternalRepeaterElement <T>(this HtmlHelper helper, TypeElementContext <T> itemTC, EntityListCheckbox entityListCheckBox, bool isChecked, Lite <IEntity> lite)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            var label = new HtmlTag("label", itemTC.Compose(EntityRepeaterKeys.RepeaterElement)).Class("sf-checkbox-element");

            entityListCheckBox.CustomizeLabel?.Invoke(label, lite);

            using (sb.SurroundLine(label))
            {
                if (EntityBaseHelper.EmbeddedOrNew((Modifiable)(object)itemTC.Value))
                {
                    sb.AddLine(EntityBaseHelper.RenderPopup(helper, itemTC, RenderPopupMode.PopupInDiv, entityListCheckBox));
                }
                else if (itemTC.Value != null)
                {
                    sb.Add(helper.Div(itemTC.Compose(EntityBaseKeys.Entity), null, "",
                                      new Dictionary <string, object> {
                        { "style", "display:none" }, { "class", "sf-entity-list" }
                    }));
                }

                var cb = new HtmlTag("input")
                         .Attr("type", "checkbox")
                         .Attr("name", itemTC.Compose(EntityBaseKeys.RuntimeInfo))
                         .Attr("value", itemTC.RuntimeInfo()?.ToString());

                if (isChecked)
                {
                    cb.Attr("checked", "checked");
                }

                if (entityListCheckBox.ReadOnly)
                {
                    cb.Attr("disabled", "disabled");
                }

                entityListCheckBox.CustomizeCheckBox?.Invoke(cb, lite);

                sb.AddLine(cb);

                if (lite != null && (entityListCheckBox.Navigate || entityListCheckBox.View))
                {
                    var dic = new Dictionary <string, object>
                    {
                        { "target", "_blank" }
                    };

                    sb.AddLine(
                        helper.Href(itemTC.Compose(EntityBaseKeys.Link),
                                    lite.ToString(),
                                    lite.IdOrNull == null ? null : Navigator.NavigateRoute(lite),
                                    lite.ToString(), "sf-entitStrip-link", dic));
                }
                else
                {
                    sb.AddLine(
                        helper.Span(itemTC.Compose(EntityBaseKeys.Link),
                                    itemTC.UntypedValue.ToString() ?? " ", "sf-entitStrip-link"));
                }
            }

            return(sb.ToHtml());
        }
Exemple #42
0
        private static MvcHtmlString InternalEntityStrip <T>(this HtmlHelper helper, EntityStrip entityStrip)
        {
            if (!entityStrip.Visible || entityStrip.HideIfNull && entityStrip.UntypedValue == null)
            {
                return(MvcHtmlString.Empty);
            }


            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("div", entityStrip.Prefix).Class("SF-entity-strip SF-control-container")))
            {
                sb.AddLine(helper.Hidden(entityStrip.Compose(EntityListBaseKeys.ListPresent), ""));

                using (sb.SurroundLine(new HtmlTag("div", entityStrip.Compose("hidden")).Class("hide")))
                {
                }

                using (sb.SurroundLine(new HtmlTag("ul", entityStrip.Compose(EntityStripKeys.ItemsContainer))
                                       .Class("sf-strip").Class(entityStrip.Vertical ? "sf-strip-vertical" : "sf-strip-horizontal")))
                {
                    if (entityStrip.UntypedValue != null)
                    {
                        foreach (var itemTC in TypeContextUtilities.TypeElementContext((TypeContext <MList <T> >)entityStrip.Parent))
                        {
                            sb.Add(InternalStripElement(helper, itemTC, entityStrip));
                        }
                    }

                    using (sb.SurroundLine(new HtmlTag("li").Class("sf-strip-input input-group")))
                    {
                        if (entityStrip.Autocomplete)
                        {
                            var htmlAttr = new Dictionary <string, object>
                            {
                                { "class", "sf-entity-autocomplete" },
                                { "autocomplete", "off" },
                            };

                            sb.AddLine(helper.TextBox(
                                           entityStrip.Compose(EntityBaseKeys.ToStr),
                                           null,
                                           htmlAttr));
                        }

                        using (sb.SurroundLine(new HtmlTag("span", entityStrip.Compose("shownButton"))))
                        {
                            sb.AddLine(EntityButtonHelper.Create(helper, entityStrip, btn: false));
                            sb.AddLine(EntityButtonHelper.Find(helper, entityStrip, btn: false));
                        }
                    }
                }

                if (entityStrip.ElementType.IsEmbeddedEntity() && entityStrip.Create)
                {
                    T embeddedEntity = (T)(object)new ConstructorContext(helper.ViewContext.Controller).ConstructUntyped(typeof(T));
                    TypeElementContext <T> templateTC = new TypeElementContext <T>(embeddedEntity, (TypeContext)entityStrip.Parent, 0, null);
                    sb.AddLine(EntityBaseHelper.EmbeddedTemplate(entityStrip, EntityBaseHelper.RenderPopup(helper, templateTC, RenderPopupMode.Popup, entityStrip, isTemplate: true), null));
                }

                sb.AddLine(entityStrip.ConstructorScript(JsModule.Lines, "EntityStrip"));
            }

            return(helper.FormGroup(entityStrip, entityStrip.Prefix, entityStrip.LabelHtml ?? entityStrip.LabelText.FormatHtml(), sb.ToHtml()));
        }
        private static MvcHtmlString CountSearchControlInternal(FindOptions findOptions, Web.CountSearchControl options, Context context)
        {
            findOptions.SearchOnLoad = true;

          

            HtmlStringBuilder sb = new HtmlStringBuilder();

            if (options.Navigate)
            {
                sb.Add(new HtmlTag("a").Id(context.Prefix)
                    .Class("count-search")
                    .Attr("href", options.Href.HasText() ? options.Href : findOptions.ToString())
                    .SetInnerText("..."));
            }
            else
            {
                sb.Add(new HtmlTag("span").Id(context.Prefix)
                    .Class("count-search")
                    .SetInnerText("..."));
            }

            if (options.View)
            {
                sb.Add(new HtmlTag("a", context.Compose("csbtnView"))
                  .Class("sf-line-button sf-view")
                  .Attr("title", EntityControlMessage.View.NiceToString())
                  .Attr("onclick", JsModule.Finder["explore"](findOptions.ToJS(context.Compose("New"))).ToString())
                  .InnerHtml(new HtmlTag("span").Class("glyphicon glyphicon-arrow-right")));
            }

            var function = new JsFunction(JsModule.Finder, "count",
                findOptions.ToJS(context.Prefix),
                new JRaw("'" + context.Prefix + "'.get()"));

            sb.Add(MvcHtmlString.Create("<script>" + function.ToHtmlString() + "</script>"));

            return sb.ToHtml();
        }
Exemple #44
0
        private static MvcHtmlString InternalEntityListCheckbox <T>(this HtmlHelper helper, EntityListCheckbox entityListCheckBox)
        {
            if (!entityListCheckBox.Visible || entityListCheckBox.HideIfNull && entityListCheckBox.UntypedValue == null)
            {
                return(MvcHtmlString.Empty);
            }

            var elementType = entityListCheckBox.Type.ElementType();

            if (!elementType.IsIEntity() && !elementType.IsLite())
            {
                throw new InvalidOperationException("EntityCombo can only be done for an identifiable or a lite, not for {0}".FormatWith(elementType.CleanType()));
            }

            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("fieldset", entityListCheckBox.Prefix).Class("SF-repeater-field SF-control-container SF-avoid-child-errors")))
            {
                sb.AddLine(helper.Hidden(entityListCheckBox.Compose(EntityListBaseKeys.ListPresent), ""));

                using (sb.SurroundLine(new HtmlTag("div", entityListCheckBox.Compose("hidden")).Class("hide")))
                {
                }

                using (sb.SurroundLine(new HtmlTag("legend")))
                    using (sb.SurroundLine(new HtmlTag("div", entityListCheckBox.Compose("header"))))
                    {
                        sb.AddLine(new HtmlTag("span").InnerHtml(entityListCheckBox.LabelHtml ?? entityListCheckBox.LabelText.FormatHtml()).ToHtml());

                        using (sb.SurroundLine(new HtmlTag("span", entityListCheckBox.Compose("shownButton")).Class("pull-right")))
                        {
                            sb.AddLine(EntityButtonHelper.Create(helper, entityListCheckBox, btn: false));
                            sb.AddLine(EntityButtonHelper.Find(helper, entityListCheckBox, btn: false));
                        }
                    }

                using (sb.SurroundLine(new HtmlTag("div").Id(entityListCheckBox.Compose(EntityRepeaterKeys.ItemsContainer)).Attr("style", GetStyle(entityListCheckBox))))
                {
                    IEnumerable <Lite <IEntity> > data = entityListCheckBox.Data ?? AutocompleteUtils.FindAllLite(entityListCheckBox.Implementations.Value).OrderBy(a => a.ToString());

                    if (entityListCheckBox.UntypedValue != null)
                    {
                        var already = TypeContextUtilities.TypeElementContext((TypeContext <MList <T> >)entityListCheckBox.Parent).ToDictionary(a => AsLite(a.Value), "repeated elements");

                        List <Lite <IEntity> > liteList = data.Except(already.Keys).ToList();

                        List <T> typedList = typeof(Lite <IEntity>).IsAssignableFrom(typeof(T)) ? liteList.Cast <T>().ToList(): Database.RetrieveFromListOfLite(liteList).Cast <T>().ToList();

                        var extra = typedList.Select((e, i) => new TypeElementContext <T>(e, (TypeContext)entityListCheckBox.Parent, i + already.Count, null)).ToDictionary(a => AsLite(a.Value), "repeated elements");

                        foreach (var lite in data)
                        {
                            sb.Add(InternalRepeaterElement(helper, already.TryGetC(lite) ?? extra.GetOrThrow(lite), entityListCheckBox, already.ContainsKey(lite), lite));
                        }
                    }
                }

                if (entityListCheckBox.ElementType.IsEmbeddedEntity() && entityListCheckBox.Create)
                {
                    T embedded = (T)(object)new ConstructorContext(helper.ViewContext.Controller).ConstructUntyped(typeof(T));
                    TypeElementContext <T> templateTC = new TypeElementContext <T>(embedded, (TypeContext)entityListCheckBox.Parent, 0, null);
                    sb.AddLine(EntityBaseHelper.EmbeddedTemplate(entityListCheckBox, EntityBaseHelper.RenderContent(helper, templateTC, RenderContentMode.Content, entityListCheckBox), null));
                }

                sb.AddLine(entityListCheckBox.ConstructorScript(JsModule.Lines, "EntityListCheckbox"));
            }

            return(sb.ToHtml());
        }
        public static MvcHtmlString NewFilter(this HtmlHelper helper, FilterOption filterOptions, Context context, int index)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            FilterType filterType = QueryUtils.GetFilterType(filterOptions.Token.Type);
            List<FilterOperation> possibleOperations = QueryUtils.GetFilterOperations(filterType);

            var id = context.Compose("trFilter", index.ToString());

            using (sb.SurroundLine(new HtmlTag("tr").Id(id)))
            {
                using (sb.SurroundLine("td"))
                {
                    if (!filterOptions.Frozen)
                    {
                        sb.AddLine(new HtmlTag("a", context.Compose("btnDelete", index.ToString()))
                        .Attr("title",  SearchMessage.DeleteFilter.NiceToString())
                        .Attr("onclick", JsModule.Finder["deleteFilter"](id).ToString())
                        .Class("sf-line-button sf-remove")
                        .InnerHtml(new HtmlTag("span").Class("glyphicon glyphicon-remove")));
                    }
                }

                using (sb.SurroundLine(new HtmlTag("td")))
                {
                    sb.AddLine(new HtmlTag("input")
                        .Attr("type", "hidden")
                        .Attr("value", filterOptions.Token.FullKey())
                        .ToHtmlSelf());
                        
                    foreach (var t in filterOptions.Token.Follow(tok => tok.Parent).Reverse())
                    {
                        sb.AddLine(new HtmlTag("span")
                            .Class("sf-filter-token")
                            .Attr("title", t.NiceTypeName)
                            .Attr("style", "color:" + t.TypeColor)
                            .SetInnerText(t.ToString()).ToHtml());
                    }
                }

                using (sb.SurroundLine("td"))
                {
                    var dic = new Dictionary<string, object> { { "class", "form-control" } };
                    if (filterOptions.Frozen)
                        dic.Add("disabled", "disabled");

                    sb.AddLine(
                        helper.SafeDropDownList(
                        context.Compose("ddlSelector", index.ToString()),
                        possibleOperations.Select(fo =>
                            new SelectListItem
                            {
                                Text = fo.NiceToString(),
                                Value = fo.ToString(),
                                Selected = fo == filterOptions.Operation
                            }),
                            dic));
                }

                using (sb.SurroundLine("td"))
                {
                    Context valueContext = new Context(context, "value_" + index.ToString());

                    if (filterOptions.Frozen && !filterOptions.Token.Type.IsLite())
                    {
                        string txtValue = (filterOptions.Value != null) ? filterOptions.Value.ToString() : "";
                        sb.AddLine(helper.TextBox(valueContext.Prefix, txtValue, new { @readonly = "readonly" }));
                    }
                    else
                        sb.AddLine(PrintValueField(helper, valueContext, filterOptions));
                }
            }

            return sb.ToHtml();
        }
Exemple #46
0
        private static MvcHtmlString InternalStripElement <T>(this HtmlHelper helper, TypeElementContext <T> itemTC, EntityStrip entityStrip)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            if (entityStrip.IsVisible == null || entityStrip.IsVisible(itemTC))
            {
                using (sb.SurroundLine(new HtmlTag("li").IdName(itemTC.Compose(EntityStripKeys.StripElement)).Class("sf-strip-element input-group")))
                {
                    var lite = (itemTC.UntypedValue as Lite <IEntity>) ?? (itemTC.UntypedValue as IEntity)?.Let(i => i.ToLite(i.IsNew));

                    if (lite != null && (entityStrip.Navigate || entityStrip.View))
                    {
                        var dic = new Dictionary <string, object>
                        {
                            { "onclick", entityStrip.SFControlThen("viewItem_click(\"" + itemTC.Prefix + "\", event)") }
                        };

                        sb.AddLine(
                            helper.Href(itemTC.Compose(EntityBaseKeys.Link),
                                        lite.ToString(),
                                        "#",
                                        lite.ToString(), "sf-entitStrip-link", dic));
                    }
                    else
                    {
                        sb.AddLine(
                            helper.Span(itemTC.Compose(EntityBaseKeys.Link),
                                        itemTC.UntypedValue.ToString() ?? " ", "sf-entitStrip-link"));
                    }

                    sb.AddLine(EntityBaseHelper.WriteIndex(helper, itemTC));
                    sb.AddLine(helper.HiddenRuntimeInfo(itemTC));

                    if (EntityBaseHelper.EmbeddedOrNew((Modifiable)(object)itemTC.Value))
                    {
                        sb.AddLine(EntityBaseHelper.RenderPopup(helper, itemTC, RenderPopupMode.PopupInDiv, entityStrip));
                    }

                    using (sb.SurroundLine(new HtmlTag("span")))
                    {
                        if (entityStrip.Move)
                        {
                            sb.AddLine(EntityButtonHelper.MoveUpItem(helper, itemTC, entityStrip, btn: false, elementType: "a", isVertical: entityStrip.Vertical));
                            sb.AddLine(EntityButtonHelper.MoveDownItem(helper, itemTC, entityStrip, btn: false, elementType: "a", isVertical: entityStrip.Vertical));
                        }

                        if (entityStrip.View)
                        {
                            sb.AddLine(EntityButtonHelper.ViewItem(helper, itemTC, entityStrip, btn: false));
                        }

                        if (entityStrip.Remove)
                        {
                            sb.AddLine(EntityButtonHelper.RemoveItem(helper, itemTC, entityStrip, btn: false));
                        }
                    }
                }
            }
            else
            {
                using (sb.SurroundLine(new HtmlTag("li").IdName(itemTC.Compose(EntityStripKeys.StripElement)).Class("sf-strip-element input-group hidden")))
                {
                    sb.AddLine(EntityBaseHelper.WriteIndex(helper, itemTC));
                    sb.AddLine(helper.HiddenRuntimeInfo(itemTC));
                }
            }

            return(sb.ToHtml());
        }
Exemple #47
0
        public string Class { get; set; } //is applied to link

     
        public void Write(HtmlStringBuilder sb, string currentUrl, int depth)
        {
            if (!this.Visible)
                throw new InvalidOperationException("Invisible menu");

            bool isActive = this.Link != null && this.Link.ToString() == currentUrl ||
                children.HasItems() && children.Any(a => a.Link != null && a.Link.ToString() == currentUrl);

            bool isHeader = IsHeader(depth);

            using (sb.SurroundLine(new HtmlTag("li").Class(isActive ? "active" : null).Class(isHeader ? "dropdown-header" : this.children.HasItems() ? "dropdown" : null)))
            {
                if (Link != null)
                {
                    string link = Link.ToString();

                    if (ManualA != null)
                        sb.AddLine(ManualA(link, title, " ".CombineIfNotEmpty(Class, "selected")));
                    else
                    {
                        HtmlTag tbA = new HtmlTag("a")
                                .Attrs(new { href = link, title = Title, id = Id })
                                .Class(Class);

                        if (Html != null)
                            tbA.InnerHtml(Html);
                        else
                            tbA.SetInnerText(Text);

                        sb.AddLine(tbA.ToHtml());
                    }
                }
                else if (this.children.HasItems() && !isHeader)
                {
                    using (sb.SurroundLine(new HtmlTag("a").Attr("href", "#")
                        .Class("dropdown-toggle")
                        .Class(Class)
                        .Attr("data-toggle", "dropdown")))
                    {
                        if (Html != null)
                            sb.Add(Html);
                        else 
                            sb.Add(new HtmlTag("span").SetInnerText(Text));

                        sb.Add(new HtmlTag("b").Class("caret"));
                    }
                }
                else if (Html != null)
                    sb.AddLine(Html);
                else
                    sb.AddLine(new HtmlTag("span").SetInnerText(Text));

                if (this.children.HasItems() && !isHeader)
                {
                    using (sb.SurroundLine(new HtmlTag("ul").Class("dropdown-menu")))
                    {
                        bool lastHeader = false;
                        foreach (WebMenuItem menu in this.children)
                        {
                            if (menu.Visible)
                            {
                                if(lastHeader)
                                    sb.AddLine(new HtmlTag("li").Class("divider")); 

                                menu.Write(sb, currentUrl, depth + 1);

                                lastHeader = menu.IsHeader(depth + 1);
                            }
                        }
                    }
                }
            }

            if (isHeader)
            {
                foreach (WebMenuItem menu in this.children)
                {
                    if (menu.Visible)
                        menu.Write(sb, currentUrl, depth + 1);
                }

               
            }
        }