pub struct ActionDef<R>where
R: Resource,{ /* private fields */ }Expand description
What an Action declares besides its name, input and body: where its button
renders, how it reads on each record, and which records it runs on. Every setting has a
default, so ActionDef::new alone is a button on each row, page header and the bulk bar,
labelled after the action’s NAME, that runs on every record the policy allows.
let def = ActionDef::<PostResource>::new()
.places(Places::ROW.with(Places::DETAIL))
.icon(tablo_ui::icons::CHECK)
.color(Color::Success)
.can_run(|_cx, post: &Post| post.status != "published")
.disabled_reason(|_cx, _post| Some("Already published".into()));Implementations§
Source§impl<R> ActionDef<R>where
R: Resource,
impl<R> ActionDef<R>where
R: Resource,
Sourcepub fn new() -> ActionDef<R>
pub fn new() -> ActionDef<R>
Every default: a gray button on each row, page header and the bulk bar, labelled after the
action’s NAME, running without confirmation on every record the policy allows.
Sourcepub fn places(self, places: Places) -> ActionDef<R>
pub fn places(self, places: Places) -> ActionDef<R>
Where the button renders. Defaults to Places::ALL: each row, the detail and edit
pages’ headers, and the bulk bar.
It decides where the button shows, not who may run it: the record route serves an action
placed on any of Places::RECORD, and the bulk route one placed on Places::BULK;
any other POST answers 404. A place no page renders shows the button nowhere:
Places::EDIT on a resource without a form, or Places::DETAIL on one that turns its
view page off (ResourcePage::View).
Sourcepub fn confirm(self) -> ActionDef<R>
pub fn confirm(self) -> ActionDef<R>
Asks first, through a confirmation dialog sharing the delete dialog’s mechanism and destructive wording.
An action with input confirms in its input dialog, or on its input page, instead, which say the action cannot be undone and whose submit renders destructive. An unconfirmed POST that would write answers 400. Both dialogs need JavaScript: without it their buttons do nothing.
Sourcepub fn confirmation(self, question: impl Into<Text>) -> ActionDef<R>
pub fn confirmation(self, question: impl Into<Text>) -> ActionDef<R>
Asks first, as confirm does, with question in place of the message
tablo-confirm-run, “Run this action?”. An action with input confirms in its input
dialog instead, which its label titles.
Sourcepub fn icon(self, icon: IconData) -> ActionDef<R>
pub fn icon(self, icon: IconData) -> ActionDef<R>
The icon before the button’s label, in every place. Defaults to none.
Sourcepub fn color(self, color: Color) -> ActionDef<R>
pub fn color(self, color: Color) -> ActionDef<R>
The colour the button is tinted in, as Delete’s is in Color::Danger. Defaults to
Color::Gray, the untinted button.
It changes how the button looks, not what it asks: confirm asks first.
Sourcepub fn label(self, label: impl Into<Text>) -> ActionDef<R>
pub fn label(self, label: impl Into<Text>) -> ActionDef<R>
The button text. Defaults to the message action-{NAME} of the panel’s catalogs, else
NAME in sentence case: "publish" reads “Publish”, and "send-invite" reads “Send
invite”.
The bulk bar, the input dialogs and the messages read it; a record’s button reads
label_for when one is declared.
Sourcepub fn label_for(
self,
label: impl Fn(&Cx, &<R as Resource>::Model) -> Text + Send + Sync + 'static,
) -> ActionDef<R>
pub fn label_for( self, label: impl Fn(&Cx, &<R as Resource>::Model) -> Text + Send + Sync + 'static, ) -> ActionDef<R>
The text of the button on one record: its row’s, or its record page’s. Defaults to the
label.
Declare it when the record’s state changes what the action reads: “Deactivate” on an active employee, “Activate” on one that is not.
Sourcepub fn icon_for(
self,
icon: impl Fn(&Cx, &<R as Resource>::Model) -> Option<IconData> + Send + Sync + 'static,
) -> ActionDef<R>
pub fn icon_for( self, icon: impl Fn(&Cx, &<R as Resource>::Model) -> Option<IconData> + Send + Sync + 'static, ) -> ActionDef<R>
The icon of the button on one record, in its row and on its record page. Defaults to the
icon.
Sourcepub fn tooltip(self, tooltip: impl Into<Text>) -> ActionDef<R>
pub fn tooltip(self, tooltip: impl Into<Text>) -> ActionDef<R>
The hint a row’s button shows on hover, for an action whose label says too little. Defaults to none.
A button refused on its record shows its disabled_reason
instead.
Sourcepub fn can_run(
self,
check: impl Fn(&Cx, &<R as Resource>::Model) -> bool + Send + Sync + 'static,
) -> ActionDef<R>
pub fn can_run( self, check: impl Fn(&Cx, &<R as Resource>::Model) -> bool + Send + Sync + 'static, ) -> ActionDef<R>
Whether the action itself runs on a record, wherever it is mounted: a published post refuses “publish”. Defaults to every record.
It is one half of Ability::Run, which the resource allows only
when both this and its policy do: can answers the two together. Who may
run the action belongs in the policy, which each panel mounts its own; a rule written here
holds on every panel and cannot be lifted by one. Asking can for this action’s own Run
from here would ask this closure again.
Sourcepub fn disabled_reason(
self,
reason: impl Fn(&Cx, &<R as Resource>::Model) -> Option<Text> + Send + Sync + 'static,
) -> ActionDef<R>
pub fn disabled_reason( self, reason: impl Fn(&Cx, &<R as Resource>::Model) -> Option<Text> + Send + Sync + 'static, ) -> ActionDef<R>
Why the button shows disabled on a record can_run refuses, rather than
hidden: “Already published” for a published post. Defaults to none, which hides it.
It is asked only of a record the policy lets the user view and run the action on, so the
reason speaks to the record’s state and never tells a user what the policy refuses them.
The route refuses a disabled record as it refuses one can_run hides.
Sourcepub fn success(
self,
message: impl Fn(usize) -> Text + Send + Sync + 'static,
) -> ActionDef<R>
pub fn success( self, message: impl Fn(usize) -> Text + Send + Sync + 'static, ) -> ActionDef<R>
The success notification after a commit that ran on count records. Defaults to the
label and the record count: "Publish: 3 records". A bulk run the action refused on some
records appends their count out of the selection: "Publish: 3 records (2 of 5 skipped)".