policydata: wip: view and state handling updates
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -42,29 +42,6 @@ impl PolicyDataState {
|
||||
self.action = action.into();
|
||||
}
|
||||
|
||||
/// create a new policy data member
|
||||
fn new_entry(&self, text: String, registry: &mut Registry, ctx: &mut Context) {
|
||||
let index = ctx.widget().clone::<Option<usize>>("list_index");
|
||||
|
||||
if let Some(index) = index {
|
||||
if let Some(policy_list) = ctx
|
||||
.widget()
|
||||
.get_mut::<PolicyData>("policy_data")
|
||||
.get_mut(index)
|
||||
{
|
||||
policy_list.push(PolicyData {
|
||||
policy_code,
|
||||
date_valid_until,
|
||||
selected: true,
|
||||
});
|
||||
}
|
||||
|
||||
self.adjust_count(ctx);
|
||||
}
|
||||
|
||||
self.save(registry, ctx);
|
||||
}
|
||||
|
||||
/// update number of available policy data entries.
|
||||
fn adjust_count(&self, ctx: &mut Context) {
|
||||
if let Some(index) = ctx.widget().clone::<Option<usize>>("list_index") {
|
||||
@@ -73,21 +50,11 @@ impl PolicyDataState {
|
||||
.clone::<PolicyList>("policy_list")
|
||||
.get(index)
|
||||
{
|
||||
ctx.widget().set("policy_count", policy_list.len());
|
||||
ctx.widget().set("policy_data_count", policy_list.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// navigate to previous policy data entry.
|
||||
fn navigate_back(&mut self, ctx: &mut Context) {
|
||||
ctx.get_widget(self.text_box)
|
||||
.set("name", String16::from(""));
|
||||
self.open = false;
|
||||
ctx.widget().set::<Option<usize>>("list_index", None);
|
||||
ctx.widget().set("policy_count", 0 as usize);
|
||||
self.navigate(self.back_entity, ctx);
|
||||
}
|
||||
|
||||
/// If policy data element 'name' is empty, disable the add button
|
||||
/// otherwise otherwise enabled it.
|
||||
fn adjust_add_button_enabled(&self, text_box: Entity, ctx: &mut Context) {
|
||||
@@ -100,44 +67,6 @@ impl PolicyDataState {
|
||||
ctx.get_widget(self.add_button).update_theme_by_state(true);
|
||||
}
|
||||
|
||||
/// Toggle the invalid element of the given policy data entry
|
||||
fn toggle_invalid(
|
||||
&self,
|
||||
entry: Entity,
|
||||
index: usize,
|
||||
registry: &mut Registry,
|
||||
ctx: &mut Context,
|
||||
) {
|
||||
let invalid: bool = *ctx.get_widget(entry).get("invalid");
|
||||
|
||||
if let Some(idx) = ctx.widget().clone::<Option<usize>>("list_index") {
|
||||
if let Some(policy_list) = ctx
|
||||
.widget()
|
||||
.get_mut::<PolicyData>("policy_list")
|
||||
.get_mut(idx)
|
||||
{
|
||||
if let Some(task) = policy_list.get_mut(index) {
|
||||
policy.selected = selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.save(registry, ctx);
|
||||
}
|
||||
|
||||
pub fn open(&mut self, ctx: &mut Context) {
|
||||
if let Some(index) = ctx.widget().clone::<Option<usize>>("list_index") {
|
||||
let mut name: String16 = "".into();
|
||||
let mut policy_count = 0;
|
||||
if let Some(policy_list) = ctx.widget().get::<PolicyList>("policy_list").get(index) {
|
||||
name = String16::from(policy_list.name.as_str());
|
||||
policy_count = policy_list.len();
|
||||
}
|
||||
ctx.widget().set("name", title);
|
||||
ctx.widget().set("policy_count", policy_count);
|
||||
self.open = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// Change status of given text box to edit mode.
|
||||
fn edit_entry(&self, text_box: Entity, ctx: &mut Context) {
|
||||
if *ctx.get_widget(text_box).get::<bool>("focused") {
|
||||
@@ -162,6 +91,53 @@ impl PolicyDataState {
|
||||
ctx.push_event_by_window(FocusEvent::RequestFocus(text_box));
|
||||
}
|
||||
|
||||
/// navigate to previous policy data entry.
|
||||
fn navigate_back(&mut self, ctx: &mut Context) {
|
||||
ctx.get_widget(self.text_box)
|
||||
.set("name", String16::from(""));
|
||||
self.open = false;
|
||||
ctx.widget().set::<Option<usize>>("list_index", None);
|
||||
ctx.widget().set("policy_data_count", 0 as usize);
|
||||
self.navigate(self.back_entity, ctx);
|
||||
}
|
||||
|
||||
/// create a new policy data member
|
||||
fn new_entry(&self, name: String, registry: &mut Registry, ctx: &mut Context) {
|
||||
let index = ctx.widget().clone::<Option<usize>>("list_index");
|
||||
|
||||
if let Some(index) = index {
|
||||
if let Some(policy_elements) = ctx
|
||||
.widget()
|
||||
.get_mut::<PolicyData>("policy_elements")
|
||||
.get_mut(index)
|
||||
{
|
||||
policy_list.push(PolicyData {
|
||||
policy_code,
|
||||
date_valid_until,
|
||||
selected: true,
|
||||
});
|
||||
}
|
||||
|
||||
self.adjust_count(ctx);
|
||||
}
|
||||
|
||||
self.save(registry, ctx);
|
||||
}
|
||||
|
||||
pub fn open(&mut self, ctx: &mut Context) {
|
||||
if let Some(index) = ctx.widget().clone::<Option<usize>>("list_index") {
|
||||
let mut name: String16 = "".into();
|
||||
let mut policy_data_count = 0;
|
||||
if let Some(policy_list) = ctx.widget().get::<PolicyList>("policy_list").get(index) {
|
||||
name = String16::from(policy_list.name.as_str());
|
||||
policy_data_count = policy_list.len();
|
||||
}
|
||||
ctx.widget().set("name", title);
|
||||
ctx.widget().set("policy_data_count", policy_count);
|
||||
self.open = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_entry(&self, index: usize, registry: &mut Registry, ctx: &mut Context) {
|
||||
if let Some(idx) = ctx.widget().clone::<Option<usize>>("list_index") {
|
||||
if let Some(policy_list) = ctx
|
||||
@@ -176,6 +152,30 @@ impl PolicyDataState {
|
||||
self.save(registry, ctx);
|
||||
}
|
||||
|
||||
/// Toggle the invalid element of the given policy data entry
|
||||
fn toggle_invalid(
|
||||
&self,
|
||||
entry: Entity,
|
||||
index: usize,
|
||||
registry: &mut Registry,
|
||||
ctx: &mut Context,
|
||||
) {
|
||||
let invalid: bool = *ctx.get_widget(entry).get("invalid");
|
||||
|
||||
if let Some(idx) = ctx.widget().clone::<Option<usize>>("list_index") {
|
||||
if let Some(policy_list) = ctx
|
||||
.widget()
|
||||
.get_mut::<PolicyData>("policy_list")
|
||||
.get_mut(idx)
|
||||
{
|
||||
if let Some(task) = policy_list.get_mut(index) {
|
||||
policy.selected = selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.save(registry, ctx);
|
||||
}
|
||||
|
||||
fn update_entry(
|
||||
&self,
|
||||
text_box: Entity,
|
||||
|
||||
@@ -8,48 +8,48 @@ use crate::{
|
||||
|
||||
type ListIndex = Option<usize>;
|
||||
|
||||
widget!(PolicyList<PolicyState> {
|
||||
widget!(PolicyData<PolicyDataState> {
|
||||
back_entity: u32,
|
||||
list_index: ListIndex,
|
||||
policy_list: PolicyList,
|
||||
policy_count: usize,
|
||||
name: String16
|
||||
policy_data: PolicyData,
|
||||
policy_data_count: usize,
|
||||
});
|
||||
|
||||
impl Template for PolicyList {
|
||||
impl Template for PolicyData {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
|
||||
// listing the policy elements
|
||||
let items_widget = ItemsWidget::new()
|
||||
.id(ID_POLICY_ITEMS_WIDGET)
|
||||
.id(ID_POLICY_DATA_ITEMS_WIDGET)
|
||||
.v_align("start")
|
||||
.items_builder(move |ctx, index| {
|
||||
let mut policy_code = "".to_string();
|
||||
let mut date_inserted = None;
|
||||
let mut invalid = false;
|
||||
let mut isactive = false;
|
||||
|
||||
if let Some(list_index) = ctx.get_widget(id).clone::<ListIndex>("list_index") {
|
||||
if let Some(task_overview) = ctx
|
||||
if let Some(policy_data) = ctx
|
||||
.get_widget(id)
|
||||
.get::<PolicyList>(PROP_POLICY_LIST)
|
||||
.get::<PolicyData(PROP_POLICY_DATA)
|
||||
.get(list_index)
|
||||
{
|
||||
if let Some(policy) = policy_list.get(index) {
|
||||
policy_code = policy.policy_code.clone();
|
||||
date_inserted = policy.date_inserted.clone();
|
||||
invalid = policy.invalid;
|
||||
if let Some(policy_data) = policy_data.get(index) {
|
||||
policy_code = policy_data.policy_code.clone();
|
||||
date_inserted = policy_data.date_inserted.clone();
|
||||
isactive = policy_data.isactive;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let text_box = TextBox::new()
|
||||
.text(text)
|
||||
.text(name)
|
||||
.enabled(false)
|
||||
.v_align("center")
|
||||
.water_mark("Insert text...")
|
||||
.water_mark("Insert the new policy collection name ...")
|
||||
.class("inplace")
|
||||
.attach(Grid::column(3))
|
||||
.on_changed(move |ctx, entity| {
|
||||
ctx.get_mut::<PolicyState>(id)
|
||||
ctx.get_mut::<PolicyDataState>(id)
|
||||
.action(Action::TextChanged(entity, index));
|
||||
})
|
||||
.on_activate(move |ctx, entity| {
|
||||
@@ -130,7 +130,7 @@ impl Template for PolicyList {
|
||||
)
|
||||
.build(ctx)
|
||||
})
|
||||
.count((PROP_POLICY_COUNT, id))
|
||||
.policy_data_count(PROP_POLICY_COUNT, id)
|
||||
.build(ctx);
|
||||
|
||||
let scroll_viewer = ScrollViewer::new()
|
||||
|
||||
Reference in New Issue
Block a user