From 2f5514d2430df39816ed38727a5bf5b5490965a9 Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Tue, 7 Feb 2017 09:09:33 -0500 Subject: [PATCH] Handle races which can be flown in any order. If the "reverse" field is set the start and finish stations can be swapped when adding an entry. --- entry.js | 14 ++++++++++++++ images/reverse.png | Bin 0 -> 1244 bytes lib/entry.php | 16 ++++++++++++---- lib/race.php | 13 ++++++++++--- propel/schema.xml | 1 + style.css | 2 ++ 6 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 images/reverse.png diff --git a/entry.js b/entry.js index 86cc697..f18ac27 100644 --- a/entry.js +++ b/entry.js @@ -813,6 +813,17 @@ function changed_joker(event) { validate(get_table()); } +/* Callback when we swap start and finish. */ +function reversed(event) { + var input = event.target; + var table = get_table(); + /* Swap heading and rows. */ + for (var j = 0; j <= last_column(table); j++) { + if (j && ! valid_column(table, j)) continue; + swap_cells(table, first_row(table), j, last_row(table), j, true); + } +} + /* Create a new input element. */ function checkpoint(id) { var date = elite_date(); @@ -965,6 +976,9 @@ function loaded() { if (typeof optional_waypoints == 'number' && optional_waypoints) waypoints = optional_waypoints; else waypoints = total_waypoints; omitted_optional = total_waypoints - waypoints - 1; + for (var input of document.getElementsByClassName('reverse')) { + input.addEventListener('dblclick', reversed, true); + } validate(table); do_plot(table, document.getElementById('plot')); var stats = document.getElementById('stats').getElementsByTagName('table')[0]; diff --git a/images/reverse.png b/images/reverse.png new file mode 100644 index 0000000000000000000000000000000000000000..d16778f72e74f331950f97451ca41a92b1c69e89 GIT binary patch literal 1244 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJOS+@4BLl<6e(pbstU$g(vPY0F z14ES>14Ba#1H&(%P{RubhEf9thF1v;3|2E37{m+a>Y{~07cB}z5+?0Mj&Za`PsPolTqbIy|QNUU+<~^KnlQq0lL8ktP853<}=VbpkLf4fDlj(&~TucAlce4 zK-Zd7e*)@t?fvc2`y1#xpkqLu1)`d7K*1a>zzpNFz73dhC_kn^y1azKN<9EyY&la^GfsQw<{0I>Th6B*qz?cGh92kti z7=Z*VMAp3F8%P}FDTu#7Q3g~13{s#8`e2iRy1-rr`5IXkXadl7WD&!P4^G{nAcZ*K z|NsAwnClgRDQ0U)kRK@ZkqS7qU0t;~^)|iz^XKg*7iJMw{ma`L8@GIUlgcEpG(>@m z-T&?zm)yUnWdpu!YLA-8ydD;(qk22b^+VASs!9I-;wFStiZsS zhHzlEVR+@~;us=vIXU3~lf=v(U!SvQbZ0~^ zU|KUR?3&rOvTuBSISz8x?UOfmub#cTefjk5{rc+6%+u%BGn6L?@aGqJWJFlV+c!J7 zq=aly2v|9xz$YhW4~MhUqieaICl@&gZk%#uOG#l{&zUuE=EQJ%vaQ_nr|Hn5q_#y%JgKLx$4!dTf3^*Znhm;mS(wt@8`5@Z>?|Lk`%GB+PzD3YJ<`#+r71awRl!# z39I?dvT=<~er0m@rEyx8p+Uy^S+?o#_Wa})(~H`ZvXU>L!Lj`2CsFP2wQ-xv=E_~s z|Hby&Jm=1q%I<}NX6u<5u1Pr^$lJxP3-q;WiEBhjN@7W>RdP`(kYX@0Ff`XSFw!+J z4>2^fGB&a@HPtpSure?R+-<;)q9HdwB{QuOiv|;jhPH{#{6Gy1p00i_>zopr0O|f8 Axc~qF literal 0 HcmV?d00001 diff --git a/lib/entry.php b/lib/entry.php index e41abcd..761f805 100644 --- a/lib/entry.php +++ b/lib/entry.php @@ -86,11 +86,12 @@ return false; } - function show_leg($station, $start_finish, $station_id, $system_id, $order, $n) { + function show_leg($station, $start_finish, $station_id, $system_id, $order, $reverse, $n) { $td_class = $start_finish ? " class=\"$start_finish\"" : ''; echo "\n"; $classes = array("station$station_id", "system$system_id"); if (is_int($order)) $classes[] = "order$order"; + if ($start_finish && $reverse) $classes[] = "reverse"; $class_list = implode(' ', $classes); echo "

$station

\n"; echo "

\n"; @@ -133,6 +134,7 @@ } } $event = $race->getEvent(); + $reverse = $race->getReverse(); $allotted_time = 0 + $race->getAllottedTime(); $legs = array(); $system_ids = array(); @@ -183,6 +185,9 @@ } if ($entry) retrieve_entry($entry); if ($_POST['lap1station1']) { + /* Don't show the swap start/finish icon. */ + $reverse = false; + echo "var reverse = false;\n"; /* XXX: Trust client validation only because furrycat is the only user and he can vouch for himself. @@ -212,7 +217,10 @@ return true; } } - else echo "//-->\n"; + else { + echo "var reverse = " . json_encode($reverse) . ";\n"; + echo "//-->\n"; + } if (! $entry) { $sq = new ShipQuery; $sq->joinWith('Ship.Competitor'); @@ -237,14 +245,14 @@ $order = 0; } else $class = ''; - show_leg($station, $class, $station_id, $system_id, $order, ++$n); + show_leg($station, $class, $station_id, $system_id, $order, $reverse, ++$n); } foreach ($legs as $station => $attributes) { list($flags, $station_id, $system_id, $order) = $attributes; if (! ($flags & Course::FinishFlag())) continue; /* Last leg. */ $order = 0; - show_leg($station, 'finish_line', $station_id, $system_id, $order, ++$n); + show_leg($station, 'finish_line', $station_id, $system_id, $order, $reverse, ++$n); } echo "\n"; echo ""; diff --git a/lib/race.php b/lib/race.php index e3bf483..fd23fdd 100644 --- a/lib/race.php +++ b/lib/race.php @@ -476,9 +476,12 @@ $race->setClassName($name); $race->setEventId($event_id); if ($hull_id) $race->setHullId($hull_id); + else $race->setHullId(null); if ($allotted_time) $race->setAllottedTime($allotted_time); - $optional = $posted['optional']; + $optional = $_POST['optional']; if (is_int($optional) && $optional > 0) $race->setWaypoints($optional); + $reverse = $_POST['reverse']; + if ($reverse) $race->setReverse(true); $prizes = 0; foreach ($posted as $k => $v) { if (! preg_match('/^prize_(.+)$/', $k, $m)) continue; @@ -568,9 +571,13 @@ echo "

\n"; echo "

Waypoints

\n"; - echo "

Number of optional waypoints: "; + echo "

"; + echo "\n"; + echo "

\n"; + echo "