z_mirror/TaskList
git clone https://git.raiguard.me/z_mirror/TaskList
c176be5
task-details-gui
1local constants =require ( "constants" ) 2 3local task =require ( "scripts.task" ) 4local util =require ( "scripts.util" ) 5 6local actions ={} 7 8--- @param Gui EditTaskGui 9function actions . close ( Gui ) 10if Gui . state . just_confirmed then 11Gui . state . just_confirmed =false 12Gui . player . opened =Gui . refs . window 13else 14Gui : destroy () 15end 16end 17 18--- @param Gui EditTaskGui 19function actions . recenter ( Gui ) 20Gui . refs . window . force_auto_center () 21end 22 23--- @param Gui EditTaskGui 24function actions . update_assignee_dropdown ( Gui ) 25local dropdown =Gui . refs . assignee_dropdown 26 27local is_private =Gui . refs . private_checkbox . state 28if is_private then 29dropdown . enabled =false 30dropdown . selected_index =Gui . state . player_selection_index 31else 32dropdown . enabled =true 33end 34end 35 36--- @param Gui EditTaskGui 37--- @param e on_gui_confirmed|CustomInputEvent 38function actions . confirm ( Gui , _ , e ) 39local refs =Gui . refs 40local clicked =e . name == defines . events . on_gui_confirmed or e . name == defines . events . on_gui_click 41 42local title =refs . title_textfield . text 43if # title == 0 then 44util . error_text ( Gui . player , { "message.tlst-task-must-have-title" } ) 45if not clicked then 46Gui . state . just_confirmed =true 47end 48return 49end 50 51local assignee 52local assignee_dropdown =refs . assignee_dropdown 53local selected_index =assignee_dropdown . selected_index 54if selected_index > 1 then 55assignee =game . players [ assignee_dropdown . items [ selected_index ]] 56end 57 58local status_index =refs . status_dropdown . selected_index 59local status 60for status_name , status_info in pairs ( constants . task_status ) do 61if status_info . index == status_index then 62status =status_name 63end 64end 65 66local Task =Gui . state . task 67if Task then 68Task : update ( refs . title_textfield . text , refs . description_textfield . text , assignee , status ) 69else 70local owner =Gui . state . parent_task 71if not owner then 72local is_private =refs . private_checkbox . state 73owner =is_private and Gui . player or Gui . player . force 74end 75 76task . new ( 77refs . title_textfield . text , 78refs . description_textfield . text , 79owner , 80assignee , 81status , 82refs . add_to_top_checkbox . state 83) 84end 85 86if clicked then 87Gui : destroy () 88end 89end 90 91--- @param Gui EditTaskGui 92function actions . delete ( Gui ) 93local Task =Gui . state . task 94Task : delete () 95 96Gui : destroy () 97end 98 99return actions