From 944a74c2637a497d43608a25272d93283bc0f895 Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Wed, 20 Jan 2016 07:32:45 -0500 Subject: [PATCH] Fixes for displaying existing lap. --- entry.js | 27 +++++++++++++++++++++------ lib/entry.php | 6 +++--- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/entry.js b/entry.js index 2106e61..076d93e 100644 --- a/entry.js +++ b/entry.js @@ -118,6 +118,13 @@ function zero_pad(n) { else return String(n); } +/* Is this an existing entry we are displaying? */ +function get_entry_id() { + var hidden = document.getElementsByName('add_entry'); + if (! hidden.length) return null; + return parseInt(hidden[0].value); +} + /* Convert a 21st century date to 34th century. */ function elite_date(then) { var now = new Date(); @@ -401,8 +408,10 @@ function do_stats(table) { var last_lap = first_column(table); var last_station = last_row(table); var complete_laps = 0; + /* Last lap is removed if we are retrieving an entry. */ + var skip = (get_entry_id()) ? 0 : 1; /* Find the last lap and last station visited. */ - for (var j = first_column(table); valid_column(table, j, 1); j++) { + for (var j = first_column(table); valid_column(table, j, skip); j++) { for (var i = last_row(table); valid_row(table, i); i--) { var input = get_cell_input(i, j); if (input.value.match(input.pattern)) { @@ -493,8 +502,6 @@ function validate(table, cloned) { var columns = table.rows[0].cells.length; var last_time = 0; for (var j = first_column(table); valid_column(table, j); j++) { -//for (var c = first_column(table); valid_column(table, c); c++) { -// var j = c - first_column(table) + 1; var lap = j - first_column(table) + 1; var first_leg_time = 0; var last_leg_time = 0; @@ -735,6 +742,12 @@ function add_lap(table, date) { propagate_placeholder(table, date); } +/* Remove the last lap. */ +function remove_lap(table) { + var lap = table.rows[0].cells.length - 1; + for (row of table.rows) row.removeChild(row.cells[lap]); +} + /* Delete empty laps other than the final one. */ function delete_empty_laps(table) { var columns = table.rows[0].cells.length; @@ -758,9 +771,6 @@ function delete_empty_laps(table) { } /* Remove header. */ table.rows[0].removeChild(table.rows[0].cells[columns - 1]); - /* Remove summary. */ - //table.rows[table.rows.length - 1].removeChild(table.rows[table.rows.length - 1].cells[columns - 1]); - //table.rows[summary_row(table)].removeChild(table.rows[summary_row(table)].cells[columns - 1]); } } @@ -769,6 +779,7 @@ function loaded() { var table = get_table(); add_lap(table); if (typeof posted != 'undefined') { + var entry_id = get_entry_id(); /* Times were submitted. */ var station_order = JSON.parse(posted['station_order']); if (station_order) { @@ -795,6 +806,7 @@ function loaded() { /* Insert times. */ var input = document.getElementById(id); input.value = posted[id]; + if (entry_id) input.disabled = true; changed_cell(table, parseInt(m[2]), parseInt(m[1]), input); return; } @@ -803,9 +815,12 @@ function loaded() { /* Insert hull. */ var input = document.getElementById(id); input.value = posted[id]; + if (entry_id) input.disabled = true; return; } }); + /* Remove dummy last lap. */ + remove_lap(table); } var joker = get_joker(); if (joker) joker.addEventListener('change', changed_joker, true); diff --git a/lib/entry.php b/lib/entry.php index b5f1413..bb0c4c5 100644 --- a/lib/entry.php +++ b/lib/entry.php @@ -7,7 +7,7 @@ $allotted_time = $entry->getRace()->getAllottedTime(); foreach ($entry->getLaps() as $lap) { $lap_number = $lap->getLapNumber(); - if ($allotted_time && $lap->getHullStart() && $lap->getHullEnd()) { + if ($lap->getHullStart() && $lap->getHullEnd()) { $_POST["lap${lap_number}hullstart"] = $lap->getHullStart(); $_POST["lap${lap_number}hullend"] = $lap->getHullEnd(); } @@ -43,9 +43,9 @@ $entry->setTotalDistance($posted['stat_total_distance']); if ($allotted_time > 0) { $entry->setPenaltyTime($posted['stat_penalty_time']); - $entry->setBonusTime($posted['stat_bonus_time']); if ($posted['stat_raced_time'] < $allotted_time) $endorsements |= endorsement('c'); } + if ($posted['stat_bonus_time']) $entry->setBonusTime($posted['stat_bonus_time']); $entry->setRacedTime($posted['stat_raced_time']); $entry->setTotalTime($posted['stat_total_time']); $entry->setFastestLap($posted['stat_fastest_lap']); @@ -221,7 +221,7 @@ $id = preg_replace('/[^a-z0-9]/', '_', strtolower($stat)); hidden("stat_$id"); } - if ($entry) hidden("add_entry"); + if ($entry) hidden("add_entry", $entry->getId()); else submit("add_entry", "Submit entry"); echo ""; echo "

total distance

\n"; /* Distance column. */ -- 2.7.4