Developer forum

Forum » Development » Custom menu actions - forms for editors

Custom menu actions - forms for editors

Jan Sangill
Reply

Hi, in the submitlist - I would like to add a new possibility to the Action menu. Delete ALL formsubmits.
/Admin/UI/Apps/SubmitList

When reading this:
https://doc.dynamicweb.dev/documentation/extending/administration-ui/action-menu.html

I am trying to find any sort of place in the namespaces under Dynamicweb.Forms to help me locate screens, so I can add this.
Maybe I am blind, but havent been able to find it.

Is there any way to add this for this view? If so, any hints?


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Jan,
you should use the custom ScreenInjector for that, here is a documentation about it and implement the override of the GetScreenActions.
BR, Dmitrij

 
Jan Sangill
Reply

Hi Dmitrij,

There was no override of this in that part of it, but I managed to do it in onAfter.

I will leave the code here. let me know if it could have been done smarter.
 

using Dynamicweb.Apps.UI.Commands.Forms;
using Dynamicweb.Apps.UI.Screens.Forms;
using Dynamicweb.CoreUI;
using Dynamicweb.CoreUI.Actions.Implementations;
using Dynamicweb.CoreUI.Screens;
using Dynamicweb.CoreUI.Layout;
using Dynamicweb.CoreUI.Actions;
using Dynamicweb.Security.Permissions;
using rksk.CustomCode.UI.Commands;


public sealed class CustomSubmitDataListScreen
    : ScreenInjector<SubmitListScreen>
{
    public override void OnAfter(
        SubmitListScreen screen, UiComponentBase content)
    {
        if (!content.TryGet<ScreenLayout>(out var layout))
        {
            return;
        }

        int formId = Dynamicweb.Core.Converter.ToInt32(screen.Model.FormId);
        if (formId == 0)
        {
            return;
        }

        var cmd = new SubmitDeleteAllCommand { FormId = screen.Model.FormId };
        var toggleAction = ConfirmAction.For(RunCommandAction.For(cmd).WithReloadOnSuccess(), $"Delete all form submits?",
            "Are you sure you want to delete all submits?"
        );
        
        var actionNodes = new ActionNode[]
        {
            new()
            {
                Name = "Delete all form submits",
                Icon = Dynamicweb.CoreUI.Icons.Icon.Delete,
                NodeAction = toggleAction,
                PermissionLevelRequired = PermissionLevel.Delete,
            },
        };

        layout.ContextActionGroups.Add(actionNodes);
    }
}

using Dynamicweb.CoreUI.Data;
using Dynamicweb.CoreUI.Data.Validation;
using Dynamicweb.Forms;

namespace rksk.CustomCode.UI.Commands;

public sealed class SubmitDeleteAllCommand : CommandBase
{
    [Required]
    public int FormId { get; set; }

    public override CommandResult Handle()
    {
        var byId = FormsServices.Forms.GetById(this.FormId);
        if (byId == null)
            return new CommandResult()
            {
                Status = CommandResult.ResultType.NotFound
            };
        var allSubmits = FormsServices.Submits.GetSubmits(byId.ID);
        foreach (var submit in allSubmits)
        {
            FormsServices.Submits.Delete(submit.ID);
        }
        return new CommandResult()
        {
            Status = CommandResult.ResultType.Ok
        };
    }
}

 

You must be logged in to post in the forum