From 7a6d0dba9bc0337790866aefe2744e6f9f1f6539 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Tue, 23 Jan 2024 16:14:09 +0800 Subject: [PATCH] * Optimize code for project::create and project::edit. --- module/project/js/common.ui.js | 13 ++++- module/project/js/create.ui.js | 36 -------------- module/project/js/edit.ui.js | 76 ------------------------------ module/project/ui/common.field.php | 6 +-- module/project/ui/create.field.php | 5 -- module/project/ui/edit.html.php | 5 +- 6 files changed, 18 insertions(+), 123 deletions(-) diff --git a/module/project/js/common.ui.js b/module/project/js/common.ui.js index 9310570080..22cea6eaf0 100644 --- a/module/project/js/common.ui.js +++ b/module/project/js/common.ui.js @@ -23,7 +23,6 @@ function changeType() else { $('.productsBox').removeClass('hidden'); - if(typeof toggleStageBy == 'function') toggleStageBy($(this)); } } @@ -317,3 +316,15 @@ function ignoreTip(tip) $('#' + tip).remove(); ignoreTips[tip] = true; } + +function toggleStageBy() +{ + let chosenProducts = 0; + $(".productsBox [name^='products']").each(function() + { + if($(this).val() > 0) chosenProducts ++; + }); + + if(chosenProducts > 1) $('.stageByBox').removeClass('hidden'); + if(chosenProducts <= 1) $('.stageByBox').addClass('hidden'); +} diff --git a/module/project/js/create.ui.js b/module/project/js/create.ui.js index bef4933bd9..b63957a469 100644 --- a/module/project/js/create.ui.js +++ b/module/project/js/create.ui.js @@ -69,39 +69,3 @@ $(document).on('keyup', '#projectName', function() if($(this).text().includes(name) || $(this).data('pinyin').includes(name)) $(this).show(); }); }); - -/** - * Set acl list when change program. - * - * @access public - * @return void - */ -window.setParentProgram = function() -{ - const programID = $('[name=parent]').val(); - const link = $.createLink('project', 'create', 'model=' + model + '&program=' + programID); - - if(programID) $('#linkProduct .input-group').addClass('required'); - if(programID == 0) $('#linkProduct .input-group.required').removeClass('required'); - - loadPage(link, '#aclList'); - $('select[name^=whitelist]').closest('.form-row').removeClass('hidden') -} - -/* Init product. */ -window.waitDom('[name^=products]', function() -{ - if($('.newProductBox').length > 0) toggleStageBy($('[name^=products]').eq(0)); -}); - -window.toggleStageBy = function() -{ - let chosenProducts = 0; - $(".productsBox [name^='products']").each(function() - { - if($(this).val() > 0) chosenProducts ++; - }); - - if(chosenProducts > 1) $('.stageByBox').removeClass('hidden'); - if(chosenProducts <= 1) $('.stageByBox').addClass('hidden'); -} diff --git a/module/project/js/edit.ui.js b/module/project/js/edit.ui.js index d26bcdb924..535b476f13 100644 --- a/module/project/js/edit.ui.js +++ b/module/project/js/edit.ui.js @@ -16,79 +16,3 @@ $(document).on('click', '.model-drop', function() $('#project-model').addClass(btnClass); $('#model').val(model); }) - - -window.productChange = function(e) -{ - let current = $(e.target).val(); - let $productBox = $(e.target).closest('.picker-box'); - let last = $productBox.attr('last'); - let lastBranch = $productBox.attr('lastBranch'); - $productBox.attr('last', current); - - let $branch = $(e.target).closest('.productBox').find("[name^='branch']"); - if($branch.val()) - { - $productBox.attr('lastBranch', $branch.val()); - } - else - { - $productBox.removeAttr('lastBranch'); - } - - if(current != last && unmodifiableProducts.includes(Number(last))) - { - if(lastBranch != undefined && lastBranch != 0) - { - if(unmodifiableBranches.includes(Number(lastBranch))) zui.Modal.alert(unLinkProductTip.replace("%s", allProducts[last] + branchGroups[last][lastBranch])); - } - else - { - zui.Modal.alert(unLinkProductTip.replace("%s", allProducts[last])); - } - } - - let chosenProducts = 0; - $(".productsBox [name^='products']").each(function() - { - if($(e.target).val() > 0) chosenProducts ++; - }); - - if(chosenProducts > 1) $('.stageBy').removeClass('hide'); - if(chosenProducts <= 1) $('.stageBy').addClass('hide'); -} - -window.branchChange = function(e) -{ - let current = $(e.target).val(); - let $productBox = $(e.target).closest('.productBox ').find('.linkProduct .picker-box'); - let last = $productBox.attr('lastBranch').split(','); - let changed = last.filter(item => !current.includes(item)); - $productBox.attr('lastBranch', current); - - if(changed.length > 0 && unmodifiableBranches.includes(parseInt(changed[0]))) - { - let productID = $productBox.find('input').val(); - if(unmodifiableProducts.includes(productID)) - { - if((last == 0 && unmodifiableMainBranches[productID]) || last != 0) - { - zui.Modal.alert(unLinkProductTip.replace("%s", branchGroups[productID][last])); - } - } - } -} - -/** - * Set acl list when change program. - * - * @access public - * @return void - */ -window.setParentProgram = function() -{ - const programID = $('[name=parent]').val(); - const link = $.createLink('project', 'edit', `projectID=${projectID}&from=${from}&pgoramID=${programID}`) ; - loadPage(link, '#aclList'); - $('select[name^=whitelist]').closest('.form-row').removeClass('hidden') -} diff --git a/module/project/ui/common.field.php b/module/project/ui/common.field.php index 132f402a50..19838cd0fc 100644 --- a/module/project/ui/common.field.php +++ b/module/project/ui/common.field.php @@ -9,7 +9,7 @@ $fields = defineFieldList('project'); $model = data('model'); $hasCode = !empty($config->setCode); $currency = data('parentProgram') ? data('parentProgram.budgetUnit') : $config->project->defaultCurrency; -$disableStageBy = !empty(data('executions')) ? true : false; +$disableStageBy = !empty(data('executions')) || data('app.rawMethod') == 'edit' ? true : false; $fields->field('parent') ->control('picker', array('required' => true)) @@ -75,11 +75,11 @@ $fields->field('productsBox') if($model == 'waterfall' || $model == 'waterfallplus') { $fields->field('stageBy') - ->className('stageByBox') + ->className('stageByBox', data('linkedProducts') && count(data('linkedProducts')) > 1 ? '' : 'hidden') ->control('radioListInline') ->labelHint($lang->project->stageByTips) ->label($lang->project->stageBy) - ->value('project') + ->value(data('copyProject') ? data('copyProject.stageBy') : (data('project') ? data('project.stageBy') : 'project')) ->disabled($disableStageBy) ->items($lang->project->stageByList); } diff --git a/module/project/ui/create.field.php b/module/project/ui/create.field.php index 395cf62d49..8d250b0fbf 100644 --- a/module/project/ui/create.field.php +++ b/module/project/ui/create.field.php @@ -37,11 +37,6 @@ $fields->field('days')->control('input', array('className' => $copyProject ? 'ha $fields->field('productsBox')->hidden(data('copyProject') && data('copyProject.hasProduct') == 0); -if($model == 'waterfall' || $model == 'waterfallplus') -{ - $fields->field('stageBy')->className('hidden'); -} - $fields->field('budget')->foldable(); $fields->field('acl') diff --git a/module/project/ui/edit.html.php b/module/project/ui/edit.html.php index 0085022f7f..a890d96ce0 100644 --- a/module/project/ui/edit.html.php +++ b/module/project/ui/edit.html.php @@ -11,6 +11,8 @@ declare(strict_types=1); namespace zin; $fields = useFields('project.edit'); +$fields->autoLoad('parent', 'acl'); +$loadUrl = $this->createLink('project', 'create', "model={$model}&program={parent}"); jsVar('model', $model); jsVar('ignore', $lang->project->ignore); @@ -60,8 +62,7 @@ formGridPanel on::change('[name=future]', 'toggleBudget'), on::change('[name=begin], [name=end]', 'computeWorkDays'), on::change('[name=parent], [name=budget]', 'checkBudget'), - on::change('[name^=products]', 'productChange'), - on::change('[name=parent]', 'setParentProgram'), + on::change('[name^=products]', 'toggleStageBy'), set::fullModeOrders(array('begin,days,PM,budget', !empty($config->setCode) ? 'parent,hasProduct,name,code,begin' : 'parent,name,hasProduct,begin')), set::modeSwitcher(false), set::defaultMode('full'),