Page 9666 Report Theme and Header/Footer

Base Application, Microsoft.Foundation.Reporting

src/Layers/W1/BaseApp/Foundation/Reporting/ReportThemeandHeaderFooter.Page.al512 lines, Copyright (c) Microsoft Corporation. MIT

// ------------------------------------------------------------------------------------------------// Copyright (c) Microsoft Corporation. All rights reserved.// Licensed under the MIT License. See License.txt in the project root for license information.// ------------------------------------------------------------------------------------------------namespace Microsoft.Foundation.Reporting;using Microsoft.Shared.Report;using System.Environment.Configuration;using System.Reflection;/// <summary>/// Central registry of reusable Composite Layout artifacts — the Theme and Header/Footer layout parts that can be/// assigned as report defaults. Lists out-of-box and tenant-defined parts with their publisher and status, and lets/// administrators add, export and remove tenant-defined parts./// </summary>page 9666 "Report Theme and Header/Footer"{    ApplicationArea = Basic, Suite;    Caption = 'Manage themes and header-footer layouts';    AdditionalSearchTerms = 'Composite Layout, Document Theme, Header Footer Part, Report Themes and Header/Footers, Report themes and header-footer setup';    PageType = List;    SourceTable = "Report Layout List";    UsageCategory = Administration;    Editable = false;    InsertAllowed = false;    ModifyAllowed = false;    Extensible = true;    AboutTitle = 'Manage themes and header-footer layouts';    AboutText = 'Add, export, and delete the themes and header/footer layouts that you can set on your body layouts. Only a body layout carries them: they are merged onto it when the report renders. Set a layout to **Approved** to make it available to choose.';    layout    {        area(content)        {            repeater(Group)            {                field(LayoutCaption; Rec."Caption")                {                    ApplicationArea = Basic, Suite;                    Caption = 'Layout Name';                    ToolTip = 'Specifies the friendly, translated display name of the theme or header/footer part. For tenant-defined parts this matches the name.';                }                field(Name; Rec.Name)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Name';                    ToolTip = 'Specifies the name that identifies the theme or header/footer part. This is the value stored when the part is assigned to a report.';                }                field(Description; Rec.Description)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Description';                    ToolTip = 'Specifies the description of the theme or header/footer part.';                }                field(Type; Rec."Layout Subtype")                {                    ApplicationArea = Basic, Suite;                    Caption = 'Type';                    ToolTip = 'Specifies whether the artifact is a Theme or a Header/Footer part.';                }                field(Publisher; Rec."Layout Publisher")                {                    ApplicationArea = Basic, Suite;                    Caption = 'Publisher';                    ToolTip = 'Specifies the extension and publisher that owns the artifact. Empty for tenant-defined parts.';                }                field(Status; Rec."Layout Status")                {                    ApplicationArea = Basic, Suite;                    Caption = 'Status';                    ToolTip = 'Specifies the lifecycle status of the artifact. New parts start as Draft; only Approved parts can be assigned as report defaults.';                }            }        }    }    actions    {        area(processing)        {            action(NewTheme)            {                ApplicationArea = Basic, Suite;                Caption = 'New theme';                Image = New;                AccessByPermission = tabledata "Tenant Report Layout" = M;                Visible = NewThemeVisible;                ToolTip = 'Upload a new theme part.';                trigger OnAction()                begin                    CreateArtifact(Enum::"Report Layout Subtype"::Theme);                end;            }            action(NewHeaderFooter)            {                ApplicationArea = Basic, Suite;                Caption = 'New header/footer';                Image = New;                AccessByPermission = tabledata "Tenant Report Layout" = M;                Visible = NewHeaderFooterVisible;                ToolTip = 'Upload a new header/footer part.';                trigger OnAction()                begin                    CreateArtifact(Enum::"Report Layout Subtype"::HeaderFooter);                end;            }            action(ExportArtifact)            {                ApplicationArea = Basic, Suite;                Caption = 'Export';                Image = Export;                ToolTip = 'Export the selected artifact file.';                trigger OnAction()                begin                    ReportLayoutsImpl.ExportReportLayout(Rec, false);                end;            }            action(ShowInfo)            {                ApplicationArea = Basic, Suite;                Caption = 'Show info';                Image = Info;                ToolTip = 'Show details of the selected theme or header/footer part, including how many report configurations currently use it.';                trigger OnAction()                begin                    ShowPartInfo();                end;            }            action(EditDescription)            {                ApplicationArea = Basic, Suite;                Caption = 'Edit description';                Image = Edit;                Scope = Repeater;                AccessByPermission = tabledata "Tenant Report Layout" = M;                ToolTip = 'Edit the description of the selected tenant-defined theme or header/footer part. Out-of-box parts cannot be edited.';                trigger OnAction()                begin                    EditPartDescription();                end;            }            action(ReplaceArtifact)            {                ApplicationArea = Basic, Suite;                Caption = 'Replace';                Image = Import;                Scope = Repeater;                AccessByPermission = tabledata "Tenant Report Layout" = M;                ToolTip = 'Replace the layout file of the selected tenant-defined theme or header/footer part. Out-of-box parts cannot be replaced.';                trigger OnAction()                begin                    ReplaceSelectedArtifact();                end;            }            action(DeleteArtifact)            {                ApplicationArea = Basic, Suite;                Caption = 'Delete';                Image = Delete;                AccessByPermission = tabledata "Tenant Report Layout" = M;                ToolTip = 'Delete the selected tenant-defined artifact. Out-of-box parts cannot be deleted.';                trigger OnAction()                begin                    DeleteSelectedArtifact();                end;            }            group(StatusActions)            {                Caption = 'Part Status';                Image = Status;                action(SetApproved)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Set as Approved';                    Image = Approve;                    Scope = Repeater;                    ToolTip = 'Approve the selected parts so they can be assigned as report defaults.';                    trigger OnAction()                    begin                        SetStatus(Enum::"Report Layout Status"::Approved);                    end;                }                action(SetDraft)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Set as Draft';                    Image = OpenWorksheet;                    Scope = Repeater;                    ToolTip = 'Move the selected parts back to Draft. Draft parts cannot be assigned as report defaults.';                    trigger OnAction()                    begin                        SetStatus(Enum::"Report Layout Status"::Draft);                    end;                }                action(SetPendingApproval)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Set as Pending Approval';                    Image = AddWatch;                    Scope = Repeater;                    ToolTip = 'Mark the selected parts as pending approval.';                    trigger OnAction()                    begin                        SetStatus(Enum::"Report Layout Status"::"Pending Approval");                    end;                }                action(SetRetired)                {                    ApplicationArea = Basic, Suite;                    Caption = 'Set as Retired';                    Image = Archive;                    Scope = Repeater;                    ToolTip = 'Retire the selected parts so they are no longer offered for assignment.';                    trigger OnAction()                    begin                        SetStatus(Enum::"Report Layout Status"::Retired);                    end;                }            }        }        area(Promoted)        {            group(Category_Process)            {                Caption = 'Process';                actionref(NewTheme_Promoted; NewTheme) { }                actionref(NewHeaderFooter_Promoted; NewHeaderFooter) { }                actionref(ReplaceArtifact_Promoted; ReplaceArtifact) { }                actionref(ShowInfo_Promoted; ShowInfo) { }                actionref(EditDescription_Promoted; EditDescription) { }                actionref(SetApproved_Promoted; SetApproved) { }                actionref(SetDraft_Promoted; SetDraft) { }            }        }    }    trigger OnOpenPage()    var        FeatureKeyManagement: Codeunit "Feature Key Management";    begin        if not FeatureKeyManagement.IsDocumentReportExperienceEnabled() then            Error(FeatureNotEnabledErr);        NewThemeVisible := (not LookupSubtypeSet) or (LookupSubtype = LookupSubtype::Theme);        NewHeaderFooterVisible := (not LookupSubtypeSet) or (LookupSubtype = LookupSubtype::HeaderFooter);        Rec.FilterGroup(2);        if LookupSubtypeSet then begin            Rec.SetRange("Report ID", LookupHelper.GetTenantReportDefaultsReportID());            Rec.SetRange("Layout Subtype", LookupSubtype);        end else            Rec.SetFilter("Layout Subtype", '%1|%2', Rec."Layout Subtype"::HeaderFooter, Rec."Layout Subtype"::Theme);        Rec.FilterGroup(0);    end;    internal procedure SetLookupSubtype(Subtype: Enum "Report Layout Subtype")    begin        LookupSubtype := Subtype;        LookupSubtypeSet := true;    end;    local procedure CreateArtifact(Subtype: Enum "Report Layout Subtype")    var        NewPartDialog: Page "New Report Theme Header/Footer";        ExcelSheetConfiguration: Enum "Excel Sheet Configuration";        ReturnReportID: Integer;        ReturnLayoutName: Text;    begin        NewPartDialog.SetSubtype(Subtype);        if NewPartDialog.RunModal() <> Action::OK then            exit;        // Create the part under Tenant Report Defaults as a global Word layout so it can be        // assigned to any report. InsertNewLayout prompts for the file and validates the subtype.        ReportLayoutsImpl.InsertNewLayout(            LookupHelper.GetTenantReportDefaultsReportID(),            NewPartDialog.GetPartName(),            NewPartDialog.GetPartDescription(),            Rec."Layout Format"::Word,            true,            NewPartDialog.GetCreateEmptyLayout(),            ExcelSheetConfiguration,            Subtype,            ReturnReportID,            ReturnLayoutName);        SetFocusedRecord(ReturnReportID, ReturnLayoutName);    end;    local procedure SetFocusedRecord(ReportID: Integer; LayoutName: Text)    var        NewPart: Record "Report Layout List";    begin        if (ReportID <> 0) and (LayoutName <> '') and NewPart.Get(ReportID, LayoutName, EmptyGuid) then            CurrPage.SetRecord(NewPart);        CurrPage.Update(false);    end;    local procedure SetStatus(NewStatus: Enum "Report Layout Status")    var        SelectedLayouts: Record "Report Layout List";        UpdatedName: Text;        UpdateCount: Integer;        AssignedCount: Integer;    begin        CurrPage.SetSelectionFilter(SelectedLayouts);        SelectedLayouts.SetRange("User Defined", true);        // Moving an assigned part away from Approved does not unassign it — it will keep applying at print time        // (status is not enforced at render). Warn so the change isn't made unknowingly.        if NewStatus <> NewStatus::Approved then begin            AssignedCount := CountAssignedInSelection(SelectedLayouts);            if AssignedCount > 0 then                if not Confirm(DemoteAssignedQst, false, AssignedCount) then                    exit;        end;        UpdateCount := ReportLayoutsImpl.SetLayoutStatusBatch(SelectedLayouts, NewStatus);        if UpdateCount > 0 then begin            UpdatedName := GetSingleUserDefinedName(SelectedLayouts);            if (UpdateCount = 1) and (UpdatedName <> '') then                Message(StatusChangedSingleMsg, UpdatedName, NewStatus)            else                Message(StatusChangedMsg, UpdateCount, NewStatus);        end;        CurrPage.Update(false);    end;    local procedure GetSingleUserDefinedName(var SelectedLayouts: Record "Report Layout List"): Text    var        FoundName: Text;        FoundCount: Integer;    begin        if SelectedLayouts.FindSet() then            repeat                FoundName := SelectedLayouts.Name;                FoundCount += 1;            until (SelectedLayouts.Next() = 0) or (FoundCount > 1);        if FoundCount = 1 then            exit(FoundName);    end;    local procedure CountAssignedInSelection(var SelectedLayouts: Record "Report Layout List"): Integer    var        Total: Integer;    begin        if SelectedLayouts.FindSet() then            repeat                Total += LookupHelper.CountPartAssignments(SelectedLayouts);            until SelectedLayouts.Next() = 0;        exit(Total);    end;    local procedure ReplaceSelectedArtifact()    var        ReturnReportID: Integer;        ReturnLayoutName: Text;        TypeText: Text;    begin        if not Rec."User Defined" then            Error(CannotReplaceOobErr);        if Rec."Layout Subtype" = Rec."Layout Subtype"::Theme then            TypeText := ThemeTypeTxt        else            TypeText := HeaderFooterTypeTxt;        if not Confirm(ReplaceArtifactQst, false, TypeText, Rec.Name) then            exit;        ReportLayoutsImpl.ReplaceLayout(Rec."Report ID", Rec.Name, Rec.Description, Rec."Layout Format", ReturnReportID, ReturnLayoutName);        CurrPage.Update(false);    end;    local procedure EditPartDescription()    var        TenantReportLayout: Record "Tenant Report Layout";        EditDescriptionDialog: Page "New Report Theme Header/Footer";    begin        if not Rec."User Defined" then            Error(CannotEditOobErr);        if not TenantReportLayout.Get(Rec."Report ID", Rec.Name, EmptyGuid) then            exit;        EditDescriptionDialog.SetEditDescriptionMode(TenantReportLayout.Description);        if EditDescriptionDialog.RunModal() <> Action::OK then            exit;        ReportLayoutsImpl.UpdateReportLayoutDescription(Rec."Report ID", Rec.Name, EditDescriptionDialog.GetPartDescription());        CurrPage.Update(false);    end;    local procedure ShowPartInfo()    var        TypeText: Text;        PublisherText: Text;        AssignedCount: Integer;    begin        if Rec."Layout Subtype" = Rec."Layout Subtype"::Theme then            TypeText := ThemeTypeTxt        else            TypeText := HeaderFooterTypeTxt;        if Rec."User Defined" then            PublisherText := TenantDefinedTxt        else            PublisherText := Rec."Layout Publisher";        AssignedCount := LookupHelper.CountPartAssignments(Rec);        // Pass values as parameters so any backslashes in the data are not turned into line breaks.        Message(PartInfoLbl, Rec.Name, Rec.Description, TypeText, Format(Rec."Layout Status"), PublisherText, AssignedCount);    end;    local procedure DeleteSelectedArtifact()    var        SelectedLayouts: Record "Report Layout List";        TempPartsToDelete: Record "Tenant Report Layout" temporary;        TenantReportLayout: Record "Tenant Report Layout";        SingleName: Text;        DeletableCount: Integer;        AssignedCount: Integer;    begin        CurrPage.SetSelectionFilter(SelectedLayouts);        SelectedLayouts.SetRange("User Defined", true);        if SelectedLayouts.FindSet() then            repeat                DeletableCount += 1;                AssignedCount += LookupHelper.CountPartAssignments(SelectedLayouts);            until SelectedLayouts.Next() = 0;        if DeletableCount = 0 then            Error(CannotDeleteOobErr);        if DeletableCount = 1 then begin            SingleName := GetSingleUserDefinedName(SelectedLayouts);            if AssignedCount > 0 then begin                if not Confirm(DeletePartWithReferencesQst, false, SingleName, AssignedCount) then                    exit;            end else                if not Confirm(DeleteArtifactQst, false, SingleName) then                    exit;        end else            if AssignedCount > 0 then begin                if not Confirm(DeletePartsWithReferencesQst, false, DeletableCount, AssignedCount) then                    exit;            end else                if not Confirm(DeleteArtifactsQst, false, DeletableCount) then                    exit;        SelectedLayouts.FindSet();        repeat            LookupHelper.ClearPartAssignments(SelectedLayouts);            TempPartsToDelete.Init();            TempPartsToDelete."Report ID" := SelectedLayouts."Report ID";            TempPartsToDelete.Name := SelectedLayouts.Name;            TempPartsToDelete.Insert();        until SelectedLayouts.Next() = 0;        if TempPartsToDelete.FindSet() then            repeat                if TenantReportLayout.Get(TempPartsToDelete."Report ID", TempPartsToDelete.Name, EmptyGuid) then                    ReportLayoutsImpl.DeleteReportLayout(TenantReportLayout);            until TempPartsToDelete.Next() = 0;        CurrPage.Update(false);    end;    var        ReportLayoutsImpl: Codeunit "Report Layouts Impl.";        LookupHelper: Codeunit "Composite Layout Lookup Helper";        LookupSubtype: Enum "Report Layout Subtype";        EmptyGuid: Guid;        LookupSubtypeSet: Boolean;        NewThemeVisible: Boolean;        NewHeaderFooterVisible: Boolean;        FeatureNotEnabledErr: Label 'The Composite Layout feature is gated by the Document Report Experience preview. Enable it in Feature Management before opening this page.';        CannotDeleteOobErr: Label 'Out-of-box themes and header/footer parts cannot be deleted.';        CannotReplaceOobErr: Label 'Out-of-box themes and header/footer parts cannot be replaced.';        CannotEditOobErr: Label 'Out-of-box themes and header/footer parts cannot be edited.';        ReplaceArtifactQst: Label 'Replace the %1 layout file for "%2"?', Comment = '%1 = layout type (Theme or Header/Footer); %2 = artifact name';        ThemeTypeTxt: Label 'Theme';        HeaderFooterTypeTxt: Label 'Header/Footer';        TenantDefinedTxt: Label 'Tenant-defined';        PartInfoLbl: Label 'Name: %1\Description: %2\Type: %3\Status: %4\Publisher: %5\Used in %6 report configuration(s).', Comment = '%1 = part name; %2 = description; %3 = type (Theme or Header/Footer); %4 = status; %5 = publisher; %6 = number of report configurations that reference the part';        DeleteArtifactQst: Label 'Delete the artifact %1?', Comment = '%1 = artifact name';        DeleteArtifactsQst: Label 'Delete the %1 selected artifacts?', Comment = '%1 = number of artifacts';        DeletePartsWithReferencesQst: Label 'The %1 selected parts are assigned in %2 report configuration(s). Deleting them will clear those assignments and the affected reports will render without these parts. Do you want to continue?', Comment = '%1 = number of parts; %2 = number of configurations';        DeletePartWithReferencesQst: Label 'The part "%1" is assigned in %2 report configuration(s). Deleting it will clear those assignments and the affected reports will render without this part. Do you want to continue?', Comment = '%1 = artifact name; %2 = number of configurations';        StatusChangedMsg: Label 'The status of %1 part(s) was changed to %2.', Comment = '%1 = number of parts; %2 = new status';        StatusChangedSingleMsg: Label 'The status of "%1" was changed to %2.', Comment = '%1 = part name; %2 = new status';        DemoteAssignedQst: Label 'The selected part(s) are currently assigned in %1 report configuration(s) and will keep applying when reports are printed, even after this status change. Change the status anyway?', Comment = '%1 = number of configurations';}