diff --git a/module/branch/control.php b/module/branch/control.php index 6f497f7abb..f10bfb8cbd 100644 --- a/module/branch/control.php +++ b/module/branch/control.php @@ -260,10 +260,12 @@ class branch extends control * @param string $param * @param int $projectID * @param bool $withMainBranch + * @param string $isSiblings + * @param string $fieldID * @access public * @return void */ - public function ajaxGetBranches($productID, $oldBranch = 0, $param = 'all', $projectID = 0, $withMainBranch = true) + public function ajaxGetBranches($productID, $oldBranch = 0, $param = 'all', $projectID = 0, $withMainBranch = true, $isSiblings = 'no', $fieldID = '0') { $product = $this->loadModel('product')->getById($productID); if(empty($product) or $product->type == 'normal') return; @@ -280,6 +282,7 @@ class branch extends control $branchTagOption[$oldBranch] = $oldBranch == BRANCH_MAIN ? $branch : ($branch->name . ($branch->status == 'closed' ? ' (' . $this->lang->branch->statusList['closed'] . ')' : '')); } + if($isSiblings == 'yes') return print(html::select("branches[$fieldID]", $branchTagOption, $oldBranch, "onchange='loadBranchRelation(this.value, $fieldID);' class='form-control chosen control-branch'")); return print(html::select('branch', $branchTagOption, $oldBranch, "class='form-control' onchange='loadBranch(this)'")); } diff --git a/module/product/control.php b/module/product/control.php index 632894c186..76a023a307 100644 --- a/module/product/control.php +++ b/module/product/control.php @@ -959,6 +959,22 @@ class product extends control } } + /** + * Ajax get product by id. + * + * @param int $productID + * @access public + * @return void + */ + public function ajaxGetProductById($productID) + { + $product = $this->product->getById($productID); + + $product->branchSourceName = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]); + $product->branchName = $this->lang->product->branchName[$product->type]; + echo json_encode($product); + } + /** * AJAX: get projects of a product in html select. * diff --git a/module/story/js/create.js b/module/story/js/create.js index f80710337e..3266d66af2 100644 --- a/module/story/js/create.js +++ b/module/story/js/create.js @@ -127,6 +127,12 @@ $(window).unload(function(){ $('#plans_i__chosen').remove(); $('#plans' + itemIndex).chosen(); $('.addBranchesBox' + itemIndex + ' #planIdBox').css('flex', '0 0 ' + gap + 'px'); + + loadBranchForSiblings($('#product').val(), 0, itemIndex) + loadModuleForSiblings($('#product').val(), 0, itemIndex) + loadPlanForSiblings($('#product').val(), 0, itemIndex) + $('.addBranchesBox' + itemIndex + ' #branchBox .input-group .input-group-addon').html($.cookie('branchSourceName')) + itemIndex ++; } diff --git a/module/story/view/create.html.php b/module/story/view/create.html.php index 5ab8d116ae..b6fb90e379 100644 --- a/module/story/view/create.html.php +++ b/module/story/view/create.html.php @@ -56,16 +56,14 @@ foreach(explode(',', $config->story->create->requiredFields) as $field) - - ' id='assignedToBox'> + switchBranch'>
story->assignedTo;?>
- - - + switchBranch'> + switchBranch'>
story->module;?>
story->create->requiredFields) as $field) ?>
- - - + switchBranch' > product->branchName[$product->type];?>
product->branch, $lang->product->branchName[$product->type])?> - +
@@ -116,14 +112,13 @@ foreach(explode(',', $config->story->create->requiredFields) as $field)
- + -  story->notice->branch;?> + story->notice->branch;?> - - + story->planAB;?>
@@ -148,7 +143,6 @@ foreach(explode(',', $config->story->create->requiredFields) as $field)
- story->source;?> @@ -360,7 +354,7 @@ foreach(explode(',', $config->story->create->requiredFields) as $field)
product->branch, $lang->product->branchName[$product->type])?> - +
diff --git a/module/story/view/header.html.php b/module/story/view/header.html.php index 78714cda3c..2077a66ed2 100644 --- a/module/story/view/header.html.php +++ b/module/story/view/header.html.php @@ -71,16 +71,59 @@ function loadBranch() /** * Load branch for multi branch or multi platform. * + * @param int $branch + * @param int $branchIndex * @access public * @return void */ -function loadBranchForBranch(branch, branchIndex) +function loadBranchRelation(branch, branchIndex) { - var branch = $('#branches' + branchIndex).val(); var productID = $('#product').val(); if(typeof(branch) == 'undefined') branch = 0; - if(typeof(productID) == 'undefined' && config.currentMethod == 'edit') productID = oldProductID; + loadModuleForSiblings(productID, branch, branchIndex) + loadPlanForSiblings(productID, branch, branchIndex) +} + +/** + * Load branch for siblings. + * + * @paran int $procutID + * @param int $branch + * @param int $branchIndex + * @access public + * @return void + */ +function loadBranchForSiblings(productID, branch, branchIndex) +{ + var param = 'all'; + if(page == 'create') param = 'active'; + + var isSiblings = storyType == 'story' ? 'yes' : 'no'; + $.get(createLink('branch', 'ajaxGetBranches', "productID=" + productID + "&oldBranch=0¶m=" + param + "&projectID=" + executionID + "&withMainBranch=1&isSiblings=" + isSiblings + "&fieldID=" + branchIndex), function(data) + { + if(data) + { + /* reload branch */ + $('#branches' + branchIndex).replaceWith(data); + $('#branches' + branchIndex + "_chosen").remove(); + $('#branches' + branchIndex).next('.picker').remove(); + $('#branches' + branchIndex).chosen(); + } + }) +} + +/** + * Load module for siblings. + * + * @paran int $procutID + * @param int $branch + * @param int $branchIndex + * @access public + * @return void + */ +function loadModuleForSiblings(productID, branch, branchIndex) +{ /* Load module */ var currentModule = 0; var moduleLink = createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=story&branch=' + branch + '&rootModuleID=0&returnType=html&fieldID=' + branchIndex + '&needManage=true&extra=¤tModuleID=' + currentModule); @@ -90,15 +133,32 @@ function loadBranchForBranch(branch, branchIndex) } else { - var $moduleIDBox = $('#moduleIdBox'); + var $moduleIDBox = $('.switchBranch #moduleIdBox'); } $moduleIDBox.load(moduleLink, function() { $moduleIDBox.find('#modules' + branchIndex).chosen(); - $moduleIDBox.prepend("" + storyModule + ""); + if(branchIndex == 0) + { + $('.switchBranch #moduleIdBox span:first-child').remove() + } + $moduleIDBox.prepend("" + storyModule + "" ); + $moduleIDBox.fixInputGroup(); }); +} +/** + * Load plan for siblings. + * + * @paran int $procutID + * @param int $branch + * @param int $branchIndex + * @access public + * @return void + */ +function loadPlanForSiblings(productID, branch, branchIndex) +{ /* Load plan */ if(typeof(branch) == 'undefined') branch = 0; if(!branch) branch = 0; @@ -133,20 +193,72 @@ function loadProductBranches(productID) if(page == 'create') param = 'active'; $('#branch').remove(); $('#branch_chosen').remove(); - $.get(createLink('branch', 'ajaxGetBranches', "productID=" + productID + "&oldBranch=0¶m=" + param + "&projectID=" + executionID), function(data) - { - var $product = $('#product'); - var $inputGroup = $product.closest('.input-group'); - $inputGroup.find('.input-group-addon').toggleClass('hidden', !data); - if(data) - { - $inputGroup.append(data); - $('#branch').css('width', config.currentMethod == 'create' ? '120px' : '65px').chosen(); - } - $inputGroup.fixInputGroup(); - loadProductModules(productID, $('#branch').val()); - loadProductPlans(productID, $('#branch').val()); + var isSiblings = storyType == 'story' ? 'yes' : 'no'; + $.get(createLink('branch', 'ajaxGetBranches', "productID=" + productID + "&oldBranch=0¶m=" + param + "&projectID=" + executionID + "&withMainBranch=1&isSiblings=" + isSiblings), function(data) + { + if(storyType == 'story') + { + $('.switchBranch').toggleClass('hidden'); + $('.switchBranch').toggleClass('disable'); + $('tr[class^="addBranchesBox"]').remove(); + + if(data) + { + $.get(createLink('product', 'ajaxGetProductById', "productID=" + productID), function(data) + { + $('.switchBranch #branchBox .input-group .input-group-addon').html(data.branchSourceName) + $('.switchBranch #branchBox').closest('td').prev().html(data.branchName) + $.cookie('branchSourceName', data.branchSourceName) + }, 'json') + + + /* reload branch */ + $('#branches0').replaceWith(data); + $('#branches0' + "_chosen").remove(); + $('#branches0').next('.picker').remove(); + $('#branches0').chosen(); + + $.get(createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=story&branch=0' + '&rootModuleID=0&returnType=html&fieldID=0' + '&needManage=true&extra=¤tModuleID=0'), function(moduleData) + { + if(moduleData) + { + $('#modules0').replaceWith(moduleData); + $('#modules0' + "_chosen").remove(); + $('#modules0').next('.picker').remove(); + $('#modules0').chosen(); + } + }); + + var expired = config.currentMethod == 'create' ? 'unexpired' : ''; + $.get(createLink('product', 'ajaxGetPlans', 'productID=' + productID + '&branch=0' + '&planID=' + $('#plan').val() + '&fieldID=0' + '&needCreate=true&expired='+ expired +'¶m=skipParent,' + config.currentMethod), function(planData) + { + if(planData) + { + $('#plans0').replaceWith(planData); + $('#plans0' + "_chosen").remove(); + $('#plans0').next('.picker').remove(); + $('#plans0').chosen(); + } + }); + } + } + else + { + var $product = $('#product'); + var $inputGroup = $product.closest('.input-group'); + $inputGroup.find('.input-group-addon').toggleClass('hidden', !data); + if(data) + { + $inputGroup.append(data); + $('#branch').css('width', config.currentMethod == 'create' ? '120px' : '65px').chosen(); + } + $inputGroup.fixInputGroup(); + + loadProductModules(productID, $('#branch').val()); + loadProductPlans(productID, $('#branch').val()); + } + }) }