Пример #1
0
        public static MvcHtmlString ExtDisplayNumberFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                         Expression <Func <TModel, TValue> > expression, NumberOptionLarge option = null, object htmlAttributes = null)
        {
            var html = htmlAttributes == null
                ? new RouteValueDictionary()
                : new RouteValueDictionary(htmlAttributes);
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(htmlHelper.ExtDisplayWidthId(expression, html).ToString());
            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            if (html.ContainsKey("id"))
            {
                var tempId = html["id"].ToString();
                if (!string.IsNullOrEmpty(tempId))
                {
                    controlId = tempId;
                }
            }
            stringBuilder.AppendLine("<script>$(function(){");
            var options = new List <string>()
            {
                "aSep: ','",
                "aDec: '.'"
            };

            if (option != null)
            {
                if (option.Min.HasValue)
                {
                    options.Add($"vMin: '{option.Min.Value}'");
                }
                if (option.Max.HasValue)
                {
                    options.Add($"vMax: '{option.Max.Value}'");
                }
                if (!string.IsNullOrEmpty(option.ASign))
                {
                    options.Add($"aSign: '{option.ASign}'");
                }
                if (!string.IsNullOrEmpty(option.PSign))
                {
                    options.Add($"pSign: '{option.PSign}'");
                }
                if (option.NumberOfDecimal.HasValue)
                {
                    options.Add($"mDec : {option.NumberOfDecimal.Value}");
                }
                if (!option.APad)
                {
                    options.Add($"aPad : {Convert.ToBoolean("false")}");
                }
            }
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine($"$('#{controlId}').autoNumeric('init', {{{optionsStr}}});");
            stringBuilder.AppendLine("});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
Пример #2
0
        private static IHtmlContent CreateTableHtmlIpsum <T>(IList <T> data, object tableAttributes) where T : new()
        {
            TagBuilder table = new TagBuilder("table");

            table.InnerHtml.SetHtmlContent(BuildTableHeader <T>());

            TagBuilder tbody = new TagBuilder("tbody");

            foreach (var item in data)
            {
                TagBuilder tr = new TagBuilder("tr");
                foreach (var property in typeof(T).GetProperties())
                {
                    TagBuilder td = new TagBuilder("td");
                    td.InnerHtml.SetContent(property.GetValue(item).ToString());
                    tr.InnerHtml.AppendHtml(td);
                }
                tbody.InnerHtml.AppendHtml(tr);
            }
            table.MergeAttributes(HtmlAttributeHelper.GetHtmlAttributeDictionaryOrNull(tableAttributes));
            //table.MergeAttribute("class", "", false);
            table.InnerHtml.AppendHtml(tbody);

            return(table);
        }
Пример #3
0
        public static MvcHtmlString ExtNumberFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                  Expression <Func <TModel, TValue> > expression, NumberOption option = null, object htmlAttributes = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            html = HtmlAttributeHelper.AddMaxLength(html, maxLength != 0 ? maxLength : 255);

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>$(function(){");
            var options = new List <string>()
            {
                "aSep: ''",
                "aDec: '.'"
            };

            if (option != null)
            {
                if (option.Min.HasValue)
                {
                    options.Add($"vMin: '{option.Min.Value}'");
                }
                if (option.Max.HasValue)
                {
                    options.Add($"vMax: '{option.Max.Value}'");
                }
                if (!string.IsNullOrEmpty(option.ASign))
                {
                    options.Add($"aSign: '{option.ASign}'");
                }
                if (!string.IsNullOrEmpty(option.PSign))
                {
                    options.Add($"pSign: '{option.PSign}'");
                }
                if (!string.IsNullOrEmpty(option.MRound))
                {
                    options.Add($"mRound: '{option.MRound}'");
                }
                if (option.NumberOfDecimal.HasValue)
                {
                    options.Add($"mDec : {option.NumberOfDecimal.Value}");
                }
                if (!option.APad)
                {
                    options.Add("aPad : false");
                }
            }
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine($"$('#{controlId}').autoNumeric('init', {{{optionsStr}}});");
            stringBuilder.AppendLine("});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
Пример #4
0
        public static MvcHtmlString ExtDropDownListFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                        Expression <Func <TModel, TValue> > expression, IEnumerable <SelectListItem> selectList,
                                                                        string optionLabel = null, object htmlAttributes = null)
        {
            var html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     htmlHelper.DropDownListFor(expression, selectList, optionLabel, html).ToString(), expression));
        }
Пример #5
0
        public static MvcHtmlString ExtTextBoxFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                   Expression <Func <TModel, TValue> > expression, object htmlAttributes = null, string format = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            html = HtmlAttributeHelper.AddMaxLength(html, maxLength != 0 ? maxLength : 255);

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     !string.IsNullOrEmpty(format)
                    ? htmlHelper.TextBoxFor(expression, format, html).ToString()
                    : htmlHelper.TextBoxFor(expression, html).ToString(), expression));
        }
Пример #6
0
        public static WireframeGenerator Image(this WireframeGenerator gen,
                                               int width,
                                               int height,
                                               string text            = null,
                                               string backgroundColor = null,
                                               string textColor       = null,
                                               object htmlAttributes  = null,
                                               ImgFormat format       = ImgFormat.GIF)
        {
            var img = new TagBuilder("img");

            img.TagRenderMode = TagRenderMode.SelfClosing;
            img.Attributes.Add("src", PlaceholditUrlBuilder.UrlFor(width, height, text, backgroundColor, textColor));
            img.MergeAttributes(HtmlAttributeHelper.GetHtmlAttributeDictionaryOrNull(htmlAttributes));
            return(gen.Add(img));
        }
Пример #7
0
        public static MvcHtmlString ExtTextAreaFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                    Expression <Func <TModel, TValue> > expression, object htmlAttributes = null)
        {
            var html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);

            html = HtmlAttributeHelper.AddTextAreaStyle(html);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     htmlHelper.TextAreaFor(expression, html).ToString(), expression));
        }
Пример #8
0
        public static MvcHtmlString ExtDisplayWidthId <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                       Expression <Func <TModel, TValue> > expression, object htmlAttributes = null)
        {
            var spanBuilder = new TagBuilder("span");
            var controlId   = HtmlAttributeHelper.GetControlIdFromExpression(expression);
            var htmlAttributesDictionary = htmlAttributes as RouteValueDictionary;

            if (htmlAttributesDictionary != null && htmlAttributesDictionary.ContainsKey("id"))
            {
                var tempId = htmlAttributesDictionary["id"].ToString();
                if (!string.IsNullOrEmpty(tempId))
                {
                    controlId = tempId;
                }
            }
            var style = string.Empty;

            if (htmlAttributesDictionary != null && htmlAttributesDictionary.ContainsKey("style"))
            {
                var tempStyle = htmlAttributesDictionary["style"].ToString();
                if (!string.IsNullOrEmpty(tempStyle))
                {
                    style = tempStyle;
                }
            }
            var cssClass = string.Empty;

            if (htmlAttributesDictionary != null && htmlAttributesDictionary.ContainsKey("class"))
            {
                var tempClass = htmlAttributesDictionary["class"].ToString();
                if (!string.IsNullOrEmpty(tempClass))
                {
                    cssClass = tempClass;
                }
            }
            if (!string.IsNullOrEmpty(cssClass))
            {
                spanBuilder.AddCssClass(cssClass);
            }
            spanBuilder.MergeAttribute("id", controlId);
            spanBuilder.MergeAttribute("style",
                                       !string.IsNullOrEmpty(style) ? style : "display: block;text-align: right");

            spanBuilder.SetInnerText(htmlHelper.DisplayFor(expression, htmlAttributes).ToString());

            return(new MvcHtmlString(spanBuilder.ToString()));
        }
Пример #9
0
        public static MvcHtmlString ExtLabelWithDefaultClassFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                                 Expression <Func <TModel, TValue> > expression, bool checkRequired = true, object htmlAttributes = null)
        {
            var propertyName = ExpressionHelper.GetExpressionText(expression);
            var property     = htmlHelper.ViewData.ModelMetadata.Properties.First(p => p.PropertyName == propertyName);
            var displayName  = string.IsNullOrEmpty(property.DisplayName) ? propertyName : property.DisplayName;

            if (checkRequired && expression.IsRequired())
            {
                displayName += "<i class=\"required\">*</i>";
            }

            var html = HtmlAttributeHelper.AddDefaultClassForLabel(htmlAttributes);

            var tempInput = htmlHelper.LabelFor(expression, "#?replace?#", html).ToString();

            tempInput = tempInput.Replace("#?replace?#", displayName);
            return(new MvcHtmlString(tempInput));
        }
Пример #10
0
        public static MvcHtmlString ExtEditorFullFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                      Expression <Func <TModel, IEnumerable <TValue> > > expression, bool readOnly = false, object htmlAttributes = null)
        {
            var html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);

            html = HtmlAttributeHelper.AddTextAreaStyle(html);

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(htmlHelper.TextAreaFor(expression, html).ToString());


            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>");
            stringBuilder.AppendLine(readOnly
                ? $"CKEDITOR.replace('{controlId}', {{ readOnly: true }})"
                : $"CKEDITOR.replace('{controlId}')");
            stringBuilder.AppendLine("</script>");

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper, stringBuilder.ToString(), expression));
        }
Пример #11
0
        private static IHtmlContent GenerateListHtmlIpsum(string outer, string inner, int listCount, bool links, object liAttributes, int wordCount, object ulAttributes)
        {
            TagBuilder element = new TagBuilder(outer);

            for (int i = 0; i < listCount; i++)
            {
                if (links)
                {
                    TagBuilder li = new TagBuilder(inner);
                    li.MergeAttributes(HtmlAttributeHelper.GetHtmlAttributeDictionaryOrNull(liAttributes));
                    li.InnerHtml.SetHtmlContent(WireframeGenerator.GenerateHtmlIpsum("a", () => Lorem.GenerateWords(wordCount), HtmlAttributeHelper.GetHtmlAttributeDictionaryOrNull(new { href = "#" })));
                    element.InnerHtml.AppendHtml(li);
                }
                else
                {
                    element.InnerHtml.AppendHtml(WireframeGenerator.GenerateHtmlIpsum(inner, () => Lorem.GenerateWords(wordCount), liAttributes));
                }
            }
            element.MergeAttributes(HtmlAttributeHelper.GetHtmlAttributeDictionaryOrNull(ulAttributes));

            return(element);
        }
Пример #12
0
        public StoreLiquidResult GetPaging(PageDesign pageDesign)
        {
            var paginator = new PaginatorLiquid();

            paginator.PaginatePath = this.PaginatePath;
            var pageOutputDictionary = PageOutput.LiquidRenderedResult;

            if (pageOutputDictionary.ContainsKey(StoreConstants.PageNumber))
            {
                paginator.Page = pageOutputDictionary[StoreConstants.PageNumber].ToInt();
            }
            else
            {
                Logger.Error("Key NOT FOUND :" + StoreConstants.PageNumber);
            }

            if (pageOutputDictionary.ContainsKey(StoreConstants.TotalItemCount))
            {
                paginator.TotalRecords = pageOutputDictionary[StoreConstants.TotalItemCount].ToInt();
            }
            else
            {
                Logger.Error("Key NOT FOUND :" + StoreConstants.TotalItemCount);
            }

            if (pageOutputDictionary.ContainsKey(StoreConstants.PageSize))
            {
                paginator.PageSize = pageOutputDictionary[StoreConstants.PageSize].ToInt();
            }
            else
            {
                Logger.Error("Key NOT FOUND :" + StoreConstants.PageSize);
            }


            object anonymousObject = new
            {
                paginator = paginator
            };
            var pagingHtml = LiquidEngineHelper.RenderPage(pageDesign, anonymousObject);



            //var pagingDic = new Dictionary<String, String>();
            //pagingDic.Add(StoreConstants.PagingOutput, indexPageOutput);
            //pagingDic = pagingDic.MergeLeft(pageOutputDictionary);
            String html = "";

            if (pageOutputDictionary.ContainsKey(StoreConstants.PageOutput))
            {
                html = pageOutputDictionary[StoreConstants.PageOutput];
            }
            else
            {
                Logger.Error("Key NOT FOUND :" + StoreConstants.PageOutput);
            }


            pageOutputDictionary[StoreConstants.PageOutput] = HtmlAttributeHelper.AddPaging(html, pagingHtml);

            //PageOutput.LiquidRenderedResult = pagingDic;
            return(PageOutput);
        }
Пример #13
0
        public static MvcHtmlString ExtDateTimeFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                    Expression <Func <TModel, TValue> > expression, DateTimeOption option = null, object htmlAttributes = null)
        {
            var html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            // html.Add("onkeydown", "return false");
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }
            var controlId     = HtmlAttributeHelper.GetControlIdFromExpression(expression);
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("<div class='input-group date ' id='dv" + controlId + "'>");
            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());



            var options = new List <string>();

            if (option != null)
            {
                if (!string.IsNullOrEmpty(option.ViewMode))
                {
                    options.Add(string.Format("viewMode: '{0}'", option.ViewMode));
                }
                if (!string.IsNullOrEmpty(option.Format))
                {
                    options.Add(string.Format("format: '{0}'", option.Format));
                    if (option.Format == "LT" || option.Format == "HH:mm" || option.Format == "HH:mm:ss")
                    {
                        stringBuilder.AppendLine("<span class='input-group-addon'><span class='glyphicon glyphicon-time'></span></span>");
                    }
                    else
                    {
                        stringBuilder.AppendLine("<span class='input-group-addon'><span class='glyphicon glyphicon-calendar'></span></span>");
                    }
                }
                if (option.DaysOfWeekDisabled != null)
                {
                    options.Add(string.Format("daysOfWeekDisabled: {0}", option.DaysOfWeekDisabled));
                }
                if (!string.IsNullOrEmpty(option.MinDate))
                {
                    options.Add(string.Format("minDate: {0}", option.MinDate));
                }
                else
                {
                    options.Add(string.Format("minDate: {0}", " moment('01/01/1990')"));
                }
                if (!string.IsNullOrEmpty(option.MaxDate))
                {
                    options.Add(string.Format("maxDate: {0}", option.MaxDate));
                }
                if (option.EnabledHours.HasValue)
                {
                    options.Add(string.Format("enabledHours : '{0}'", option.EnabledHours.Value));
                }
                if (option.ViewDate.HasValue)
                {
                    options.Add(string.Format("viewDate : {0}", option.ViewDate.Value));
                }
                if (option.Inline.HasValue)
                {
                    options.Add(string.Format("inline : {0}", option.Inline.Value));
                }
                // options.Add(string.Format("defaultDate:{0}", DateTime.Now.ToString("d")));
            }
            stringBuilder.AppendLine("</div><script>$(function(){");
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine(string.Format("$('#dv{0}').datetimepicker( {{{1}}});", controlId, optionsStr));
            //stringBuilder.AppendLine(string.Format("$('#{0}').datetimepicker('setDate',{1});", controlId,string.Format( "$('#{0}').val()",controlId)));
            stringBuilder.AppendLine("});</script>");

            if (option != null && option.IsValidationMessageSupported)
            {
                return(new MvcHtmlString(stringBuilder.ToString()));
            }
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
Пример #14
0
        public static MvcHtmlString ExtMultiSuggestionFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                           Expression <Func <TModel, TValue> > expression, MultiSuggestionOption option, object htmlAttributes = null)
        {
            var html = htmlAttributes == null
                ? new RouteValueDictionary()
                : new RouteValueDictionary(htmlAttributes);
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>$(function(){");
            stringBuilder.AppendLine($"$('#{controlId}').tokenInput('{option.SearchUrl}',{{");
            stringBuilder.AppendLine("theme: 'facebook',");
            if (option.LimitedItem != 0)
            {
                stringBuilder.AppendLine($"tokenLimit: {option.LimitedItem},");
            }
            stringBuilder.AppendLine("method: 'POST',");
            stringBuilder.AppendLine("queryParam: 'query',");
            stringBuilder.AppendLine("tokenValue: 'Id',");
            stringBuilder.AppendLine($"required: {expression.IsRequired().ToString().ToLower()},");
            stringBuilder.AppendLine("propertyToSearch: 'Name',");
            stringBuilder.AppendLine("preventDuplicates: true,");
            stringBuilder.AppendLine("minChars: " + option.MinChars + ",");
            if (option.DefaultValues != null)
            {
                stringBuilder.AppendLine(
                    $"prePopulate: {JsonConvert.SerializeObject(option.DefaultValues).Replace("/", "\\/")},");
            }

            if (!string.IsNullOrEmpty(option.OnAdd))
            {
                stringBuilder.AppendLine($"onAdd: {option.OnAdd},");
            }

            if (!string.IsNullOrEmpty(option.OnDelete))
            {
                stringBuilder.AppendLine($"onDelete: {option.OnDelete},");
            }

            if (!string.IsNullOrEmpty(option.AdditionalParam))
            {
                stringBuilder.AppendLine($"additionalParam: {option.AdditionalParam},");
            }
            if (option.LocalData != null)
            {
                stringBuilder.AppendLine(
                    $"local_data: {JsonConvert.SerializeObject(option.LocalData)},");
            }
            if (option.CreateNew.HasValue)
            {
                stringBuilder.AppendLine($"createNew: {option.CreateNew.Value.ToString().ToLower()},");
            }
            if (!string.IsNullOrEmpty(option.OnResult))
            {
                stringBuilder.AppendLine($"onResult: {option.OnResult},");
            }

            stringBuilder.AppendLine("});});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }