public static MvcHtmlString SearchControl(this HtmlHelper helper, FindOptions findOptions, Context context, Action<SearchControl> settingsModifier)
        {
            var options = new SearchControl { Prefix = context.Prefix }; 
            if (settingsModifier != null)
                settingsModifier(options);

            QueryDescription description = DynamicQueryManager.Current.QueryDescription(findOptions.QueryName);

            Navigator.SetTokens(findOptions.FilterOptions, description, false);
            Navigator.SetTokens(findOptions.OrderOptions, description, false);
            Navigator.SetTokens(findOptions.ColumnOptions, description, false);
            Navigator.Manager.SetSearchViewableAndCreable(findOptions, description);
            Navigator.Manager.SetDefaultOrder(findOptions, description);

            var viewData = new ViewDataDictionary(context);
            viewData[ViewDataKeys.FindOptions] = findOptions;
            viewData[ViewDataKeys.QueryDescription] = DynamicQueryManager.Current.QueryDescription(findOptions.QueryName);

            viewData[ViewDataKeys.Title] = helper.ViewData.ContainsKey(ViewDataKeys.Title) ?
                helper.ViewData[ViewDataKeys.Title] :
                Navigator.Manager.SearchTitle(findOptions.QueryName);

            if (!options.ToolBarButton.IsNullOrEmpty())
                viewData[ViewDataKeys.ManualToolbarButtons] = options.ToolBarButton;

            return helper.Partial(Navigator.Manager.SearchControlView, viewData);
        }
        public static MvcHtmlString CountSearchControlValue(this HtmlHelper helper, FindOptions findOptions, Context context, Action<CountSearchControl> settingsModifier)
        {
            var options = new CountSearchControl();
            if (settingsModifier != null)
                settingsModifier(options);

            return CountSearchControlInternal(findOptions, options, context);
        }
        public static MvcHtmlString CountSearchControlSpan(this HtmlHelper helper, FindOptions findOptions, Context context, Action<CountSearchControl> settingsModifier = null)
        {
            var options = new CountSearchControl();
            if (settingsModifier != null)
                settingsModifier(options);

            return "{0} {1}".FormatHtml(
            options.QueryLabelText ?? QueryUtils.GetNiceName(findOptions.QueryName),
            CountSearchControlInternal(findOptions, options, context));
        }
        private static MvcHtmlString CountSearchControlInternal(FindOptions findOptions, Web.CountSearchControl options)
        {
            findOptions.SearchOnLoad = true;

            int count = Navigator.QueryCount(new CountOptions(findOptions.QueryName)
            {
                FilterOptions = findOptions.FilterOptions
            });

            HtmlStringBuilder sb = new HtmlStringBuilder();

            if (options.Navigate)
            {
                sb.Add(new HtmlTag("a")
                    .Class("count-search").Class(count > 0 ? "count-with-results badge" : "count-no-results")
                    .Attr("href", options.Href.HasText() ? options.Href : findOptions.ToString())
                    .SetInnerText(count.ToString()));
            }
            else
            {
                sb.Add(new HtmlTag("span")
                    .Class("count-search").Class(count > 0 ? "count-with-results badge" : "count-no-results")
                    .SetInnerText(count.ToString()));
            }

            if (options.PopupViewPrefix != null)
            {
                sb.Add(new HtmlTag("a", options.PopupViewPrefix + "csbtnView")
                  .Class("sf-line-button sf-view")
                  .Attr("title", EntityControlMessage.View.NiceToString())
                  .Attr("onclick", new JsFunction(JsFunction.FinderModule, "explore", findOptions.ToJS(options.PopupViewPrefix)).ToString())
                  .InnerHtml(new HtmlTag("span").Class("glyphicon glyphicon-arrow-right")));
            }

            return sb.ToHtml();
        }
Exemple #5
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            FindOptions fo = new FindOptions();

            NameValueCollection parameters = controllerContext.HttpContext.Request.Params;

            if (parameters.AllKeys.Any(name => !name.HasText()))
            {
                throw new Exception("Incorrect URL: " + controllerContext.HttpContext.Request.Url.ToString());
            }

            object rawValue = bindingContext.ValueProvider.GetValue("webQueryName")?.RawValue;

            if (rawValue == null)
            {
                return(null);
            }

            string webQueryName = rawValue.GetType() == typeof(string[]) ? ((string[])rawValue)[0]: (string)rawValue;

            if (!webQueryName.HasText())
            {
                throw new InvalidOperationException("webQueryName not provided");
            }

            fo.QueryName = Finder.ResolveQueryName(webQueryName);

            QueryDescription queryDescription = DynamicQueryManager.Current.QueryDescription(fo.QueryName);

            fo.FilterOptions = ExtractFilterOptions(controllerContext.HttpContext, queryDescription);
            fo.OrderOptions  = ExtractOrderOptions(controllerContext.HttpContext, queryDescription);
            fo.ColumnOptions = ExtractColumnsOptions(controllerContext.HttpContext, queryDescription);

            if (parameters.AllKeys.Contains("allowSelection"))
            {
                bool aux;
                if (bool.TryParse(parameters["allowSelection"], out aux))
                {
                    fo.AllowSelection = aux;
                }
            }

            if (parameters.AllKeys.Contains("allowChangeColumns"))
            {
                fo.AllowChangeColumns = bool.Parse(parameters["allowChangeColumns"]);
            }

            if (parameters.AllKeys.Contains("allowOrder"))
            {
                fo.AllowOrder = bool.Parse(parameters["allowOrder"]);
            }

            if (parameters.AllKeys.Contains("showHeader"))
            {
                fo.ShowHeader = bool.Parse(parameters["showHeader"]);
            }

            if (parameters.AllKeys.Contains("showFilters"))
            {
                fo.ShowFilters = bool.Parse(parameters["showFilters"]);
            }

            if (parameters.AllKeys.Contains("showFilterButton"))
            {
                fo.ShowFilterButton = bool.Parse(parameters["showFilterButton"]);
            }

            if (parameters.AllKeys.Contains("showFooter"))
            {
                fo.ShowFooter = bool.Parse(parameters["showFooter"]);
            }

            if (parameters.AllKeys.Contains("showContextMenu"))
            {
                fo.ShowContextMenu = bool.Parse(parameters["showContextMenu"]);
            }

            if (parameters.AllKeys.Contains("columnMode"))
            {
                fo.ColumnOptionsMode = parameters["columnMode"].ToEnum <ColumnOptionsMode>();
            }

            if (parameters.AllKeys.Contains("create"))
            {
                fo.Create = bool.Parse(parameters["create"]);
            }

            if (parameters.AllKeys.Contains("navigate"))
            {
                fo.Navigate = bool.Parse(parameters["navigate"]);
            }

            if (parameters.AllKeys.Contains("pagination"))
            {
                switch (parameters["pagination"].ToEnum <PaginationMode>())
                {
                case PaginationMode.All:
                    fo.Pagination = new Pagination.All();
                    break;

                case PaginationMode.Firsts:
                    fo.Pagination = new Pagination.Firsts(int.Parse(parameters["elems"]));
                    break;

                case PaginationMode.Paginate:
                    fo.Pagination = new Pagination.Paginate(int.Parse(parameters["elems"]),
                                                            parameters.AllKeys.Contains("page") ? parameters["page"].ToInt() ?? 1 : 1);
                    break;

                default:
                    break;
                }
            }

            if (parameters.AllKeys.Contains("searchOnLoad"))
            {
                fo.SearchOnLoad = bool.Parse(parameters["searchOnLoad"]);
            }

            return(fo);
        }
Exemple #6
0
 public static PartialViewResult SearchPopup(this ControllerBase controller, FindOptions findOptions, FindMode mode, string prefix)
 {
     return(Manager.SearchPopup(controller, findOptions, mode, new Context(null, prefix)));
 }
Exemple #7
0
 public static PartialViewResult SearchPopup(this ControllerBase controller, FindOptions findOptions, FindMode mode, Context context)
 {
     return(Manager.SearchPopup(controller, findOptions, mode, context));
 }
Exemple #8
0
 public static ViewResult SearchPage(this ControllerBase controller, FindOptions findOptions)
 {
     return(Manager.SearchPage(controller, findOptions));
 }
Exemple #9
0
        protected internal virtual PartialViewResult SearchPopup(ControllerBase controller, FindOptions findOptions, FindMode mode, Context context)
        {
            if (!Finder.IsFindable(findOptions.QueryName))
            {
                throw new UnauthorizedAccessException(NormalControlMessage.ViewForType0IsNotAllowed.NiceToString().FormatWith(findOptions.QueryName));
            }

            var desc = DynamicQueryManager.Current.QueryDescription(findOptions.QueryName);

            SetSearchViewableAndCreable(findOptions, desc);
            SetDefaultOrder(findOptions, desc);

            controller.ViewData.Model = context;

            controller.ViewData[ViewDataKeys.FindMode]         = mode;
            controller.ViewData[ViewDataKeys.FindOptions]      = findOptions;
            controller.ViewData[ViewDataKeys.QueryDescription] = desc;

            if (!controller.ViewData.ContainsKey(ViewDataKeys.Title))
            {
                controller.ViewData[ViewDataKeys.Title] = QueryUtils.GetNiceName(findOptions.QueryName);
            }

            return(new PartialViewResult
            {
                ViewName = SearchPopupControlView,
                ViewData = controller.ViewData,
                TempData = controller.TempData
            });
        }
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            FindOptions fo = new FindOptions();

            NameValueCollection parameters = controllerContext.HttpContext.Request.Params;

            if (parameters.AllKeys.Any(name => !name.HasText()))
                throw new Exception("Incorrect URL: " + controllerContext.HttpContext.Request.Url.ToString());

            object rawValue = bindingContext.ValueProvider.GetValue("webQueryName")?.RawValue;
            if (rawValue == null)
                return null;

            string webQueryName = rawValue.GetType() == typeof(string[]) ? ((string[])rawValue)[0]: (string)rawValue;

            if (!webQueryName.HasText())
                throw new InvalidOperationException("webQueryName not provided");

            fo.QueryName = Finder.ResolveQueryName(webQueryName);

            QueryDescription queryDescription = DynamicQueryManager.Current.QueryDescription(fo.QueryName);

            fo.FilterOptions = ExtractFilterOptions(controllerContext.HttpContext, queryDescription);
            fo.OrderOptions = ExtractOrderOptions(controllerContext.HttpContext, queryDescription);
            fo.ColumnOptions = ExtractColumnsOptions(controllerContext.HttpContext, queryDescription);

            if (parameters.AllKeys.Contains("allowSelection"))
            {
                bool aux;
                if (bool.TryParse(parameters["allowSelection"], out aux))
                    fo.AllowSelection = aux;
            }

            if (parameters.AllKeys.Contains("allowChangeColumns"))
                fo.AllowChangeColumns = bool.Parse(parameters["allowChangeColumns"]);

            if (parameters.AllKeys.Contains("allowOrder"))
                fo.AllowOrder = bool.Parse(parameters["allowOrder"]);

            if (parameters.AllKeys.Contains("showHeader"))
                fo.ShowHeader =  bool.Parse(parameters["showHeader"]);

            if (parameters.AllKeys.Contains("showFilters"))
                fo.ShowFilters = bool.Parse(parameters["showFilters"]);

            if (parameters.AllKeys.Contains("showFilterButton"))
                fo.ShowFilterButton = bool.Parse(parameters["showFilterButton"]);

            if (parameters.AllKeys.Contains("showFooter"))
                fo.ShowFooter = bool.Parse(parameters["showFooter"]);

            if (parameters.AllKeys.Contains("showContextMenu"))
                fo.ShowContextMenu = bool.Parse(parameters["showContextMenu"]);

            if (parameters.AllKeys.Contains("columnMode"))
                fo.ColumnOptionsMode = parameters["columnMode"].ToEnum<ColumnOptionsMode>();

            if (parameters.AllKeys.Contains("create"))
                fo.Create = bool.Parse(parameters["create"]);

            if (parameters.AllKeys.Contains("navigate"))
                fo.Navigate = bool.Parse(parameters["navigate"]);

            if (parameters.AllKeys.Contains("pagination"))
            {
                switch (parameters["pagination"].ToEnum<PaginationMode>())
                {
                    case PaginationMode.All:
                        fo.Pagination = new Pagination.All();
                        break;
                    case PaginationMode.Firsts:
                        fo.Pagination = new Pagination.Firsts(int.Parse(parameters["elems"]));
                        break;
                    case PaginationMode.Paginate:
                        fo.Pagination = new Pagination.Paginate(int.Parse(parameters["elems"]),
                            parameters.AllKeys.Contains("page") ? parameters["page"].ToInt() ?? 1 : 1);
                        break;
                    default:
                        break;
                }
            }

            if (parameters.AllKeys.Contains("searchOnLoad"))
                fo.SearchOnLoad = bool.Parse(parameters["searchOnLoad"]);

            return fo;
        }
 public static MvcHtmlString SearchControl(this HtmlHelper helper, FindOptions findOptions, Context context)
 {
     return SearchControl(helper, findOptions, context, null);
 }
        public static MvcHtmlString CountSearchControl(this HtmlHelper helper, Context context,  FindOptions findOptions, Action<CountSearchControl> settingsModifier)
        {
            var options = new CountSearchControl();
            if (settingsModifier != null)
                settingsModifier(options);

            var val  = CountSearchControlInternal(findOptions, options); 

            return helper.FormGroup(context, null, options.QueryLabelText ?? QueryUtils.GetNiceName(findOptions.QueryName),
                   new HtmlTag("p").Class("form-control-static").InnerHtml(val));
        }
Exemple #13
0
 public static MvcHtmlString SearchControl(this HtmlHelper helper, FindOptions findOptions, Context context)
 {
     return(SearchControl(helper, findOptions, context, null));
 }
        private static MvcHtmlString CountSearchControlInternal(FindOptions findOptions, Web.CountSearchControl options, Context context)
        {
            findOptions.SearchOnLoad = true;

          

            HtmlStringBuilder sb = new HtmlStringBuilder();

            if (options.Navigate)
            {
                sb.Add(new HtmlTag("a").Id(context.Prefix)
                    .Class("count-search")
                    .Attr("href", options.Href.HasText() ? options.Href : findOptions.ToString())
                    .SetInnerText("..."));
            }
            else
            {
                sb.Add(new HtmlTag("span").Id(context.Prefix)
                    .Class("count-search")
                    .SetInnerText("..."));
            }

            if (options.View)
            {
                sb.Add(new HtmlTag("a", context.Compose("csbtnView"))
                  .Class("sf-line-button sf-view")
                  .Attr("title", EntityControlMessage.View.NiceToString())
                  .Attr("onclick", JsModule.Finder["explore"](findOptions.ToJS(context.Compose("New"))).ToString())
                  .InnerHtml(new HtmlTag("span").Class("glyphicon glyphicon-arrow-right")));
            }

            var function = new JsFunction(JsModule.Finder, "count",
                findOptions.ToJS(context.Prefix),
                new JRaw("'" + context.Prefix + "'.get()"));

            sb.Add(MvcHtmlString.Create("<script>" + function.ToHtmlString() + "</script>"));

            return sb.ToHtml();
        }