Exemplo n.º 1
0
        private static TagBuilder CreateLookup(MvcLookup lookup, String name, Object?htmlAttributes)
        {
            IDictionary <String, Object?> attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            attributes["data-filters"]  = String.Join(",", lookup.AdditionalFilters);
            attributes["data-search"]   = lookup.Filter.Search;
            attributes["data-offset"]   = lookup.Filter.Offset;
            attributes["data-order"]    = lookup.Filter.Order;
            attributes["data-readonly"] = lookup.ReadOnly;
            attributes["data-sort"]     = lookup.Filter.Sort;
            attributes["data-rows"]     = lookup.Filter.Rows;
            attributes["data-dialog"]   = lookup.Dialog;
            attributes["data-title"]    = lookup.Title;
            attributes["data-multi"]    = lookup.Multi;
            attributes["data-url"]      = lookup.Url;
            attributes["data-for"]      = name;

            TagBuilder group = new TagBuilder("div");

            group.MergeAttributes(attributes);
            group.AddCssClass("mvc-lookup");

            if (lookup.ReadOnly)
            {
                group.AddCssClass("mvc-lookup-readonly");
            }

            return(group);
        }
Exemplo n.º 2
0
        public static IHtmlContent AutoComplete <TModel>(this IHtmlHelper <TModel> html,
                                                         String name, Object value, MvcLookup model, Object htmlAttributes = null)
        {
            HtmlContentBuilder autocomplete = new HtmlContentBuilder();

            autocomplete.AppendHtml(FormAutoComplete(html, model, name, htmlAttributes));
            autocomplete.AppendHtml(FormHiddenInput(html, name, value));

            return(autocomplete);
        }
Exemplo n.º 3
0
        public static IHtmlContent Lookup <TModel>(this IHtmlHelper <TModel> html,
                                                   String name, Object value, MvcLookup model, Object htmlAttributes = null)
        {
            TagBuilder lookup = new TagBuilder("div");

            lookup.InnerHtml.AppendHtml(html.AutoComplete(name, value, model, htmlAttributes));
            lookup.InnerHtml.AppendHtml(FormLookupOpenSpan());
            lookup.AddCssClass("input-group");

            return(lookup);
        }
Exemplo n.º 4
0
        public static TagBuilder Lookup <TModel>(this IHtmlHelper <TModel> html,
                                                 String name, MvcLookup model, Object?value = null, Object?htmlAttributes = null)
        {
            TagBuilder lookup = CreateLookup(model, name, htmlAttributes);

            lookup.InnerHtml.AppendHtml(CreateLookupValues(html, model, name, value));
            lookup.InnerHtml.AppendHtml(CreateLookupControl(html, model, name));
            lookup.InnerHtml.AppendHtml(CreateLookupBrowser(name));

            return(lookup);
        }
Exemplo n.º 5
0
        public static TagBuilder AutoComplete <TModel>(this IHtmlHelper <TModel> html,
                                                       String name, MvcLookup model, Object?value = null, Object?htmlAttributes = null)
        {
            TagBuilder lookup = CreateLookup(model, name, htmlAttributes);

            lookup.AddCssClass("mvc-lookup-browseless");

            lookup.InnerHtml.AppendHtml(CreateLookupValues(html, model, name, value));
            lookup.InnerHtml.AppendHtml(CreateLookupControl(html, model, name));

            return(lookup);
        }
Exemplo n.º 6
0
        private static IHtmlContent CreateLookupControl(IHtmlHelper html, MvcLookup lookup, String name)
        {
            TagBuilder search = new TagBuilder("input")
            {
                TagRenderMode = TagRenderMode.SelfClosing
            };
            Dictionary <String, Object> attributes = new Dictionary <String, Object>();
            TagBuilder control = new TagBuilder("div");
            TagBuilder loader  = new TagBuilder("div");
            TagBuilder error   = new TagBuilder("div");

            if (lookup.Name != null)
            {
                attributes["id"] = ExpressionHelper.GetExpressionText(lookup.Name);
            }
            if (lookup.Placeholder != null)
            {
                attributes["placeholder"] = lookup.Placeholder;
            }
            if (lookup.Name != null)
            {
                attributes["name"] = lookup.Name;
            }
            if (lookup.ReadOnly)
            {
                attributes["readonly"] = "readonly";
            }
            attributes["class"]        = "mvc-lookup-input";
            attributes["autocomplete"] = "off";

            loader.AddCssClass("mvc-lookup-control-loader");
            error.AddCssClass("mvc-lookup-control-error");
            control.AddCssClass("mvc-lookup-control");
            control.Attributes["data-for"] = name;
            search.MergeAttributes(attributes);
            error.InnerHtml.Append("!");

            if (lookup.Name != null)
            {
                control.InnerHtml.AppendHtml(html.TextBox(lookup.Name, null, attributes));
            }
            else
            {
                control.InnerHtml.AppendHtml(search);
            }
            control.InnerHtml.AppendHtml(loader);
            control.InnerHtml.AppendHtml(error);

            return(control);
        }
Exemplo n.º 7
0
        private static IHtmlContent CreateLookupValues(IHtmlHelper html, MvcLookup lookup, String name, Object?value)
        {
            IDictionary <String, Object> attributes = new Dictionary <String, Object>
            {
                ["class"]        = "mvc-lookup-value",
                ["autocomplete"] = "off"
            };

            TagBuilder container = new TagBuilder("div");

            container.AddCssClass("mvc-lookup-values");
            container.Attributes["data-for"] = name;

            if (lookup.Multi)
            {
                IEnumerable <Object>?values = (value as IEnumerable)?.Cast <Object>();
                if (values == null)
                {
                    return(container);
                }

                IHtmlContentBuilder inputs = new HtmlContentBuilder();
                foreach (Object val in values)
                {
                    TagBuilder input = new TagBuilder("input");
                    input.Attributes["value"] = html.FormatValue(val, null);
                    input.TagRenderMode       = TagRenderMode.SelfClosing;
                    input.Attributes["type"]  = "hidden";
                    input.MergeAttributes(attributes);
                    input.Attributes["name"] = name;

                    inputs.AppendHtml(input);
                }

                container.InnerHtml.AppendHtml(inputs);
            }
            else
            {
                container.InnerHtml.AppendHtml(html.Hidden(name, value, attributes));
            }

            return(container);
        }
Exemplo n.º 8
0
        private static IHtmlContent FormAutoComplete(IHtmlHelper html, MvcLookup model, String hiddenInput, Object htmlAttributes)
        {
            IDictionary <String, Object> attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            if (attributes.ContainsKey("class"))
            {
                attributes["class"] = $"{attributes["class"]} form-control mvc-lookup-input".Trim();
            }
            else
            {
                attributes["class"] = "form-control mvc-lookup-input";
            }
            attributes.Add("data-mvc-lookup-for", TagBuilder.CreateSanitizedId(hiddenInput, html.IdAttributeDotReplacement));
            attributes.Add("data-mvc-lookup-filters", String.Join(",", model.AdditionalFilters));
            attributes.Add("data-mvc-lookup-sort-column", model.Filter.SortColumn);
            attributes.Add("data-mvc-lookup-sort-order", model.Filter.SortOrder);
            attributes.Add("data-mvc-lookup-search", model.Filter.Search);
            attributes.Add("data-mvc-lookup-page", model.Filter.Page);
            attributes.Add("data-mvc-lookup-rows", model.Filter.Rows);
            attributes.Add("data-mvc-lookup-title", model.Title);
            attributes.Add("data-mvc-lookup-url", model.Url);

            return(html.TextBox(hiddenInput + MvcLookup.Prefix, null, attributes));
        }
Exemplo n.º 9
0
        public static IHtmlContent LookupFor <TModel, TProperty>(this IHtmlHelper <TModel> html,
                                                                 Expression <Func <TModel, TProperty> > expression, MvcLookup model, Object htmlAttributes = null)
        {
            TagBuilder inputGroup = new TagBuilder("div");

            inputGroup.AddCssClass("input-group");
            inputGroup.InnerHtml.AppendHtml(html.AutoCompleteFor(expression, model, htmlAttributes));
            inputGroup.InnerHtml.AppendHtml(FormLookupOpenSpan());

            return(inputGroup);
        }
Exemplo n.º 10
0
        public static IHtmlContent AutoCompleteFor <TModel, TProperty>(this IHtmlHelper <TModel> html,
                                                                       Expression <Func <TModel, TProperty> > expression, MvcLookup model, Object htmlAttributes = null)
        {
            String             name         = ExpressionHelper.GetExpressionText(expression);
            HtmlContentBuilder autocomplete = new HtmlContentBuilder();

            autocomplete.AppendHtml(FormAutoComplete(html, model, name, htmlAttributes));
            autocomplete.AppendHtml(FormHiddenInputFor(html, expression));

            return(autocomplete);
        }
Exemplo n.º 11
0
        private static IHtmlContent CreateLookupValues <TModel, TProperty>(IHtmlHelper <TModel> html, MvcLookup lookup, Expression <Func <TModel, TProperty> > expression)
        {
            Object value = LookupExpressionMetadata.GetValue(html, expression).Model;
            String name  = LookupExpressionMetadata.GetName(expression);

            if (lookup.Multi)
            {
                return(CreateLookupValues(html, lookup, name, value));
            }

            IDictionary <String, Object> attributes = new Dictionary <String, Object>
            {
                ["class"]        = "mvc-lookup-value",
                ["autocomplete"] = "off"
            };

            TagBuilder container = new TagBuilder("div");

            container.AddCssClass("mvc-lookup-values");
            container.Attributes["data-for"] = name;

            container.InnerHtml.AppendHtml(html.HiddenFor(expression, attributes));

            return(container);
        }
Exemplo n.º 12
0
        public static TagBuilder LookupFor <TModel, TProperty>(this IHtmlHelper <TModel> html,
                                                               Expression <Func <TModel, TProperty> > expression, MvcLookup model, Object?htmlAttributes = null)
        {
            String     name   = LookupExpressionMetadata.GetName(expression);
            TagBuilder lookup = CreateLookup(model, name, htmlAttributes);

            lookup.InnerHtml.AppendHtml(CreateLookupValues(html, model, expression));
            lookup.InnerHtml.AppendHtml(CreateLookupControl(html, model, name));
            lookup.InnerHtml.AppendHtml(CreateLookupBrowser(name));

            return(lookup);
        }
Exemplo n.º 13
0
        public static TagBuilder AutoCompleteFor <TModel, TProperty>(this IHtmlHelper <TModel> html,
                                                                     Expression <Func <TModel, TProperty> > expression, MvcLookup model, Object htmlAttributes = null)
        {
            String     name   = ExpressionHelper.GetExpressionText(expression);
            TagBuilder lookup = CreateLookup(model, name, htmlAttributes);

            lookup.AddCssClass("mvc-lookup-browseless");

            lookup.InnerHtml.AppendHtml(CreateLookupValues(html, model, expression));
            lookup.InnerHtml.AppendHtml(CreateLookupControl(html, model, name));

            return(lookup);
        }
Exemplo n.º 14
0
        public virtual JsonResult GetData(MvcLookup lookup, LookupFilter filter)
        {
            lookup.Filter = filter;

            return Json(lookup.GetData());
        }