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_COUNT_BLOCK: &str = "ticket_data_count_block";
|
||||||
pub static ID_TICKET_DATA_DEDUCTIBLE: &str = "ticket_data_deductible";
|
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: &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: &str = "ticket_data_grid";
|
||||||
pub static ID_TICKET_DATA_GRID_MAIL: &str = "ticket_data_grid_mail";
|
pub static ID_TICKET_DATA_GRID_MAIL: &str = "ticket_data_grid_mail";
|
||||||
pub static ID_TICKET_DATA_HARM_TYPE: &str = "ticket_data_harm_type";
|
pub static ID_TICKET_DATA_HARM_TYPE: &str = "ticket_data_harm_type";
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ use crate::{
|
|||||||
data::{constants::*, structures::Email},
|
data::{constants::*, structures::Email},
|
||||||
widgets::global_state::GlobalState,
|
widgets::global_state::GlobalState,
|
||||||
services::exports::send_ticketdata::sendticketdata,
|
services::exports::send_ticketdata::sendticketdata,
|
||||||
widgets::ticketdata::ticketdata_view::TicketdataView,
|
//widgets::ticketdata::ticketdata_view::TicketdataView,
|
||||||
widgets::policycheck::policycheck_state::PolicycheckAction,
|
widgets::policycheck::policycheck_state::PolicycheckAction,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ use crate::{
|
|||||||
pub enum TicketdataAction {
|
pub enum TicketdataAction {
|
||||||
ClearEntry(Entity),
|
ClearEntry(Entity),
|
||||||
/// Clear text in the form
|
/// Clear text in the form
|
||||||
ClearForm(),
|
ClearForm(String),
|
||||||
ChangeTheme(),
|
ChangeTheme(),
|
||||||
//ChangeMailCc(),
|
//ChangeMailCc(),
|
||||||
//ChangeMailTo(),
|
//ChangeMailTo(),
|
||||||
@@ -66,37 +66,58 @@ impl GlobalState for TicketdataState {}
|
|||||||
/// Method definitions, that react on any given state change inside the `Ticketdata` widget.
|
/// Method definitions, that react on any given state change inside the `Ticketdata` widget.
|
||||||
impl TicketdataState {
|
impl TicketdataState {
|
||||||
/// Clear the text property of all children of the given form entity
|
/// Clear the text property of all children of the given form entity
|
||||||
pub fn clear_form(entity: Entity, ctx: &mut Context<'_>) {
|
pub fn clear_form(entity: Entity, id: &str, 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"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// form is identified by its id
|
// form is identified by its id
|
||||||
if let form_entity = ctx.child(ID_TICKET_DATA_GRID).entity() {
|
if ctx.entity_of_child(id).is_some() {
|
||||||
info!("Form id: {:?}", ctx.get_widget(form_entity).get::<String>("id"));
|
let form_entity = ctx.entity_of_child(ID_TICKET_DATA_FORM_GRID).unwrap();
|
||||||
info!("Form node name: {:?}", ctx.get_widget(form_entity).get::<String>("name"));
|
|
||||||
|
|
||||||
// Loop through children
|
let form_container: WidgetContainer<'_> = ctx.get_widget(form_entity);
|
||||||
if let Some(count) = ctx.get_widget(form_entity).children_count() {
|
// BUG: Why does name defer from id, they are using the same constant?
|
||||||
for c in 1..=count {
|
info!("Form id: {:?}", form_container.get::<String>("id"));
|
||||||
info!("WIP clear entry of child {:?}", c);
|
info!("Form name: {:?}", form_container.get::<String>("name"));
|
||||||
//info!("WIP clear entry of child {:?}: {:?}", c, ctx.get_child(form_entity).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) {
|
pub fn send_form(_entity: Entity, ctx: &mut Context<'_>, lang: &str) {
|
||||||
// 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) {
|
|
||||||
|
|
||||||
// type conversion (String -> u64)
|
// type conversion (String -> u64)
|
||||||
//let policy_code = ctx.child(ID_TICKET_DATA_POLICY_CODE).get::<String>("text").unwrap().parse::<u64>().unwrap();
|
//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>() {
|
for message in messages.read::<TicketdataAction>() {
|
||||||
match message {
|
match message {
|
||||||
TicketdataAction::ClearForm() => {
|
TicketdataAction::ClearForm(id) => {
|
||||||
info!("message: {:?} recieved", message);
|
info!("message: {:?} recieved", id);
|
||||||
TicketdataState::clear_form(ctx.entity(), ctx);
|
// change into the context of the given form
|
||||||
|
|
||||||
|
TicketdataState::clear_form(ctx.entity(), &id, ctx);
|
||||||
}
|
}
|
||||||
TicketdataAction::SendForm() => {
|
TicketdataAction::SendForm() => {
|
||||||
info!("message: {:?} recieved", message);
|
info!("message: {:?} recieved", message);
|
||||||
@@ -199,9 +222,9 @@ impl State for TicketdataState {
|
|||||||
|
|
||||||
for action in actions {
|
for action in actions {
|
||||||
match action {
|
match action {
|
||||||
TicketdataAction::ClearForm() => {
|
TicketdataAction::ClearForm(ref id) => {
|
||||||
info!("update: send_message {:?}", action);
|
info!("update: send_message {:?}", action);
|
||||||
ctx.send_message(TicketdataAction::ClearForm(), self.target);
|
ctx.send_message(TicketdataAction::ClearForm(id.to_string()), self.target);
|
||||||
}
|
}
|
||||||
TicketdataAction::SendForm() => {
|
TicketdataAction::SendForm() => {
|
||||||
//ctx.send_message(TicketdataAction::SendForm(), self.ID_TICKETDATA_FORM);
|
//ctx.send_message(TicketdataAction::SendForm(), self.ID_TICKETDATA_FORM);
|
||||||
|
|||||||
@@ -110,8 +110,8 @@ impl Template for TicketdataView {
|
|||||||
.style("container_form")
|
.style("container_form")
|
||||||
.child(
|
.child(
|
||||||
Grid::new()
|
Grid::new()
|
||||||
.id(ID_TICKET_DATA_GRID)
|
.id(ID_TICKET_DATA_FORM_GRID)
|
||||||
.name(ID_TICKET_DATA_GRID)
|
.name(ID_TICKET_DATA_FORM_GRID)
|
||||||
.columns(
|
.columns(
|
||||||
Columns::create()
|
Columns::create()
|
||||||
.push("auto") // Label
|
.push("auto") // Label
|
||||||
@@ -292,8 +292,8 @@ impl Template for TicketdataView {
|
|||||||
.id(ID_TICKET_DATA_ACTION_BUTTON_CLEAR)
|
.id(ID_TICKET_DATA_ACTION_BUTTON_CLEAR)
|
||||||
.style(STYLE_BUTTON_ACTION)
|
.style(STYLE_BUTTON_ACTION)
|
||||||
.text("Clear")
|
.text("Clear")
|
||||||
.on_click(move |states, _| {
|
.on_click(move |states, _entity| {
|
||||||
states.send_message(TicketdataAction::ClearForm(), id);
|
states.send_message(TicketdataAction::ClearForm(ID_TICKET_DATA_FORM_GRID.to_string()), id);
|
||||||
false
|
false
|
||||||
})
|
})
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
@@ -316,11 +316,13 @@ impl Template for TicketdataView {
|
|||||||
|
|
||||||
let ticket_data_form_mail = Container::new()
|
let ticket_data_form_mail = Container::new()
|
||||||
.id(ID_TICKET_DATA_CONTAINER_MAIL)
|
.id(ID_TICKET_DATA_CONTAINER_MAIL)
|
||||||
|
|
||||||
.name(ID_TICKET_DATA_CONTAINER_MAIL)
|
.name(ID_TICKET_DATA_CONTAINER_MAIL)
|
||||||
.attach(Grid::row(1))
|
.attach(Grid::row(1))
|
||||||
.attach(Grid::column(1))
|
.attach(Grid::column(1))
|
||||||
.style(STYLE_CONTAINER_MAIL)
|
.style(STYLE_CONTAINER_MAIL)
|
||||||
.child(
|
.child(
|
||||||
|
|
||||||
Grid::new()
|
Grid::new()
|
||||||
.columns(
|
.columns(
|
||||||
Columns::create()
|
Columns::create()
|
||||||
|
|||||||
Reference in New Issue
Block a user