diff --git a/module/productplan/control.php b/module/productplan/control.php index 72de3120ed..24b3c4575d 100644 --- a/module/productplan/control.php +++ b/module/productplan/control.php @@ -102,6 +102,8 @@ class productplan extends control if(!empty($_POST)) { $changes = $this->productplan->update($planID); + $change[$planID] = $changes; + $this->synchronizeStory($change); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); if($changes) { @@ -144,6 +146,7 @@ class productplan extends control elseif($_POST) { $changes = $this->productplan->batchUpdate($productID); + $this->productplan->synchronizeStory($changes); $this->loadModel('action'); foreach($changes as $planID => $change) { @@ -651,6 +654,68 @@ class productplan extends control die(js::locate($this->createLink('productplan', 'view', "planID=$planID&type=bug&orderBy=$orderBy"), 'parent')); } + /** + * Synchronize story when edit plan. + * @param int $planID + * @param int $oldBranch + * @access public + * @return void + */ + + public function synchronizeStory($changes) + { + $oldBranch = ''; + $newBranch = ''; + foreach($changes as $planID => $changes) + { + foreach($changes as $changeId => $change) + { + if($change['field'] == 'branch') + { + $oldBranch = $change['old']; + $newBranch = $change['new']; + break; + } + } + $planStories = $this->loadModel('story')->getPlanStories($planID, 'all'); + if($oldBranch) + { + foreach($planStories as $storyID => $story) + { + if($story->branch and $story->branch != $newBranch)$this->productplan->unlinkStory($storyID, $planID); + } + } + $oldBranch = ''; + } + } + /** + * AJAX: Get conflict story. + * + * @param int $planID + * @param int $branch + * @access public + * @return void + */ + public function ajaxGetConflictStory($planID, $oldBranch, $newBranch) + { + $planStories = $this->loadModel('story')->getPlanStories($planID, 'all'); + $conflictStoryIdList = ''; + if($oldBranch) + { + foreach($planStories as $storyID => $story) + { + if($story->branch and $story->branch != $newBranch) $conflictStoryIdList .= '[' . $storyID . ']'; + } + } + if($conflictStoryIdList != '') + { + echo sprintf($this->lang->story->confirmChangePlan, $conflictStoryIdList); + } + else + { + echo ''; + } + } /** * AJAX: Get last plan. diff --git a/module/productplan/js/edit.js b/module/productplan/js/edit.js index 6b4d8cc604..faa69a78ec 100644 --- a/module/productplan/js/edit.js +++ b/module/productplan/js/edit.js @@ -12,6 +12,13 @@ function convertStringToDate(dateString) return Date.parse(dateString); } +function loadWarning(branch) +{ + $.get(createLink('productplan', 'ajaxGetConflictStory', 'planID=' + planID + '&oldBranch=' + oldBranch + '&newBranch=' + branch), function(conflictStories) + { + if(conflictStories != '') alert(conflictStories); + }); +} /** * Compute the end date for productplan. diff --git a/module/productplan/view/edit.html.php b/module/productplan/view/edit.html.php index 67c25b8426..d3a4a10e07 100644 --- a/module/productplan/view/edit.html.php +++ b/module/productplan/view/edit.html.php @@ -15,6 +15,8 @@ execution->weekend);?> +id);?> +branch);?>