diff --git a/module/productplan/control.php b/module/productplan/control.php index 8ef3268a79..f2fad8c605 100644 --- a/module/productplan/control.php +++ b/module/productplan/control.php @@ -1008,20 +1008,26 @@ class productplan extends control /** * AJAX: Get parent branches. * - * @param int $parentID + * @param int $productID + * @param int $parentID + * @param string $currentBranches * @access public * @return void */ - public function ajaxGetParentBranches($productID = 0, $parentID = 0) + public function ajaxGetParentBranches($productID = 0, $parentID = 0, $currentBranches = '') { $branchPairs = $this->loadModel('branch')->getPairs($productID, 'active'); if(!empty($parentID)) { $parentBranches = array(); $parentPlan = $this->productplan->getByID($parentID); - foreach(explode(',', $parentPlan->branch) as $parentBranchID) $parentBranches[$parentBranchID] = $branchPairs[$parentBranchID]; + foreach(explode(',', $parentPlan->branch) as $parentBranchID) + { + $parentBranches[$parentBranchID] = $branchPairs[$parentBranchID]; + if(!empty($currentBranches) and strpos(",$currentBranches,", ",$parentBranchID,") === false) $currentBranches = str_replace(",$parentBranchID,", ',', $currentBranches); + } } - return print(html::select('branch[]', empty($parentID) ? $branchPairs : $parentBranches, '', "class='form-control chosen' multiple required")); + return print(html::select('branch[]', empty($parentID) ? $branchPairs : $parentBranches, trim($currentBranches, ','), "class='form-control chosen' multiple required")); } /** diff --git a/module/productplan/js/create.js b/module/productplan/js/create.js index 6bfe71b4ba..dc43f76277 100644 --- a/module/productplan/js/create.js +++ b/module/productplan/js/create.js @@ -65,12 +65,14 @@ $('#future').on('change', function() $('#parent').change(function() { - var parentID = $(this).val(); - $.post(createLink('productplan', 'ajaxGetParentBranches', "productID=" + productID + "&parentID=" + parentID), function(data) + var parentID = $(this).val(); + var currentBranches = $('#branch').val() ? $('#branch').val().toString() : ''; + $.post(createLink('productplan', 'ajaxGetParentBranches', "productID=" + productID + "&parentID=" + parentID + "¤tBranches=" + currentBranches), function(data) { $('#branch').replaceWith(data); $('#branch_chosen').remove(); $('#branch').chosen(); + $('#branch').change(); }) }) diff --git a/module/productplan/js/edit.js b/module/productplan/js/edit.js index 7e0541f621..9d3733f176 100644 --- a/module/productplan/js/edit.js +++ b/module/productplan/js/edit.js @@ -23,7 +23,6 @@ $('#dataform').on('change', '#branch', function() var result = confirm(conflictStories) ? true : false; if(!result) { - newBranch = oldBranch[planID]; $('#branch').val(oldBranch[planID].split(',')); $('#branch').trigger("chosen:updated"); } @@ -59,8 +58,9 @@ function computeEndDate(delta) $('#parent').change(function() { - var parentID = $(this).val(); - $.post(createLink('productplan', 'ajaxGetParentBranches', "productID=" + productID + "&parentID=" + parentID), function(data) + var parentID = $(this).val(); + var currentBranches = $('#branch').val() ? $('#branch').val().toString() : ''; + $.post(createLink('productplan', 'ajaxGetParentBranches', "productID=" + productID + "&parentID=" + parentID + "¤tBranches=" + currentBranches), function(data) { $('#branch').replaceWith(data); $('#branch_chosen').remove();