Skip to main content

BusinessObject

Derive Macro BusinessObject 

Source
#[derive(BusinessObject)]
{
    // Attributes available to this derive:
    #[object]
    #[field]
    #[rule]
    #[appearance]
    #[variant]
    #[list_filter]
    #[action]
}
Expand description

Declares a struct as a business object: an entity for the model, and the way to and from a record.

On the struct, #[object(caption = "...", navigation = "...", icon = "...", list_criteria = "...", form_columns = 2, cloneable, transient, checks_on_leave, list_editable, data_access = "server", form_actions = "name", focus_order = "a,b")], where data_access is client, server or data_view, and focus_order the fields the form goes through first.

On a field, #[field(...)]:

  • key numbered by the application, or typed_key typed by people. Exactly one field has one. With guid, a key is made up when a record is created instead of being numbered.
  • caption = "..." what people see.
  • default_property what names a record. read_only. no_list, no_detail, lookup.
  • What it holds, when the type does not say: money, long, color, date, guid, decimals = 2, reference = "Entity", collection = "Entity", tags = "a,b".
  • calculated = "[a] + [b]", in the criteria language, checked here.
  • default = ... what a new record starts with.
  • required, unique, min = 1, max = 10, matches = "^[A-Z]+$": what it has to meet on saving, and message = "..." what to say instead of the usual words.
  • On a form: editor = "...", placeholder = "...", hint = "...", wide, autofocus, group = "..." for the titled group it goes in, edit_mask = "(00) 0000-0000", predefined = "a,b" for values to pick from, criteria_of = "Entity" for a filter builder.
  • For screen readers: accessible_name = "..." instead of the caption, and accessible_description = "..." instead of the hint.
  • display_format = "{:.2} %", how its value shows when it is not being edited.
  • On a reference: lookup_filter = "[flow] = ?flow", none_caption = "...". On a collection: back_reference = "...", aggregated. secret never leaves a secured space. non_cloneable stays behind on cloning, and most_bytes = 1024 limits a picture or a file.

On the struct, as many as needed:

  • #[rule(criteria = "[a] <= [b]", message = "...", context = "Pay", target = "[c] > 0")], or #[rule(unique = "a,b")]. With warning people can go on anyway, and with information it only leaves a note. A message can say {field} and {reference.field}.
  • #[appearance(names = "a,b*", criteria = "...", font = "danger", back = "warning", bold, enabled = false, visible = false, priority = 1, context = "list", action)]. With layout, the names are groups of a form; with action, actions. A context is list, detail or a view’s id. Tints are danger, warning, success, accent and muted.
  • #[action(caption = "...", set = "state = 'done'; finished = Today()", enabled = "...", selection = "many", confirm = "...", id = "...")]: an action that sets fields of the records selected, each read from the record as it was, and keeps them once they meet the rules. selection is one, many (the default) or any; enabled is what every record selected has to meet for it to be on. Both expressions are checked here.
  • #[variant(id = "...", caption = "...", filter = "...", columns = "a,b")] and #[list_filter(id = "...", caption = "...", filter = "...")], for people to pick on the list.