/// <summary> /// Inserts a modal in the queue. /// </summary> /// <param name="step">The step configuration (same object as in the Swal.fire() call).</param> /// <param name="index">The index to insert the step at. By default a modal will be added to the end of a queue.</param> public Task <double> InsertQueueStepAsync(SweetAlertOptions step, double?index = null) { var requestId = Guid.NewGuid(); AddCallbackToDictionaries(step, requestId); return(jSRuntime.InvokeAsync <double>("CurrieTechnologies.Blazor.SweetAlert2.InsertQueueStep", requestId, step.ToPOCO(), index)); }
/// <summary> /// Normalizes the arguments you can give to Swal.fire() in an object of type SweetAlertOptions. /// </summary> /// <param name="paramaters">The array of arguments to normalize.</param> /// <exception cref="ArgumentException">Thrown if parameters is not 1, 2, or 3 elements long.</exception> public SweetAlertOptions ArgsToParams(IEnumerable <string> paramaters) { int paramLength = paramaters.Count(); if (paramLength > 3 || paramLength < 1) { throw new ArgumentException("parameters can only be 1, 2, or 3 elements long."); } var paramEnum = paramaters.GetEnumerator(); paramEnum.MoveNext(); var optionsToReturn = new SweetAlertOptions { Title = paramEnum.Current }; if (paramEnum.MoveNext()) { optionsToReturn.Html = paramEnum.Current; } if (paramEnum.MoveNext()) { optionsToReturn.Type = (SweetAlertType)paramEnum.Current; } return(optionsToReturn); }
/// <summary> /// Inserts a modal in the queue. /// </summary> /// <param name="step">The step configuration (same object as in the Swal.fire() call).</param> /// <param name="index">The index to insert the step at. By default a modal will be added to the end of a queue.</param> public double InsertQueueStep(SweetAlertOptions step, double?index) { var requestId = Guid.NewGuid(); AddCallbackToDictionaries(step, requestId); return(jSInProcessRuntime.Invoke <double>("CurrieTechnologies.Blazor.SweetAlert2.InsertQueueStep", requestId, step.ToPOCO(), index)); }
private static void AddCallbackToDictionaries(SweetAlertOptions settings, Guid requestId) { if (settings.PreConfirm != null) { PreConfirmCallbacks.Add(requestId, settings.PreConfirm); } if (settings.InputValidator != null) { InputValidatorCallbacks.Add(requestId, settings.InputValidator); } if (settings.OnOpen != null) { OnOpenCallbacks.Add(requestId, settings.OnOpen); } if (settings.OnClose != null) { OnCloseCallbacks.Add(requestId, settings.OnClose); } if (settings.OnBeforeOpen != null) { OnBeforeOpenCallbacks.Add(requestId, settings.OnBeforeOpen); } if (settings.OnAfterClose != null) { OnAfterCloseCallbacks.Add(requestId, settings.OnAfterClose); } }
/// <summary> /// Function to display a simple SweetAlert2 modal. /// </summary> /// <param name="title"></param> /// <param name="message"></param> /// <param name="type"></param> /// <returns></returns> public Task <SweetAlertResult> FireAsync(string title, string message = null, SweetAlertType type = null) { SweetAlertOptions newSettings = this.Mix(this.storedOptions); newSettings.Title = title; newSettings.Html = message ?? newSettings.Html; newSettings.Type = type ?? newSettings.Type; return(this.swal.FireAsync(newSettings)); }
/// <summary> /// Updates popup options. /// </summary> /// <param name="newSettings"></param> public async Task UpdateAsync(SweetAlertOptions newSettings) { Guid requestId = Guid.NewGuid(); AddCallbackToDictionaries(newSettings, requestId); await jSRuntime.InvokeAsync <SweetAlertResult>( "CurrieTechnologies.Blazor.SweetAlert2.Update", requestId, newSettings.ToPOCO()); }
/// <summary> /// Updates popup options. /// </summary> /// <param name="newSettings"></param> public void Update(SweetAlertOptions newSettings) { Guid requestId = Guid.NewGuid(); AddCallbackToDictionaries(newSettings, requestId); jSInProcessRuntime.Invoke <SweetAlertResult>( "CurrieTechnologies.Blazor.SweetAlert2.Update", requestId, newSettings.ToPOCO()); }
/// <summary> /// Function to display a SweetAlert2 modal, with an object of options, all being optional. /// </summary> /// <example> /// <code> /// Swal.FireAsync(new SweetAlertOptions { /// Title = "Auto close alert!", /// Text = "I will close in 2 seconds.", /// Timer = 2000 /// }); /// </code> /// </example> /// <param name="settings"></param> public async Task <SweetAlertResult> FireAsync(SweetAlertOptions settings) { var tcs = new TaskCompletionSource <SweetAlertResult>(); Guid requestId = Guid.NewGuid(); PendingFireRequests.Add(requestId, tcs); AddCallbackToDictionaries(settings, requestId); await jSRuntime.InvokeAsync <SweetAlertResult>( "CurrieTechnologies.Blazor.SweetAlert2.FireSettings", requestId, settings.ToPOCO()); return(await tcs.Task); }
/// <summary> /// Reuse configuration by creating a Swal instance. /// </summary> /// <param name="settings">The default options to set for this instance.</param> /// <returns></returns> public SweetAlertMixin Mixin(SweetAlertOptions settings) { return(new SweetAlertMixin(settings, this)); }
/// <summary> /// Inserts a modal in the queue. /// </summary> /// <param name="step">The step configuration (same object as in the Swal.fire() call).</param> /// <param name="index">The index to insert the step at. By default a modal will be added to the end of a queue.</param> public double InsertQueueStep(SweetAlertOptions step, double?index) { return(this.swal.InsertQueueStep(this.Mix(step), index)); }
/// <summary> /// Reuse configuration by creating a Swal instance. /// </summary> /// <param name="settings">The default options to set for this instance.</param> /// <returns></returns> public SweetAlertMixin Mixin(SweetAlertOptions settings) { return(new SweetAlertMixin(this.Mix(settings), this.swal)); }
/// <summary> /// Updates popup options. /// </summary> /// <param name="newSettings"></param> public void Update(SweetAlertOptions newSettings) { this.swal.Update(this.Mix(newSettings)); }
/// <summary> /// Function to display a SweetAlert2 modal, with an object of options, all being optional. /// </summary> /// <param name="settings"></param> public Task <SweetAlertResult> FireAsync(SweetAlertOptions settings) { return(this.swal.FireAsync(this.Mix(settings))); }
private SweetAlertOptions Mix(SweetAlertOptions newSettings) { return(new SweetAlertOptions { Title = newSettings.Title ?? this.storedOptions.Title, TitleText = newSettings.TitleText ?? this.storedOptions.TitleText, Text = newSettings.Text ?? this.storedOptions.Text, Html = newSettings.Html ?? this.storedOptions.Html, Footer = newSettings.Footer ?? this.storedOptions.Footer, Type = newSettings.Type ?? this.storedOptions.Type, Backdrop = newSettings.Backdrop ?? this.storedOptions.Backdrop, Toast = newSettings.Toast ?? this.storedOptions.Toast, Target = newSettings.Target ?? this.storedOptions.Target, Input = newSettings.Input ?? this.storedOptions.Input, Width = newSettings.Width ?? this.storedOptions.Width, Padding = newSettings.Padding ?? this.storedOptions.Padding, Background = newSettings.Background ?? this.storedOptions.Background, Position = newSettings.Position ?? this.storedOptions.Position, Grow = newSettings.Grow ?? this.storedOptions.Grow, CustomClass = newSettings.CustomClass ?? this.storedOptions.CustomClass, Timer = newSettings.Timer ?? this.storedOptions.Timer, Animation = newSettings.Animation ?? this.storedOptions.Animation, HeightAuto = newSettings.HeightAuto ?? this.storedOptions.HeightAuto, AllowOutsideClick = newSettings.AllowOutsideClick ?? this.storedOptions.AllowOutsideClick, AllowEscapeKey = newSettings.AllowEscapeKey ?? this.storedOptions.AllowEscapeKey, AllowEnterKey = newSettings.AllowEnterKey ?? this.storedOptions.AllowEnterKey, StopKeydownPropagation = newSettings.StopKeydownPropagation ?? this.storedOptions.StopKeydownPropagation, KeydownListenerCapture = newSettings.KeydownListenerCapture ?? this.storedOptions.KeydownListenerCapture, ShowConfirmButton = newSettings.ShowConfirmButton ?? this.storedOptions.ShowConfirmButton, ShowCancelButton = newSettings.ShowCancelButton ?? this.storedOptions.ShowCancelButton, ConfirmButtonText = newSettings.ConfirmButtonText ?? this.storedOptions.ConfirmButtonText, CancelButtonText = newSettings.CancelButtonText ?? this.storedOptions.CancelButtonText, ConfirmButtonColor = newSettings.ConfirmButtonColor ?? this.storedOptions.ConfirmButtonColor, CancelButtonColor = newSettings.CancelButtonColor ?? this.storedOptions.CancelButtonColor, ConfirmButtonAriaLabel = newSettings.ConfirmButtonAriaLabel ?? this.storedOptions.ConfirmButtonAriaLabel, CancelButtonAriaLabel = newSettings.CancelButtonAriaLabel ?? this.storedOptions.CancelButtonAriaLabel, ButtonsStyling = newSettings.ButtonsStyling ?? this.storedOptions.ButtonsStyling, ReverseButtons = newSettings.ReverseButtons ?? this.storedOptions.ReverseButtons, FocusConfirm = newSettings.FocusConfirm ?? this.storedOptions.FocusConfirm, FocusCancel = newSettings.FocusCancel ?? this.storedOptions.FocusCancel, ShowCloseButton = newSettings.ShowCloseButton ?? this.storedOptions.ShowCloseButton, CloseButtonAriaLabel = newSettings.CloseButtonAriaLabel ?? this.storedOptions.CloseButtonAriaLabel, ShowLoaderOnConfirm = newSettings.ShowLoaderOnConfirm ?? this.storedOptions.ShowLoaderOnConfirm, PreConfirm = newSettings.PreConfirm ?? this.storedOptions.PreConfirm, ImageUrl = newSettings.ImageUrl ?? this.storedOptions.ImageUrl, ImageWidth = newSettings.ImageWidth ?? this.storedOptions.ImageWidth, ImageHeight = newSettings.ImageHeight ?? this.storedOptions.ImageHeight, ImageAlt = newSettings.ImageAlt ?? this.storedOptions.ImageAlt, InputPlaceholder = newSettings.InputPlaceholder ?? this.storedOptions.InputPlaceholder, InputValue = newSettings.InputValue ?? this.storedOptions.InputValue, InputOptions = newSettings.InputOptions ?? this.storedOptions.InputOptions, InputAutoTrim = newSettings.InputAutoTrim ?? this.storedOptions.InputAutoTrim, InputAttributes = newSettings.InputAttributes ?? this.storedOptions.InputAttributes, InputValidator = newSettings.InputValidator ?? this.storedOptions.InputValidator, ValidationMessage = newSettings.ValidationMessage ?? this.storedOptions.ValidationMessage, ProgressSteps = newSettings.ProgressSteps ?? this.storedOptions.ProgressSteps, CurrentProgressStep = newSettings.CurrentProgressStep ?? this.storedOptions.CurrentProgressStep, ProgressStepsDistance = newSettings.ProgressStepsDistance ?? this.storedOptions.ProgressStepsDistance, OnBeforeOpen = newSettings.OnBeforeOpen ?? this.storedOptions.OnBeforeOpen, OnAfterClose = newSettings.OnAfterClose ?? this.storedOptions.OnAfterClose, OnOpen = newSettings.OnOpen ?? this.storedOptions.OnOpen, OnClose = newSettings.OnClose ?? this.storedOptions.OnClose, ScrollbarPadding = newSettings.ScrollbarPadding ?? this.storedOptions.ScrollbarPadding, }); }
/// <summary> /// Inserts a modal in the queue. /// </summary> /// <param name="step">The step configuration (same object as in the Swal.fire() call).</param> /// <param name="index">The index to insert the step at. By default a modal will be added to the end of a queue.</param> public Task <double> InsertQueueStepAsync(SweetAlertOptions step, double?index = null) { return(this.swal.InsertQueueStepAsync(this.Mix(step), index)); }
/// <summary> /// Updates popup options. /// </summary> /// <param name="newSettings"></param> public Task UpdateAsync(SweetAlertOptions newSettings) { return(this.swal.UpdateAsync(this.Mix(newSettings))); }
internal SweetAlertMixin(SweetAlertOptions settings, SweetAlertService service) { this.storedOptions = settings; this.swal = service; }