diff options
Diffstat (limited to 'Pages/Component/MiniPrincipalSelect.razor')
| -rw-r--r-- | Pages/Component/MiniPrincipalSelect.razor | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/Pages/Component/MiniPrincipalSelect.razor b/Pages/Component/MiniPrincipalSelect.razor index 2202b95..89409bd 100644 --- a/Pages/Component/MiniPrincipalSelect.razor +++ b/Pages/Component/MiniPrincipalSelect.razor @@ -1,18 +1,19 @@ @inject ISecurityService securityService +@inject IJSRuntime jsRuntime -<div> - @if(edit) { +<div @ref=div> + @if(newName is not null) { <label>@Label</label> - <input type="text" autocomplete="off" @bind=name/> - <button class="secondary" @onclick=@(() => Edit(false))>Cancel</button> + <input type="text" autocomplete="off" @bind=newName/> + <button class="secondary" @onclick=Cancel>Cancel</button> <button @onclick=Submit>OK</button> } else { <label>@(Label):</label> - <a href="javascript:;" @onclick=@(() => Edit(true))> + <a href="javascript:;" @onclick=Edit> @if(SecurityIdentifier is null || SecurityIdentifier == WellKnownSid.NullSid) { <i>Please select a user or group</i> } else { - @securityService.TranslateName(SecurityIdentifier) + @name } </a> } @@ -25,20 +26,44 @@ [Parameter] public EventCallback<SecurityIdentifier> OnChange { get; set; } - private bool edit = false; - private string name; + private bool edit = false; + private string? name; + private string? newName; - public SecurityIdentifier? SecurityIdentifier { get; set; } + private ElementReference div; - private void Edit(bool enableEdit) { - edit = enableEdit; + private HyperBooru.SecurityIdentifier? securityIdentifier; - if(enableEdit) - name = SecurityIdentifier is null ? "" : - securityService.TranslateName(SecurityIdentifier); + public SecurityIdentifier? SecurityIdentifier { + get => securityIdentifier; + set { + securityIdentifier = value; + name = value is null ? null : securityService.TranslateName(value); + } } - private void Submit() { - Edit(false); + private void Edit() { + newName = SecurityIdentifier == WellKnownSid.NullSid ? "" : name; + StateHasChanged(); } -}
\ No newline at end of file + + private async void Cancel() { + newName = null; + await jsRuntime.InvokeVoidAsync("removeClass", div, "bad-principal"); + StateHasChanged(); + } + + private async void Submit() { + var sid = securityService.TranslateName(newName!); + if(sid is null) { + await jsRuntime.InvokeVoidAsync("cycleClass", div, "bad-principal"); + return; + } + + await jsRuntime.InvokeVoidAsync("removeClass", div, "bad-principal"); + SecurityIdentifier = sid; + await OnChange.InvokeAsync(sid); + newName = null; + StateHasChanged(); + } +} |
