From 4119c8bb6156715e33409c6d363dd8db2f600925 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Mon, 17 Feb 2025 14:30:57 +0800 Subject: [PATCH] * [task#137378,doing,1h] optimize code. --- db/update21.4.sql | 2 ++ db/zentao.sql | 1 + lib/zin/wg/productcharterbox/js/v1.js | 33 ++++++++++++++++----------- lib/zin/wg/productcharterbox/v1.php | 2 +- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/db/update21.4.sql b/db/update21.4.sql index 2734062996..bc3aec8bf0 100644 --- a/db/update21.4.sql +++ b/db/update21.4.sql @@ -16,3 +16,5 @@ CREATE TABLE IF NOT EXISTS `zt_extuser` ( `account` char(30) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE `zt_charter` ADD COLUMN `branch` text NULL AFTER `product`; diff --git a/db/zentao.sql b/db/zentao.sql index 20121e2db8..af8361c1f3 100755 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -15728,6 +15728,7 @@ CREATE TABLE `zt_charter` ( `budget` char(30) NOT NULL DEFAULT '', `budgetUnit` char(30) NOT NULL DEFAULT '', `product` text NULL, + `branch` text NULL, `roadmap` text NULL, `plan` text NULL, `type` varchar(30) NOT NULL DEFAULT 'roadmap', diff --git a/lib/zin/wg/productcharterbox/js/v1.js b/lib/zin/wg/productcharterbox/js/v1.js index 5e1953132b..2aa7659536 100644 --- a/lib/zin/wg/productcharterbox/js/v1.js +++ b/lib/zin/wg/productcharterbox/js/v1.js @@ -142,8 +142,8 @@ window.loadPlan = function(product) { let productID = product.val(); let branchID = product.closest('.productBox').find('.linkBranch .pick-value').val(); - if(typeof branchID == 'undefined') $branchID = ''; - let link = $.createLink('charter', 'ajaxGetPlans', 'productID=' + productID + '&branchID' + branchID); + if(typeof branchID == 'undefined') branchID = ''; + let link = $.createLink('charter', 'ajaxGetPlans', 'productID=' + productID + '&branchID=' + branchID); const $items = [{text: '', value: '', key: ''}]; const $plan = product.closest('.productBox').find('.planBox .pick-value'); @@ -162,11 +162,24 @@ window.refreshPicker = function(event) { if(typeof event !== "undefined") { - const objectType = $(event.target).closest('.productsBox').data('objecttype'); - if(objectType == 'roadmap') loadRoadmap($(event.target)); - if(objectType == 'plan') loadPlan($(event.target)); + const $product = $(event.target); + const productID = $product.val(); + if(multiBranchProducts[productID]) + { + loadBranches($product); + } + else + { + updateItems(); - loadBranches($(event.target)); + const objectType = $product.closest('.productsBox').data('objecttype'); + if(objectType == 'roadmap') loadRoadmap($product); + if(objectType == 'plan') loadPlan($product); + + let $formRow = $product.closest('.productBox'); + $formRow.find('.form-group').eq(0).addClass('w-1/2').removeClass('w-1/4'); + $formRow.find('.form-group').eq(1).addClass('hidden'); + } } } @@ -186,11 +199,6 @@ window.loadBranches = function(product) let $formRow = product.closest('.productBox'); let charterID = $('[name="charter"]').length ? $('[name="charter"]').val() : 0; const objectType = $('.productsBox').data('linkType'); - if(!multiBranchProducts[currentProduct]) - { - $formRow.find('.form-group').eq(0).addClass('w-1/2').removeClass('w-1/4'); - $formRow.find('.form-group').eq(1).addClass('hidden'); - } if(typeof projectID == 'undefined') projectID = 0; $.getJSON($.createLink('branch', 'ajaxGetBranches', "productID=" + currentProduct + "&oldBranch=¶m=active&projectID=" + projectID + "&withMainBranch=true&isTwins=no&fieldID=0&multiple=&charterID=" + charterID), function(data) @@ -272,7 +280,7 @@ window.updateItems = function(currentProduct = '', currentBranch = '') const branchItems = $branch.zui('picker').options.items if(!chosenBranches[productID]) chosenBranches[productID] = []; - $('[name^=product][value="' + productID + '"]').closest('.productBox').find('[name^="branch"]').each(function() + $branch.each(function() { const branchID = $(this).val().toString(); if(!isNaN(branchID) && !chosenBranches[productID].includes(branchID) && branchID !== '') chosenBranches[productID].push(branchID); @@ -302,5 +310,4 @@ window.updateItems = function(currentProduct = '', currentBranch = '') window.branchChange = function(event) { const productID = $(event.target).closest('.productBox').find('.linkProduct .picker-box').zui('picker').$.value; - updateItems(productID, $(event.target).val()); } diff --git a/lib/zin/wg/productcharterbox/v1.php b/lib/zin/wg/productcharterbox/v1.php index 18d28f97e7..e4a5b37bde 100644 --- a/lib/zin/wg/productcharterbox/v1.php +++ b/lib/zin/wg/productcharterbox/v1.php @@ -99,7 +99,7 @@ class productCharterBox extends wg setClass('branchBox'), picker ( - set::name('branch[0]'), + set::name("branch[$index]"), set::items(array()), setData(array('on' => 'change', 'call' => 'branchChange', 'params' => 'event')) )