private async Task Modal_OnUpdate(ConfirmRef confirmRef)
 {
     if (confirmRef.Config.Visible)
     {
         await InvokeAsync(StateHasChanged);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// open the Confirm dialog
 /// </summary>
 /// <param name="confirmRef"></param>
 /// <returns></returns>
 internal async Task OpenConfirmAsync(ConfirmRef confirmRef)
 {
     if (OnConfirmOpenEvent != null)
     {
         await OnConfirmOpenEvent.Invoke(confirmRef);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// show a confirm dialog like MessageBox of Windows
        /// </summary>
        /// <param name="content">the content of dialog</param>
        /// <param name="title">the title of dialog</param>
        /// <param name="confirmButtons">the buttons of dialog</param>
        /// <param name="confirmIcon">the icon of dialog</param>
        /// <param name="options">the configuration options for dialog</param>
        /// <param name="autoFocusButton">the autofocus button</param>
        /// <returns></returns>
        public async Task <ConfirmResult> Show(
            OneOf <string, RenderFragment> content,
            OneOf <string, RenderFragment> title,
            ConfirmButtons confirmButtons,
            ConfirmIcon confirmIcon,
            ConfirmButtonOptions options,
            ConfirmAutoFocusButton?autoFocusButton = ConfirmAutoFocusButton.Ok)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            ConfirmOptions confirmOptions = new ConfirmOptions()
            {
                Content        = content,
                ConfirmButtons = confirmButtons,
                ConfirmIcon    = confirmIcon,
            };

            if (autoFocusButton != null)
            {
                confirmOptions.AutoFocusButton = (ConfirmAutoFocusButton)autoFocusButton;
            }

            if (title.IsT0)
            {
                confirmOptions.Title = title.AsT0;
            }
            else
            {
                confirmOptions.TitleTemplate = title.AsT1;
            }

            #region config button default properties

            if (options.Button1Props != null)
            {
                confirmOptions.Button1Props = options.Button1Props;
            }
            if (options.Button2Props != null)
            {
                confirmOptions.Button2Props = options.Button2Props;
            }
            if (options.Button3Props != null)
            {
                confirmOptions.Button3Props = options.Button3Props;
            }

            #endregion

            var confirmRef = new ConfirmRef(confirmOptions)
            {
                TaskCompletionSource = new TaskCompletionSource <ConfirmResult>()
            };
            if (OnOpenEvent != null)
            {
                await OnOpenEvent.Invoke(confirmRef);
            }
            return(await confirmRef.TaskCompletionSource.Task);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// after Confirm dialog remove from DOM, to remove it from _confirmRefs
 /// </summary>
 /// <param name="confirmRef"></param>
 /// <returns></returns>
 private Task OnConfirmRemove(ConfirmRef confirmRef)
 {
     if (_confirmRefs.Contains(confirmRef))
     {
         _confirmRefs.Remove(confirmRef);
     }
     return(Task.CompletedTask);
 }
Ejemplo n.º 5
0
        public ConfirmRef Confirm(ConfirmOptions props)
        {
            ConfirmRef confirmRef = new ConfirmRef(props, this);

            confirmRef.TaskCompletionSource = new TaskCompletionSource <ConfirmResult>();
            OnOpenEvent?.Invoke(confirmRef);
            return(confirmRef);
        }
Ejemplo n.º 6
0
 internal Task CloseAsync(ConfirmRef confirmRef)
 {
     if (OnCloseEvent != null)
     {
         return(OnCloseEvent.Invoke(confirmRef));
     }
     return(Task.CompletedTask);
 }
Ejemplo n.º 7
0
 internal Task OpenAsync(ConfirmRef confirmRef)
 {
     if (OnOpenEvent != null)
     {
         OnOpenEvent.Invoke(confirmRef);
     }
     return(Task.CompletedTask);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Create and open a Moal
        /// </summary>
        /// <param name="config">Options</param>
        /// <returns></returns>
        public Task <ConfirmRef> CreateAsync(ConfirmOptions config)
        {
            CheckIsNull(config);
            ConfirmRef confirmRef = new ConfirmRef(config, this);

            OnOpenEvent?.Invoke(confirmRef);
            return(Task.FromResult(confirmRef));
        }
        /// <summary>
        /// destroy Confirm dialog
        /// </summary>
        /// <param name="confirmRef"></param>
        /// <returns></returns>
        private async Task OnConfirmClose(ConfirmRef confirmRef)
        {
            confirmRef.Config.Visible = false;
            await InvokeAsync(StateHasChanged);

            if (confirmRef.OnClose != null)
            {
                await confirmRef.OnClose.Invoke();
            }
        }
 /// <summary>
 /// 创建并打开窗体
 /// </summary>
 private async Task Modal_OnOpen(ConfirmRef confirmRef)
 {
     confirmRef.Config.Visible = true;
     if (!_modalRefs.Contains(confirmRef))
     {
         confirmRef.Config.BuildButtonsDefaultOptions();
         _modalRefs.Add(confirmRef);
     }
     await InvokeAsync(StateHasChanged);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// create and open a OK-Cancel Confirm dialog,
        /// and return a bool value which indicates whether the OK button has been clicked
        /// </summary>
        /// <param name="props"></param>
        /// <returns></returns>
        public async Task <bool> ConfirmAsync(ConfirmOptions props)
        {
            ConfirmRef confirmRef = new ConfirmRef(props, this);

            confirmRef.TaskCompletionSource = new TaskCompletionSource <ConfirmResult>();
            if (OnConfirmOpenEvent != null)
            {
                await OnConfirmOpenEvent.Invoke(confirmRef);
            }

            return(await confirmRef.TaskCompletionSource.Task
                   .ContinueWith(t => t.Result == ConfirmResult.OK, TaskScheduler.Default));
        }
        private async Task Modal_OnDestroy(ConfirmRef confirmRef)
        {
            confirmRef.Config.Visible = false;
            await InvokeAsync(StateHasChanged);

            await Task.Delay(250);

            if (_modalRefs.Contains(confirmRef))
            {
                _modalRefs.Remove(confirmRef);
            }
            confirmRef.OnDestroy?.Invoke();
        }
        /// <summary>
        /// 关闭窗体
        /// </summary>
        private async Task Modal_OnClose(ConfirmRef confirmRef)
        {
            confirmRef.Config.Visible = false;
            await InvokeAsync(StateHasChanged);

            await Task.Delay(250);

            if (_modalRefs.Contains(confirmRef))
            {
                _modalRefs.Remove(confirmRef);
                await JsInvokeAsync(JSInteropConstants.EnableBodyScroll);
            }
            confirmRef.OnClose?.Invoke();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// show a confirm dialog like MessageBox of Windows
        /// </summary>
        /// <param name="content">the content of dialog</param>
        /// <param name="title">the title of dialog</param>
        /// <param name="confirmButtons">the buttons of dialog</param>
        /// <param name="confirmIcon">the icon of dialog</param>
        /// <param name="options">the configuration options for dialog</param>
        /// <returns></returns>
        public async Task <ConfirmResult> Show(
            OneOf <string, RenderFragment> content,
            OneOf <string, RenderFragment> title,
            ConfirmButtons confirmButtons,
            ConfirmIcon confirmIcon,
            ConfirmButtonOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            ConfirmOptions confirmOptions = new ConfirmOptions()
            {
                Title          = title,
                Content        = content,
                ConfirmButtons = confirmButtons,
                ConfirmIcon    = confirmIcon,
            };

            #region config button default properties

            if (options.Button1Props != null)
            {
                confirmOptions.Button1Props = options.Button1Props;
            }
            if (options.Button2Props != null)
            {
                confirmOptions.Button2Props = options.Button2Props;
            }
            if (options.Button3Props != null)
            {
                confirmOptions.Button3Props = options.Button3Props;
            }

            #endregion

            var modalRef = new ConfirmRef(confirmOptions)
            {
                TaskCompletionSource = new TaskCompletionSource <ConfirmResult>()
            };
            if (OnOpenEvent != null)
            {
                await OnOpenEvent.Invoke(modalRef);
            }
            return(await modalRef.TaskCompletionSource.Task);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Create and open template Confirm dialog
        /// </summary>
        /// <typeparam name="TComponent"></typeparam>
        /// <typeparam name="TComponentOptions"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="config"></param>
        /// <param name="componentOptions"></param>
        /// <returns></returns>
        public Task <ConfirmRef <TResult> > CreateConfirmAsync <TComponent, TComponentOptions, TResult>(ConfirmOptions config, TComponentOptions componentOptions) where TComponent : ConfirmTemplate <TComponentOptions, TResult>
        {
            CheckConfirmOptionsIsNull(config);

            ConfirmRef <TResult> confirmRef = new ConfirmRef <TResult>(config, this);

            OnConfirmOpenEvent?.Invoke(confirmRef);

            RenderFragment child = (builder) =>
            {
                builder.OpenComponent <TComponent>(0);
                builder.AddAttribute(1, "ConfirmRef", confirmRef);
                builder.AddAttribute(2, "Options", componentOptions);
                builder.CloseComponent();
            };

            config.Content = child;

            return(Task.FromResult(confirmRef));
        }
Ejemplo n.º 16
0
 public Task Destroy(ConfirmRef confirmRef)
 {
     return(DestroyConfirmAsync(confirmRef));
 }
Ejemplo n.º 17
0
 public Task Destroy(ConfirmRef confirmRef)
 {
     return(OnDestroyEvent?.Invoke(confirmRef));
 }
Ejemplo n.º 18
0
 public Task Update(ConfirmRef confirmRef)
 {
     return(UpdateConfirmAsync(confirmRef));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// update Confirm which Visible=true
 /// </summary>
 /// <param name="confirmRef"></param>
 /// <returns></returns>
 public async Task UpdateConfirmAsync(ConfirmRef confirmRef)
 {
     await(OnConfirmUpdateEvent?.Invoke(confirmRef) ?? Task.CompletedTask);
 }
Ejemplo n.º 20
0
 public Task Update(ConfirmRef confirmRef)
 {
     return(OnUpdateEvent?.Invoke(confirmRef));
 }
Ejemplo n.º 21
0
 /// <summary>
 /// close the Confirm dialog
 /// </summary>
 /// <param name="confirmRef"></param>
 /// <returns></returns>
 public async Task DestroyConfirmAsync(ConfirmRef confirmRef)
 {
     await(OnConfirmCloseEvent?.Invoke(confirmRef) ?? Task.CompletedTask);
 }