diff --git a/module/productplan/control.php b/module/productplan/control.php index 7b89d95e8d..c2a745e912 100644 --- a/module/productplan/control.php +++ b/module/productplan/control.php @@ -91,6 +91,10 @@ class productplan extends control if($parent) $this->view->parentPlan = $this->productplan->getById($parent); $branchPairs = $product->type == 'normal' ? array() : $this->loadModel('branch')->getPairs($productID, 'active'); + /* Get parent plan pairs. */ + $parentPlanPairs = $this->productplan->getTopPlanPairs($productID, $branchID); + $this->view->parentPlanPairs = $parentPlanPairs; + /*Get default branch.*/ $branchList = $this->loadModel('branch')->getList($productID); foreach($branchList as $branch) @@ -140,10 +144,12 @@ class productplan extends control $oldBranch = array($planID => $plan->branch); $this->commonAction($plan->product, $plan->branch); - $this->view->title = $this->view->product->name . $this->lang->colon . $this->lang->productplan->edit; - $this->view->position[] = $this->lang->productplan->edit; - $this->view->oldBranch = $oldBranch; - $this->view->plan = $plan; + $this->view->title = $this->view->product->name . $this->lang->colon . $this->lang->productplan->edit; + $this->view->position[] = $this->lang->productplan->edit; + $this->view->productID = $plan->product; + $this->view->oldBranch = $oldBranch; + $this->view->plan = $plan; + $this->view->parentPlanPairs = $this->productplan->getTopPlanPairs($plan->product, $plan->branch, $planID); $this->display(); } @@ -942,4 +948,18 @@ class productplan extends control $lastPlan = $this->productplan->getLast($productID, $branch, $parent); echo json_encode($lastPlan); } + + /** + * AJAX: Get top plan. + * + * @param int $productID + * @param int $branch + * @access public + * @return object + */ + public function ajaxGetTopPlan($productID, $branch = 0) + { + $parentPlanPairs = $this->productplan->getTopPlanPairs($productID, $branch); + return print(html::select('parent', array('0' => '') + $parentPlanPairs, '', 'class="form-control"')); + } } diff --git a/module/productplan/js/create.js b/module/productplan/js/create.js index 09617fe5d4..e9ecce37c7 100644 --- a/module/productplan/js/create.js +++ b/module/productplan/js/create.js @@ -66,12 +66,20 @@ $('#future').on('change', function() $('#branch').change(function() { var branchID = $(this).val(); - var link = createLink('productplan', 'ajaxGetLast', "productID=" + productID + "&branch=" + branchID); + var getLastLink = createLink('productplan', 'ajaxGetLast', "productID=" + productID + "&branch=" + branchID); + var getTopPlanLink = createLink('productplan', 'ajaxGetTopPlan', "productID=" + productID + "&branch=" + branchID); - $.post(link, function(data) + $.post(getLastLink, function(data) { data = JSON.parse(data); var planTitle = data ? '(' + lastLang + ': ' + data.title + ')' : ''; $('#title').parent().next('td').html(planTitle); }) -}) + + $.post(getTopPlanLink, function(data) + { + $('#parent').replaceWith(data); + $('#parent_chosen').remove(); + $('#parent').chosen(); + }) +}); diff --git a/module/productplan/js/edit.js b/module/productplan/js/edit.js index cf0449041d..44147dfdc7 100644 --- a/module/productplan/js/edit.js +++ b/module/productplan/js/edit.js @@ -25,11 +25,23 @@ function getConflictStories(planID, branch) { $.get(createLink('productplan', 'ajaxGetConflictStory', 'planID=' + planID + '&newBranch=' + branch), function(conflictStories) { - if(conflictStories != '' && !confirm(conflictStories)) + var result = confirm(conflictStories) ? true : false; + if(conflictStories != '' && !result) { $('#branch').val(oldBranch[planID]); $('#branch').trigger("chosen:updated"); } + + if(result) + { + var link = createLink('productplan', 'ajaxGetTopPlan', "productID=" + productID + "&branch=" + branch); + $.post(link, function(data) + { + $('#parent').replaceWith(data); + $('#parent_chosen').remove(); + $('#parent').chosen(); + }) + } }); } @@ -73,4 +85,3 @@ $('#future').on('change', function() } }); -$('#future').change(); diff --git a/module/productplan/model.php b/module/productplan/model.php index cea66f66ff..1f7da91ec3 100644 --- a/module/productplan/model.php +++ b/module/productplan/model.php @@ -177,6 +177,29 @@ class productplanModel extends model return $plans; } + /** + * Get top plan pairs. + * + * @param int $productID + * @param int $branch + * @param int $exclude + * @access public + * @return array + */ + public function getTopPlanPairs($productID, $branch = '', $exclude = '') + { + $planPairs = $this->dao->select("id,title")->from(TABLE_PRODUCTPLAN) + ->where('product')->eq($productID) + ->beginIF($branch !== '')->andWhere('branch')->eq($branch)->fi() + ->andWhere('parent')->le(0) + ->andWhere('deleted')->eq(0) + ->fetchPairs(); + + if($exclude) unset($planPairs[$exclude]); + + return $planPairs; + } + /** * Get plan pairs. * @@ -404,19 +427,17 @@ class productplanModel extends model if($plan->parent > 0) { - if($plan->parentBegin != $this->config->productplan->future) + $parentPlan = $this->getByID($plan->parent); + if($parentPlan->begin != $this->config->productplan->future) { - if($plan->begin < $plan->parentBegin) dao::$errors['begin'] = sprintf($this->lang->productplan->beginLetterParent, $plan->parentBegin); + if($plan->begin < $parentPlan->begin) dao::$errors['begin'] = sprintf($this->lang->productplan->beginLetterParent, $parentPlan->begin); } - if($plan->parentEnd != $this->config->productplan->future) + if($parentPlan->end != $this->config->productplan->future) { - if($plan->end !== $this->config->productplan->future and $plan->end > $plan->parentEnd) dao::$errors['end'] = sprintf($this->lang->productplan->endGreaterParent, $plan->parentEnd); + if($plan->end !== $this->config->productplan->future and $plan->end > $parentPlan->end) dao::$errors['end'] = sprintf($this->lang->productplan->endGreaterParent, $parentPlan->end); } } - unset($plan->parentBegin); - unset($plan->parentEnd); - 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); @@ -442,7 +463,6 @@ class productplanModel extends model $this->loadModel('score')->create('productplan', 'create', $planID); if(!empty($plan->parent)) { - $parentPlan = $this->getByID($plan->parent); if($parentPlan->parent == '0') { $this->dao->update(TABLE_PRODUCTPLAN)->set('parent')->eq('-1')->where('id')->eq($plan->parent)->andWhere('parent')->eq('0')->exec(); @@ -473,7 +493,7 @@ class productplanModel extends model */ public function update($planID) { - $oldPlan = $this->dao->findByID((int)$planID)->from(TABLE_PRODUCTPLAN)->fetch(); + $oldPlan = $this->getByID($planID); $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) @@ -481,9 +501,11 @@ class productplanModel extends model ->remove('delta,uid,future') ->get(); - if($oldPlan->parent > 0) + $parentPlan = $this->getByID($plan->parent); + + + if($plan->parent > 0) { - $parentPlan = $this->getByID($oldPlan->parent); if($parentPlan->begin !== $this->config->productplan->future) { if($plan->begin < $parentPlan->begin) dao::$errors['begin'] = sprintf($this->lang->productplan->beginLetterParent, $parentPlan->begin); @@ -493,9 +515,9 @@ class productplanModel extends model if($plan->end !== $this->config->productplan->future and $plan->end > $parentPlan->end) dao::$errors['end'] = sprintf($this->lang->productplan->endGreaterParent, $parentPlan->end); } } - elseif($oldPlan->parent == -1 and $plan->begin != $this->config->productplan->future) + elseif($parentPlan and $plan->begin != $this->config->productplan->future) { - $childPlans = $this->dao->select('*')->from(TABLE_PRODUCTPLAN)->where('parent')->eq($planID)->andWhere('deleted')->eq(0)->fetchAll('id'); + $childPlans = $this->getChildren($parentPlan->id); $minBegin = $plan->begin; $maxEnd = $plan->end; foreach($childPlans as $childID => $childPlan) @@ -520,11 +542,31 @@ class productplanModel extends model ->exec(); if(dao::isError()) return false; + if($plan->parent > 0) $this->updateParentStatus($plan->parent); if($oldPlan->parent > 0) $this->updateParentStatus($oldPlan->parent); if(!dao::isError()) { $this->file->updateObjectID($this->post->uid, $planID, 'plan'); + if(!empty($plan->parent)) + { + if($parentPlan->parent == '0') + { + $this->dao->update(TABLE_PRODUCTPLAN)->set('parent')->eq('-1')->where('id')->eq($plan->parent)->andWhere('parent')->eq('0')->exec(); + + /* Transfer stories and bugs linked with the parent plan to the child plan. */ + $this->dao->update(TABLE_PLANSTORY)->set('plan')->eq($planID)->where('plan')->eq($plan->parent)->exec(); + $this->dao->update(TABLE_BUG)->set('plan')->eq($planID)->where('plan')->eq($plan->parent)->exec(); + $stories = $this->dao->select('*')->from(TABLE_STORY)->where("CONCAT(',', plan, ',')")->like("%,{$plan->parent},%")->fetchAll('id'); + foreach($stories as $storyID => $story) + { + $storyPlan = str_replace(",{$plan->parent},", ",$planID,", ",$story->plan,"); + $storyPlan = trim($storyPlan, ','); + + $this->dao->update(TABLE_STORY)->set('plan')->eq($storyPlan)->where('id')->eq($storyID)->exec(); + } + } + } return common::createChanges($oldPlan, $plan); } } diff --git a/module/productplan/view/create.html.php b/module/productplan/view/create.html.php index 9bc121ac68..3d37c51178 100644 --- a/module/productplan/view/create.html.php +++ b/module/productplan/view/create.html.php @@ -28,8 +28,6 @@