Exemple #1
0
        private static ComponentBuilder <MvcBootstrapConfig <TModel>, ControlLabel> GetControlLabel <TComponent, TModel, TValue>(
            BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, Expression <Func <TModel, TValue> > expression)
            where TComponent : Component
        {
            string expressionText = ExpressionHelper.GetExpressionText(expression);

            ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, helper.GetConfig().HtmlHelper.ViewData);
            string        name     = GetControlName(helper, expressionText);
            string        label    = GetControlLabel(metadata, expressionText);

            return(new MvcBootstrapHelper <TModel>(helper.GetConfig().HtmlHelper).ControlLabel(label).For(TagBuilder.CreateSanitizedId(name)));
        }
 public static ComponentBuilder <MvcBootstrapConfig <TModel>, Pagination> Pagination <TComponent, TModel>(
     this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, IEnumerable <KeyValuePair <string, ActionResult> > textAndResults, int?activePageNumber = null, int?firstPageNumber = null)
     where TComponent : Component, ICanCreate <Pagination>
 {
     return(new ComponentBuilder <MvcBootstrapConfig <TModel>, Pagination>(helper.GetConfig(), helper.Pagination().GetComponent())
            .AddPages(textAndResults, activePageNumber, firstPageNumber));
 }
        // Navbar

        public static ComponentBuilder <MvcBootstrapConfig <TModel>, Navbar> Navbar <TComponent, TModel>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, string brand, ActionResult result, bool fluid = true)
            where TComponent : Component, ICanCreate <Navbar>
        {
            return(new ComponentBuilder <MvcBootstrapConfig <TModel>, Navbar>(helper.GetConfig(), helper.Navbar(fluid).GetComponent())
                   .AddChild(x => x.Brand(brand, result)));
        }
        // Navbar

        public static ComponentBuilder <MvcBootstrapConfig <TModel>, Navbar> Navbar <TComponent, TModel>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, string brand, string actionName, string controllerName, object routeValues = null, bool fluid = true)
            where TComponent : Component, ICanCreate <Navbar>
        {
            return(new ComponentBuilder <MvcBootstrapConfig <TModel>, Navbar>(helper.GetConfig(), helper.Navbar(fluid).GetComponent())
                   .AddChild(x => x.Brand(brand, actionName, controllerName, routeValues)));
        }
 public static ComponentBuilder <MvcBootstrapConfig <TModel>, FormControl> FormControl <TComponent, TModel, TValue>(
     this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, Expression <Func <TModel, TValue> > labelExpression)
     where TComponent : Component, ICanCreate <FormControl>
 {
     return(new ComponentBuilder <MvcBootstrapConfig <TModel>, FormControl>(helper.GetConfig(), helper.FormControl().GetComponent())
            .SetControlLabel(labelExpression));
 }
        // ListGroup

        public static ComponentBuilder <MvcBootstrapConfig <TModel>, ListGroupItem> ListGroupItem <TComponent, TModel>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, string text, ActionResult result)
            where TComponent : Component, ICanCreate <ListGroupItem>
        {
            return(new ComponentBuilder <MvcBootstrapConfig <TModel>, ListGroupItem>(helper.GetConfig(), helper.ListGroupItem(text, (string)null).GetComponent())
                   .SetLinkAction(result));
        }
Exemple #7
0
        protected Component(BootstrapHelper helper)
        {
            _config   = helper.GetConfig();
            _parent   = helper.GetParent();
            _implicit = GetOutputStack().Count > 0;

            // Get any component override(s)
            ComponentOverride componentOverride = null;
            Type thisType = GetType();

            foreach (KeyValuePair <Type, Func <BootstrapConfig, Component, ComponentOverride> > match
                     in Config.ComponentOverrides.Where(x => x.Key.IsAssignableFrom(thisType)))
            {
                ComponentOverride lastComponentOverride = componentOverride;
                componentOverride = match.Value(Config, this);
                componentOverride.BaseStartAction  = OnStart;
                componentOverride.BaseFinishAction = OnFinish;
                if (lastComponentOverride != null)
                {
                    // If this is an override higher up the hierarchy, redirect the lower override to call this one
                    lastComponentOverride.BaseStartAction  = componentOverride.OnStart;
                    lastComponentOverride.BaseFinishAction = componentOverride.OnFinish;
                }
                _componentOverrides.Enqueue(componentOverride);
            }
        }
        // MediaObject

        public static ComponentBuilder <MvcBootstrapConfig <TModel>, MediaObject> MediaObject <TComponent, TModel>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, string src, ActionResult result, string alt = null)
            where TComponent : Component, ICanCreate <MediaObject>
        {
            return(new ComponentBuilder <MvcBootstrapConfig <TModel>, MediaObject>(helper.GetConfig(), helper.MediaObject(src, (string)null, alt).GetComponent())
                   .SetLinkAction(result));
        }
        // MediaObject

        public static ComponentBuilder <MvcBootstrapConfig <TModel>, MediaObject> MediaObject <TComponent, TModel>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, string src, string actionName, string controllerName, object routeValues = null, string alt = null)
            where TComponent : Component, ICanCreate <MediaObject>
        {
            return(new ComponentBuilder <MvcBootstrapConfig <TModel>, MediaObject>(helper.GetConfig(), helper.MediaObject(src, null, alt).GetComponent())
                   .SetAction(actionName, controllerName, routeValues));
        }
        // Button

        public static ComponentBuilder <MvcBootstrapConfig <TModel>, LinkButton> LinkButton <TComponent, TModel>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, string text, string actionName, string controllerName, object routeValues = null)
            where TComponent : Component, ICanCreate <LinkButton>
        {
            return(new ComponentBuilder <MvcBootstrapConfig <TModel>, LinkButton>(helper.GetConfig(), helper.LinkButton(text, null).GetComponent())
                   .SetAction(actionName, controllerName, routeValues));
        }
        // Form

        public static ComponentBuilder <MvcBootstrapConfig <TModel>, Form> Form <TComponent, TModel>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, ActionResult result, FormMethod method = FormMethod.Post)
            where TComponent : Component, ICanCreate <Form>
        {
            return(new ComponentBuilder <MvcBootstrapConfig <TModel>, Form>(helper.GetConfig(), helper.Form().GetComponent())
                   .SetAction(result)
                   .SetFormMethod(method));
        }
        // Dropdown

        public static ComponentBuilder <MvcBootstrapConfig <TModel>, DropdownLink> DropdownLink <TComponent, TModel>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, string text, string actionName, string controllerName, object routeValues = null)
            where TComponent : Component, ICanCreate <DropdownLink>
        {
            return(new ComponentBuilder <MvcBootstrapConfig <TModel>, DropdownLink>(helper.GetConfig(), helper.DropdownLink(text, null).GetComponent())
                   .SetLinkAction(actionName, controllerName, routeValues)
                   .SetText(text));
        }
        // Dropdown

        public static ComponentBuilder <MvcBootstrapConfig <TModel>, DropdownLink> DropdownLink <TComponent, TModel>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, string text, ActionResult result)
            where TComponent : Component, ICanCreate <DropdownLink>
        {
            return(new ComponentBuilder <MvcBootstrapConfig <TModel>, DropdownLink>(helper.GetConfig(), helper.DropdownLink(text, (string)null).GetComponent())
                   .SetLinkAction(result)
                   .SetText(text));
        }
Exemple #14
0
        public static ComponentBuilder <MvcBootstrapConfig <TModel>, FormButton> ButtonFor <TComponent, TModel, TValue>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> bootstrap, Expression <Func <TModel, TValue> > expression, string text, TValue value)
            where TComponent : Component, ICanCreate <FormButton>
        {
            var config         = (MvcBootstrapConfig <TModel>)bootstrap.GetConfig();
            var html           = config.GetHtmlHelper();
            var metadata       = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
            var expressionText = ExpressionHelper.GetExpressionText(expression);
            var name           = GetControlName(html, expressionText);
            var label          = GetControlLabel(metadata, expressionText);

            return(bootstrap.FormButton(text: text, label: label, value: value));
        }
Exemple #15
0
 protected Tag(BootstrapHelper helper, string tagName, params string[] cssClasses)
     : base(helper)
 {
     _tagName     = tagName;
     CssClasses   = new HashSet <string>();
     Attributes   = new MergeableDictionary();
     InlineStyles = new MergeableDictionary();
     foreach (string cssClass in cssClasses.Where(x => !string.IsNullOrWhiteSpace(x)))
     {
         CssClasses.Add(cssClass);
     }
     PrettyPrint  = helper.GetConfig().PrettyPrint;
     OutputEndTag = true;
 }
        // Typography

        public static ComponentBuilder <MvcBootstrapConfig <TModel>, Typography.List> ListFor <TComponent, TModel, TValue>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper,
            Expression <Func <TModel, IEnumerable <TValue> > > expression, Func <TValue, object> item, ListType listType = ListType.Unstyled)
            where TComponent : Component, ICanCreate <Typography.List>
        {
            ComponentBuilder <MvcBootstrapConfig <TModel>, Typography.List> builder =
                new ComponentBuilder <MvcBootstrapConfig <TModel>, Typography.List>(helper.GetConfig(), helper.List(listType).GetComponent());
            IEnumerable <TValue> values = ModelMetadata.FromLambdaExpression(expression, builder.GetConfig().HtmlHelper.ViewData).Model as IEnumerable <TValue>;

            if (values != null)
            {
                foreach (TValue value in values)
                {
                    builder.AddChild(x => x.ListItem(item(value)));
                }
            }
            return(builder);
        }
Exemple #17
0
        public static ComponentBuilder <MvcBootstrapConfig <TModel>, FormButton> ButtonFor <TComponent, TModel, TValue>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper,
            Expression <Func <TModel, TValue> > expression, params string[] options)
            where TComponent : Component, ICanCreate <FormButton>
        {
            var    metadata       = ModelMetadata.FromLambdaExpression(expression, helper.GetConfig().HtmlHelper.ViewData);
            string expressionText = ExpressionHelper.GetExpressionText(expression);
            var    name           = helper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(expressionText);
            string name           = GetControlName(helper, expressionText);
            string label          = GetControlLabel(metadata, expressionText);
            ComponentBuilder <MvcBootstrapConfig <TModel>, Select> builder = helper.Select(name, label);

            if (metadata.Model != null && !string.IsNullOrEmpty(name))
            {
                // Add the model value before adding options so they'll get selected on a match
                builder.GetComponent().ModelValue = metadata.Model.ToString();
            }
            return(builder.AddOptions(options));
        }
 public static ComponentBuilder <MvcBootstrapConfig <TModel>, HiddenFor <TModel, TValue> > HiddenFor <TComponent, TModel, TValue>(
     this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, Expression <Func <TModel, TValue> > expression)
     where TComponent : Component, ICanCreate <Hidden>
 {
     return(new ComponentBuilder <MvcBootstrapConfig <TModel>, HiddenFor <TModel, TValue> >(helper.GetConfig(), new HiddenFor <TModel, TValue>(helper, expression)));
 }
        public static ComponentBuilder <MvcBootstrapConfig <TModel>, Select> SelectFor <TComponent, TModel, TValue>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, Expression <Func <TModel, TValue> > expression, IEnumerable <SelectListItem> selectList = null)
            where TComponent : Component, ICanCreate <Select>
        {
            ModelMetadata metadata       = ModelMetadata.FromLambdaExpression(expression, helper.GetConfig().HtmlHelper.ViewData);
            string        expressionText = ExpressionHelper.GetExpressionText(expression);
            string        name           = GetControlName(helper, expressionText);
            string        label          = GetControlLabel(metadata, expressionText);

            return(helper.Select(name, label, selectList));
        }
        public static ComponentBuilder <MvcBootstrapConfig <TModel>, CheckedControl> RadioFor <TComponent, TModel, TValue>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, Expression <Func <TModel, TValue> > expression, object value = null)
            where TComponent : Component, ICanCreate <CheckedControl>
        {
            ModelMetadata metadata       = ModelMetadata.FromLambdaExpression(expression, helper.GetConfig().HtmlHelper.ViewData);
            string        expressionText = ExpressionHelper.GetExpressionText(expression);
            string        name           = GetControlName(helper, expressionText);
            string        label          = GetControlLabel(metadata, expressionText);
            bool          isChecked      = false;

            if (metadata.Model == null || !bool.TryParse(metadata.Model.ToString(), out isChecked))
            {
                isChecked = false;
            }
            return(helper.Radio(name, label, null, value, isChecked));
        }
        public static ComponentBuilder <MvcBootstrapConfig <TModel>, Input> InputFor <TComponent, TModel, TValue>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, Expression <Func <TModel, TValue> > expression, FormInputType inputType = FormInputType.Text)
            where TComponent : Component, ICanCreate <Input>
        {
            ModelMetadata metadata       = ModelMetadata.FromLambdaExpression(expression, helper.GetConfig().HtmlHelper.ViewData);
            string        expressionText = ExpressionHelper.GetExpressionText(expression);
            string        name           = GetControlName(helper, expressionText);
            string        label          = GetControlLabel(metadata, expressionText);

            return(helper.Input(name, label, metadata.Model, null, inputType));
        }
        public static ComponentBuilder <MvcBootstrapConfig <TModel>, FormControlListFor <TModel, TValue> > EditorOrDisplayListFor <TComponent, TModel, TValue>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, bool editor, Expression <Func <TModel, IEnumerable <TValue> > > expression,
            ListType listType = ListType.Unstyled, bool addDescription = true, bool addValidationMessage = true, string templateName = null, object additionalViewData = null, bool addHidden = true)
            where TComponent : Component, ICanCreate <FormControl>
        {
            ComponentBuilder <MvcBootstrapConfig <TModel>, FormControlListFor <TModel, TValue> > builder =
                new ComponentBuilder <MvcBootstrapConfig <TModel>, FormControlListFor <TModel, TValue> >(helper.GetConfig(), new FormControlListFor <TModel, TValue>(helper, editor, expression, listType))
                .AddHidden(addHidden)
                .AddDescription(addDescription)
                .AddValidationMessage(addValidationMessage)
                .SetTemplateName(templateName)
                .AddAdditionalViewData(additionalViewData);

            builder.GetComponent().Label = GetControlLabel(helper, expression).GetComponent();
            return(builder);
        }
        public static ComponentBuilder <MvcBootstrapConfig <TModel>, Select> SelectFor <TComponent, TModel, TValue>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, Expression <Func <TModel, TValue> > expression, IEnumerable <SelectListItem> selectList = null)
            where TComponent : Component, ICanCreate <Select>
        {
            ModelMetadata metadata       = ModelMetadata.FromLambdaExpression(expression, helper.GetConfig().HtmlHelper.ViewData);
            string        expressionText = ExpressionHelper.GetExpressionText(expression);
            string        name           = GetControlName(helper, expressionText);
            string        label          = GetControlLabel(metadata, expressionText);
            ComponentBuilder <MvcBootstrapConfig <TModel>, Select> builder = helper.Select(name, label);

            if (metadata.Model != null && !string.IsNullOrEmpty(name))
            {
                // Add the model value before adding options so they'll get selected on a match
                builder.GetComponent().ModelValue = metadata.Model.ToString();
            }
            return(builder.AddOptions(selectList));
        }
        public static ComponentBuilder <MvcBootstrapConfig <TModel>, CheckedControl> RadioFor <TComponent, TModel, TValue>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, Expression <Func <TModel, TValue> > expression, object value = null)
            where TComponent : Component, ICanCreate <CheckedControl>
        {
            ModelMetadata metadata       = ModelMetadata.FromLambdaExpression(expression, helper.GetConfig().HtmlHelper.ViewData);
            string        expressionText = ExpressionHelper.GetExpressionText(expression);
            string        name           = GetControlName(helper, expressionText);
            string        label          = GetControlLabel(metadata, expressionText);
            string        valueString    = Convert.ToString(value, (IFormatProvider)CultureInfo.CurrentCulture);
            bool          isChecked      = metadata.Model != null && !string.IsNullOrEmpty(name) && string.Equals(metadata.Model.ToString(), valueString, StringComparison.OrdinalIgnoreCase);

            return(helper.Radio(name, label, null, value, isChecked));
        }
Exemple #25
0
        public static ComponentBuilder <MvcBootstrapConfig <TModel>, TextArea> TextAreaFor <TComponent, TModel, TValue>(
            this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, Expression <Func <TModel, TValue> > expression, int?rows = null)
            where TComponent : Component, ICanCreate <TextArea>
        {
            ModelMetadata metadata       = ModelMetadata.FromLambdaExpression(expression, helper.GetConfig().HtmlHelper.ViewData);
            string        expressionText = ExpressionHelper.GetExpressionText(expression);
            string        name           = GetControlName(helper, expressionText);
            string        label          = GetControlLabel(metadata, expressionText);

            return(helper.TextArea(name, label, metadata.Model, null, rows));
        }
 private static string GetControlName <TComponent, TModel>(BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, string expressionText)
     where TComponent : Component
 {
     return(TagBuilder.CreateSanitizedId(
                helper.GetConfig().HtmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(expressionText)));
 }
 public static ComponentBuilder <MvcBootstrapConfig <TModel>, ValidationSummary <TModel> > ValidationSummary <TComponent, TModel>(
     this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, bool includePropertyErrors = false)
     where TComponent : Component, ICanCreate <FormControl>
 {
     return(new ComponentBuilder <MvcBootstrapConfig <TModel>, ValidationSummary <TModel> >(helper.GetConfig(), new ValidationSummary <TModel>(helper)));
 }
 public static ComponentBuilder <MvcBootstrapConfig <TModel>, CheckBoxFor <TModel, TValue> > CheckBoxFor <TComponent, TModel, TValue>(
     this BootstrapHelper <MvcBootstrapConfig <TModel>, TComponent> helper, Expression <Func <TModel, TValue> > expression, bool isNameInLabel = true)
     where TComponent : Component, ICanCreate <CheckedControl>
 {
     return(new ComponentBuilder <MvcBootstrapConfig <TModel>, CheckBoxFor <TModel, TValue> >(helper.GetConfig(), new CheckBoxFor <TModel, TValue>(helper, expression, isNameInLabel)));
 }