From 5095e566d8f29ae297f9bb9aef5600cddf4aecc8 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Wed, 30 Nov 2022 09:30:44 +0800 Subject: [PATCH] * Code for task#77794. Edit productplan. --- module/productplan/control.php | 16 ++++++++------ module/productplan/js/edit.js | 22 +++++++++---------- module/productplan/model.php | 31 +++++++++++++++++---------- module/productplan/view/edit.html.php | 4 ++-- 4 files changed, 42 insertions(+), 31 deletions(-) diff --git a/module/productplan/control.php b/module/productplan/control.php index 38ac2d476b..83693364eb 100644 --- a/module/productplan/control.php +++ b/module/productplan/control.php @@ -917,7 +917,7 @@ class productplan extends control { foreach($planStories as $storyID => $story) { - if($story->branch and $story->branch != $newBranch) $this->productplan->unlinkStory($storyID, $planID); + if($story->branch and strpos(",$newBranch,", ",$story->branch,") === false) $this->productplan->unlinkStory($storyID, $planID); } } } @@ -933,15 +933,17 @@ class productplan extends control */ public function ajaxGetConflictStory($planID, $newBranch) { - $plan = $this->productplan->getByID($planID); - $oldBranch = $plan->branch; - $planStories = $this->loadModel('story')->getPlanStories($planID, 'all'); $conflictStoryIdList = ''; + if(empty($newBranch)) return $conflictStoryIdList; + + $plan = $this->productplan->getByID($planID); + $oldBranch = $plan->branch; + $planStories = $this->loadModel('story')->getPlanStories($planID, 'all'); if($oldBranch) { foreach($planStories as $storyID => $story) { - if($story->branch and $story->branch != $newBranch) $conflictStoryIdList .= '[' . $storyID . ']'; + if($story->branch and strpos(",$newBranch,", ",$story->branch,") === false) $conflictStoryIdList .= '[' . $storyID . ']'; } } if($conflictStoryIdList != '') printf($this->lang->story->confirmChangePlan, $conflictStoryIdList); @@ -967,12 +969,14 @@ class productplan extends control * * @param int $productID * @param int $branch + * @param int $planID * @access public * @return object */ - public function ajaxGetTopPlan($productID, $branch = 0) + public function ajaxGetTopPlan($productID, $branch = 0, $planID = 0) { $parentPlanPairs = $this->productplan->getTopPlanPairs($productID, $branch); + if(isset($parentPlanPairs[$planID])) unset($parentPlanPairs[$planID]); return print(html::select('parent', array(0 => '') + $parentPlanPairs, 0, 'class="form-control"')); } } diff --git a/module/productplan/js/edit.js b/module/productplan/js/edit.js index 76f811cabf..ea7b6c9c42 100644 --- a/module/productplan/js/edit.js +++ b/module/productplan/js/edit.js @@ -17,34 +17,32 @@ function convertStringToDate(dateString) * Get conflict stories. * * @param int $planID - * @param int $branch * @access public * @return void */ -function getConflictStories(planID, branch) +function getConflictStories(planID) { - $.get(createLink('productplan', 'ajaxGetConflictStory', 'planID=' + planID + '&newBranch=' + branch), function(conflictStories) + var newBranch = $('#branch').val() ? $('#branch').val().toString() : ''; + $.get(createLink('productplan', 'ajaxGetConflictStory', 'planID=' + planID + '&newBranch=' + newBranch), function(conflictStories) { if(conflictStories != '') { var result = confirm(conflictStories) ? true : false; if(!result) { + newBranch = oldBranch[planID]; $('#branch').val(oldBranch[planID]); $('#branch').trigger("chosen:updated"); } } - if(conflictStories == '' || result) + var link = createLink('productplan', 'ajaxGetTopPlan', "productID=" + productID + "&branch=" + newBranch + "&planID=" + planID); + $.post(link, function(data) { - var link = createLink('productplan', 'ajaxGetTopPlan', "productID=" + productID + "&branch=" + branch); - $.post(link, function(data) - { - $('#parent').replaceWith(data); - $('#parent_chosen').remove(); - $('#parent').chosen(); - }) - } + $('#parent').replaceWith(data); + $('#parent_chosen').remove(); + $('#parent').chosen(); + }) }); } diff --git a/module/productplan/model.php b/module/productplan/model.php index 7fe3f12f32..78e8ffbe43 100644 --- a/module/productplan/model.php +++ b/module/productplan/model.php @@ -481,6 +481,13 @@ class productplanModel extends model ->remove('delta,uid,future') ->get(); + $product = $this->loadModel('product')->getByID($plan->product); + if($product->type != 'normal' and !isset($_POST['branch'])) + { + $this->lang->product->branch = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]); + dao::$errors['branch'] = sprintf($this->lang->error->notempty, $this->lang->product->branch); + } + if($plan->parent > 0) { $parentPlan = $this->getByID($plan->parent); @@ -494,12 +501,6 @@ class productplanModel extends model } } - $product = $this->loadModel('product')->getByID($plan->product); - if($product->type != 'normal' and empty($plan->branch)) - { - $this->lang->product->branch = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]); - dao::$errors['branch'] = sprintf($this->lang->error->notempty, $this->lang->product->branch); - } if(!$this->post->future and strpos($this->config->productplan->create->requiredFields, 'begin') !== false and empty($_POST['begin'])) { dao::$errors['begin'] = sprintf($this->lang->error->notempty, $this->lang->productplan->begin); @@ -558,10 +559,19 @@ class productplanModel extends model $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) + ->setDefault('branch', 0) + ->join('branch', ',') ->add('id', $planID) ->remove('delta,uid,future') ->get(); + $product = $this->loadModel('product')->getByID($oldPlan->product); + if($product->type != 'normal' and !isset($_POST['branch'])) + { + $this->lang->product->branch = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]); + dao::$errors['branch'] = sprintf($this->lang->error->notempty, $this->lang->product->branch); + } + $parentPlan = $this->getByID($plan->parent); $futureTime = $this->config->productplan->future; @@ -578,9 +588,9 @@ class productplanModel extends model } elseif($oldPlan->parent == -1 and ($plan->begin != $futureTime or $plan->end != $futureTime)) { - $childPlans = $this->getChildren($planID); - $minBegin = $plan->begin; - $maxEnd = $plan->end; + $childPlans = $this->getChildren($planID); + $minBegin = $plan->begin; + $maxEnd = $plan->end; foreach($childPlans as $childID => $childPlan) { $childPlan = isset($plans[$childID]) ? $plans[$childID] : $childPlan; @@ -593,8 +603,7 @@ class productplanModel extends model 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) + $this->dao->update(TABLE_PRODUCTPLAN)->data($plan) ->autoCheck() ->batchCheck($this->config->productplan->edit->requiredFields, 'notempty') ->checkIF(!$this->post->future && !empty($_POST['begin']) && !empty($_POST['end']), 'end', 'ge', $plan->begin) diff --git a/module/productplan/view/edit.html.php b/module/productplan/view/edit.html.php index 1f0df1c99d..469eb90018 100644 --- a/module/productplan/view/edit.html.php +++ b/module/productplan/view/edit.html.php @@ -33,7 +33,7 @@ type != 'normal' and $plan->parent != '-1'):?> product->branch;?> - branch, "onchange='getConflictStories($plan->id, this.value); 'class='form-control chosen' multiple");?> + branch, "onchange='getConflictStories($plan->id);' class='form-control chosen' multiple");?> @@ -46,7 +46,7 @@ productplan->parent;?> - '') + $parentPlanPairs, $plan->parent, "class='form-control chosen'");?> + '') + $parentPlanPairs, $plan->parent, "class='form-control chosen'");?>