Skip to main content

Module action

Module action 

Source
Expand description

The action export: an item on the menus of the screens in the manifest entry’s places. Hammer asks for any [[actions.field]]s first, then calls it, and every call returns a Reply as JSON. A reply with a Page shows it in the action’s dialog; pressing one of the page’s buttons calls the action again with the button’s id, the page’s values as Request::input, and the page’s state. A reply with errors keeps the user on the page they were on, one with open ends the action and goes to an item, and one with none of these ends the action. A message is shown briefly either way.

ⓘ
let page = Page {
    title: Some("Who?".into()),
    fields: vec![Field::text("name", "Name").required()],
    buttons: vec![Button::new("back", "Back").skip_checks(), Button::new("next", "Next").primary()],
    ..Page::default()
}
.with_state(&Step { step: 2 })?;
Reply::page(page).to_json()

Structs§

Button
A button of a page. Pressing it calls the action again with its id as Request::button. It sits in the dialog’s footer, or with inline under the markdown, for acting on something in it.
Choice
One of a choice field’s options: value is what comes back in the input, label what is shown.
Context
The screen an action was run from, and the id of the item it shows there (none on Project Home).
EntityRef
An item of the project, as an entity field’s value: kind is scene, note, entry, or event, and id the item’s. Read one field as Option<EntityRef> and one with Field::multiple as Vec<EntityRef>; Open::new(&it.kind, Some(it.id)) goes to it.
Field
A field of a page. Its value comes back in the next call’s input under its key: a string for text and choice, a bool, an integer, for scenes a list of scene ids (one id or null when Field::single), and for entity an EntityRef or null (a list of them when Field::multiple). Hammer checks required, an int’s bounds, a choice’s options, and that an entity’s picks exist and match its filters before calling, unless the button pressed skips them.
Open
An item for Hammer to go to: place is project, scene, note, entry, or event, and id the item’s (none for project). An id that does not exist fails.
Page
What the action’s dialog shows: a title, markdown, the fields in order, and buttons.
Reply
What an action export returns, as Reply::to_json. Every part is optional; the default ends the action without a word.
Request

Enums§

FieldKind
TextFormat
What edits a text field: an ordinary text field, or the scene editor’s, whose value is markdown, with its format bar or the extended one (highlight, task lists, tables).