pub struct Action(/* private fields */);Expand description
Something people can do. A handle: the frame and its controller hold the same action, so a controller can turn it off by a reason of its own.
use ravenrs_app::{Action, ActionCategory, CriteriaMode, Selection};
let pay = Action::simple("Pay", "Pagar")
.category(ActionCategory::Edit)
.target_entity("Bill")
.selection(Selection::RequireMultiple)
.target_criteria("[Status] = 'Open'", CriteriaMode::TrueForAll)
.on_execute(|cx| {
for bill in &cx.selected {
let mut bill = bill.clone();
bill.set("Status", "Paid");
cx.space.borrow_mut().save(bill).map_err(|e| e.to_string())?;
}
cx.space.borrow_mut().commit().map_err(|e| e.to_string())
});
assert_eq!(pay.caption(), "Pagar");Implementations§
Source§impl Action
impl Action
Sourcepub fn simple(id: impl Into<String>, caption: impl Into<String>) -> Self
pub fn simple(id: impl Into<String>, caption: impl Into<String>) -> Self
A button: it just runs.
Sourcepub fn background(
id: impl Into<String>,
caption: impl Into<String>,
work: impl Fn(&JobContext) -> Result<(), String> + Send + Sync + 'static,
) -> Self
pub fn background( id: impl Into<String>, caption: impl Into<String>, work: impl Fn(&JobContext) -> Result<(), String> + Send + Sync + 'static, ) -> Self
A button whose work runs away from the screen, on a thread of its own: it shows how far it got, can be stopped, and what it hands back is kept on the screen’s thread. While it runs, the action is off, so it never runs twice at once.
use ravenrs_app::{Action, Selection};
let archive = Action::background("Archive", "Arquivar", |job| {
for record in job.selected() {
let mut record = record.clone();
record.set("Archived", true);
job.save(record);
}
Ok(())
})
.selection(Selection::RequireMultiple);
assert!(archive.is_background());Sourcepub fn popup(
id: impl Into<String>,
caption: impl Into<String>,
view: impl Into<String>,
) -> Self
pub fn popup( id: impl Into<String>, caption: impl Into<String>, view: impl Into<String>, ) -> Self
Opens a view in a window, and runs on OK.
Sourcepub fn single_choice(
id: impl Into<String>,
caption: impl Into<String>,
items: Vec<ChoiceItem>,
) -> Self
pub fn single_choice( id: impl Into<String>, caption: impl Into<String>, items: Vec<ChoiceItem>, ) -> Self
Offers these options, and runs with the one picked.
Sourcepub fn parametrized(
id: impl Into<String>,
caption: impl Into<String>,
kind: FieldKind,
) -> Self
pub fn parametrized( id: impl Into<String>, caption: impl Into<String>, kind: FieldKind, ) -> Self
Asks for a value of this kind, and runs with it.
Sourcepub fn url(
id: impl Into<String>,
caption: impl Into<String>,
template: impl Into<String>,
) -> Self
pub fn url( id: impl Into<String>, caption: impl Into<String>, template: impl Into<String>, ) -> Self
Opens an address made from the selected record, where {field} takes its value.
Sourcepub fn in_background(
self,
work: impl Fn(&JobContext) -> Result<(), String> + Send + Sync + 'static,
) -> Self
pub fn in_background( self, work: impl Fn(&JobContext) -> Result<(), String> + Send + Sync + 'static, ) -> Self
Runs this work away from the screen once it runs, after on_execute, with what people gave
it. See Action::background.
Sourcepub fn is_background(&self) -> bool
pub fn is_background(&self) -> bool
Whether its work runs away from the screen.
Sourcepub fn category(self, category: ActionCategory) -> Self
pub fn category(self, category: ActionCategory) -> Self
Where it belongs.
Sourcepub fn target_entity(self, entity: impl Into<String>) -> Self
pub fn target_entity(self, entity: impl Into<String>) -> Self
Only on views of this entity.
Sourcepub fn target_view(self, id: impl Into<String>) -> Self
pub fn target_view(self, id: impl Into<String>) -> Self
Only on the view with this id.
Sourcepub fn target_view_kind(self, kind: ViewKind) -> Self
pub fn target_view_kind(self, kind: ViewKind) -> Self
Only on views of this kind.
Sourcepub fn target_criteria(
self,
criteria: impl Into<String>,
mode: CriteriaMode,
) -> Self
pub fn target_criteria( self, criteria: impl Into<String>, mode: CriteriaMode, ) -> Self
What the selected records have to meet. With nothing selected, it does not stop anything;
selection says whether something has to be.
Sourcepub fn validation_contexts(
self,
contexts: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn validation_contexts( self, contexts: impl IntoIterator<Item = impl Into<String>>, ) -> Self
The validation contexts to pass before it runs.
Sourcepub fn confirmation(self, text: impl Into<String>) -> Self
pub fn confirmation(self, text: impl Into<String>) -> Self
A question to ask before it runs.
Sourcepub fn confirmation_words(
self,
detail: impl Into<String>,
answer: impl Into<String>,
) -> Self
pub fn confirmation_words( self, detail: impl Into<String>, answer: impl Into<String>, ) -> Self
What the question says besides, and what the answer that runs it says.
Sourcepub fn on_prepare(
self,
handler: impl Fn(&ActionContext, &mut Object) + 'static,
) -> Self
pub fn on_prepare( self, handler: impl Fn(&ActionContext, &mut Object) + 'static, ) -> Self
For a popup that opens a form: fills in the record it starts with.
Sourcepub fn requires(self, operation: Operation) -> Self
pub fn requires(self, operation: Operation) -> Self
What it does to the records of its view, so it fades for who cannot. The secured space refuses it anyway.
Sourcepub fn hotkey(self, keys: impl Into<String>) -> Self
pub fn hotkey(self, keys: impl Into<String>) -> Self
The keys that run it, in the words of whoever shows it.
Sourcepub fn accessible_name(self, name: impl Into<String>) -> Self
pub fn accessible_name(self, name: impl Into<String>) -> Self
What screen readers call it, instead of its caption: for a caption that only makes sense on the screen, such as an arrow.
Sourcepub fn accessible_description(self, text: impl Into<String>) -> Self
pub fn accessible_description(self, text: impl Into<String>) -> Self
What screen readers say after its name, such as what it does to the selected records.
Sourcepub fn on_execute(
self,
handler: impl Fn(&ActionContext) -> Result<(), String> + 'static,
) -> Self
pub fn on_execute( self, handler: impl Fn(&ActionContext) -> Result<(), String> + 'static, ) -> Self
What it does.
Sourcepub fn assign(self, entity: &EntityInfo, set: &str) -> Self
pub fn assign(self, entity: &EntityInfo, set: &str) -> Self
Runs as an update: sets fields of every record selected of this entity, as
field = expression; ..., each read from the record as it was; checks them against the
rules of Save, and keeps them all or none. What does not parse, or names a field the
entity has not, is found when the application is put together.
use ravenrs_app::{Action, EntityInfo, FieldInfo, FieldKind, Selection};
let task = EntityInfo::new("Task")
.field(FieldInfo::new("id", FieldKind::Integer).key())
.field(FieldInfo::new("state", FieldKind::Text));
let finish = Action::simple("Finish", "Concluir")
.target_entity("Task")
.selection(Selection::RequireMultiple)
.assign(&task, "state = 'done'");
assert_eq!(finish.caption(), "Concluir");Sourcepub fn on_cancel(self, handler: impl Fn(&ActionContext) + 'static) -> Self
pub fn on_cancel(self, handler: impl Fn(&ActionContext) + 'static) -> Self
What a popup does when canceled.
Sourcepub fn on_executing(
self,
guard: impl Fn(&ActionContext) -> bool + 'static,
) -> Self
pub fn on_executing( self, guard: impl Fn(&ActionContext) -> bool + 'static, ) -> Self
Asked before it runs; false stops it.
Sourcepub fn on_executed(self, notice: impl Fn(&ActionContext) + 'static) -> Self
pub fn on_executed(self, notice: impl Fn(&ActionContext) + 'static) -> Self
Told after it ran.
Sourcepub fn kind(&self) -> &ActionKind
pub fn kind(&self) -> &ActionKind
How it asks for what it needs.
Sourcepub fn action_category(&self) -> &ActionCategory
pub fn action_category(&self) -> &ActionCategory
Where it belongs.
Sourcepub fn confirmation_text(&self) -> Option<&str>
pub fn confirmation_text(&self) -> Option<&str>
The question to ask before it runs.
Sourcepub fn confirmation_detail(&self) -> Option<&str>
pub fn confirmation_detail(&self) -> Option<&str>
What the question says besides.
Sourcepub fn confirmation_answer(&self) -> Option<&str>
pub fn confirmation_answer(&self) -> Option<&str>
What the answer that runs it says.
Sourcepub fn required_operation(&self) -> Option<Operation>
pub fn required_operation(&self) -> Option<Operation>
What it does to the records of its view, if it said.
Sourcepub fn hotkey_text(&self) -> Option<&str>
pub fn hotkey_text(&self) -> Option<&str>
The keys that run it.
Sourcepub fn accessible_name_text(&self) -> Option<&str>
pub fn accessible_name_text(&self) -> Option<&str>
What screen readers call it, when it is not its caption.
Sourcepub fn accessible_description_text(&self) -> Option<&str>
pub fn accessible_description_text(&self) -> Option<&str>
What screen readers say after its name, when anything.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether it can be used. If not, it is shown faded.
Sourcepub fn active_reasons(&self) -> Reasons
pub fn active_reasons(&self) -> Reasons
Why it is or is not in place.
Sourcepub fn enabled_reasons(&self) -> Reasons
pub fn enabled_reasons(&self) -> Reasons
Why it can or cannot be used.
Sourcepub fn set_active(&self, reason: &str, on: bool)
pub fn set_active(&self, reason: &str, on: bool)
Gives a reason for it being in place or not.
Sourcepub fn set_enabled(&self, reason: &str, on: bool)
pub fn set_enabled(&self, reason: &str, on: bool)
Gives a reason for it being usable or not. Prefer this to
set_active when it depends on the record: taking a button away
moves the ones beside it, and people click the wrong one.