Enable conditional Delete button in grid toolbars
Add EnableDelete parameter to MgGridToolbarTemplate and set it dynamically in GridShippingDocument and GridShippingItemTemplate based on MeasuringStatus. Import relevant enums, make Grid_CustomizeElement static, and remove checked attribute from NavMenu. Improves safety and user experience for deletions.
This commit is contained in:
parent
cd954a1dd3
commit
a75c152ac9
|
|
@ -12,6 +12,7 @@
|
|||
@using AyCode.Core.Interfaces
|
||||
@using AyCode.Core.Loggers
|
||||
@using FruitBank.Common
|
||||
@using FruitBank.Common.Enums
|
||||
@using FruitBank.Common.Models
|
||||
@using FruitBankHybrid.Shared.Services.Loggers
|
||||
|
||||
|
|
@ -98,7 +99,7 @@
|
|||
<ToolbarTemplate>
|
||||
@if (IsMasterGrid)
|
||||
{
|
||||
<MgGridToolbarTemplate Grid="Grid" OnReloadDataClick="() => ReloadDataFromDb(true)">
|
||||
<MgGridToolbarTemplate @ref="toolbar" Grid="Grid" OnReloadDataClick="() => ReloadDataFromDb(true)">
|
||||
<ToolbarItemsExtended>
|
||||
@* <DxToolbarItem BeginGroup="true">
|
||||
<Template Context="ctxToolbarItemFileUpload">
|
||||
|
|
@ -106,7 +107,7 @@
|
|||
</Template>
|
||||
</DxToolbarItem>
|
||||
*@
|
||||
<DxToolbarItem BeginGroup="true" Text="Ai process..." IconCssClass="grid-ai" Click="Callback" Enabled="@(!windowVisible)">
|
||||
<DxToolbarItem BeginGroup="true" Text="Ai process..." IconCssClass="grid-ai" Click="Callback" Enabled="@(!windowVisible)">
|
||||
</DxToolbarItem>
|
||||
|
||||
</ToolbarItemsExtended>
|
||||
|
|
@ -166,6 +167,7 @@
|
|||
public bool ParentDataItemIsPartner => (ParentDataItem is Partner);
|
||||
string GridCss => !IsMasterGrid ? "hide-toolbar" : string.Empty;
|
||||
|
||||
MgGridToolbarTemplate toolbar;
|
||||
const string ExportFileName = "ExportResult";
|
||||
string _localStorageKey = "GridShippingDocument_";
|
||||
|
||||
|
|
@ -254,6 +256,12 @@
|
|||
if (Grid != null && Grid.IsEditing() && !Grid.IsEditingNewRow())
|
||||
await Grid.SaveChangesAsync();
|
||||
|
||||
if (toolbar != null)
|
||||
{
|
||||
var shippingDocument = (args.DataItem as ShippingDocument)!;
|
||||
toolbar.EnableDelete = shippingDocument.ShippingItems?.All(x => x.MeasuringStatus == MeasuringStatus.NotStarted) ?? true;
|
||||
}
|
||||
|
||||
FocusedRowVisibleIndex = args.VisibleIndex;
|
||||
EditItemsEnabled = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
@using AyCode.Utils.Extensions
|
||||
@using FruitBank.Common.Dtos
|
||||
@using FruitBank.Common.Entities
|
||||
@using FruitBank.Common.Enums
|
||||
@using FruitBank.Common.Interfaces
|
||||
@using FruitBankHybrid.Shared.Components.Grids.ShippingItems
|
||||
@using FruitBankHybrid.Shared.Databases
|
||||
|
|
@ -110,7 +111,7 @@
|
|||
<ToolbarTemplate>
|
||||
@if (IsMasterGrid)
|
||||
{
|
||||
<MgGridToolbarTemplate Grid="Grid" OnReloadDataClick="() => ReloadDataFromDb(true)" />
|
||||
<MgGridToolbarTemplate Grid="Grid" @ref="toolbar" OnReloadDataClick="() => ReloadDataFromDb(true)" />
|
||||
}
|
||||
</ToolbarTemplate>
|
||||
<GroupSummary>
|
||||
|
|
@ -143,6 +144,8 @@
|
|||
public bool ParentDataItemIsShippingDocument => (ParentDataItem is ShippingDocument);
|
||||
string GridCss => !IsMasterGrid ? "hide-toolbar" : string.Empty;
|
||||
|
||||
MgGridToolbarTemplate toolbar;
|
||||
|
||||
const string ExportFileName = "ExportResult";
|
||||
string _localStorageKey = "GridShippingItem_";
|
||||
|
||||
|
|
@ -193,7 +196,7 @@
|
|||
if (forceReload) Grid.Reload();
|
||||
}
|
||||
|
||||
void Grid_CustomizeElement(GridCustomizeElementEventArgs e)
|
||||
static void Grid_CustomizeElement(GridCustomizeElementEventArgs e)
|
||||
{
|
||||
if (e.ElementType != GridElementType.DataCell) return;
|
||||
|
||||
|
|
@ -247,6 +250,13 @@
|
|||
if ((args.Grid.IsEditing() || args.Grid.IsEditingNewRow()) && (args.DataItem as IId<int>).Id > 0)
|
||||
await args.Grid.SaveChangesAsync();
|
||||
|
||||
if (toolbar != null)
|
||||
{
|
||||
var shippingItem = (args.DataItem as ShippingItem)!;
|
||||
toolbar.EnableDelete = shippingItem.MeasuringStatus == MeasuringStatus.NotStarted;
|
||||
|
||||
}
|
||||
|
||||
FocusedRowVisibleIndex = args.VisibleIndex;
|
||||
EditItemsEnabled = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
@using FruitBank.Common.Models
|
||||
@inject LoggedInModel LoggedInModel
|
||||
|
||||
<input type="checkbox" title="Navigation menu" class="navbar-toggler" checked />
|
||||
<input type="checkbox" title="Navigation menu" class="navbar-toggler" />
|
||||
|
||||
<div class="top-row ps-3 navbar navbar-dark">
|
||||
<div class="container-fluid">
|
||||
|
|
|
|||
Loading…
Reference in New Issue