Пример #1
0
        protected virtual string BeginForm <TModel>(IHtmlHelper htmlHelper, RoboUIFormResult <TModel> roboForm, string formId) where TModel : class
        {
            string formActionUrl = string.IsNullOrEmpty(roboForm.FormActionUrl)
                ? htmlHelper.ViewContext.HttpContext.Request.Path.ToString()
                : roboForm.FormActionUrl;

            var form = new FluentTagBuilder("form", TagRenderMode.StartTag)
                       .MergeAttribute("action", formActionUrl)
                       .MergeAttribute("id", formId)
                       .MergeAttribute("method", roboForm.FormMethod.ToString().ToLowerInvariant());

            if (roboForm.AjaxEnabled && roboForm.Layout == RoboFormLayout.Tab)
            {
                form = form.MergeAttribute("data-ajax-begin", formId.Replace("-", "_") + "_ValidateTabs");
            }

            if (!roboForm.AjaxEnabled)
            {
                form = form.MergeAttribute("enctype", "multipart/form-data");
            }
            else
            {
                form = form.MergeAttribute("data-ajax", "true");
            }

            form = form.MergeAttribute("method", roboForm.FormMethod.ToString().ToLowerInvariant());
            form = form.MergeAttributes(roboForm.HtmlAttributes);

            return(form.ToString());
        }
Пример #2
0
        protected virtual string BeginForm <TModel>(IHtmlHelper htmlHelper, RoboUIFormResult <TModel> roboForm, string formId) where TModel : class
        {
            var formActionUrl = string.IsNullOrEmpty(roboForm.FormActionUrl)
                ? htmlHelper.ViewContext.HttpContext.Request.Path.ToString()
                : roboForm.FormActionUrl;

            var form = new FluentTagBuilder("form", TagRenderMode.StartTag)
                       .MergeAttribute("role", "form")
                       .MergeAttribute("action", formActionUrl)
                       .MergeAttribute("id", formId)
                       .MergeAttribute("method", roboForm.FormMethod.ToString().ToLowerInvariant());

            if (roboForm.IsHorizontal)
            {
                form.MergeAttribute("class", "form-horizontal");
            }

            var formIdAsName = formId.Replace("-", "_");

            if (roboForm.AjaxEnabled && roboForm.Layout == RoboFormLayout.Tab)
            {
                form.MergeAttribute("data-ajax-begin", formIdAsName + "_ValidateTabs");
            }

            if (roboForm.AjaxEnabled)
            {
                form.MergeAttribute("data-ajax", "true");
                form.MergeAttribute("data-ajax-failure", formIdAsName + "_OnFailure");
                var scriptRegister = roboForm.ControllerContext.HttpContext.RequestServices.GetService <IScriptRegister>();
                scriptRegister.AddInlineScript(string.Format("function {0}_OnFailure(xhr, status, error){{ var ct = xhr.getResponseHeader('content-type') || ''; if(ct.indexOf('application/x-javascript') == -1) {{ alert(xhr.responseText); }} }}", formIdAsName));
            }
            else
            {
                form.MergeAttribute("enctype", "multipart/form-data");
            }

            form.MergeAttribute("method", roboForm.FormMethod.ToString().ToLowerInvariant());
            form.MergeAttributes(roboForm.HtmlAttributes);

            return(form.ToString());
        }
Пример #3
0
 public virtual void RenderControl <TModel>(HtmlTextWriter writer, IHtmlHelper htmlHelper, RoboUIFormResult <TModel> roboForm, RoboControlAttribute roboAttribute) where TModel : class
 {
     if (roboAttribute is RoboTextAttribute)
     {
         RenderTextAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboTextAttribute);
     }
     else if (roboAttribute is RoboNumericAttribute)
     {
         RenderNumericAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboNumericAttribute);
     }
     else if (roboAttribute is RoboChoiceAttribute)
     {
         RenderChoiceAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboChoiceAttribute);
     }
     else if (roboAttribute is RoboHiddenAttribute)
     {
         RenderHiddenFieldAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboHiddenAttribute);
     }
     else if (roboAttribute is RoboButtonAttribute)
     {
         RenderButtonAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboButtonAttribute);
     }
     else if (roboAttribute is RoboCascadingCheckBoxListAttribute)
     {
         RenderCascadingCheckBoxListAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboCascadingCheckBoxListAttribute);
     }
     else if (roboAttribute is RoboCascadingDropDownAttribute)
     {
         RenderCascadingDropDownAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboCascadingDropDownAttribute);
     }
     else if (roboAttribute is RoboComplexAttribute)
     {
         RenderComplexAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboComplexAttribute);
     }
     else if (roboAttribute is RoboDatePickerAttribute)
     {
         RenderDatePickerAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboDatePickerAttribute);
     }
     else if (roboAttribute is RoboTimePickerAttribute)
     {
         RenderTimePickerAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboTimePickerAttribute);
     }
     else if (roboAttribute is RoboDivAttribute)
     {
         RenderDivAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboDivAttribute);
     }
     else if (roboAttribute is RoboEditableGridAttribute)
     {
         RenderEditableGridAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboEditableGridAttribute);
     }
     else if (roboAttribute is RoboGridAttribute)
     {
         RenderGridAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboGridAttribute);
     }
     else if (roboAttribute is RoboHtmlViewAttribute)
     {
         RenderHtmlViewAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboHtmlViewAttribute);
     }
     else if (roboAttribute is RoboImageAttribute)
     {
         RenderImageAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboImageAttribute);
     }
     else if (roboAttribute is RoboLabelAttribute)
     {
         RenderLabelAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboLabelAttribute);
     }
     else if (roboAttribute is RoboSlugAttribute)
     {
         RenderSlugAttribute(writer, htmlHelper, roboForm, roboAttribute as RoboSlugAttribute);
     }
     else
     {
         throw new ArgumentOutOfRangeException();
     }
 }
Пример #4
0
 public virtual void RenderTextAttribute <TModel>(HtmlTextWriter writer, IHtmlHelper htmlHelper, RoboUIFormResult <TModel> roboForm, RoboTextAttribute roboAttribute) where TModel : class
 {
     throw new NotSupportedException();
 }
Пример #5
0
 public virtual string RenderForm <TModel>(IHtmlHelper htmlHelper, RoboUIFormResult <TModel> roboForm) where TModel : class
 {
     throw new NotSupportedException();
 }