Example #1
0
        /// <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)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (_defaultOptions != null)
            {
                settings = SweetAlertOptionsMixingService.Mix(_defaultOptions, settings);
            }

            var tcs       = new TaskCompletionSource <SweetAlertResult>();
            var requestId = Guid.NewGuid();

            PendingFireRequests.Add(requestId, tcs);

            AddCallbackToDictionaries(settings, requestId);

            await _jSRuntime.InvokeAsync <SweetAlertResult>(
                "CurrieTechnologies.Razor.SweetAlert2.FireSettings",
                requestId,
                settings.ToPOCO()).ConfigureAwait(false);

            return(await tcs.Task.ConfigureAwait(false));
        }
Example #2
0
 /// <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)
 {
     if (_defaultOptions != null)
     {
         settings = SweetAlertOptionsMixingService.Mix(_defaultOptions, settings);
     }
     return(new SweetAlertMixin(settings, this));
 }
Example #3
0
        /// <summary>
        ///     Updates popup options.
        /// </summary>
        /// <param name="newSettings"></param>
        public async Task UpdateAsync(SweetAlertOptions newSettings)
        {
            if (newSettings == null)
            {
                throw new ArgumentNullException(nameof(newSettings));
            }
            if (_defaultOptions != null)
            {
                newSettings = SweetAlertOptionsMixingService.Mix(_defaultOptions, newSettings);
            }

            var requestId = Guid.NewGuid();

            AddCallbackToDictionaries(newSettings, requestId);
            await _jSRuntime.InvokeAsync <SweetAlertResult>(
                "CurrieTechnologies.Razor.SweetAlert2.Update",
                requestId,
                newSettings.ToPOCO()).ConfigureAwait(false);
        }
Example #4
0
 private SweetAlertOptions Mix(SweetAlertOptions newSettings)
 {
     return(SweetAlertOptionsMixingService.Mix(_storedOptions, newSettings));
 }