コード例 #1
0
        public static MvcHtmlString ListBox(this AjaxHelper ajaxHelper,
                                            string name,
                                            IEnumerable <SelectListItem> selectList = null,
                                            string cssClass = null,
                                            string dir      = null,
                                            bool disabled   = false,
                                            string id       = null,
                                            string lang     = null,
                                            int?size        = null,
                                            string style    = null,
                                            int?tabIndex    = null,
                                            string title    = null,
                                            string dataBind = null)
        {
            HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper();

            if (dataBind == null)
            {
                dataBind = "value: " + name;
            }
            return(htmlHelper.ListBox(
                       name,
                       selectList,
                       SelectAttributes(cssClass, dir, disabled, id, lang, size, style, tabIndex, title, dataBind)));
        }
コード例 #2
0
ファイル: KoMapping.cs プロジェクト: ruze00/Kickbox
        public static MvcHtmlString EnableSubmit(this AjaxHelper ajaxHelper,
                                                 string formName,
                                                 string controller,
                                                 string processMethod = null)
        {
            HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper();
            var        sb         = new StringBuilder();

            sb.AppendLine();
            sb.AppendLine("$('" + formName + "').submit(function (e) {");
            sb.AppendLine("\te.preventDefault();");
            sb.AppendLine("\t$.ajax({");
            sb.AppendLine(
                "\t\turl: '" + new UrlHelper(HttpContext.Current.Request.RequestContext).Action(controller) + "',");
            sb.AppendLine("\t\ttype: 'POST',");
            sb.AppendLine("\t\tdataType: 'json',");
            sb.AppendLine("\t\tdata: $(this).serialize(),");
            sb.AppendLine("\t\tsuccess: function (data) {");
            if (!String.IsNullOrEmpty(processMethod))
            {
                sb.AppendLine("\t\t\t" + processMethod + "(data);");
            }
            else
            {
                // default behavior
                sb.AppendLine("\t\t\talert('saved');");
            }
            sb.AppendLine("\t\t}");
            sb.AppendLine("\t});");
            sb.AppendLine("\treturn false;");
            sb.AppendLine("});");

            return(MvcHtmlString.Create(sb.ToString()));
        }
コード例 #3
0
ファイル: Action.cs プロジェクト: ruze00/Kickbox
 public static MvcHtmlString Action(this AjaxHelper ajaxHelper,
                                    string actionName,
                                    string controllerName = null,
                                    object routeValues    = null)
 {
     return(ajaxHelper.GetHtmlHelper().Action(actionName, controllerName, routeValues));
 }
コード例 #4
0
ファイル: Input.cs プロジェクト: ruze00/Kickbox
        public static MvcHtmlString TextBox(this AjaxHelper ajaxHelper,
                                            string name,
                                            object value    = null,
                                            string cssClass = null,
                                            string dir      = null,
                                            bool disabled   = false,
                                            string id       = null,
                                            string lang     = null,
                                            int?maxLength   = null,
                                            bool readOnly   = false,
                                            int?size        = null,
                                            string style    = null,
                                            int?tabIndex    = null,
                                            string title    = null,
                                            string dataBind = null)
        {
            HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper();

            if (dataBind == null)
            {
                dataBind = "value: " + name;
            }

            return(htmlHelper.TextBox(
                       name,
                       value,
                       InputAttributes(
                           name, cssClass, dir, disabled, id, lang, maxLength, readOnly, size, style, tabIndex, title, dataBind)));
        }
コード例 #5
0
        public static MvcHtmlString DropDownListFor <TModel, TProperty>(this AjaxHelper <TModel> ajaxHelper,
                                                                        Expression <Func <TModel, TProperty> > expression,
                                                                        IEnumerable <SelectListItem> selectList = null,
                                                                        string optionLabel = null,
                                                                        string cssClass    = null,
                                                                        string dir         = null,
                                                                        bool disabled      = false,
                                                                        string id          = null,
                                                                        string lang        = null,
                                                                        int?size           = null,
                                                                        string style       = null,
                                                                        int?tabIndex       = null,
                                                                        string title       = null,
                                                                        string dataBind    = null)
        {
            HtmlHelper <TModel> htmlHelper = ajaxHelper.GetHtmlHelper();
            string name = ExpressionHelper.GetExpressionText(expression);

            if (dataBind == null)
            {
                dataBind = "value: " + name;
            }

            return(htmlHelper.DropDownList(
                       name,
                       selectList,
                       optionLabel,
                       SelectAttributes(cssClass, dir, disabled, id, lang, size, style, tabIndex, title, dataBind)));
        }
コード例 #6
0
ファイル: Input.cs プロジェクト: ruze00/Kickbox
        public static MvcHtmlString CheckBoxFor <TModel>(this AjaxHelper <TModel> ajaxHelper,
                                                         Expression <Func <TModel, bool> > expression,
                                                         string cssClass = null,
                                                         string dir      = null,
                                                         bool disabled   = false,
                                                         string id       = null,
                                                         string lang     = null,
                                                         int?maxLength   = null,
                                                         bool readOnly   = false,
                                                         int?size        = null,
                                                         string style    = null,
                                                         int?tabIndex    = null,
                                                         string title    = null,
                                                         string dataBind = null)
        {
            HtmlHelper <TModel> htmlHelper = ajaxHelper.GetHtmlHelper();
            string name = ExpressionHelper.GetExpressionText(expression);

            if (dataBind == null)
            {
                dataBind = "checked: " + name;
            }

            return(htmlHelper.CheckBoxFor(
                       expression,
                       InputAttributes(
                           name, cssClass, dir, disabled, id, lang, maxLength, readOnly, size, style, tabIndex, title, dataBind)));
        }
コード例 #7
0
ファイル: Input.cs プロジェクト: ruze00/Kickbox
        public static MvcHtmlString RadioButton(this AjaxHelper ajaxHelper,
                                                string name,
                                                object value,
                                                bool?isChecked  = null,
                                                string cssClass = null,
                                                string dir      = null,
                                                bool disabled   = false,
                                                string id       = null,
                                                string lang     = null,
                                                int?maxLength   = null,
                                                bool readOnly   = false,
                                                int?size        = null,
                                                string style    = null,
                                                int?tabIndex    = null,
                                                string title    = null,
                                                string dataBind = null)
        {
            HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper();

            if (dataBind == null)
            {
                dataBind = "checked: " + name;
            }

            IDictionary <string, object> htmlAttributes = InputAttributes(
                name, cssClass, dir, disabled, id, lang, maxLength, readOnly, size, style, tabIndex, title, dataBind);

            return(isChecked.HasValue
                       ? htmlHelper.RadioButton(name, value, isChecked.Value, htmlAttributes)
                       : htmlHelper.RadioButton(name, value, htmlAttributes));
        }
コード例 #8
0
        public static MvcHtmlString DisplayForModel(this AjaxHelper ajaxHelper,
                                                    string templateName  = null,
                                                    string htmlFieldName = null,
                                                    string dataBind      = null)
        {
            //todo See what to do with that
            HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper();

            return(htmlHelper.DisplayForModel(templateName, htmlFieldName));
        }
コード例 #9
0
ファイル: KoMapping.cs プロジェクト: ruze00/Kickbox
        public static MvcHtmlString EnableRefresh(this AjaxHelper ajaxHelper,
                                                  string elementName,
                                                  string controller,
                                                  string processMethod = null)
        {
            HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper();
            var        sb         = new StringBuilder();

            sb.AppendLine();
            sb.AppendLine("$('#" + elementName + "').click(function (e) {");
            sb.AppendLine("\t$.ajax({");
            sb.AppendLine(
                "\t\turl: '" + new UrlHelper(HttpContext.Current.Request.RequestContext).Action(controller) + "',");
            sb.AppendLine("\t\ttype: 'GET',");
            sb.AppendLine("\t\tdataType: 'json',");
            sb.AppendLine("\t\tdata: null,");
            sb.AppendLine("\t\tsuccess: function (data) {");
            if (!String.IsNullOrEmpty(processMethod))
            {
                sb.AppendLine("\t\t\t" + processMethod + "(data);");
            }
            else
            {
                // default behavior is to copy to ViewModel
                sb.AppendLine("\t\t\tvar parsed=JSON.parse(data);");
                object         model = ajaxHelper.ViewData.Model;
                Type           type  = model.GetType();
                string         name  = type.Name;
                PropertyInfo[] props = type.GetProperties();
                foreach (PropertyInfo prop in props)
                {
                    if (prop.PropertyType.IsArray || prop.PropertyType.IsConstructedGenericType)
                    {
                        continue;
                    }

                    sb.AppendLine("\t\t\twindow.vm." + prop.Name + "(parsed." + prop.Name + ");");
                }
//                sb.AppendLine("\t\t\tko.applyBindings(" + name + ");");
            }
            sb.AppendLine("\t\t}");
            sb.AppendLine("\t});");
            sb.AppendLine("\treturn false;");
            sb.AppendLine("});");

            return(MvcHtmlString.Create(sb.ToString()));
        }
コード例 #10
0
ファイル: Input.cs プロジェクト: ruze00/Kickbox
        public static MvcHtmlString Hidden(this AjaxHelper ajaxHelper,
                                           string name,
                                           object value    = null,
                                           string cssClass = null,
                                           string id       = null,
                                           string style    = null,
                                           string dataBind = null)
        {
            HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper();

            if (dataBind == null)
            {
                dataBind = "value: " + name;
            }

            return(htmlHelper.Hidden(name, value, Attributes(cssClass, id, style, dataBind)));
        }
コード例 #11
0
ファイル: Input.cs プロジェクト: ruze00/Kickbox
        public static MvcHtmlString HiddenFor <TModel, TProperty>(this AjaxHelper <TModel> ajaxHelper,
                                                                  Expression <Func <TModel, TProperty> > expression,
                                                                  string cssClass = null,
                                                                  string id       = null,
                                                                  string style    = null,
                                                                  string dataBind = null)
        {
            HtmlHelper <TModel> htmlHelper = ajaxHelper.GetHtmlHelper();
            string name = ExpressionHelper.GetExpressionText(expression);

            if (dataBind == null)
            {
                dataBind = "value: " + name;
            }

            return(htmlHelper.HiddenFor(expression, Attributes(cssClass, id, style, dataBind)));
        }
コード例 #12
0
ファイル: KoMapping.cs プロジェクト: ruze00/Kickbox
        public static MvcHtmlString MapModelToKnockout(this AjaxHelper ajaxHelper, object model = null)
        {
            if (model == null)
            {
                model = ajaxHelper.ViewData.Model;
            }

            Type   type = model.GetType();
            string name = type.Name;

            var sb = new StringBuilder();

            sb.AppendLine();
            sb.AppendLine("window.vm = ko.mapping.fromJS(" + ajaxHelper.GetHtmlHelper().Raw(model.ToJson()) + ");");
            sb.AppendLine("ko.applyBindings(window.vm);");

            return(MvcHtmlString.Create(sb.ToString()));
        }
コード例 #13
0
        // DisplayTextExtensions

        public static MvcHtmlString DisplayText(this AjaxHelper ajaxHelper,
                                                string name,
                                                string dataBind   = null,
                                                string wrapperTag = null)
        {
            HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper();

            if (dataBind == null)
            {
                dataBind = "text: " + name;
            }
            if (wrapperTag == null)
            {
                wrapperTag = "span";
            }
            return
                (MvcHtmlString.Create(
                     string.Format(
                         "<{0}  data-bind=\"{1}\">{2}</{0}>", wrapperTag, dataBind, htmlHelper.DisplayText(name))));
        }
コード例 #14
0
        public static MvcHtmlString DisplayFor <TModel, TValue>(this AjaxHelper <TModel> ajaxHelper,
                                                                Expression <Func <TModel, TValue> > expression,
                                                                string templateName  = null,
                                                                string htmlFieldName = null,
                                                                string dataBind      = null,
                                                                string wrapperTag    = null)
        {
            HtmlHelper <TModel> htmlHelper = ajaxHelper.GetHtmlHelper();
            string name = ExpressionHelper.GetExpressionText(expression);

            if (dataBind == null)
            {
                dataBind = "text: " + name;
            }
            if (wrapperTag == null)
            {
                wrapperTag = "span";
            }
            return
                (MvcHtmlString.Create(
                     string.Format(
                         "<{0}  data-bind=\"{1}\">{2}</{0}>", wrapperTag, dataBind, htmlHelper.DisplayFor(expression))));
        }