diff --git a/frontend/src/policydata_state.rs b/frontend/src/policydata_state.rs index 650bc8a..876b376 100644 --- a/frontend/src/policydata_state.rs +++ b/frontend/src/policydata_state.rs @@ -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::>("list_index"); - - if let Some(index) = index { - if let Some(policy_list) = ctx - .widget() - .get_mut::("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::>("list_index") { @@ -73,21 +50,11 @@ impl PolicyDataState { .clone::("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::>("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::>("list_index") { - if let Some(policy_list) = ctx - .widget() - .get_mut::("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::>("list_index") { - let mut name: String16 = "".into(); - let mut policy_count = 0; - if let Some(policy_list) = ctx.widget().get::("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::("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::>("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::>("list_index"); + + if let Some(index) = index { + if let Some(policy_elements) = ctx + .widget() + .get_mut::("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::>("list_index") { + let mut name: String16 = "".into(); + let mut policy_data_count = 0; + if let Some(policy_list) = ctx.widget().get::("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::>("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::>("list_index") { + if let Some(policy_list) = ctx + .widget() + .get_mut::("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, diff --git a/frontend/src/policydata_view.rs b/frontend/src/policydata_view.rs index 35c5c37..103812d 100644 --- a/frontend/src/policydata_view.rs +++ b/frontend/src/policydata_view.rs @@ -8,48 +8,48 @@ use crate::{ type ListIndex = Option; -widget!(PolicyList { +widget!(PolicyData { 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::("list_index") { - if let Some(task_overview) = ctx + if let Some(policy_data) = ctx .get_widget(id) - .get::(PROP_POLICY_LIST) + .get::(id) + ctx.get_mut::(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()