From c0b16334ee0dcc4bae301c150c1879e538f85344 Mon Sep 17 00:00:00 2001 From: zhengrunyu Date: Thu, 6 Jan 2022 11:12:29 +0800 Subject: [PATCH 1/2] *Code chenge status of parent and fix bug --- module/productplan/js/batchedit.js | 7 ---- module/productplan/js/edit.js | 6 +-- module/productplan/model.php | 47 ++++++++-------------- module/productplan/view/batchedit.html.php | 18 ++++----- module/productplan/view/edit.html.php | 9 ++--- 5 files changed, 31 insertions(+), 56 deletions(-) diff --git a/module/productplan/js/batchedit.js b/module/productplan/js/batchedit.js index 9c6b7dd997..5b8cf09d81 100644 --- a/module/productplan/js/batchedit.js +++ b/module/productplan/js/batchedit.js @@ -33,12 +33,8 @@ function setPlanStatus(planID, status) if(status != 'wait') { $('#future' + planID).closest('div').addClass('hidden'); - - $("input[name='begin[" + planID + "]']").closest('td').addClass('required'); - $("input[name='end[" + planID + "]']").closest('td').addClass('required'); $("input[name='begin[" + planID + "]']").removeAttr('disabled'); $("input[name='end[" + planID + "]']").removeAttr('disabled'); - $('.form-date').datetimepicker('update'); } else @@ -46,15 +42,12 @@ function setPlanStatus(planID, status) var isFuture = $('#future' + planID).prop('checked'); $('#future' + planID).closest('div').removeClass('hidden'); - $("input[name='begin[" + planID + "]']").closest('td').removeClass('required'); - $("input[name='end[" + planID + "]']").closest('td').removeClass('required'); if(isFuture) { $("input[name='begin[" + planID + "]']").attr('disabled', 'disabled'); $("input[name='end[" + planID + "]']").attr('disabled', 'disabled'); } - } } diff --git a/module/productplan/js/edit.js b/module/productplan/js/edit.js index 340aaa5c09..8aa184ecee 100644 --- a/module/productplan/js/edit.js +++ b/module/productplan/js/edit.js @@ -72,8 +72,6 @@ function setPlanStatus() { $('#checkBox').closest('div').addClass('hidden'); $('#future').val(0); - $('#begin').closest('td').addClass('required'); - $('#end').closest('td').addClass('required'); $('#begin').removeAttr('disabled'); $('#end').parents('tr').show(); } @@ -82,12 +80,10 @@ function setPlanStatus() var isFuture = $('#future').prop('checked'); $('#checkBox').closest('div').removeClass('hidden'); - $('#begin').closest('td').removeClass('required'); - $('#end').closest('td').removeClass('required'); if(isFuture) { $('#begin').attr('disabled', 'disabled'); - $('#end').val('').parents('tr').hide(); + $('#end').parents('tr').hide(); } } } diff --git a/module/productplan/model.php b/module/productplan/model.php index 38e49cd42e..4b30bd23d1 100644 --- a/module/productplan/model.php +++ b/module/productplan/model.php @@ -464,19 +464,19 @@ class productplanModel extends model { $oldPlan = $this->dao->findByID((int)$planID)->from(TABLE_PRODUCTPLAN)->fetch(); $plan = fixer::input('post')->stripTags($this->config->productplan->editor->edit['id'], $this->config->allowedTags) - ->setIF($this->post->future or empty($_POST['begin']), 'begin', $this->config->productplan->future) - ->setIF($this->post->future or empty($_POST['end']), 'end', $this->config->productplan->future) + ->setIF($this->post->future and empty($_POST['begin']), 'begin', $this->config->productplan->future) + ->setIF($this->post->future and empty($_POST['end']), 'end', $this->config->productplan->future) ->remove('delta,uid,future') ->get(); if($oldPlan->parent > 0) { $parentPlan = $this->getByID($oldPlan->parent); - if($parentPlan->begin != $this->config->productplan->future) + if($parentPlan->begin !== $this->config->productplan->future) { if($plan->begin < $parentPlan->begin) dao::$errors['begin'] = sprintf($this->lang->productplan->beginLetterParent, $parentPlan->begin); } - if($parentPlan->end != $this->config->productplan->future) + if($parentPlan->end !== $this->config->productplan->future) { if($plan->end !== $this->config->productplan->future and $plan->end > $parentPlan->end) dao::$errors['end'] = sprintf($this->lang->productplan->endGreaterParent, $parentPlan->end); } @@ -496,22 +496,12 @@ class productplanModel extends model if($maxEnd > $plan->end and $maxEnd != $this->config->productplan->future) dao::$errors['end'] = sprintf($this->lang->productplan->endLetterChildTip, $planID, $plan->end, $maxEnd); } - $requiredFields = $oldPlan->status == 'wait' ? $this->config->productplan->edit->requiredFields : 'title, begin, end'; - if($plan->status != 'wait' and $plan->begin == $this->config->productplan->future) - { - dao::$errors['begin'] = sprintf($this->lang->error->notempty, $this->lang->productplan->begin); - } - if($plan->status != 'wait' and $plan->end == $this->config->productplan->future) - { - dao::$errors['end'] = sprintf($this->lang->error->notempty, $this->lang->productplan->end); - } if(dao::isError()) return false; - $plan = $this->loadModel('file')->processImgURL($plan, $this->config->productplan->editor->edit['id'], $this->post->uid); $this->dao->update(TABLE_PRODUCTPLAN) ->data($plan) ->autoCheck() - ->batchCheck($requiredFields, 'notempty') + ->batchCheck($this->config->productplan->edit->requiredFields, 'notempty') ->checkIF(!$this->post->future && !empty($_POST['begin']) && !empty($_POST['end']), 'end', 'ge', $plan->begin) ->where('id')->eq((int)$planID) ->exec(); @@ -667,21 +657,13 @@ class productplanModel extends model $plan->begin = isset($data->begin[$planID]) ? $data->begin[$planID] : ''; $plan->end = isset($data->end[$planID]) ? $data->end[$planID] : ''; $plan->status = isset($data->status[$planID]) ? $data->status[$planID] : $oldPlans[$planID]->status; + $plan->parent = $oldPlans[$planID]->parent; if(empty($plan->title)) die(js::alter(sprintf($this->lang->productplan->errorNoTitle, $planID))); + if($plan->begin > $plan->end and !empty($plan->end)) die(js::alert(sprintf($this->lang->productplan->beginGeEnd, $planID))); - if(!$isFuture and $plan->status != 'wait') - { - if($plan->begin == '') die(js::alert(sprintf($this->lang->productplan->errorNoBegin, $planID))); - if($plan->end == '') die(js::alert(sprintf($this->lang->productplan->errorNoEnd, $planID))); - if($plan->begin > $plan->end) die(js::alert(sprintf($this->lang->productplan->beginGeEnd, $planID))); - } - - if($plan->begin == '' or $plan->end == '') - { - $plan->begin = $this->config->productplan->future; - $plan->end = $this->config->productplan->future; - } + if($plan->begin == '') $plan->begin = $this->config->productplan->future; + if($plan->end == '') $plan->end = $this->config->productplan->future; foreach($extendFields as $extendField) { @@ -697,12 +679,14 @@ class productplanModel extends model } $changes = array(); + $parents = array(); foreach($plans as $planID => $plan) { + $parentID = $oldPlans[$planID]->parent; /* Determine whether the begin and end dates of the parent plan and the child plan are correct. */ - if($oldPlans[$planID]->parent > 0) + if($parentID > 0) { - $parentID = $oldPlans[$planID]->parent; + $parentID = $parentID; $parent = isset($plans[$parentID]) ? $plans[$parentID] : $this->getByID($parentID); if($parent->begin != $this->config->productplan->future and $plan->begin != $this->config->productplan->future and $plan->begin < $parent->begin) { @@ -713,7 +697,7 @@ class productplanModel extends model die(js::alert(sprintf($this->lang->productplan->endGreaterParentTip, $planID, $plan->end, $parent->end))); } } - elseif($oldPlans[$planID]->parent == -1 and $plan->begin != $this->config->productplan->future) + elseif($parentID == -1 and $plan->begin != $this->config->productplan->future) { $childPlans = $this->dao->select('*')->from(TABLE_PRODUCTPLAN)->where('parent')->eq($planID)->andWhere('deleted')->eq(0)->fetchAll('id'); $minBegin = $plan->begin; @@ -731,12 +715,15 @@ class productplanModel extends model $change = common::createChanges($oldPlans[$planID], $plan); if($change) { + if($parentID > 0 and !isset($parents[$parentID])) $parents[$parentID] = $parentID; $this->dao->update(TABLE_PRODUCTPLAN)->data($plan)->autoCheck()->where('id')->eq($planID)->exec(); if(dao::isError()) die(js::error(dao::getError())); $changes[$planID] = $change; } } + foreach($parents as $parent) $this->updateParentStatus($parent); + return $changes; } diff --git a/module/productplan/view/batchedit.html.php b/module/productplan/view/batchedit.html.php index 5d3d08eb0b..eab73ee039 100644 --- a/module/productplan/view/batchedit.html.php +++ b/module/productplan/view/batchedit.html.php @@ -38,28 +38,28 @@ - begin == '2030-01-01' || $plan->end == '2030-01-01') ? 'checked="checked"' : '';?> + begin == '2030-01-01' or $plan->end == '2030-01-01') ? 'checked="checked"' : '';?> id . html::hidden("id[$plan->id]", $plan->id);?> type != 'normal'):?> - parent == '-1' ? "disabled='disabled'" : '';?> + parent != -1 ? "disabled='disabled'" : '';?> id]", $plan->parent == '-1' ? '' : $branchTagOption, $plan->branch, "onchange='getConflictStories($plan->id, this.value); 'class='form-control chosen' $disabled");?> id]", $plan->title, "class='form-control'")?> parent != -1):?> - id]", array_slice($lang->productplan->statusList,($plan->status == 'wait' ? 0 : 1)), $plan->status, "class='form-control chosen' onchange='setPlanStatus($plan->id, this.value)'");?> + id]", array_slice($lang->productplan->statusList,($plan->status == 'wait' ? 0 : 1)), $plan->status, "class='form-control chosen' onchange='setPlanStatus($plan->id, this.value, $plan->parent)'");?> - id]", array_slice($lang->productplan->statusList,($plan->status == 'wait' ? 0 : 1)), $plan->status, "class='form-control chosen' disabled onchange='setPlanStatus($plan->id, this.value)'");?> + id]", array_slice($lang->productplan->statusList,($plan->status == 'wait' ? 0 : 1)), $plan->status, "class='form-control chosen' disabled onchange='setPlanStatus($plan->id, this.value, $plan->parent)'");?> - status != 'wait' ? 'required' : '' ;?> - begin == '2030-01-01' || $plan->end == '2030-01-01') ? 'disabled="disabled"' : '';?> + begin == '2030-01-01' or $plan->end == '2030-01-01') and $plan->status == 'wait') ? 'disabled="disabled"' : '';?> + parent == -1 and ($plan->begin == '2030-01-01' or $plan->end == '2030-01-01')) $disabled = 'disabled="disabled"';?> begin == '2030-01-01') $plan->begin = '';?> end == '2030-01-01') $plan->end = '';?> - >id]", $plan->begin, "class='form-control form-date' $disabled");?> - >id]", $plan->end, "class='form-control form-date' $disabled");?> - status != 'wait') ? 'hidden' : '';?> + id]", $plan->begin, "class='form-control form-date' $disabled");?> + id]", $plan->end, "class='form-control form-date' $disabled");?> + status != 'wait' and $plan->parent != -1) ? 'hidden' : '';?>
onclick="changeDate(id;?>);"/>
control == 'select' or $extendField->control == 'multi-select') ? " style='overflow:visible'" : '') . ">" . $this->loadModel('flow')->getFieldControl($extendField, $plan, $extendField->field . "[{$plan->id}]") . "";?> diff --git a/module/productplan/view/edit.html.php b/module/productplan/view/edit.html.php index 37ddaa9172..580878bf26 100644 --- a/module/productplan/view/edit.html.php +++ b/module/productplan/view/edit.html.php @@ -47,11 +47,10 @@ - status != 'wait' ? 'required' : '' ;?> - status != 'wait' ? 'hidden' : '';?> - begin == '2030-01-01' || $plan->end == '2030-01-01' ? "checked='checked'" : '';?> + status != 'wait' ? 'hidden' : '';?> + begin == '2030-01-01' || $plan->end == '2030-01-01' ? "checked='checked'" : '';?> productplan->begin;?> - begin != '2030-01-01' ? formatTime($plan->begin) : '', "class='form-control form-date' $required");?> + begin != '2030-01-01' ? formatTime($plan->begin) : '', "class='form-control form-date'");?> status == 'wait'):?>
@@ -63,7 +62,7 @@ productplan->end;?> - end != '2030-01-01' ? formatTime($plan->end) : '', "class='form-control form-date' $required");?> + end != '2030-01-01' ? formatTime($plan->end) : '', "class='form-control form-date'");?> end == '2030-01-01' ? 0 : (strtotime($plan->end) - strtotime($plan->begin)) / 3600 / 24 + 1;?> productplan->endList , $deltaValue, "onclick='computeEndDate(this.value)'");?> From 666760a95c1e3186fdd520a6c8903b5fa9281243 Mon Sep 17 00:00:00 2001 From: zhengrunyu Date: Thu, 6 Jan 2022 11:20:27 +0800 Subject: [PATCH 2/2] *Code bug. --- module/productplan/model.php | 1 - 1 file changed, 1 deletion(-) diff --git a/module/productplan/model.php b/module/productplan/model.php index 4b30bd23d1..71725b6530 100644 --- a/module/productplan/model.php +++ b/module/productplan/model.php @@ -686,7 +686,6 @@ class productplanModel extends model /* Determine whether the begin and end dates of the parent plan and the child plan are correct. */ if($parentID > 0) { - $parentID = $parentID; $parent = isset($plans[$parentID]) ? $plans[$parentID] : $this->getByID($parentID); if($parent->begin != $this->config->productplan->future and $plan->begin != $this->config->productplan->future and $plan->begin < $parent->begin) {