* Optimize code for project::create and project::edit.

This commit is contained in:
liumengyi
2024-01-23 16:14:09 +08:00
parent 6f9a923267
commit 7a6d0dba9b
6 changed files with 18 additions and 123 deletions
+12 -1
View File
@@ -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');
}
-36
View File
@@ -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');
}
-76
View File
@@ -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')
}
+3 -3
View File
@@ -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);
}
-5
View File
@@ -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')
+3 -2
View File
@@ -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'),