SHA256
GuestDocument - Add edit mode.
Added Edit mode for GuestDocument in GuestDocument details page.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
@inject NavigationManager Navigation
|
||||
@inject IGuestDocumentEntityService guestDocService
|
||||
@inject IStayEntryEntityService stayService
|
||||
@inject IDialogService DialogService
|
||||
|
||||
|
||||
<PageTitle>Somnia - Guest Docs - Details</PageTitle>
|
||||
@@ -16,14 +17,28 @@
|
||||
<MudStack Row="true" Class="my-4">
|
||||
<MudText Typo="Typo.h4" GutterBottom="true">Guest Document: @docId - @documentModel?.FullDocument</MudText>
|
||||
<MudSpacer />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Success" Size="Size.Small" StartIcon="@Icons.Material.Filled.Edit"
|
||||
OnClick="() => BtnEdit()" Disabled>
|
||||
@LanguageLocale.general_btnEdit
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Default" Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.ArrowBack" OnClick="() => BtnReturn()">
|
||||
@LanguageLocale.general_btnReturn
|
||||
</MudButton>
|
||||
@if (_isEditMode)
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Error" Size="Size.Small" StartIcon="@Icons.Material.Filled.Cancel"
|
||||
OnClick="() => BtnCancelEdit()" Disabled="!_isEditMode">
|
||||
@LanguageLocale.general_btnCancel
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Success" Size="Size.Small" StartIcon="@Icons.Material.Filled.Save"
|
||||
OnClick="() => BtnSaveEdit()" Disabled="!_isEditMode">
|
||||
@LanguageLocale.general_btnSave
|
||||
</MudButton>
|
||||
}
|
||||
@if (!_isEditMode)
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Success" Size="Size.Small" StartIcon="@Icons.Material.Filled.Edit"
|
||||
OnClick="() => BtnEnableEdit()" Disabled="_isEditMode">
|
||||
@LanguageLocale.general_btnEdit
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Default" Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.ArrowBack" OnClick="() => BtnReturn()">
|
||||
@LanguageLocale.general_btnReturn
|
||||
</MudButton>
|
||||
}
|
||||
</MudStack>
|
||||
|
||||
@if (documentModel is not null)
|
||||
@@ -32,10 +47,11 @@
|
||||
Centered>
|
||||
|
||||
<MudTabPanel Text="Details" Icon="@Icons.Material.Filled.Info">
|
||||
<GuestDocForm @ref="_form" Model="documentModel" ReadOnly="true" />
|
||||
<GuestDocForm @ref="_form" Model="documentModel" ReadOnly="!_isEditMode" />
|
||||
</MudTabPanel>
|
||||
|
||||
<MudTabPanel Text="Stays" ToolTip="Guest stays" OnClick="LoadTabGuestStays" Icon="@Icons.Material.Filled.Bed">
|
||||
<MudTabPanel Text="Stays" ToolTip="Guest stays" Icon="@Icons.Material.Filled.Bed" OnClick="LoadTabGuestStays"
|
||||
Disabled="_isEditMode">
|
||||
<MudText>Total Stays: @(guestStaysLoading ? "Loading..." : guestStayList.Count())</MudText>
|
||||
<MudTable Items="@guestStayList" Hover="true" Loading="@guestStaysLoading" Class="mt-2" Elevation="2">
|
||||
<HeaderContent>
|
||||
@@ -87,8 +103,16 @@
|
||||
IEnumerable<StayEntryDTO> guestStayList = [];
|
||||
bool guestStaysLoading = true;
|
||||
|
||||
private bool _isEditMode = false;
|
||||
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
//Get model from db.
|
||||
await LoadGuestDocumentAsync();
|
||||
}
|
||||
|
||||
private async Task LoadGuestDocumentAsync()
|
||||
{
|
||||
//Get model from db.
|
||||
documentModel = await guestDocService.GetLastVersionDtoByIdAsync(docId);
|
||||
@@ -121,9 +145,68 @@
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private void BtnEdit()
|
||||
private void BtnEnableEdit()
|
||||
{
|
||||
userMessage.ShowMessage("Not implemented yet!", MessageKind.Info);
|
||||
Debug.Assert(_isEditMode == false);
|
||||
|
||||
userMessage.ShowMessage(LanguageLocale.page_GuestDocDetail_msgEditEnabled, MessageKind.Normal);
|
||||
_isEditMode = true;
|
||||
}
|
||||
|
||||
private async Task BtnCancelEdit()
|
||||
{
|
||||
Debug.Assert(_isEditMode == true);
|
||||
|
||||
var result = await DialogService.ShowMessageBoxAsync(
|
||||
LanguageLocale.general_confirmTitle, LanguageLocale.page_GuestDocDetail_msgConfirmCancelEdit,
|
||||
yesText: "OK", cancelText: LanguageLocale.general_btnCancel);
|
||||
|
||||
if (result == null || result.Value == false)
|
||||
{
|
||||
// Cancel cancel -> Continue with edit.
|
||||
return;
|
||||
}
|
||||
|
||||
//Cancel edit -> Reload data from DB.
|
||||
await LoadGuestDocumentAsync();
|
||||
|
||||
userMessage.ShowMessage(LanguageLocale.general_msgEditCanceled, MessageKind.Normal);
|
||||
_isEditMode = false;
|
||||
}
|
||||
|
||||
private async Task BtnSaveEdit()
|
||||
{
|
||||
Debug.Assert(_isEditMode == true && documentModel is not null);
|
||||
|
||||
var confirmResult = await DialogService.ShowMessageBoxAsync(
|
||||
LanguageLocale.general_confirmTitle, LanguageLocale.page_GuestDocDetail_msgConfirmSaveEdit,
|
||||
yesText: "OK", cancelText: LanguageLocale.general_btnCancel);
|
||||
|
||||
if (confirmResult == null || confirmResult.Value == false)
|
||||
{
|
||||
// Cancel save -> Continue with edit.
|
||||
return;
|
||||
}
|
||||
|
||||
//Show Loading dialog...
|
||||
var loadingDialog = await DialogService.ShowAsync<LoadingDialog>();
|
||||
|
||||
//Save edit.
|
||||
Result updateResult = await guestDocService.UpdateDocumentAsync(documentModel);
|
||||
if (!updateResult.IsSuccess)
|
||||
{
|
||||
string errorMsg = string.Format(LanguageLocale.page_GuestDocDetail_msgEditError, documentModel.FullDocument);
|
||||
userMessage.ShowResultWithMessage(updateResult, errorMsg);
|
||||
loadingDialog.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
//Reload data from DB.
|
||||
await LoadGuestDocumentAsync();
|
||||
loadingDialog.Close();
|
||||
userMessage.ShowMessage(LanguageLocale.general_msgEditSaved, MessageKind.Success);
|
||||
|
||||
_isEditMode = false;
|
||||
}
|
||||
|
||||
private void BtnReturn()
|
||||
|
||||
Reference in New Issue
Block a user