Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

A class can contain actions that are generally shown as buttons or links in a UI and run some code when pressed.

A build adds an action with Action(), shown below.

Builder.Add.Action(...)

The action defined above doesn't do anything yet.

While a product can of course include code directly, it's strongly recommended to make some sort of method container that can be tested. The following example from the Sandbox passes the call to DeletePerson to a _businessLogic. The Result is a hint to the caller so that it can update the UI.

private void DeletePerson([NotNull] object sender, [NotNull] MetaActionEventArgs args)
{
  if (sender is Person person)
  {
    _businessLogic.DeletePerson(person);

    args.Result = MetaActionResult.CallingObjectChanged;
  }

  args.Result = MetaActionResult.None;
}

A product can attach code using the Body(...) method.

Builder.Add
  .Action("DeletePerson")
  .Body(DeletePerson)

Actions with Parameters

Some action require more context than other to work properly.

For example the given action will require a “Contact” as a parameter:

// Builder
Elements.Person.Add.Action<Person, Contact>("AddContact", nameof(Elements.Contact), AddContact)
        .Caption(German, "Kontakt hinzufügen...")
        .Caption(English, "Add contact...");
  
// Method      
private void AddContact([NotNull] Person person, [NotNull] Contact contact, MetaActionExecutionContext executionContext)
{
  if (person == null) { throw new ArgumentNullException(nameof(person)); }
  if (contact == null) { throw new ArgumentNullException(nameof(contact)); }

  person.Contacts.Add(contact);
  person.Save();
}        

This will lead to a popup once the action is invoked and the user will have to fill out the popup before being able to execute the action.

Actions with Confirmation

If an action wants to display a warning or hint before executing an action the following method can be used:

builder.Get.Class(nameof(elements.Person)).Add.Action("TestActionWithConfirmation")
        .RequiresConfirmation()
        .Content(German, "Inhalt")
        .Title(German, "Titel")
        .ContinueCaption(German, "Weiter")
        .CancelCaption(German, "Abbrechen");

Die Captions für die einzelnen Bereich können dabei auch leer gelassen werden um die Standardübersetzungen zu verwenden.

Placement of actions in a List

If an action is added to a list via LinkAction the placement can be controlled with the following options:

list.Add.LinkAction(metadata.Person.LowerCaseNameListAction).ShowInListSelection().IsOverflowByDefault();
list.Add.LinkAction(metadata.Person.UpperCaseNameListAction).ShowInListRow();

Placement of actions in a Detail

If an action is added directly to a detail layout the action will be displayed in the sidebar

detail.Add.LinkAction(metadata.Person.LowerCaseNameListAction);
detail.Add.LinkAction(metadata.Person.UpperCaseNameListAction);

To show an action in a layout add it to the parent element e.g a group:

group.Add.LinkAction(metadata.Person.LowerCaseNameDetailAction);

  • No labels