Esempio n. 1
0
        public static IHtmlContent RAToolbarShowDialogButton(
            this IHtmlHelper htmlHelper,
            string buttonText,
            string contentUrl,
            string returnUrl             = null,
            object htmlAttributes        = null,
            string dialogTitle           = null,
            bool showActionButton        = true,
            string actionButtonCaption   = "Save",
            bool showCancelButton        = true,
            string cancelButtonCaption   = "Cancel",
            string buttonClass           = "btn-secondary",
            string buttonStyle           = null,
            RAModalDialogSize dialogSize = RAModalDialogSize.Medium)
        {
            var attributes = HtmlHelperHelper.ToAttributesDictionary(htmlAttributes);

            attributes.AddToolbarButtonAttributes();

            return(htmlHelper.RAShowModalDialogButton(
                       buttonText,
                       contentUrl,
                       returnUrl,
                       attributes,
                       dialogTitle,
                       showActionButton,
                       actionButtonCaption,
                       showCancelButton,
                       cancelButtonCaption,
                       buttonClass,
                       buttonStyle,
                       dialogSize));
        }
        public static IHtmlContent RAShowDialogLink(
            this IHtmlHelper htmlHelper,
            string linkText,
            string contentUrl,
            string returnAction          = null,
            object htmlAttributes        = null,
            string dialogTitle           = null,
            bool showActionButton        = true,
            string actionButtonCaption   = "Save",
            bool showCancelButton        = true,
            string cancelButtonCaption   = "Cancel",
            RAModalDialogSize dialogSize = RAModalDialogSize.Medium)
        {
            var attributes = HtmlHelperHelper.ToAttributesDictionary(htmlAttributes);

            attributes.AddOrInsertToExisting("class", "ra-clickable");
            attributes.Add("href", "#");
            attributes.Add("onmouseup", htmlHelper.RAShowModalDialogScript(contentUrl, returnAction, dialogTitle ?? linkText,
                                                                           showActionButton, actionButtonCaption, showCancelButton, cancelButtonCaption, dialogSize));

            var tagBuilder = new TagBuilder("a")
            {
                TagRenderMode = TagRenderMode.Normal
            };

            tagBuilder.MergeAttributes(attributes);
            tagBuilder.InnerHtml.AppendHtml(linkText);

            return(tagBuilder);
        }
        public static IHtmlContent FileFor <TModel, TProperty>(this IHtmlHelper <TModel> helper,
                                                               Expression <Func <TModel, TProperty> > expression, object htmlAttributes = null)
        {
            var builder    = new TagBuilder("input");
            var attributes = HtmlHelperHelper.ToAttributesDictionary(htmlAttributes);

            var id = helper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(
                helper.GetExpressionText(expression));

            builder.GenerateId(id, "");
            builder.MergeAttribute("name", id);
            builder.MergeAttribute("type", "file");
            builder.MergeAttributes(attributes);
            builder.TagRenderMode = TagRenderMode.SelfClosing;

            return(builder);
        }
        public static IHtmlContent RAButton(
            this IHtmlHelper htmlHelper,
            string buttonHtml,
            string actionScript,
            object htmlAttributes = null,
            string buttonId       = null,
            string buttonClass    = "btn-secondary",
            string buttonStyle    = null,
            string buttonType     = "button")
        {
            var attributes = HtmlHelperHelper.ToAttributesDictionary(htmlAttributes);

            attributes.AddButtonAttributes(buttonClass, buttonStyle, buttonType);
            if (!string.IsNullOrEmpty(buttonId))
            {
                attributes.AddIfMissing("id", buttonId);
            }
            attributes.Add("onmouseup", actionScript);

            return(attributes.ToButton(buttonHtml));
        }
        public static IHtmlContent RADropdownItem(
            this IHtmlHelper htmlHelper,
            string itemHtml,
            string actionScript,
            object htmlAttributes = null)
        {
            var attributes = HtmlHelperHelper.ToAttributesDictionary(htmlAttributes);

            attributes.AddOrInsertToExisting("class", "dropdown-item ra-dropdown-item");
            attributes.AddOrInsertToExisting("onmousedown", actionScript);

            var tagBuilder = new TagBuilder("a")
            {
                TagRenderMode = TagRenderMode.Normal
            };

            tagBuilder.MergeAttributes(attributes);
            tagBuilder.InnerHtml.AppendHtml(itemHtml);

            return(tagBuilder);
        }
Esempio n. 6
0
        public static IHtmlContent RAToolbarButton(
            this IHtmlHelper htmlHelper,
            string buttonText,
            object htmlAttributes = null,
            string navigateToUrl  = null,
            string buttonClass    = "btn-secondary",
            string buttonStyle    = null,
            bool newWindow        = false)
        {
            var action = newWindow ? "newWindowTo" : "navigateTo";

            var attributes = HtmlHelperHelper.ToAttributesDictionary(htmlAttributes);

            attributes.AddButtonAttributes(buttonClass, buttonStyle);
            attributes.AddToolbarButtonAttributes();
            if (!String.IsNullOrEmpty(navigateToUrl))
            {
                attributes.AddOrAppendToExisting("onmouseup", $"{action}('{navigateToUrl}');");
            }

            return(attributes.ToButton(buttonText));
        }
        public static IHtmlContent RAShowModalDialogButton(
            this IHtmlHelper htmlHelper,
            string buttonHtml,
            string contentUrl,
            string returnAction          = null,
            object htmlAttributes        = null,
            string dialogTitle           = null,
            bool showActionButton        = true,
            string actionButtonCaption   = "Save",
            bool showCancelButton        = true,
            string cancelButtonCaption   = "Cancel",
            string buttonClass           = "btn-secondary",
            string buttonStyle           = null,
            RAModalDialogSize dialogSize = RAModalDialogSize.Medium)
        {
            var attributes = HtmlHelperHelper.ToAttributesDictionary(htmlAttributes);

            attributes.AddButtonAttributes(buttonClass, buttonStyle);
            attributes.Add("onmouseup", htmlHelper.RAShowModalDialogScript(contentUrl, returnAction, dialogTitle ?? buttonHtml,
                                                                           showActionButton, actionButtonCaption, showCancelButton, cancelButtonCaption, dialogSize));

            return(attributes.ToButton(buttonHtml));
        }
        private static IHtmlContent GetEditorFor <TModel, TProperty>(
            this IHtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, TProperty> > expression,
            ModelExplorer modelExplorer,
            object htmlAttributes           = null,
            SelectList selectList           = null,
            RAEditorType?editorTypeOverride = null,
            bool isToolbar = false,
            string selectListOptionLabel = null)
        {
            var content = new HtmlContentBuilder();

            var attributes = HtmlHelperHelper.ToAttributesDictionary(htmlAttributes);

            attributes.AddOrInsertToExisting("class", "form-control");

            // Gather data.
            var nullableUnderlyingType = Nullable.GetUnderlyingType(modelExplorer.ModelType);
            var dataTypeAttribute      = expression.GetAttribute <TModel, TProperty, DataTypeAttribute>();
            var zipCodeAttribute       = expression.GetAttribute <TModel, TProperty, ZipCodeAttribute>();

            // Create a dynamic select list for enum types.
            if (selectList == null)
            {
                if (modelExplorer.ModelType.IsEnum)
                {
                    selectList = SelectListHelper.EnumToSelectList(modelExplorer.ModelType);
                }
                else if (nullableUnderlyingType != null && nullableUnderlyingType.IsEnum)
                {
                    selectList = SelectListHelper.EnumToSelectList(nullableUnderlyingType);
                }
            }

            if (selectList != null)
            {
                // Check for radio button specification.
                if (editorTypeOverride.HasValue && editorTypeOverride.Value == RAEditorType.RadioButton)
                {
                    foreach (var item in selectList)
                    {
                        var enumValue = Enum.Parse(modelExplorer.ModelType, item.Value);
                        content.AppendHtml(htmlHelper.RARadioButtonFor(expression, enumValue,
                                                                       ((Enum)enumValue).ToDisplayString(), attributes));
                    }
                }
                // Else use a dropdown.
                else
                {
                    if (isToolbar)
                    {
                        attributes.AddOrAppendToExisting("class", "ra-toolbar-dropdown");
                    }
                    content.AppendHtml(htmlHelper.DropDownListFor(expression, selectList, selectListOptionLabel, attributes));
                }
            }
            else if (modelExplorer.ModelType == typeof(bool) ||
                     (editorTypeOverride.HasValue && editorTypeOverride.Value == RAEditorType.Boolean))
            {
                const string TRUE  = "Yes";
                const string FALSE = "No";
                content.AppendHtml("<div class='form=group'><span class='switch switch-sm'>");
                attributes.AddIfMissing("data-checked", TRUE);
                attributes.AddIfMissing("data-unchecked", FALSE);
                attributes.AddOrAppendToExisting("onclick", "raUpdateFlipswitchLabel(this);");
                content.AppendHtml(htmlHelper.CheckBoxFor(expression as Expression <Func <TModel, bool> >, attributes));
                content.AppendHtml(htmlHelper.LabelFor(expression,
                                                       (bool)modelExplorer.Model ? attributes["data-checked"].ToString() : attributes["data-unchecked"].ToString(), null));
                content.AppendHtml("</span></div>");
            }
            else if (modelExplorer.ModelType == typeof(DateTime) || modelExplorer.ModelType == typeof(DateTime?) ||
                     (editorTypeOverride.HasValue && editorTypeOverride.Value == RAEditorType.Date))
            {
                var value = String.Empty;
                if (modelExplorer.ModelType == typeof(DateTime))
                {
                    value = ((DateTime)modelExplorer.Model).ToString("yyyy-MM-dd");
                }
                else if (modelExplorer.ModelType == typeof(DateTime?))
                {
                    value = ((DateTime?)modelExplorer.Model)?.ToString("yyyy-MM-dd");
                }
                attributes.Add("Value", value);
                //attributes.AddOrAppendToExisting("class", "ra-behavior-datepicker ra-clickable");
                if (isToolbar)
                {
                    attributes.AddOrAppendToExisting("class", "ra-toolbar-datepicker");
                }
                //attributes.AddIfMissing("readonly", "true");
                attributes.AddIfMissing("type", "date");

                // TODO: We really just need to format the date property in TextBoxFor,
                // but supplying the format doesn't appear to be working.
                var temp  = htmlHelper.TextBoxFor(expression, attributes).GetString();
                var temp2 = temp.FindFirstBetween("value=\"", "\"");
                if (temp2.HasText() && value.HasText())
                {
                    temp = temp.Replace(temp2, value);
                }
                content.AppendHtml(temp);
            }
            else if (modelExplorer.ModelType.IsNumeric() ||
                     (editorTypeOverride.HasValue && editorTypeOverride == RAEditorType.Number))
            {
                attributes.AddIfMissing("type", "number");
                if (modelExplorer.ModelType == typeof(decimal) || modelExplorer.ModelType == typeof(decimal?))
                {
                    attributes.AddIfMissing("placeholder", "0.00");
                    attributes.AddIfMissing("min", "0");
                    attributes.AddIfMissing("oninput", "onInputCurrency(event)");
                }
                content.AppendHtml(htmlHelper.TextBoxFor(expression, attributes));
            }
            else if (dataTypeAttribute?.DataType == DataType.PostalCode || zipCodeAttribute != null ||
                     (editorTypeOverride.HasValue && editorTypeOverride.Value == RAEditorType.ZipCode))
            {
                attributes.AddIfMissing("inputmode", "numeric");
                attributes.AddIfMissing("pattern", "[0-9]*");
                content.AppendHtml(htmlHelper.TextBoxFor(expression, attributes));
            }
            else if (dataTypeAttribute?.DataType == DataType.PhoneNumber || expression.HasAttribute(typeof(PhoneAttribute)) ||
                     (editorTypeOverride.HasValue && editorTypeOverride.Value == RAEditorType.PhoneNumber))
            {
                attributes.AddIfMissing("inputmode", "numeric");
                attributes.AddIfMissing("pattern", "[0-9]*");
                content.AppendHtml(htmlHelper.TextBoxFor(expression, attributes));
            }
            else if (dataTypeAttribute?.DataType == DataType.EmailAddress || expression.HasAttribute(typeof(EmailAddressAttribute)) ||
                     (editorTypeOverride.HasValue && editorTypeOverride.Value == RAEditorType.Email))
            {
                attributes.AddIfMissing("type", "email");
                content.AppendHtml(htmlHelper.TextBoxFor(expression, attributes));
            }
            else if (dataTypeAttribute?.DataType == DataType.Password || expression.HasAttribute(typeof(PasswordAttribute)))
            {
                attributes.Add("value", modelExplorer.Model?.ToString());
                content.AppendHtml(htmlHelper.PasswordFor(expression, attributes));
            }
            else
            {
                if (modelExplorer.ModelType == typeof(IFormFile))
                {
                    content.AppendHtml(htmlHelper.FileFor(expression, attributes));
                }
                else if (dataTypeAttribute?.DataType == DataType.MultilineText ||
                         (editorTypeOverride.HasValue && editorTypeOverride.Value == RAEditorType.TextMultiLine))
                {
                    //attributes.AddOrAppendToExisting("class", "ra-container-scrollable-y");   // JVE: Does not appear to work correctly.
                    attributes.AddIfMissing("rows", 4);
                    content.AppendHtml(htmlHelper.TextAreaFor(expression, attributes));
                }
                else
                {
                    if (editorTypeOverride.HasValue && editorTypeOverride.Value == RAEditorType.Number)
                    {
                        attributes.AddIfMissing("type", "number");
                    }

                    content.AppendHtml(htmlHelper.TextBoxFor(expression, attributes));
                }
            }

            return(content);
        }