Benutzer-Werkzeuge

Webseiten-Werkzeuge


extensibility:assessments:confirmation:example

Beispielcode für ein Plugin vom Typ "Erweiterung" um einen Bestätigungsdialog zu einem Formular anzuzeigen

confirmation_dialog_plugin_example.cs
using Grpc.Core;
using System;
using System.Threading.Tasks;
using Caats.Infrastructure.Authorization;
using Caats.Infrastructure.Helper;
using Caats.Infrastructure.Extensions;
using Caats.Proto;
 
namespace Caats.Service.Infrastructure.Extensibility;
 
[PluginServiceDto(typeof(ChecklistInstanceDto))]
public class ChkValidationPoC : PluginBase
{
    public override PluginDto Ident() => new() { };
 
    public async override Task<(RequestMsg, ResponseMsg?)> OnBeforeUpdate(RequestMsg request, Lazy<IdentityBase> identity, ServerCallContext context)
    {
        var candidate = RequestMsgHelper.GetSingleOrDefault<ChecklistInstanceDto>(request);
        ResponseMsg? response = null;
 
        if (candidate == null)
        {
            return (request, null);
        }
 
        // evaluate conditions to decide whether confirmation is needed
        // set to "true" for brevity (because this is not the subject of the tutorial)
        var confirmationNeeded = true;
 
        if (request.IsConfirmationPromptAnswered())
        {
            // user has already answered the confirmation prompt
        }
        else if (confirmationNeeded)
        {
            // this will result in the user being asked for confirmation
            // (and the update call will not immediately go ahead in the backend)
            // the prompt supports html (no script) for formatting:
 
            var prompt = @"Die eingegebene Leistungszeit liegt mehr als 7 Tage in der Vergangenheit 
            <ul>
              <li>Leistungen eines Einsatzes sollten <strong>aufeinanderfolgen</strong></li>
              <li>Anfahrt und Abfahrt sollten an die Leistungszeit <strong>angrenzen</strong></li>
            </ul>
            Bitte bestätigen: Trotzdem buchen?";
 
            response = ResponseMsg.PromptForConfirmation(
                dialogTitle: "Bestätigung erforderlich",
                dialogPrompt: prompt,
                [
                    (choiceDialogResult: ResponseMsg.DialogResult.Save, choiceKey: "indeed", choiceLabel: "COMMON.YES"),
                    (choiceDialogResult: ResponseMsg.DialogResult.Cancel, choiceKey: "nope", choiceLabel: "COMMON.DIALOG_ACTION_CANCEL")
                ]
            );
        }
 
        return await Task.FromResult((request, response));
    }
}

Die dem Beispiel zugrunde liegende Checklisten-Definition sieht in der Excel-Datei folgendermaßen aus:

extensibility/assessments/confirmation/example.txt · Zuletzt geändert: 2025/07/17 13:47 von agoldman

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki