Beispiel #1
0
        /// <summary>
        /// Complete JavaScript rendered to HTML output. See:
        /// <see cref="kuujinbo.Mvc.NET.SessionTerminator.Logout" />.
        /// <see cref="kuujinbo.Mvc.NET.Attributes.SessionTerminatorIgnoreAttribute" />.
        /// </summary>
        public static MvcHtmlString TerminateSession(
            this HtmlHelper helper, int timeout, string url)
        {
            var tempData = helper.ViewContext.Controller.TempData;

            if (tempData[SessionTerminator.IgnoreSessionTimeout] == null)
            {
                url = helper.ViewContext.HttpContext.Request.AppendQueryString(
                    url, ShowClientModalKey
                    );

                ScriptManagerHelper.AddInlineScript(
                    helper,
                    JavaScriptBlock + string.Format(InitFormat, timeout, url),
                    ScriptKey
                    );
            }
            else if (tempData[SessionTerminator.SessionTimedOut] != null)
            {
                ScriptManagerHelper.AddInlineScript(
                    helper,
                    JavaScriptBlock + ShowLogout,
                    ScriptKey
                    );
            }

            return(new MvcHtmlString(""));
        }
Beispiel #2
0
        public static MvcHtmlString CheckboxGroupToggler(
            this HtmlHelper helper,
            string cssSelector,
            bool addAfter = false)
        {
            ScriptManagerHelper.AddInlineScript(helper, JavaScriptBlock, ScriptKey);
            ScriptManagerHelper.AddInlineScript(
                helper,
                string.Format(JavaScriptFormat, cssSelector, addAfter.ToString().ToLower())
                );

            return(new MvcHtmlString(""));
        }
Beispiel #3
0
        /// <summary>
        /// File upload HTML, ONLY USE ONCE PER View. You **MUST** pass a
        /// `HttpPostedFileBase` with parameter name 'fileUploadField' to the
        /// controller action. E.g.:
        /// public ActionResult Create(Model model, HttpPostedFileBase fileUploadField)
        /// </summary>
        public static MvcHtmlString FileUploadField(
            this HtmlHelper helper
            , string buttonText = DefaultButtonText
            , string[] accept   = null
            )
        {
            ScriptManagerHelper.AddInlineScript(helper, JavaScriptBlock, ScriptKey);
            ScriptManagerHelper.AddInlineScript(helper, "new FileUploadField().addListeners();");

            var maxuploadSize = WebConfigurationManagerHelper.GetMaxUploadSize(
                new WebConfigHelper(helper.ViewContext.HttpContext.Request.ApplicationPath)
                );

            return(new MvcHtmlString(string.Format(
                                         HtmlFormat
                                         , maxuploadSize
                                         , accept != null ? string.Format("accept='{0}'", string.Join(",", accept)) : string.Empty
                                         , buttonText
                                         , maxuploadSize / 1024
                                         , accept != null ? string.Format(AcceptFormat, string.Join(",", accept)) : string.Empty
                                         )));
        }
Beispiel #4
0
        public static MvcHtmlString JQueryAutoComplete(
            this HtmlHelper helper
            , string idAttribute
            , string searchUrl
            , int minSearchLength   = 1
            , object htmlAttributes = null)
        {
            JQueryXhrHelper.JQueryXhr(helper);

            var tagBuilder = new TagBuilder("input");

            tagBuilder.MergeAttributes <string, object>(
                HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)
                );
            tagBuilder.MergeAttribute(IdAttribute, idAttribute, true);
            tagBuilder.MergeAttribute(NameAttribute, idAttribute, true);
            tagBuilder.MergeAttribute(UrlAttribute, searchUrl, true);
            tagBuilder.MergeAttribute(MinLengthAttribute, minSearchLength.ToString(), true);

            ScriptManagerHelper.AddInlineScript(helper, JavaScriptBlock, ScriptKey);

            return(new MvcHtmlString(tagBuilder.ToString()));
        }
Beispiel #5
0
        public static MvcHtmlString JQueryXhr(this HtmlHelper helper)
        {
            ScriptManagerHelper.AddInlineScript(helper, JavaScriptBlock, ScriptKey);

            return(new MvcHtmlString(""));
        }