public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var selectListItems = new List <SelectListItem>();
            var kvList          = For?.Metadata.EnumGroupedDisplayNamesAndValues;

            if (kvList != null)
            {
                selectListItems = For.Metadata.EnumGroupedDisplayNamesAndValues.Select(a => new SelectListItem {
                    Text = a.Key.Name.ToString(), Value = a.Value.ToString(), Selected = a.Value == ((int)((For.Model) ?? -1)).ToString()
                }).ToList();
            }

            if (kvList == null && Data != null)
            {
                selectListItems = (List <SelectListItem>)Data;
            }

            var idStr = TagBuilder.CreateSanitizedId(For.Name,
                                                     _generator.IdAttributeDotReplacement);

            var tagBuilder = new StringBuilder(32);

            selectListItems.ForEach(item =>
            {
                var attributes = new Dictionary <string, object>
                {
                    { "title", item.Text },
                    { "lay-skin", "primary" }
                };
                var inputTagBuilder = _generator.GenerateCheckBox(ViewContext,
                                                                  For.ModelExplorer,
                                                                  For.Name,
                                                                  item.Value == (string)For.ModelExplorer.Model,
                                                                  attributes);
                tagBuilder.Append(inputTagBuilder.GetString());
            });

            var outpuHtml = $@"
              <label class='layui-form-label'>{Text ?? For.Metadata.DisplayName}</label>
            <div id='{idStr}_checkGroup' class='layui-input-block'>
              {tagBuilder}
            </div>";

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("class", InputDisplay.GetDisplayName());
            output.Attributes.Add("id", $"{idStr}_div");
            output.Content.SetHtmlContent(outpuHtml);
            if (kvList == null && !Url.IsNullOrEmpty())
            {
                output.PostElement.SetHtmlContent($@"<script type='text/javascript'>
                 $(function () {{
                    $('#{idStr}_checkGroup').bindCheckBoxData('{Url}','{For.Model}','{For.Name}');
                    }});
                </script>");
            }
        }
Exemple #2
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var modelExplorer = For.ModelExplorer;
            var attributes    = new Dictionary <string, object>
            {
                { PlaceholderAttributeName, Placeholder ?? modelExplorer.Metadata.Description ?? modelExplorer.Metadata.DisplayName },
                { "class", "layui-input" },
                { "type", Type.ToString() }
            };

            if (modelExplorer.Metadata != null && modelExplorer.Metadata.IsRequired)
            {
                attributes["required"] = "required";
            }
            if (Disabled)
            {
                attributes["Disabled"] = "Disabled";
            }

            var value = modelExplorer.Model ?? Value;

            var inputTagBuilder = _generator.GenerateTextBox(ViewContext, modelExplorer, For.Name, value, Format, attributes);

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Content.SetHtmlContent(inputTagBuilder);
            output.Attributes.Add("class", InputDisplay.GetDisplayName());
        }
Exemple #3
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var kvList          = Data.GetKeyValueList();
            var selectListItems = kvList.Select(a => new SelectListItem {
                Text = a.Key, Value = a.Value.ToString(), Selected = a.Value == (int)(For.Model ?? -1)
            }).ToList();

            if (!DefaultText.IsNullOrEmpty())
            {
                selectListItems.Insert(0, new SelectListItem {
                    Text = DefaultText, Value = ""
                });
            }
            var tagBuilder = _generator.GenerateSelect(ViewContext, For.ModelExplorer, null, For.Name, selectListItems, null, false, null);

            output.Content.AppendHtml(tagBuilder);
            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("class", InputDisplay.GetDisplayName());

            var idStr = NameAndIdProvider.CreateSanitizedId(ViewContext, For.Name,
                                                            _generator.IdAttributeDotReplacement);

            if (Data == null && !Url.IsNullOrEmpty())
            {
                output.PostElement.SetHtmlContent(string.Format(@"<script type='text/javascript'>
                 $(function () {{
                    $('#{0}').bindSelectData('{1}','{2}');
                    }});
                </script>", idStr, Url, For.Model));
            }
        }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var modelExplorer = For.ModelExplorer;
            var attributes    = new Dictionary <string, object>
            {
                { PlaceholderAttributeName, Placeholder ?? modelExplorer.Metadata.Description ?? modelExplorer.Metadata.DisplayName },
                { "class", "layui-input" }
            };

            if (modelExplorer.Metadata != null && modelExplorer.Metadata.IsRequired)
            {
                attributes["required"] = "required";
            }

            var value = modelExplorer.Model ?? Value;

            if (value is DateTime)
            {
                value = ((DateTime)value).ToString(DateTimeType.GetDisplayName());
            }
            var inputTagBuilder = _generator.GenerateTextBox(ViewContext,
                                                             modelExplorer,
                                                             For.Name,
                                                             value,
                                                             Format,
                                                             attributes);



            var dateTimeTypeStr = DateTimeType.ToString();
            var idStr           = TagBuilder.CreateSanitizedId(For.Name,
                                                               _generator.IdAttributeDotReplacement);

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("id", $"{idStr}_div");
            output.Attributes.Add("class", InputDisplay.GetDisplayName());
            output.Content.SetHtmlContent(inputTagBuilder);

            output.PostElement.SetHtmlContent($@"<script type='text/javascript'>
             layui.use('laydate',
                    function () {{
                        var laydate = layui.laydate;
                        laydate.render({{
                            elem: '#{idStr}',
                            type: '{dateTimeTypeStr}'
                        }});
                    }});
            </script>");
        }
Exemple #5
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var selectListItems = new List <SelectListItem>();
            var kvList          = For?.Metadata.EnumGroupedDisplayNamesAndValues;

            if (kvList != null)
            {
                selectListItems = For.Metadata.EnumGroupedDisplayNamesAndValues.Select(a => new SelectListItem
                {
                    Text  = a.Key.Name.ToString(),
                    Value = a.Value.TryInt().ToString()
                }).ToList();
            }

            if (kvList == null && Data != null)
            {
                selectListItems = ((IEnumerable <SelectListItem>)Data).ToList();
            }

            if (!DefaultText.IsNullOrWhiteSpace())
            {
                selectListItems.Insert(0, new SelectListItem {
                    Text = DefaultText, Value = ""
                });
            }

            var idStr      = TagBuilder.CreateSanitizedId(For.Name, _generator.IdAttributeDotReplacement);
            var attributes = new Dictionary <string, object>
            {
                { "lay-search", "" },
                { "lay-filter", idStr }
            };

            var cValue = For.Metadata.IsEnum ? ((int)(For.Model ?? 0)).ToStr() : For.Model.ToStr();

            selectListItems.ForEach(item =>
            {
                item.Selected = For.Model != null && item.Value == cValue;
            });

            var tagBuilder = _generator.GenerateSelect(ViewContext, For.ModelExplorer, null, For.Name, selectListItems, null, false, attributes);

            var outpuHtml = $@"
              <label class='layui-form-label'>{Text ?? For.Metadata.DisplayName}</label>
            <div class='layui-input-block'>
              {tagBuilder.GetString().Replace("&amp;nbsp;", "&nbsp;")}
            </div>";

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("id", $"{idStr}_div");
            output.Attributes.Add("class", InputDisplay.GetDisplayName());
            output.Content.SetHtmlContent(outpuHtml);
            if (kvList == null && !Url.IsNullOrEmpty())
            {
                output.PostElement.SetHtmlContent($@"<script type='text/javascript'>
                 $(function () {{
                    $('#{idStr}').bindSelectData('{Url}','{For.Model}');
                    }});
                </script>");
            }
        }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            context.ThrowIfNull();
            output.ThrowIfNull();

            var selectListItems = new List <SelectListItem>();
            var kvList          = For?.Metadata.EnumGroupedDisplayNamesAndValues;

            if (kvList != null)
            {
                selectListItems = For.Metadata.EnumGroupedDisplayNamesAndValues.Select(a => new SelectListItem
                {
                    Text  = a.Key.Name.ToString(),
                    Value = a.Value.ToString()
                }).ToList();
            }

            if (kvList == null && Data != null)
            {
                selectListItems = ((IEnumerable <SelectListItem>)Data).ToList();
            }

            if (!DefaultText.IsNullOrWhiteSpace())
            {
                selectListItems.Insert(0, new SelectListItem {
                    Text = DefaultText, Value = ""
                });
            }

            var idStr      = NameAndIdProvider.CreateSanitizedId(ViewContext, For.Name, _generator.IdAttributeDotReplacement);
            var attributes = new Dictionary <string, object>
            {
                { "xm-select", idStr },
                { "xm-select-skin", "default" }
            };

            IList l = new ArrayList();

            if (For.Model != null)
            {
                l = (IList)For.Model;
            }

            selectListItems.ForEach(item =>
            {
                item.Selected = For.Model != null && l.Contains(item.Value);
            });

            var tagBuilder = _generator.GenerateSelect(ViewContext, For.ModelExplorer, null, For.Name, selectListItems, null, false, attributes);

            var outpuHtml = $@"
              <label class='layui-form-label'>{Text ?? For.Metadata.DisplayName}</label>
            <div class='layui-input-block'>
              {tagBuilder.GetString().Replace("&amp;nbsp;", "&nbsp;")}
            </div>";

            output.TagName = "div";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Attributes.Add("id", $"{idStr}_div");
            output.Attributes.Add("class", InputDisplay.GetDisplayName());
            output.Content.SetHtmlContent(outpuHtml);

            var jsValue = l.Cast <object>().Aggregate("", (current, t) => current + (t + ",")).TrimEnd(',');

            if (kvList == null && !Url.IsNullOrEmpty())
            {
                output.PostElement.SetHtmlContent($@"<script type='text/javascript'>
                 $(function () {{
                    $('#{idStr}').bindMultiSelectData('{Url}','{jsValue}','{idStr}');
                    }});
                </script>");
            }
        }