Esempio n. 1
0
 /// <summary>
 /// Adds an action button to the modal footer.
 /// </summary>
 /// <param name="text">Close button text.</param>
 /// <param name="jsFunc">Name of java script method to call when button is pressed.</param>
 /// <param name="state">Close button contextual state.</param>
 /// <returns>The modal builder instance.</returns>
 public MvcCoreBootstrapModalFooterBuilder SubmitButton(string text, ContextualState state = ContextualState.Default)
 {
     _config.Buttons.Add(new ModalButton {
         Text = text, State = state, Submit = true
     });
     return(this);
 }
Esempio n. 2
0
 private void AddContextualState(TagBuilder builder, ContextualState state)
 {
     if (state != ContextualState.Default)
     {
         builder.AddCssClass(state.ToString().ToLower());
     }
 }
 /// <summary>
 /// Sets the contextual state for the list group item.
 /// </summary>
 /// <param name="state">Item contextual state.</param>
 /// <param name="condition">Condition for applying contextual state.</param>
 /// <returns>The list group item builder instance.</returns>
 public MvcCoreBootstrapListGroupItemBuilder Contextual(ContextualState state, bool condition = true)
 {
     if (condition)
     {
         _item.State = state;
     }
     return(this);
 }
Esempio n. 4
0
 /// <summary>
 /// Adds an action button to the modal footer.
 /// </summary>
 /// <param name="text">Close button text.</param>
 /// <param name="jsFunc">Name of java script method to call when button is pressed.</param>
 /// <param name="state">Close button contextual state.</param>
 /// <returns>The modal builder instance.</returns>
 public MvcCoreBootstrapModalFooterBuilder ActionButton(string text, string jsFunc,
                                                        ContextualState state = ContextualState.Default)
 {
     _config.Buttons.Add(new ModalButton {
         Text = text, State = state, JsFunc = jsFunc
     });
     return(this);
 }
 /// <summary>
 /// Configures a basic modal with title, body and a close button.
 /// </summary>
 /// <param name="title">Modal title.</param>
 /// <param name="body">Modal body.</param>
 /// <param name="closeBtnText">Close button text.</param>
 /// <param name="closeBtnState">Close button contextual state.</param>
 public void Modal(string title, string body, string closeBtnText,
                   ContextualState closeBtnState = ContextualState.Default)
 {
     _config.Title = title;
     _config.Body  = body;
     _config.Buttons.Add(new ModalButton {
         Text = closeBtnText, State = closeBtnState
     });
     _config.Dismissable = true;
 }
Esempio n. 6
0
 protected void AddContextualState(TagBuilder element, ContextualState state, string prefix = null,
                                   string qualifier = null)
 {
     if (qualifier != null)
     {
         element.AddCssClass($"{prefix}{qualifier}-{state.ToString().ToLower()}");
     }
     else
     {
         element.AddCssClass(prefix + state.ToString().ToLower());
     }
 }
        /// <summary>Get the text representation of a token's values.</summary>
        /// <param name="context">Provides access to contextual tokens.</param>
        /// <param name="part">The token string part whose value to fetch.</param>
        /// <param name="state">The context state to update with errors, unavailable tokens, etc.</param>
        /// <param name="text">The text representation, if available.</param>
        /// <returns>Returns true if the token is ready and <paramref name="text"/> was set, else false.</returns>
        private bool TryGetTokenText(IContext context, TokenStringPart part, ContextualState state, out string text)
        {
            switch (part.LexToken)
            {
            case LexTokenToken lexToken:
                {
                    // get token
                    IToken token = context.GetToken(lexToken.Name, enforceContext: false);
                    if (token == null)
                    {
                        state.AddInvalidTokens(lexToken.Name);
                        text = null;
                        return(false);
                    }
                    if (!token.IsReady)
                    {
                        this.State.AddUnreadyTokens(lexToken.Name);
                        text = null;
                        return(false);
                    }

                    // get token input
                    if (part.Input != null)
                    {
                        part.Input.UpdateContext(context);
                        if (!part.Input.IsReady)
                        {
                            state.MergeFrom(part.Input.GetDiagnosticState());
                            text = null;
                            return(false);
                        }
                    }

                    // validate input
                    if (!token.TryValidateInput(part.InputArgs, out string error))
                    {
                        state.AddErrors(error);
                        text = null;
                        return(false);
                    }

                    // get text representation
                    string[] values = token.GetValues(part.InputArgs).ToArray();
                    text = string.Join(", ", values);
                    return(true);
                }

            default:
                text = part.LexToken.ToString();
                return(true);
            }
        }
        /// <summary>
        /// Renders an Mvc Core Bootstrap alert.
        /// </summary>
        /// <param name="htmlHelper">Html helper instance.</param>
        /// <param name="text">Alert text.</param>
        /// <param name="state">Alert contextual state.</param>
        /// <param name="configAction">Action that implements alert configuration.</param>
        /// <returns>Alert html markup.</returns>
        public static IHtmlContent MvcCoreBootstrapAlert(this IHtmlHelper htmlHelper, string text,
                                                         ContextualState state, Action <MvcCoreBootstrapAlertBuilder> configAction = null)
        {
            AlertConfig config = new AlertConfig {
                Text = text, State = state
            };

            if (state == ContextualState.Default)
            {
                throw new ArgumentException(@"""Default"" is not a valid state for the alert.");
            }
            configAction?.Invoke(new MvcCoreBootstrapAlertBuilder(config));

            return(new AlertRenderer().Render(config));
        }
        /// <summary>
        /// Renders an Mvc Core Bootstrap form validation summary.
        /// </summary>
        /// <param name="htmlHelper">Html helper instance.</param>
        /// <param name="state">Validation summary contextual state. Defaults to "Danger"</param>
        /// <returns>Validation summary html markup.</returns>
        public static IHtmlContent MvcCoreBootstrapValidationSummary(this IHtmlHelper htmlHelper,
                                                                     ContextualState state = ContextualState.Danger)
        {
            ValidationSummaryConfig config = new ValidationSummaryConfig {
                State = state
            };

            if (htmlHelper == null)
            {
                throw new ArgumentNullException(nameof(htmlHelper));
            }
            if (state == ContextualState.Default)
            {
                throw new ArgumentException(@"""Default"" is not a valid state for the validation summary.");
            }

            return(new ValidationSummaryRenderer(config, htmlHelper).Render());
        }
 /// <summary>
 /// Sets the <see cref="ContextualState"/> of the table.
 /// </summary>
 /// <param name="state">Contextual state</param>
 /// <param name="condition">If true, the contextual state will be applied.</param>
 /// <returns>The button builder instance.</returns>
 public MvcCoreBootstrapTableBuilder <T> Contextual(ContextualState state, bool condition = true)
 {
     return(this.SetConfigProp <MvcCoreBootstrapTableBuilder <T> >(() => _config.State = condition ? state : ContextualState.Default));
 }
 /// <summary>
 /// Sets the <see cref="ContextualState"/> of the footer.
 /// </summary>
 /// <param name="state">Contextual state</param>
 /// <param name="condition">If true, the contextual state will be applied.</param>
 /// <returns>Footer builder instance.</returns>
 public MvcCoreBootstrapTableFooterBuilder Contextual(ContextualState state, bool condition = true)
 {
     _config.State = condition ? state : ContextualState.Default;
     return(this);
 }
Esempio n. 12
0
 public void Initialize()
 {
     _instance = new ContextualState();
 }
 /// <summary>
 /// Adds a badge to the list group item.
 /// </summary>
 /// <param name="badge">Badge content.</param>
 /// <param name="state">Badge contextual state.</param>
 /// <returns>The list group item builder instance.</returns>
 public MvcCoreBootstrapListGroupItemBuilder Badge(string badge, ContextualState state = ContextualState.Default)
 {
     _item.Badge = badge;
     _item.BadgeContextualState = state;
     return(this);
 }
Esempio n. 14
0
 /// <summary>
 /// Sets the <see cref="ContextualState"/> of the row.
 /// </summary>
 /// <param name="state">Contextual state</param>
 /// <param name="condition">If true, the contextual state will be applied.</param>
 /// <returns>Row builder instance.</returns>
 public RowBuilder <T> Contextual(ContextualState state, bool condition = true)
 {
     Config.State = condition ? state : ContextualState.Default;
     return(this);
 }
Esempio n. 15
0
 /// <summary>
 /// Sets the <see cref="ContextualState"/> of the cell.
 /// </summary>
 /// <param name="state">Contextual state</param>
 /// <param name="condition">If true, the contextual state will be applied.</param>
 /// <returns>The cell builder instance.</returns>
 public CellBuilder Contextual(ContextualState state, bool condition = true)
 {
     _config.State = condition ? state : ContextualState.Default;
     return(this);
 }