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:
@@ -12,12 +12,19 @@ use crate::{
|
|||||||
widgets::ticketdata::ticketdata_state::{TicketdataAction, TicketdataState},
|
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
|
// Macro that initializes the widget structures/variables for the policy check view
|
||||||
widget!(
|
widget!(
|
||||||
/// Form to enter data of a ticket record
|
/// Form to enter data of a ticket record
|
||||||
TicketdataView<TicketdataState> {
|
TicketdataView<TicketdataState> {
|
||||||
// language used inside the widget
|
// language used inside the widget
|
||||||
lang: String,
|
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
|
// title used in the header
|
||||||
ticket_data_title: String,
|
ticket_data_title: String,
|
||||||
// entity id that will receive the messages
|
// 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
|
/// All GUI elements are styled using the "style" attribute referencing to a ron based css
|
||||||
impl Template for TicketdataView {
|
impl Template for TicketdataView {
|
||||||
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
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()
|
let tenent_logo = Container::new()
|
||||||
.margin((16, 16, 0, 0))
|
.margin((16, 16, 0, 0))
|
||||||
.attach(Grid::column(0))
|
.attach(Grid::column(0))
|
||||||
@@ -329,35 +352,17 @@ impl Template for TicketdataView {
|
|||||||
.attach(Grid::row(0))
|
.attach(Grid::row(0))
|
||||||
.attach(Grid::column(3))
|
.attach(Grid::column(3))
|
||||||
.style(STYLE_MAIL_TO)
|
.style(STYLE_MAIL_TO)
|
||||||
.on_changed("selected_item", move |states, _entity| {
|
.count(count_mail_to)
|
||||||
states
|
// create the items builder context (ibc) for the mail to items
|
||||||
.get_mut::<TicketdataState>(id);
|
.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 {
|
.selected_index(1)
|
||||||
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)
|
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
@@ -371,25 +376,24 @@ impl Template for TicketdataView {
|
|||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
ComboBox::new()
|
ComboBox::new()
|
||||||
.id(ID_TICKET_DATA_MAIL_CC)
|
.id(ID_TICKET_DATA_COMBO_BOX_MAIL_CC)
|
||||||
.attach(Grid::row(2))
|
.attach(Grid::row(2))
|
||||||
.attach(Grid::column(3))
|
.attach(Grid::column(3))
|
||||||
.style(STYLE_MAIL_CC)
|
.style(STYLE_MAIL_CC)
|
||||||
.items_builder(move |ictx, index| match index {
|
.count(count_mail_cc)
|
||||||
0 => TextBlock::new()
|
// create the items builder context (ibc) for the mail cc items
|
||||||
.text(PROP_MAIL_CC_1)
|
.items_builder(move |ibc, index| {
|
||||||
.h_align("start")
|
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")
|
.v_align("center")
|
||||||
.build(ictx),
|
.build(ibc)
|
||||||
1 => TextBlock::new()
|
|
||||||
.text(PROP_MAIL_CC_2)
|
|
||||||
.h_align("start")
|
|
||||||
.v_align("center")
|
|
||||||
.build(ictx),
|
|
||||||
_ => panic!(),
|
|
||||||
})
|
})
|
||||||
.count(2)
|
|
||||||
.selected_index(0)
|
.selected_index(0)
|
||||||
|
// .on_changed("selected_mail_cc_index", move |states, _| {
|
||||||
|
// states.get_mut::<TicketdataState>(id).change_mail_cc();
|
||||||
|
//})
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
@@ -416,6 +420,8 @@ impl Template for TicketdataView {
|
|||||||
// Widget: Ticket data view
|
// Widget: Ticket data view
|
||||||
self.id(ID_TICKET_DATA_VIEW)
|
self.id(ID_TICKET_DATA_VIEW)
|
||||||
.name(ID_TICKET_DATA_VIEW)
|
.name(ID_TICKET_DATA_VIEW)
|
||||||
|
.mail_to(mail_to)
|
||||||
|
.mail_cc(mail_cc)
|
||||||
.min_height(410.0)
|
.min_height(410.0)
|
||||||
.child(
|
.child(
|
||||||
Grid::new()
|
Grid::new()
|
||||||
|
|||||||
Reference in New Issue
Block a user