* Code for task#78669.

This commit is contained in:
xieqiyu
2022-12-06 10:24:11 +08:00
parent c23d02ca73
commit 62157bf79e
3 changed files with 17 additions and 9 deletions
+10 -4
View File
@@ -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"));
}
/**
+4 -2
View File
@@ -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 + "&currentBranches=" + currentBranches), function(data)
{
$('#branch').replaceWith(data);
$('#branch_chosen').remove();
$('#branch').chosen();
$('#branch').change();
})
})
+3 -3
View File
@@ -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 + "&currentBranches=" + currentBranches), function(data)
{
$('#branch').replaceWith(data);
$('#branch_chosen').remove();