diff --git a/lib/zin/wg/productsbox/v1.php b/lib/zin/wg/productsbox/v1.php index 6b1dc0b232..187b15fe27 100644 --- a/lib/zin/wg/productsbox/v1.php +++ b/lib/zin/wg/productsbox/v1.php @@ -67,7 +67,7 @@ class productsBox extends wg protected function initProductsBox(): array { global $lang; - list($productItems, $project, $isStage, $productPlans) = $this->prop(array('productItems', 'project', 'isStage', 'productPlans')); + list($productItems, $project, $isStage) = $this->prop(array('productItems', 'project', 'isStage')); $productsBox = array(); $hidden = empty($project->hasProduct) ? 'hidden' : ''; diff --git a/module/execution/css/edit.ui.css b/module/execution/css/edit.ui.css index 9bb5416dcd..d19ff7b5c8 100644 --- a/module/execution/css/edit.ui.css +++ b/module/execution/css/edit.ui.css @@ -1,5 +1,3 @@ .editPanel {max-width: 1200px !important;} .items-center {align-items: center !important;} #lifeTimeTips {padding-left: 1rem; align-items: center;} -.productsBox .line-btn {width: 48px; margin-right: 32px;} -.productsBox div[id^=plan] {flex: 1 1;} diff --git a/module/execution/js/edit.ui.js b/module/execution/js/edit.ui.js index 30ae550424..58f29e4124 100644 --- a/module/execution/js/edit.ui.js +++ b/module/execution/js/edit.ui.js @@ -5,76 +5,6 @@ $(function() if(isWaterfall) hidePlanBox(executionAttr); }); -/** - * Change product interaction. - * - * @access public - * @return void - */ -function productChange(e) -{ - loadBranches(e); - - let $product = $(e.target); - let current = $product.val(); - let last = $product.attr('last'); - let lastBranch = $product.attr('lastBranch'); - - $product.attr('data-last', current); - - let $branch = $product.closest('.productBox').find("[name^='branch']"); - if($branch.val()) - { - $product.attr('lastBranch', $branch.val()); - } - else - { - $product.removeAttr('lastBranch'); - } - - if(current != last && unmodifiableProducts.includes(Number(last))) - { - if(lastBranch != 0) - { - if(unmodifiableBranches.includes(Number(lastBranch))) - { - if(linkedStoryIDList[last][lastBranch]) zui.Modal.alert(unLinkProductTip.replace("%s", allProducts[last] + branchGroups[last][lastBranch])); - } - } - else - { - zui.Modal.alert(unLinkProductTip.replace("%s", allProducts[last])); - } - } -} - -/** - * Change branch interaction. - * - * @access public - * @return void - */ -function branchChange(e) -{ - let $branch = $(e.target); - let current = $branch.val(); - let last = $branch.attr('data-last'); - $branch.attr('data-last', current); - - let $product = $branch.closest('.form-row').find("[name^='products']"); - $product.attr('lastBranch', current); - loadPlans($product, $branch); - - if(unmodifiableBranches.includes(last)) - { - let productID = $product.val(); - if(unmodifiableBranches.includes(productID) && linkedStoryIDList[productID][last]) - { - zui.Modal.alert(tip.replace('%s', linkedStoryIDList[productID][last])); - } - } -} - /** * Change project interaction. * @@ -100,157 +30,3 @@ function changeProject(e) } }); }; - -/** - * Load branches. - * - * @param event $e - * @access public - * @return void - */ -function loadBranches(e) -{ - /* When selecting a product, delete a plan that is empty by default. */ - $("#planDefault").remove(); - - let chosenProducts = []; - let $product = $(e.target); - $("[name^='products']").each(function() - { - let productID = $(this).val(); - if(productID > 0 && chosenProducts.indexOf(productID) == -1) chosenProducts.push(productID); - if($product.val() != 0 && $product.val() == $(this).val() && $product.attr('id') != $(this).attr('id')) - { - zui.Modal.alert(errorSameProducts); - $product.zui('picker').$.setValue(0); - return false; - } - }); - - let $formRow = $product.closest('.form-row'); - let index = $formRow.find("[name^='products']").first().attr('name').match(/\d+/)[0]; - let oldBranch = $(e.target).attr('data-branch') !== undefined ? $product.attr('data-branch') : 0; - - if(!multiBranchProducts[$product.val()]) - { - $formRow.find('.form-group').last().find('select').val(''); - $formRow.find('.form-group').eq(0).addClass('w-1/2').removeClass('w-1/4'); - $formRow.find('.form-group').eq(1).addClass('hidden'); - } - - $.getJSON($.createLink('branch', 'ajaxGetBranches', "productID=" + $product.val() + "&oldBranch=" + oldBranch + "¶m=active&projectID=" + projectID + "&withMainBranch=true"), function(data) - { - if(data.length > 0) - { - $formRow.find('.form-group').eq(0).addClass('w-1/4').removeClass('w-1/2'); - $formRow.find('.form-group').eq(1).removeClass('hidden'); - const $branchPicker = $formRow.find('select[name^=branch]').zui('picker'); - $branchPicker.render({items: data, multiple: true}); - } - }); - - let branch = $('#branch' + index); - loadPlans(e.target, branch); -} - -/** - * Load plans. - * - * @param obj $product - * @param obj $branchID - * @access public - * @return void - */ -window.loadPlans = function(product, branch) -{ - let productID = $(product).val(); - let branchID = $(branch).val() == null ? 0 : '0,' + $(branch).val(); - let planID = $(product).attr('data-plan') !== undefined ? $(product).attr('data-plan') : 0; - let index = $(product).attr('name').match(/\d+/)[0]; - - $.get($.createLink('product', 'ajaxGetPlans', "productID=" + productID + '&branch=' + branchID + '&planID=' + planID + '&fieldID&needCreate=&expired=unexpired,noclosed¶m=skipParent,multiple'), function(data) - { - if(data) - { - data = JSON.parse(data); - - $("div#plan" + index).find('.picker-box').empty(); - $("div#plan" + index).find('.picker-box').append(`
`); - - new zui.Picker(`#plans${productID}`, { - items: data, - multiple: true, - name: `plans[${productID}][]`, - }); - } - }); -} - -/** - * Add new line for link product. - * - * @param obj $obj - * @access public - * @return void - */ -function addNewLine(e) -{ - const obj = e.target - const newLine = $(obj).closest('.form-row').clone(); - - let index = 0; - let options = zui.Picker.query("[name^='products']").options; - - /* 将已有产品下拉的最大name属性的值加1赋值给新行. */ - $("[name^='products']").each(function() - { - let id = $(this).attr('name').replace(/[^\d]/g, ''); - - id = parseInt(id); - id ++; - - index = id > index ? id : index; - }) - - /* 处理新一行控件的显示/隐藏,宽度/是否居中等样式问题. */ - newLine.addClass('newLine'); - newLine.find('.form-label').html(''); - newLine.find('.form-group').eq(0).addClass('w-1/2').removeClass('w-1/4'); - newLine.find('.form-group').eq(1).addClass('hidden'); - newLine.find("div[id^='plan']").attr('id', 'plan' + index); - newLine.find('.linkProduct > .form-label').html('').removeClass('required'); - newLine.find('.removeLine').removeClass('hidden'); - - - $(obj).closest('.form-row').after(newLine); - - /* 重新初始化新一行的下拉控件. */ - newLine.find('.form-group').eq(0).find('.picker-box').empty(); - newLine.find('.form-group').eq(0).find('.picker-box').append(``); - - newLine.find('div[id^=plan] .picker-box').empty(); - newLine.find('div[id^=plan] .picker-box').append(``); - - options.name = `products[${index}]`; - options.defaultValue = ''; - new zui.Picker(`#products${index}`, options); - - new zui.Picker(`#plans${index}`, { - items:[], - multiple: true, - name: `plans[${index}]`, - }); -} - -/** - * Remove line for link product. - * - * @param obj e - * @access public - * @return void - */ -function removeLine(e) -{ - const obj = e.target; - $(obj).closest('.form-row').remove(); -} diff --git a/module/execution/ui/edit.field.php b/module/execution/ui/edit.field.php index d95f4607e2..88feba402d 100644 --- a/module/execution/ui/edit.field.php +++ b/module/execution/ui/edit.field.php @@ -110,130 +110,19 @@ $fields->field('days') ->value(data('execution.days')) ->width('1/2'); -if($project->model != 'waterfall' && $project->model != 'waterfallplus') -{ - if(!empty($project->hasProduct) && $linkedProducts) - { - $i = 0; - foreach($linkedProducts as $product) - { - $plans = isset($productPlans[$product->id]) ? $productPlans[$product->id] : array(); - $branches = isset($branchGroups[$product->id]) ? $branchGroups[$product->id] : array(); - $hasBranch = $product->type != 'normal' && !empty($branches); - $fields->field("products[{$i}]") - ->width($hasBranch ? '1/4' : '1/2') - ->className($hidden ? 'hidden' : '') - ->label($i == 0 ? $lang->project->manageProducts : '') - ->items(data('allProducts')) - ->value($product->id); - - $fields->field("branch[{$i}][]") - ->width('1/4') - ->multiple() - ->className($hidden || !$hasBranch ? 'hidden' : '') - ->label($i == 0 ? $lang->product->branchName['branch'] : '') - ->items($branches) - ->value($productBranches ? implode(',', $productBranches) : array()); - - $fields->field("plans[$product->id][]") - ->width('1/2') - ->multiple() - ->label($lang->project->associatePlan) - ->items($plans) - ->value($linkedPlans ? implode(',', $linkedPlans) : array()); - - $i ++; - } - } - elseif(empty($project->hasProduct)) - { - $planProductID = current(array_keys($linkedProducts)); - $fields->field("plans[$planProductID][]") - ->width('1/2') - ->multiple() - ->label($lang->execution->linkPlan) - ->items(isset($productPlans[$planProductID]) ? $productPlans[$planProductID] : array()) - ->value(isset($linkedProducts[$planProductID]) ? $linkedProducts[$planProductID]->plans : ''); - - $fields->field('products[0]')->type('hidden')->value($planProductID); - $fields->field('branch[0]')->type('hidden')->value(''); - } - else - { - $fields->field('products[0]') - ->width('1/2') - ->className($hidden ? 'hidden' : '') - ->label($lang->project->manageProducts) - ->items(data('allProducts')) - ->value(''); - - $fields->field('branch[0][]') - ->width('1/4') - ->className('hidden') - ->multiple() - ->label($lang->product->branchName['branch']) - ->items(array()) - ->value(''); - - $fields->field('plans[0][]') - ->width('1/2') - ->multiple() - ->label($lang->project->associatePlan) - ->items(array()) - ->value(''); - } -} -elseif(!empty($project->hasProduct)) -{ - $i = 0; - foreach($linkedProducts as $product) - { - $plans = isset($productPlans[$product->id]) ? $productPlans[$product->id] : array(); - $branches = isset($branchGroups[$product->id]) ? $branchGroups[$product->id] : array(); - $hasBranch = $product->type != 'normal' && !empty($branches); - $fields->field("products[{$i}]") - ->width($hasBranch ? '1/4' : '1/2') - ->className($hidden ? 'hidden' : '') - ->label($i == 0 ? $lang->project->manageProducts : '') - ->items(data('allProducts')) - ->value(data('product.id')) - ->disabled(in_array($project->model, array('waterfall', 'waterfallplus'))) - ->required(in_array($project->model, array('waterfall', 'waterfallplus'))); - - $fields->field("branch[{$i}][]") - ->width('1/4') - ->multiple() - ->className($hidden || !$hasBranch ? 'hidden' : '') - ->label($i == 0 ? $lang->product->branchName['branch'] : '') - ->disabled($project->model == 'waterfall' || $project->model == 'waterfallplus') - ->items($branches) - ->value($productBranches ? implode(',', $productBranches) : '0'); - - $fields->field("plans[$product->id][]") - ->width('1/2') - ->multiple() - ->label($lang->project->associatePlan) - ->items($plans) - ->value($linkedPlans ? implode(',', $linkedPlans) : array()); - - $i ++; - } - - if(empty($linkedProducts)) - { - $fields->field('products[0]')->type('hidden')->value(array()); - $fields->field('branch[][]')->type('hidden')->items(array())->value('')->multiple(); - } -} -else -{ - $fields->field('products[0]')->type('hidden')->value(key($linkedProducts)); - $fields->field('branch[][]') - ->className('hidden') - ->items(isset($linkedBranches[key($linkedProducts)]) ? $linkedBranches[key($linkedProducts)] : array()) - ->value(isset($linkedBranches[key($linkedProducts)]) ? implode(',', $linkedBranches[key($linkedProducts)]) : '') - ->multiple(); -} +$fields->field('productsBox') + ->width('full') + ->control(array( + 'control' => 'productsBox', + 'productItems' => data('allProducts'), + 'branchGroups' => data('branchGroups'), + 'planGroups' => data('productPlans'), + 'linkedProducts' => data('linkedProducts'), + 'linkedBranches' => data('linkedBranches'), + 'productPlans' => data('productPlans'), + 'project' => data('project'), + 'isStage' => data('isStage') + )); if(data('execution.type') == 'stage' && isset($config->setPercent) && $config->setPercent == 1) { diff --git a/module/execution/ui/edit.html.php b/module/execution/ui/edit.html.php index 18d3c2ffaa..f92999a760 100644 --- a/module/execution/ui/edit.html.php +++ b/module/execution/ui/edit.html.php @@ -25,15 +25,12 @@ jsVar('branchGroups', $branchGroups); jsVar('isWaterfall', isset($project) && ($project->model == 'waterfall' || $project->model == 'waterfallplus')); jsVar('executionAttr', $execution->attribute); jsVar('window.lastProjectID', $execution->project); -jsVar('multiBranchProducts', $multiBranchProducts); formGridPanel ( - on::change('[name^=products]', 'productChange'), - on::change('[name^=project]', 'changeProject'), on::change('[name=begin]', 'computeWorkDays(NaN)'), on::change('[name=end]', 'computeWorkDays(NaN)'), - set::fullModeOrders('project', !empty($config->setCode) ? 'type,name,code' : 'method,name,type', 'planDate,days,products,branch,plans,PO,QD,PM,RD,teamMembers,desc,acl'), + set::fullModeOrders('project', !empty($config->setCode) ? 'type,name,code' : 'method,name,type', 'planDate,days,productsBox,PO,QD,PM,RD,teamMembers,desc,acl'), set::title($lang->execution->edit), set::modeSwitcher(false), set::defaultMode('full'),