From 294b1d61aef012487e498b5e2cc8b5cfa95e6887 Mon Sep 17 00:00:00 2001 From: Michal Dziekonski Date: Sat, 12 Dec 2020 14:12:53 +0100 Subject: [PATCH] GH-139 Build available holding times selections dynamically --- fleet2.php | 29 +++++++++++++++++++++- templates/default_template/fleet2_body.tpl | 7 +----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/fleet2.php b/fleet2.php index b060d2e6c..7eab06b5f 100644 --- a/fleet2.php +++ b/fleet2.php @@ -19,6 +19,11 @@ $_Lang['SelectResources'] = 'false'; $_Lang['SelectQuantumGate'] = 'false'; + +$setFormValues = [ + 'holdingtime' => null, +]; + if(!empty($_POST['gobackVars'])) { $_POST['gobackVars'] = json_decode(base64_decode($_POST['gobackVars']), true); @@ -36,7 +41,7 @@ } if(isset($_POST['gobackVars']['holdingtime'])) { - $_Lang['SelectHolding_'.$_POST['gobackVars']['holdingtime']] = 'selected'; + $setFormValues['holdingtime'] = $_POST['gobackVars']['holdingtime']; } if(isset($_POST['gobackVars']['expeditiontime'])) { @@ -668,6 +673,28 @@ $_Lang['Insert_AllyPact_AttackWarn'] = 'false'; } +$availableHoldTimes = FlightControl\Utils\Helpers\getAvailableHoldTimes([]); + +$missionHoldTimeOptions = array_map( + function ($holdTimeValue) use ($setFormValues) { + return buildDOMElementHTML([ + 'tagName' => 'option', + 'contentHTML' => $holdTimeValue, + 'attrs' => [ + 'value' => $holdTimeValue, + 'selected' => ( + $holdTimeValue == $setFormValues['holdingtime'] ? + '' : + null + ), + ], + ]); + }, + $availableHoldTimes +); + +$_Lang['P_HTMLBuilder_MissionHold_AvailableTimes'] = implode('', $missionHoldTimeOptions); + display(parsetemplate(gettemplate('fleet2_body'), $_Lang), $_Lang['fl_title']); ?> diff --git a/templates/default_template/fleet2_body.tpl b/templates/default_template/fleet2_body.tpl index 357bc6c24..fc05c8492 100644 --- a/templates/default_template/fleet2_body.tpl +++ b/templates/default_template/fleet2_body.tpl @@ -151,12 +151,7 @@ var AllyPact_AttackWarn = {Insert_AllyPact_AttackWarn}; {fl_expe_hours}