aboutsummaryrefslogtreecommitdiff
path: root/logic
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-02-09 00:21:59 +0000
committerdam <dam@gudinoff>2022-02-09 00:21:59 +0000
commitcc3f6e5ea29bfe006576a35b5fa24d029a07cf7c (patch)
tree05a9671dde552fbebadd326df0fbc9d2b58b1b60 /logic
parent9478682f845d5518ca1c6a4552a8b710d1a2b238 (diff)
downloadsurgery-log-cc3f6e5ea29bfe006576a35b5fa24d029a07cf7c.tar.zst
surgery-log-cc3f6e5ea29bfe006576a35b5fa24d029a07cf7c.zip
Add confirmation dialog to entry destructive actions.
Diffstat (limited to 'logic')
-rw-r--r--logic/database.gd8
-rw-r--r--logic/stage.gd27
2 files changed, 28 insertions, 7 deletions
diff --git a/logic/database.gd b/logic/database.gd
index 3c2d6b7..1518490 100644
--- a/logic/database.gd
+++ b/logic/database.gd
@@ -7,6 +7,7 @@ var db: Array
var selected_idx: int
var staged_idx: int
+onready var confirm_action := get_node("/root/main/confirm_action") as ConfirmationDialog
onready var stage := get_node("/root/main/stage") as Stage
onready var delete_button := get_node("actions/delete") as Button
onready var edit_button := get_node("actions/edit") as Button
@@ -65,6 +66,13 @@ func delete_action():
if selected_idx < 0:
return
+ confirm_action.window_title = "DELETE ENTRY"
+ confirm_action.dialog_text = "Do you want to delete entry with process ID '%s' from the database?" % db[selected_idx].process_id
+ confirm_action.connect("confirmed", self, "delete_action_confirmed", [], CONNECT_ONESHOT)
+ confirm_action.show_modal(true)
+
+
+func delete_action_confirmed():
db.remove(selected_idx)
self.remove_item(selected_idx)
selected_idx = -1
diff --git a/logic/stage.gd b/logic/stage.gd
index 1352816..6f46489 100644
--- a/logic/stage.gd
+++ b/logic/stage.gd
@@ -19,8 +19,10 @@ const OPTION_SETS_TREE_STRUCTURE := {
}
}
+var staged_entry_hash: int
var option_sets: Dictionary
+onready var confirm_action := get_node("/root/main/confirm_action") as ConfirmationDialog
onready var process_id := get_node("controls/process_id") as LineEdit
onready var surgery_id := get_node("controls/surgery_id") as LineEdit
onready var date := get_node("controls/date_picker") as DatePicker
@@ -65,8 +67,8 @@ func _ready():
"intervention": intervention
}
for key in option_sets_map:
- var button := option_sets_map[key].get_node("auto") as Button
- button.connect("pressed", self, "auto_populate", [key])
+ var button := option_sets_map[key].get_node("option_set") as Button
+ button.connect("pressed", self, "show_option_sets", [key])
func get_option_sets(field: String):
@@ -86,13 +88,13 @@ func get_option_sets(field: String):
return options
-func auto_populate(field: String):
+func show_option_sets(field: String):
var stage_options = get_node("/root/main/popup_list") as Popup
- stage_options.connect("item_selected", self, "auto_selected", [field], CONNECT_ONESHOT)
+ stage_options.connect("item_selected", self, "option_set_selected", [field], CONNECT_ONESHOT)
stage_options.popup_options(get_option_sets(field))
-func auto_selected(index: int, field: String):
+func option_set_selected(index: int, field: String):
var field_input: LineEdit = self[field]
field_input.text = get_option_sets(field)[index]
field_input.caret_position = field_input.text.length()
@@ -107,11 +109,22 @@ func save_action():
func discard_action():
+ if get_stage().hash() != staged_entry_hash:
+ confirm_action.window_title = "DISCARD ENTRY"
+ confirm_action.dialog_text = "Do you want to discard the changes made?"
+ confirm_action.connect("confirmed", self, "discard_action_confirmed", [], CONNECT_ONESHOT)
+ confirm_action.show_modal(true)
+ else:
+ discard_action_confirmed()
+
+
+func discard_action_confirmed():
self.visible = false
emit_signal("discard")
func set_stage(entry: Dictionary):
+ staged_entry_hash = entry.hash()
process_id.text = entry.process_id
surgery_id.text = entry.surgery_id
date.set_date(entry.date_year, entry.date_month, entry.date_day)
@@ -225,8 +238,8 @@ func pointer_input_on_click_handler(pointer: PointerInputSensor.PointerInputData
var button: Button
if target is Button:
button = target
- elif target.get_node("auto") is Button:
- button = target.get_node("auto")
+ elif target.get_node("option_set") is Button:
+ button = target.get_node("option_set")
if button != null && button.get_global_rect().has_point(pointer.current_position):
if button is CheckBox || button is CheckButton: