From 6b4d39a350249fb3f71d49706d242e6d341c2200 Mon Sep 17 00:00:00 2001 From: anuko Date: Wed, 27 Dec 2017 19:10:29 +0000 Subject: [PATCH] Made week view controls read-only for locked days. --- WEB-INF/lib/form/TextField.class.php | 45 ++++++++++--------------- WEB-INF/lib/ttTimeHelper.class.php | 50 ++++++++++++++++++++-------- WEB-INF/templates/footer.tpl | 2 +- week.php | 12 +++++-- 4 files changed, 63 insertions(+), 46 deletions(-) diff --git a/WEB-INF/lib/form/TextField.class.php b/WEB-INF/lib/form/TextField.class.php index 4904e248..db29a0c7 100644 --- a/WEB-INF/lib/form/TextField.class.php +++ b/WEB-INF/lib/form/TextField.class.php @@ -36,33 +36,22 @@ class TextField extends FormElement { $this->name = $name; } - // TODO: refactoring ongoing down from here. - function getHtml() { - if (!$this->isEnabled()) { - $html = "name\" value=\"".htmlspecialchars($this->getValue())."\" readonly>\n"; - } else { - - if ($this->id=="") $this->id = $this->name; - - $html = "\n\tname\" id=\"$this->id\""; - - if ($this->size!="") - $html .= " size=\"$this->size\""; - - if ($this->style!="") - $html .= " style=\"$this->style\""; - - if ($this->max_length!="") - $html .= " maxlength=\"$this->max_length\""; - - if ($this->on_change!="") - $html .= " onchange=\"$this->on_change\""; + function getHtml() { + if (empty($this->id)) $this->id = $this->name; + $html = "\n\tid\" name=\"$this->name\""; + if (!empty($this->size)) $html .= " size=\"$this->size\""; + if (!empty($this->style)) $html .= " style=\"$this->style\""; - $html .= " value=\"".htmlspecialchars($this->getValue())."\""; - $html .= ">"; - } - - return $html; - } + if($this->isEnabled()) { + if (!empty($this->max_length)) $html .= " maxlength=\"$this->max_length\""; + if (!empty($this->on_change)) $html .= " onchange=\"$this->on_change\""; + } + + $html .= " value=\"".htmlspecialchars($this->getValue())."\""; + + if(!$this->isEnabled()) $html .= " readonly"; + $html .= ">\n"; + return $html; + } } diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index 60ebe446..354bd2b2 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -747,24 +747,24 @@ class ttTimeHelper { // array( // Row 0. // 'row_id' => 'cl:546,bl:1,pr:23456,ts:27464,cf_1:7623_0', // Row identifier. See ttTimeHelper::makeRecordIdentifier(). // 'label' => 'Anuko - Time Tracker - Coding', // Human readable label for the row describing what this time entry is for. - // 'day_0' => array('control_id' => '0_day_0', 'duration' => '00:00'), // control_id is row_id plus day header for column. - // 'day_1' => array('control_id' => '0_day_1', 'duration' => '01:00'), - // 'day_2' => array('control_id' => '0_day_2', 'duration' => '02:00'), - // 'day_3' => array('control_id' => '0_day_3', 'duration' => null), - // 'day_4' => array('control_id' => '0_day_4', 'duration' => '04:00'), - // 'day_5' => array('control_id' => '0_day_5', 'duration' => '04:00'), - // 'day_6' => array('control_id' => '0_day_6', 'duration' => null) + // 'day_0' => array('control_id' => '0_day_0', 'tt_log_id' => 12345, 'duration' => '00:00'), // control_id is row_id plus day header for column. + // 'day_1' => array('control_id' => '0_day_1', 'tt_log_id' => 12346, 'duration' => '01:00'), + // 'day_2' => array('control_id' => '0_day_2', 'tt_log_id' => 12347, 'duration' => '02:00'), + // 'day_3' => array('control_id' => '0_day_3', 'tt_log_id' => null, 'duration' => null), + // 'day_4' => array('control_id' => '0_day_4', 'tt_log_id' => 12348, 'duration' => '04:00'), + // 'day_5' => array('control_id' => '0_day_5', 'tt_log_id' => 12349, 'duration' => '04:00'), + // 'day_6' => array('control_id' => '0_day_6', 'tt_log_id' => null, 'duration' => null) // ), // array( // Row 1. // 'row_id' => 'bl:0_0', // 'label' => '', // In this case the label is empty as we don't have anything to put into it, as we only have billable flag. - // 'day_0' => array('control_id' => '1_day_0', 'duration' => null), - // 'day_1' => array('control_id' => '1_day_1', 'duration' => '01:30'), - // 'day_2' => array('control_id' => '1_day_2', 'duration' => null), - // 'day_3' => array('control_id' => '1_day_3', 'duration' => '02:30'), - // 'day_4' => array('control_id' => '1_day_4', 'duration' => '04:00'), - // 'day_5' => array('control_id' => '1_day_5', 'duration' => null), - // 'day_6' => array('control_id' => '1_day_6', 'duration' => null) + // 'day_0' => array('control_id' => '1_day_0', 'tt_log_id' => null, 'duration' => null), + // 'day_1' => array('control_id' => '1_day_1', 'tt_log_id' => 12350, 'duration' => '01:30'), + // 'day_2' => array('control_id' => '1_day_2', 'tt_log_id' => null, 'duration' => null), + // 'day_3' => array('control_id' => '1_day_3', 'tt_log_id' => 12351,'duration' => '02:30'), + // 'day_4' => array('control_id' => '1_day_4', 'tt_log_id' => 12352, 'duration' => '04:00'), + // 'day_5' => array('control_id' => '1_day_5', 'tt_log_id' => null, 'duration' => null), + // 'day_6' => array('control_id' => '1_day_6', 'tt_log_id' => null, 'duration' => null) // ) // ); static function getDataForWeekView($user_id, $start_date, $end_date, $dayHeaders) { @@ -902,6 +902,28 @@ class ttTimeHelper { return $dayHeaders; } + // getLockedDaysForWeek - builds an arrays of locked days in week. + static function getLockedDaysForWeek($start_date) { + global $user; + $lockedDays = array(); + $objDate = new DateAndTime(DB_DATEFORMAT, $start_date); + $lockedDays[] = $user->isDateLocked($objDate); + $objDate->incDay(); + $lockedDays[] = $user->isDateLocked($objDate); + $objDate->incDay(); + $lockedDays[] = $user->isDateLocked($objDate); + $objDate->incDay(); + $lockedDays[] = $user->isDateLocked($objDate); + $objDate->incDay(); + $lockedDays[] = $user->isDateLocked($objDate); + $objDate->incDay(); + $lockedDays[] = $user->isDateLocked($objDate); + $objDate->incDay(); + $lockedDays[] = $user->isDateLocked($objDate); + unset($objDate); + return $lockedDays; + } + // getDayTotals calculates total durations for each day from the existing data in $dataArray. static function getDayTotals($dataArray, $dayHeaders) { $dayTotals = array(); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 494880d0..a3ab15e0 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.13.0.3699 | Copyright © Anuko | +  Anuko Time Tracker 1.13.0.3700 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/week.php b/week.php index fa791504..8d3e2ba3 100644 --- a/week.php +++ b/week.php @@ -109,6 +109,7 @@ $_SESSION['task'] = $cl_task; // Get the data we need to display week view. // Get column headers, which are day numbers in month. $dayHeaders = ttTimeHelper::getDayHeadersForWeek($startDate->toString(DB_DATEFORMAT)); +$lockedDays = ttTimeHelper::getLockedDaysForWeek($startDate->toString(DB_DATEFORMAT)); // Build data array for the table. Format is described in the function.. $dataArray = ttTimeHelper::getDataForWeekView($user->getActiveUser(), $startDate->toString(DB_DATEFORMAT), $endDate->toString(DB_DATEFORMAT), $dayHeaders); // Build day totals (total durations for each day in week). @@ -116,9 +117,10 @@ $dayTotals = ttTimeHelper::getDayTotals($dataArray, $dayHeaders); // TODO: refactoring ongoing down from here. -// 1) Start coding modification of existing records. -// 2) Then adding new records for existing rows. -// 3) Then add code and UI for adding a new row. +// 1) Handle editable - not editable records properly meaning that UI should reflect this. +// 2) Start coding modification of existing records. +// 3) Then adding new records for existing rows. +// 4) Then add code and UI for adding a new row. // Actually this is work in progress at this point, even documenting the array, as we still miss control IDs, and // editing entries is not yet implemented. When this is done, we will have to re-document the above. @@ -137,6 +139,10 @@ class TimeCellRenderer extends DefaultCellRenderer { function render(&$table, $value, $row, $column, $selected = false) { $field_name = $table->getValueAt($row,$column)['control_id']; // Our text field names (and ids) are like x_y (row_column). $field = new TextField($field_name); + // Disable control if the date is locked. + global $lockedDays; + if ($lockedDays[$column-1]) + $field->setEnabled(false); $field->setFormName($table->getFormName()); $field->setSize(2); $field->setValue($table->getValueAt($row,$column)['duration']); -- 2.20.1