diff --git a/ResourceInformationV2/Components/Pages/OrgChart/Edit.razor b/ResourceInformationV2/Components/Pages/OrgChart/Edit.razor index 4dcffb1..8e81c26 100644 --- a/ResourceInformationV2/Components/Pages/OrgChart/Edit.razor +++ b/ResourceInformationV2/Components/Pages/OrgChart/Edit.razor @@ -53,7 +53,7 @@ } -

Children of Current Level

+

Children of "@VisibleOrgchartItem.Title"

@foreach (var child in VisibleOrgchartItems) {

@child.Title, @child.Subtitle

diff --git a/ResourceInformationV2/Components/Pages/OrgChart/Edit.razor.cs b/ResourceInformationV2/Components/Pages/OrgChart/Edit.razor.cs index b133183..ed10c9e 100644 --- a/ResourceInformationV2/Components/Pages/OrgChart/Edit.razor.cs +++ b/ResourceInformationV2/Components/Pages/OrgChart/Edit.razor.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; using ResourceInformationV2.Components.Layout; using ResourceInformationV2.Data.DataHelpers; using ResourceInformationV2.Data.DataModels; @@ -23,6 +24,9 @@ public partial class Edit { [CascadingParameter] public SidebarLayout Layout { get; set; } = default!; + [Inject] + protected IJSRuntime JsRuntime { get; set; } = default!; + [Inject] protected NavigationManager NavigationManager { get; set; } = default!; @@ -56,11 +60,14 @@ protected void AddChild() { RefreshVisibleItems(); } - protected void DeleteChild(Orgchart child) { + protected async Task DeleteChild(Orgchart child) { if (VisibleOrgchartItem.Children is null) { return; } - _ = VisibleOrgchartItem.Children.Remove(child); + var alert = child.Children is not null && child.Children.Count > 0 ? "This will delete this item and all children" : "This will delete this item"; + if (!(await JsRuntime.InvokeAsync("confirm", $"{alert}. Are you sure?"))) { + _ = VisibleOrgchartItem.Children.Remove(child); + } RefreshVisibleItems(); } @@ -79,6 +86,7 @@ protected void GoUpLevel() { protected async Task Save() { SetParents(CurrentOrgchart, null); var saved = await OrgChartHelper.SaveOrgChartJson(_sourceCode, CurrentOrgchart.ToString()); + Layout.IsDirty = false; await Layout.AddMessage(saved ? "Org chart saved." : "Unable to save org chart."); }