ticketdata: update ticketdata_view using widget builder

* create and handle items in combo boxes using list
  and widget builder

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2021-03-04 20:26:36 +01:00
parent 8184af8135
commit ba3a6fb4d3

View File

@@ -12,12 +12,19 @@ use crate::{
widgets::ticketdata::ticketdata_state::{TicketdataAction, TicketdataState},
};
// Used to define ComboBox list members
type List = Vec<String>;
// Macro that initializes the widget structures/variables for the policy check view
widget!(
/// Form to enter data of a ticket record
TicketdataView<TicketdataState> {
// language used inside the widget
lang: String,
// list capturing the mail recipients (mail_to)
mail_to: List,
// list capturing the carbo copy recipients (mail_to)
mail_cc: List,
// title used in the header
ticket_data_title: String,
// entity id that will receive the messages
@@ -29,6 +36,22 @@ widget!(
/// All GUI elements are styled using the "style" attribute referencing to a ron based css
impl Template for TicketdataView {
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
// vector with valid strings of mail recipients addresses (mail_to)
let mail_to = vec![
PROP_MAIL_TO_1.to_string(),
PROP_MAIL_TO_2.to_string(),
PROP_MAIL_TO_3.to_string(),
PROP_MAIL_TO_4.to_string(),
];
let count_mail_to = mail_to.len();
// vector with valid carbon copy recipients addresses (mail_to)
let mail_cc = vec![
PROP_MAIL_CC_1.to_string(),
PROP_MAIL_CC_2.to_string(),
];
let count_mail_cc = mail_cc.len();
let tenent_logo = Container::new()
.margin((16, 16, 0, 0))
.attach(Grid::column(0))
@@ -329,35 +352,17 @@ impl Template for TicketdataView {
.attach(Grid::row(0))
.attach(Grid::column(3))
.style(STYLE_MAIL_TO)
.on_changed("selected_item", move |states, _entity| {
states
.get_mut::<TicketdataState>(id);
.count(count_mail_to)
// create the items builder context (ibc) for the mail to items
.items_builder(move |ibc, index| {
let text = TicketdataView::mail_to_ref(&ibc.get_widget(id))[index].clone();
TextBox::new()
.name(ID_TICKET_DATA_MAIL_TO)
.text(text)
.v_align("center")
.build(ibc)
})
.items_builder(move |ictx, index| match index {
0 => TextBlock::new()
.text(PROP_MAIL_TO_1)
.h_align("start")
.v_align("center")
.build(ictx),
1 => TextBlock::new()
.text(PROP_MAIL_TO_2)
.h_align("start")
.v_align("center")
.build(ictx),
2 => TextBlock::new()
.text(PROP_MAIL_TO_3)
.h_align("start")
.v_align("center")
.build(ictx),
3 => TextBlock::new()
.text(PROP_MAIL_TO_4)
.h_align("start")
.v_align("center")
.build(ictx),
_ => panic!(),
})
.count(4)
.selected_index(0)
.selected_index(1)
.build(ctx),
)
.child(
@@ -371,25 +376,24 @@ impl Template for TicketdataView {
)
.child(
ComboBox::new()
.id(ID_TICKET_DATA_MAIL_CC)
.id(ID_TICKET_DATA_COMBO_BOX_MAIL_CC)
.attach(Grid::row(2))
.attach(Grid::column(3))
.style(STYLE_MAIL_CC)
.items_builder(move |ictx, index| match index {
0 => TextBlock::new()
.text(PROP_MAIL_CC_1)
.h_align("start")
.count(count_mail_cc)
// create the items builder context (ibc) for the mail cc items
.items_builder(move |ibc, index| {
let text = TicketdataView::mail_cc_ref(&ibc.get_widget(id))[index].clone();
TextBox::new()
.name(ID_TICKET_DATA_MAIL_CC)
.text(text)
.v_align("center")
.build(ictx),
1 => TextBlock::new()
.text(PROP_MAIL_CC_2)
.h_align("start")
.v_align("center")
.build(ictx),
_ => panic!(),
.build(ibc)
})
.count(2)
.selected_index(0)
// .on_changed("selected_mail_cc_index", move |states, _| {
// states.get_mut::<TicketdataState>(id).change_mail_cc();
//})
.build(ctx),
)
.build(ctx),
@@ -416,6 +420,8 @@ impl Template for TicketdataView {
// Widget: Ticket data view
self.id(ID_TICKET_DATA_VIEW)
.name(ID_TICKET_DATA_VIEW)
.mail_to(mail_to)
.mail_cc(mail_cc)
.min_height(410.0)
.child(
Grid::new()