widget:ticketdata: implement ClearForm
* reset all children of a given form to clean initial state * use `match` expression that compares the widget name, that resolves to the widget type (here: TextBox) Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -135,6 +135,7 @@ pub static ID_TICKET_DATA_CONTAINER_MAIL: &str = "ticket_data_container_mail";
|
||||
pub static ID_TICKET_DATA_COUNT_BLOCK: &str = "ticket_data_count_block";
|
||||
pub static ID_TICKET_DATA_DEDUCTIBLE: &str = "ticket_data_deductible";
|
||||
pub static ID_TICKET_DATA_FORM: &str = "ticket_data_form";
|
||||
pub static ID_TICKET_DATA_FORM_GRID: &str = "ticket_data_form_grid";
|
||||
pub static ID_TICKET_DATA_GRID: &str = "ticket_data_grid";
|
||||
pub static ID_TICKET_DATA_GRID_MAIL: &str = "ticket_data_grid_mail";
|
||||
pub static ID_TICKET_DATA_HARM_TYPE: &str = "ticket_data_harm_type";
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::{
|
||||
data::{constants::*, structures::Email},
|
||||
widgets::global_state::GlobalState,
|
||||
services::exports::send_ticketdata::sendticketdata,
|
||||
widgets::ticketdata::ticketdata_view::TicketdataView,
|
||||
//widgets::ticketdata::ticketdata_view::TicketdataView,
|
||||
widgets::policycheck::policycheck_state::PolicycheckAction,
|
||||
};
|
||||
|
||||
@@ -27,7 +27,7 @@ use crate::{
|
||||
pub enum TicketdataAction {
|
||||
ClearEntry(Entity),
|
||||
/// Clear text in the form
|
||||
ClearForm(),
|
||||
ClearForm(String),
|
||||
ChangeTheme(),
|
||||
//ChangeMailCc(),
|
||||
//ChangeMailTo(),
|
||||
@@ -66,37 +66,58 @@ impl GlobalState for TicketdataState {}
|
||||
/// Method definitions, that react on any given state change inside the `Ticketdata` widget.
|
||||
impl TicketdataState {
|
||||
/// Clear the text property of all children of the given form entity
|
||||
pub fn clear_form(entity: Entity, ctx: &mut Context<'_>) {
|
||||
if let Some(count) = ctx.get_widget(entity).children_count() {
|
||||
info!("Widget name: {:?}", ctx.get_widget(entity).get::<String>("name"));
|
||||
info!("Widget id: {:?}", ctx.get_widget(entity).get::<String>("id"));
|
||||
}
|
||||
|
||||
pub fn clear_form(entity: Entity, id: &str, ctx: &mut Context<'_>) {
|
||||
// form is identified by its id
|
||||
if let form_entity = ctx.child(ID_TICKET_DATA_GRID).entity() {
|
||||
info!("Form id: {:?}", ctx.get_widget(form_entity).get::<String>("id"));
|
||||
info!("Form node name: {:?}", ctx.get_widget(form_entity).get::<String>("name"));
|
||||
if ctx.entity_of_child(id).is_some() {
|
||||
let form_entity = ctx.entity_of_child(ID_TICKET_DATA_FORM_GRID).unwrap();
|
||||
|
||||
// Loop through children
|
||||
if let Some(count) = ctx.get_widget(form_entity).children_count() {
|
||||
for c in 1..=count {
|
||||
info!("WIP clear entry of child {:?}", c);
|
||||
//info!("WIP clear entry of child {:?}: {:?}", c, ctx.get_child(form_entity).get::<String>("name"));
|
||||
let form_container: WidgetContainer<'_> = ctx.get_widget(form_entity);
|
||||
// BUG: Why does name defer from id, they are using the same constant?
|
||||
info!("Form id: {:?}", form_container.get::<String>("id"));
|
||||
info!("Form name: {:?}", form_container.get::<String>("name"));
|
||||
|
||||
//ctx.clear_children_of(form_entity); // complete form is cleared!
|
||||
|
||||
// switch into the context of the form_container
|
||||
ctx.change_into(form_entity);
|
||||
|
||||
if let Some(count) = ctx.widget().children_count() {
|
||||
for i in 0..count {
|
||||
// process child
|
||||
if let Some(child) = &mut ctx.try_child_from_index(i) {
|
||||
let child_name: &str = child.get::<String>("name");
|
||||
let child_id: &str = child.get::<String>("id");
|
||||
info!("child({:?}) name: {:?}",
|
||||
i, child_name);
|
||||
// match child_name {
|
||||
// "TextBox" => TextBox::text_set(child, ""),
|
||||
// "ticket_data_policy_code" => TextBox::text_set(child, ""),
|
||||
// _ => info!("don't act on types other than 'TextBox'"),
|
||||
// }
|
||||
|
||||
info!("child({:?}) id: {:?}",
|
||||
i, child_id);
|
||||
match child_id {
|
||||
"ticket_data_policy_code" => TextBox::text_set(child, ""),
|
||||
"ticket_data_policy_holder" => TextBox::text_set(child, ""),
|
||||
"ticket_data_policy_deductible" => TextBox::text_set(child, ""),
|
||||
"ticket_data_policy_callback_number" => TextBox::text_set(child, ""),
|
||||
"ticket_data_policy_callback_date" => TextBox::text_set(child, ""),
|
||||
"ticket_data_policy_callback_harm_type" => TextBox::text_set(child, ""),
|
||||
"ticket_data_policy_callback_ivr_comment" => TextBox::text_set(child, ""),
|
||||
_ => info!("don't act on child_id '{:?}", child_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// switch back to parent entity
|
||||
ctx.change_into(entity);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn change_mail_cc(&mut self) {
|
||||
// self.actions.push(TicketdataAction::ChangeMailCc());
|
||||
// }
|
||||
|
||||
// pub fn change_mail_to(&mut self) {
|
||||
// self.actions.push(TicketdataAction::ChangeMailTo());
|
||||
// }
|
||||
|
||||
pub fn send_form(entity: Entity, ctx: &mut Context<'_>, lang: &str) {
|
||||
|
||||
pub fn send_form(_entity: Entity, ctx: &mut Context<'_>, lang: &str) {
|
||||
// type conversion (String -> u64)
|
||||
//let policy_code = ctx.child(ID_TICKET_DATA_POLICY_CODE).get::<String>("text").unwrap().parse::<u64>().unwrap();
|
||||
|
||||
@@ -171,9 +192,11 @@ impl State for TicketdataState {
|
||||
) {
|
||||
for message in messages.read::<TicketdataAction>() {
|
||||
match message {
|
||||
TicketdataAction::ClearForm() => {
|
||||
info!("message: {:?} recieved", message);
|
||||
TicketdataState::clear_form(ctx.entity(), ctx);
|
||||
TicketdataAction::ClearForm(id) => {
|
||||
info!("message: {:?} recieved", id);
|
||||
// change into the context of the given form
|
||||
|
||||
TicketdataState::clear_form(ctx.entity(), &id, ctx);
|
||||
}
|
||||
TicketdataAction::SendForm() => {
|
||||
info!("message: {:?} recieved", message);
|
||||
@@ -199,9 +222,9 @@ impl State for TicketdataState {
|
||||
|
||||
for action in actions {
|
||||
match action {
|
||||
TicketdataAction::ClearForm() => {
|
||||
TicketdataAction::ClearForm(ref id) => {
|
||||
info!("update: send_message {:?}", action);
|
||||
ctx.send_message(TicketdataAction::ClearForm(), self.target);
|
||||
ctx.send_message(TicketdataAction::ClearForm(id.to_string()), self.target);
|
||||
}
|
||||
TicketdataAction::SendForm() => {
|
||||
//ctx.send_message(TicketdataAction::SendForm(), self.ID_TICKETDATA_FORM);
|
||||
|
||||
@@ -110,8 +110,8 @@ impl Template for TicketdataView {
|
||||
.style("container_form")
|
||||
.child(
|
||||
Grid::new()
|
||||
.id(ID_TICKET_DATA_GRID)
|
||||
.name(ID_TICKET_DATA_GRID)
|
||||
.id(ID_TICKET_DATA_FORM_GRID)
|
||||
.name(ID_TICKET_DATA_FORM_GRID)
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push("auto") // Label
|
||||
@@ -292,8 +292,8 @@ impl Template for TicketdataView {
|
||||
.id(ID_TICKET_DATA_ACTION_BUTTON_CLEAR)
|
||||
.style(STYLE_BUTTON_ACTION)
|
||||
.text("Clear")
|
||||
.on_click(move |states, _| {
|
||||
states.send_message(TicketdataAction::ClearForm(), id);
|
||||
.on_click(move |states, _entity| {
|
||||
states.send_message(TicketdataAction::ClearForm(ID_TICKET_DATA_FORM_GRID.to_string()), id);
|
||||
false
|
||||
})
|
||||
.build(ctx),
|
||||
@@ -316,11 +316,13 @@ impl Template for TicketdataView {
|
||||
|
||||
let ticket_data_form_mail = Container::new()
|
||||
.id(ID_TICKET_DATA_CONTAINER_MAIL)
|
||||
|
||||
.name(ID_TICKET_DATA_CONTAINER_MAIL)
|
||||
.attach(Grid::row(1))
|
||||
.attach(Grid::column(1))
|
||||
.style(STYLE_CONTAINER_MAIL)
|
||||
.child(
|
||||
|
||||
Grid::new()
|
||||
.columns(
|
||||
Columns::create()
|
||||
|
||||
Reference in New Issue
Block a user