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.Interfaces
|
||||||
@using AyCode.Core.Loggers
|
@using AyCode.Core.Loggers
|
||||||
@using FruitBank.Common
|
@using FruitBank.Common
|
||||||
|
@using FruitBank.Common.Enums
|
||||||
@using FruitBank.Common.Models
|
@using FruitBank.Common.Models
|
||||||
@using FruitBankHybrid.Shared.Services.Loggers
|
@using FruitBankHybrid.Shared.Services.Loggers
|
||||||
|
|
||||||
|
|
@ -98,7 +99,7 @@
|
||||||
<ToolbarTemplate>
|
<ToolbarTemplate>
|
||||||
@if (IsMasterGrid)
|
@if (IsMasterGrid)
|
||||||
{
|
{
|
||||||
<MgGridToolbarTemplate Grid="Grid" OnReloadDataClick="() => ReloadDataFromDb(true)">
|
<MgGridToolbarTemplate @ref="toolbar" Grid="Grid" OnReloadDataClick="() => ReloadDataFromDb(true)">
|
||||||
<ToolbarItemsExtended>
|
<ToolbarItemsExtended>
|
||||||
@* <DxToolbarItem BeginGroup="true">
|
@* <DxToolbarItem BeginGroup="true">
|
||||||
<Template Context="ctxToolbarItemFileUpload">
|
<Template Context="ctxToolbarItemFileUpload">
|
||||||
|
|
@ -166,6 +167,7 @@
|
||||||
public bool ParentDataItemIsPartner => (ParentDataItem is Partner);
|
public bool ParentDataItemIsPartner => (ParentDataItem is Partner);
|
||||||
string GridCss => !IsMasterGrid ? "hide-toolbar" : string.Empty;
|
string GridCss => !IsMasterGrid ? "hide-toolbar" : string.Empty;
|
||||||
|
|
||||||
|
MgGridToolbarTemplate toolbar;
|
||||||
const string ExportFileName = "ExportResult";
|
const string ExportFileName = "ExportResult";
|
||||||
string _localStorageKey = "GridShippingDocument_";
|
string _localStorageKey = "GridShippingDocument_";
|
||||||
|
|
||||||
|
|
@ -254,6 +256,12 @@
|
||||||
if (Grid != null && Grid.IsEditing() && !Grid.IsEditingNewRow())
|
if (Grid != null && Grid.IsEditing() && !Grid.IsEditingNewRow())
|
||||||
await Grid.SaveChangesAsync();
|
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;
|
FocusedRowVisibleIndex = args.VisibleIndex;
|
||||||
EditItemsEnabled = true;
|
EditItemsEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
@using AyCode.Utils.Extensions
|
@using AyCode.Utils.Extensions
|
||||||
@using FruitBank.Common.Dtos
|
@using FruitBank.Common.Dtos
|
||||||
@using FruitBank.Common.Entities
|
@using FruitBank.Common.Entities
|
||||||
|
@using FruitBank.Common.Enums
|
||||||
@using FruitBank.Common.Interfaces
|
@using FruitBank.Common.Interfaces
|
||||||
@using FruitBankHybrid.Shared.Components.Grids.ShippingItems
|
@using FruitBankHybrid.Shared.Components.Grids.ShippingItems
|
||||||
@using FruitBankHybrid.Shared.Databases
|
@using FruitBankHybrid.Shared.Databases
|
||||||
|
|
@ -110,7 +111,7 @@
|
||||||
<ToolbarTemplate>
|
<ToolbarTemplate>
|
||||||
@if (IsMasterGrid)
|
@if (IsMasterGrid)
|
||||||
{
|
{
|
||||||
<MgGridToolbarTemplate Grid="Grid" OnReloadDataClick="() => ReloadDataFromDb(true)" />
|
<MgGridToolbarTemplate Grid="Grid" @ref="toolbar" OnReloadDataClick="() => ReloadDataFromDb(true)" />
|
||||||
}
|
}
|
||||||
</ToolbarTemplate>
|
</ToolbarTemplate>
|
||||||
<GroupSummary>
|
<GroupSummary>
|
||||||
|
|
@ -143,6 +144,8 @@
|
||||||
public bool ParentDataItemIsShippingDocument => (ParentDataItem is ShippingDocument);
|
public bool ParentDataItemIsShippingDocument => (ParentDataItem is ShippingDocument);
|
||||||
string GridCss => !IsMasterGrid ? "hide-toolbar" : string.Empty;
|
string GridCss => !IsMasterGrid ? "hide-toolbar" : string.Empty;
|
||||||
|
|
||||||
|
MgGridToolbarTemplate toolbar;
|
||||||
|
|
||||||
const string ExportFileName = "ExportResult";
|
const string ExportFileName = "ExportResult";
|
||||||
string _localStorageKey = "GridShippingItem_";
|
string _localStorageKey = "GridShippingItem_";
|
||||||
|
|
||||||
|
|
@ -193,7 +196,7 @@
|
||||||
if (forceReload) Grid.Reload();
|
if (forceReload) Grid.Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Grid_CustomizeElement(GridCustomizeElementEventArgs e)
|
static void Grid_CustomizeElement(GridCustomizeElementEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.ElementType != GridElementType.DataCell) return;
|
if (e.ElementType != GridElementType.DataCell) return;
|
||||||
|
|
||||||
|
|
@ -247,6 +250,13 @@
|
||||||
if ((args.Grid.IsEditing() || args.Grid.IsEditingNewRow()) && (args.DataItem as IId<int>).Id > 0)
|
if ((args.Grid.IsEditing() || args.Grid.IsEditingNewRow()) && (args.DataItem as IId<int>).Id > 0)
|
||||||
await args.Grid.SaveChangesAsync();
|
await args.Grid.SaveChangesAsync();
|
||||||
|
|
||||||
|
if (toolbar != null)
|
||||||
|
{
|
||||||
|
var shippingItem = (args.DataItem as ShippingItem)!;
|
||||||
|
toolbar.EnableDelete = shippingItem.MeasuringStatus == MeasuringStatus.NotStarted;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
FocusedRowVisibleIndex = args.VisibleIndex;
|
FocusedRowVisibleIndex = args.VisibleIndex;
|
||||||
EditItemsEnabled = true;
|
EditItemsEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
@using FruitBank.Common.Models
|
@using FruitBank.Common.Models
|
||||||
@inject LoggedInModel LoggedInModel
|
@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="top-row ps-3 navbar navbar-dark">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue