* assets: all resources are bundled in this subdirectory * widgets: use subdirs to group them by function the subdir hold their callbacks (state handling) and views * theming: update to new theming syntax * fonts: remove fonts that are provovided by default in OrbTK Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
395 lines
16 KiB
Rust
395 lines
16 KiB
Rust
/*
|
|
* advotracker - Hotline tackingtool for Advocats
|
|
*
|
|
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
|
* SPDX-License-Identifier: (0BSD or MIT)
|
|
*/
|
|
|
|
use orbtk::prelude::*;
|
|
|
|
use crate::{
|
|
constants::*,
|
|
data::{PolicyList, Status},
|
|
policydata_state::{Action, PolicyDataState},
|
|
};
|
|
use chrono::NaiveDateTime;
|
|
|
|
type ListIndex = Option<usize>;
|
|
|
|
// Dialog to manage policy identifiers.
|
|
// The elements may be toggled to be deactivated. The optional value 'data_valid_until'
|
|
// will render this value unvalid after the given date.
|
|
widget!(
|
|
PolicyDataView<PolicyDataState> {
|
|
back_entity: u32,
|
|
policy_list_count: usize,
|
|
policylist_view: u32,
|
|
list_index: ListIndex,
|
|
date_valid_until: NaiveDateTime,
|
|
policy_list: PolicyList
|
|
});
|
|
|
|
impl Template for PolicyDataView {
|
|
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
|
|
// listing the policy elements
|
|
let items_widget = ItemsWidget::new()
|
|
.id(ID_POLICY_DATA_ITEMS_WIDGET)
|
|
.v_align("start")
|
|
.items_builder(move |ctx, index| {
|
|
let mut date_inserted = None;
|
|
let mut dion = 1;
|
|
let mut policy_code = "".to_string();
|
|
let mut policy_number = None;
|
|
let mut status = false; // Status::<Active, Inactive>;
|
|
|
|
if let Some(list_index) = ctx.get_widget(id).clone::<ListIndex>("list_index") {
|
|
if let Some(policy_data) = ctx
|
|
.get_widget(id)
|
|
.get::<PolicyList>(PROP_POLICY_LIST)
|
|
.get(list_index)
|
|
{
|
|
if let Some(policy_data) = policy_data.get(index) {
|
|
date_inserted = policy_data.date_inserted.clone();
|
|
dion = policy_data.dion.clone();
|
|
policy_code = policy_data.policy_code.clone();
|
|
policy_number = policy_data.policy_number.clone();
|
|
status = policy_data.status;
|
|
}
|
|
}
|
|
}
|
|
|
|
let policy_data_status = CheckBox::new()
|
|
.attach(Grid::column(1))
|
|
.v_align("center")
|
|
// status: true -> State::Active false -> State::Inactive
|
|
.enabled(status)
|
|
.on_changed(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::StatusChanged(entity, index));
|
|
})
|
|
.build(ctx);
|
|
|
|
let policy_data_dion = TextBox::new()
|
|
.id(ID_POLICY_DATA_DION)
|
|
.attach(Grid::row(3))
|
|
.v_align("center")
|
|
.margin((4.0, 0.0, 0.0, 0.0))
|
|
.text(dion)
|
|
.lost_focus_on_activation(false)
|
|
.on_activate(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::CreateEntry(entity));
|
|
})
|
|
.on_changed(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::InputTextChanged(entity));
|
|
})
|
|
.build(ctx);
|
|
|
|
let policy_data_dion = TextBox::new()
|
|
.id(ID_POLICY_DATA_DION)
|
|
.attach(Grid::row(5))
|
|
.v_align("center")
|
|
.margin((4.0, 0.0, 0.0, 0.0))
|
|
.text(policy_code)
|
|
.lost_focus_on_activation(false)
|
|
.on_activate(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::TextChanged(entity));
|
|
})
|
|
.on_changed(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::RemoveFocus(entity));
|
|
})
|
|
.build(ctx);
|
|
|
|
let policy_data_policy_code = TextBox::new()
|
|
.id(ID_POLICY_DATA_POLICY_CODE)
|
|
.attach(Grid::row(7))
|
|
.v_align("center")
|
|
.margin((4.0, 0.0, 0.0, 0.0))
|
|
.text(policy_code)
|
|
.lost_focus_on_activation(false)
|
|
.on_activate(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::TextChanged(entity));
|
|
})
|
|
.on_changed(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::RemoveFocus(entity));
|
|
})
|
|
.build(ctx);
|
|
|
|
|
|
let policy_data_policy_number = TextBox::new()
|
|
.id(ID_POLICY_DATA_POLICY_NUMBER)
|
|
.attach(Grid::column(9))
|
|
.text(policy_number)
|
|
.enabled(false)
|
|
.v_align("center")
|
|
.water_mark("Insert the new policy number ...")
|
|
.class("inplace")
|
|
.on_activate(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::TextChanged(entity));
|
|
})
|
|
.on_changed(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::RemoveFocus(entity));
|
|
})
|
|
.build(ctx);
|
|
|
|
let policy_data_date_inserted = TextBlock::new()
|
|
.id(ID_POLICY_DATA_DATE_INSERTED)
|
|
.attach(Grid::column(9))
|
|
.text(date_inserted)
|
|
.v_align("start")
|
|
.on_activate(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::TextChanged(entity));
|
|
})
|
|
.on_changed(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::RemoveFocus(entity));
|
|
})
|
|
.build(ctx);
|
|
|
|
Grid::new()
|
|
.height(48.0)
|
|
.columns(
|
|
Columns::new()
|
|
.add(10.0)
|
|
.add(24.0)
|
|
.add(8.0)
|
|
.add(24.0)
|
|
.add(8.0)
|
|
.add(24.0)
|
|
.add(8.0)
|
|
.add("auto")
|
|
.add(8.0)
|
|
.add("auto")
|
|
.add(8.0)
|
|
.add(32.0)
|
|
.add(4.0)
|
|
.add(32.0)
|
|
.add(8.0)
|
|
.build(),
|
|
)
|
|
.child(policy_data_status)
|
|
.child(policy_data_dion)
|
|
.child(policy_data_policy_code)
|
|
.child(policy_data_policy_number)
|
|
.child(policy_data_date_inserted)
|
|
.child(
|
|
// edit active policy data element
|
|
Button::new()
|
|
.class(CLASS_ICON_ONLY)
|
|
.attach(Grid::column(11))
|
|
.min_size(32.0, 32.0)
|
|
.v_align("center")
|
|
.icon(material_icons_font_ttf::MD_EDIT)
|
|
//.icon("")
|
|
.on_mouse_down(|_, _| true)
|
|
.on_click(move |ctx, _| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::EditEntry(text_box));
|
|
true
|
|
})
|
|
.build(ctx),
|
|
)
|
|
.child(
|
|
// delete active policy data element
|
|
Button::new()
|
|
.class("icon_only")
|
|
.attach(Grid::column(13))
|
|
.min_size(32.0, 32.0)
|
|
.v_align("center")
|
|
.icon(material_icons_font_ttf::MD_DELETE)
|
|
//.icon("")
|
|
.on_mouse_down(|_, _| true)
|
|
.on_click(move |ctx, _| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::RemoveEntry(index));
|
|
true
|
|
})
|
|
.build(ctx),
|
|
)
|
|
.build(ctx)
|
|
})
|
|
.policy_data_count(PROP_POLICY_DATA_COUNT, id)
|
|
.build(ctx);
|
|
|
|
let scroll_viewer = ScrollViewer::new()
|
|
.scroll_viewer_mode(("disabled", "auto"))
|
|
.child(items_widget)
|
|
.build(ctx);
|
|
|
|
let policy_data_list_name = TextBox::new()
|
|
.id(ID_POLICY_DATA_LIST_NAME)
|
|
.attach(Grid::row(4))
|
|
.v_align("center")
|
|
.margin((4.0, 0.0, 0.0, 0.0))
|
|
.lost_focus_on_activation(false)
|
|
.on_activate(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::CreateEntry(entity));
|
|
})
|
|
.on_changed(move |ctx, entity| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::InputTextChanged(entity));
|
|
})
|
|
.build(ctx);
|
|
|
|
// Child page: list available policy data elements
|
|
self.name("PolicyDataListView").child(
|
|
Grid::new()
|
|
.rows(
|
|
Rows::new()
|
|
.add(52.0)
|
|
.add(1.0)
|
|
.add("*")
|
|
.add(1.0)
|
|
.add("auto")
|
|
.build(),
|
|
)
|
|
.columns(
|
|
Columns::new()
|
|
.add("*")
|
|
.add(4.0)
|
|
.add(36.0)
|
|
.build(),
|
|
)
|
|
// Top Bar
|
|
.child(
|
|
Container::new()
|
|
.class(CLASS_TOP_BAR)
|
|
.attach(Grid::row(0))
|
|
.attach(Grid::column(0))
|
|
.attach(Grid::column_span(3))
|
|
.child(
|
|
Grid::new()
|
|
.columns(
|
|
Columns::new()
|
|
.add(32.0)
|
|
.add(4.0)
|
|
.add("*")
|
|
.add(4.0)
|
|
.add(32.0)
|
|
.build(),
|
|
)
|
|
.child(
|
|
Button::new()
|
|
.height(32.0)
|
|
.icon(material_icons_font_ttf::MD_ARROW_LEFT)
|
|
//.icon("")
|
|
.class(CLASS_ICON_ONLY)
|
|
.v_align("center")
|
|
.on_click(move |ctx, _| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::NavigateBack());
|
|
true
|
|
})
|
|
.build(ctx),
|
|
)
|
|
.child(
|
|
TextBlock::new()
|
|
.class(CLASS_HEADER)
|
|
.attach(Grid::column(2))
|
|
.v_align("center")
|
|
.h_align("center")
|
|
.text(("name", id))
|
|
.build(ctx),
|
|
)
|
|
.child(
|
|
Stack::new()
|
|
.class(CLASS_HEADER)
|
|
.attach(Grid::column(3))
|
|
.h_align("start")
|
|
.orientation("horizontal")
|
|
.child(
|
|
TextBox::new()
|
|
.class(CLASS_HEADER)
|
|
//.v_align("center")
|
|
.h_align("start")
|
|
.text(("Anzahl:", id))
|
|
.build(ctx),
|
|
)
|
|
.child(
|
|
TextBlock::new()
|
|
.class(CLASS_HEADER)
|
|
.id(PROP_POLICY_DATA_COUNT)
|
|
.attach(Grid::column(3))
|
|
//.v_align("center")
|
|
.h_align("end")
|
|
.text("policy_data_count")
|
|
.build(ctx),
|
|
)
|
|
.build,
|
|
)
|
|
.build(ctx),
|
|
)
|
|
.build(ctx),
|
|
)
|
|
.child(
|
|
Container::new()
|
|
.class("separator")
|
|
.attach(Grid::row(1))
|
|
.attach(Grid::column_span(3))
|
|
.build(ctx),
|
|
)
|
|
// Content
|
|
.child(
|
|
Container::new()
|
|
.attach(Grid::row(2))
|
|
.attach(Grid::column(0))
|
|
.attach(Grid::column_span(3))
|
|
.child(scroll_viewer)
|
|
.child(
|
|
ScrollIndicator::new()
|
|
.padding((0.0, 4.0, 0.0, 0.0))
|
|
.content_id(items_widget.0)
|
|
.scroll_offset(scroll_viewer)
|
|
.build(ctx),
|
|
)
|
|
.build(ctx),
|
|
)
|
|
.child(
|
|
Container::new()
|
|
.class("separator")
|
|
.attach(Grid::row(3))
|
|
.attach(Grid::column_span(3))
|
|
.build(ctx),
|
|
)
|
|
// Bottom bar
|
|
.child(
|
|
Container::new()
|
|
.class(CLASS_BOTTOM_BAR)
|
|
.attach(Grid::row(4))
|
|
.attach(Grid::column(0))
|
|
.attach(Grid::column_span(3))
|
|
.build(ctx),
|
|
)
|
|
.child(policy_data_list_name)
|
|
.child(
|
|
Button::new()
|
|
.id(ID_POLICY_DATA_ADD_BUTTON)
|
|
.class(CLASS_ICON_ONLY)
|
|
.attach(Grid::row(4))
|
|
.attach(Grid::column(2))
|
|
.margin((0.0, 0.0, 4.0, 0.0))
|
|
.enabled(false)
|
|
.min_size(32.0, 32.0)
|
|
.v_align("center")
|
|
.icon(material_icons_font_ttf::MD_ADD_CIRCLE)
|
|
.on_click(move |ctx, _| {
|
|
ctx.get_mut::<PolicyDataState>(id)
|
|
.action(Action::CreateEntry(policy_data_list_name));
|
|
true
|
|
})
|
|
.build(ctx),
|
|
)
|
|
.build(ctx),
|
|
)
|
|
}
|
|
}
|