diff --git a/module/execution/control.php b/module/execution/control.php index 66745019f8..20e4ae71ec 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -1048,13 +1048,12 @@ class execution extends control ->setIF($oldExecution->type == 'stage', 'project', $oldExecution->project) ->setDefault('days', '0') ->setDefault('team', $this->post->name) - ->setDefault('products', $this->post->products) ->setDefault('branch', $this->post->branch) ->stripTags($this->config->execution->editor->edit['id'], $this->config->allowedTags) ->cleanInt('id,project') ->get(); - $changes = $this->execution->update($executionID, $postData); + $changes = $this->execution->update($executionID, $postData, $formData); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->execution->updateProducts($executionID, $formData); diff --git a/module/execution/js/common.ui.js b/module/execution/js/common.ui.js index 4640e32bae..e7eda1544c 100644 --- a/module/execution/js/common.ui.js +++ b/module/execution/js/common.ui.js @@ -166,22 +166,14 @@ function loadBranches(e) $formRow.find('.form-group').eq(1).addClass('hidden'); } - $.get($.createLink('branch', 'ajaxGetBranches', "productID=" + $product.val() + "&oldBranch=" + oldBranch + "¶m=active&projectID=" + projectID + "&withMainBranch=true"), function(data) + $.getJSON($.createLink('branch', 'ajaxGetBranches', "productID=" + $product.val() + "&oldBranch=" + oldBranch + "¶m=active&projectID=" + projectID + "&withMainBranch=true"), function(data) { if(data) { - $formRow.find('.form-group').eq(1).find('.picker-box').empty(); - $formRow.find('.form-group').eq(1).find('.picker-box').append(`
`); - $formRow.find('.form-group').eq(0).addClass('w-1/4').removeClass('w-1/2'); $formRow.find('.form-group').eq(1).removeClass('hidden'); - - data = JSON.parse(data); - new zui.Picker(`#branch${index}`, { - items: data, - multiple: true, - name: `branch[${index}]`, - }); + const $branchPicker = $formRow.find('select[name^=branch]').zui('picker'); + $branchPicker.render({items: data, multiple: true}); } }); diff --git a/module/execution/model.php b/module/execution/model.php index 456a1f1405..2974ded434 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -288,10 +288,11 @@ class executionModel extends model * * @param int $executionID * @param object $postData + * @param object $formData * @access public * @return array|false */ - public function update(int $executionID, object $postData): array|false + public function update(int $executionID, object $postData, object $formData = null): array|false { $oldExecution = $this->dao->findById($executionID)->from(TABLE_EXECUTION)->fetch(); @@ -312,21 +313,22 @@ class executionModel extends model return false; } - if($postData->products) + if(!empty($formData->products)) { $multipleProducts = $this->loadModel('product')->getMultiBranchPairs(); - if(!empty($postData->branch)) $postData->branch = is_array($postData->branch) ? $postData->branch : json_decode($postData->branch, true); - foreach($postData->products as $index => $productID) + if(!empty($formData->branch)) $formData->branch = is_array($formData->branch) ? $formData->branch : json_decode($formData->branch, true); + foreach($formData->products as $index => $productID) { - if(isset($multipleProducts[$productID]) and !isset($postData->branch[$index])) + if(!isset($formData->branch[$index])) continue; + $branches = implode(',', $formData->branch[$index]); + if(isset($multipleProducts[$productID]) && $branches == '') { - dao::$errors[] = $this->lang->project->emptyBranch; + dao::$errors["branch[$index][]"] = $this->lang->project->error->emptyBranch; return false; } } } - if(!empty($postData->heightType) && $postData->heightType == 'custom' && !$this->loadModel('kanban')->checkDisplayCards($postData->displayCards)) return false; if(in_array($postData->status, array('closed', 'suspended'))) $this->computeBurn($executionID); @@ -1158,10 +1160,11 @@ class executionModel extends model /* The total workload of the first stage should not exceed 100%. */ if($type == 'create' || ($oldExecutionGrade == 1 && isset($this->lang->execution->typeList[$oldExecutionType]))) { + $branchID = !empty($_POST['branch'][0]) ? current($this->post->branch[0]) : 0; $oldPercentTotal = $this->dao->select('SUM(t2.percent) as total')->from(TABLE_PROJECTPRODUCT)->alias('t1') ->leftJoin(TABLE_EXECUTION)->alias('t2')->on('t1.project=t2.id') ->where('t1.product')->eq($this->post->products[0]) - ->beginIF(!empty($_POST['branch'][0]))->andWhere('t1.branch')->eq(current($this->post->branch[0]))->fi() + ->beginIF($branchID)->andWhere('t1.branch')->eq($branchID)->fi() ->andWhere('t2.type')->eq('stage') ->andWhere('t2.grade')->eq(1) ->andWhere('t2.deleted')->eq(0) diff --git a/module/execution/ui/edit.html.php b/module/execution/ui/edit.html.php index e881cfe8de..781e74c71c 100644 --- a/module/execution/ui/edit.html.php +++ b/module/execution/ui/edit.html.php @@ -133,6 +133,8 @@ elseif($execution->type != 'kanban') $productsBox = null; if($project->model != 'waterfall' && $project->model != 'waterfallplus') { + $hidden = true; + if(!empty($project->hasProduct)) $hidden = false; if(!empty($project) && !empty($project->hasProduct) && $linkedProducts) { $i = 0; @@ -143,12 +145,11 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') $plans = isset($productPlans[$product->id]) ? $productPlans[$product->id] : array(); $productsBox[] = formRow ( - set::className('productsBox'), + set::hidden($hidden), formGroup ( set::width($hasBranch ? '1/4' : '1/2'), setClass('linkProduct'), - set::required(true), $i == 0 ? set::label($lang->project->manageProducts) : set::label(''), inputGroup ( @@ -158,15 +159,13 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') picker ( set::id("products{$i}"), - set::name("products[$i]"), - set::value($product->id), + set::name("products[{$i}]"), set::items($allProducts), + set::value($product->id), set::last($product->id), $hasBranch ? set::lastBranch(implode(',', $product->branches)) : null, - set::disabled($execution->type == 'stage' && $project->stageBy == 'project'), - $execution->type == 'stage' && $project->stageBy == 'project' ? formHidden("products[$i]", $product->id) : null, ) - ), + ) ) ), formGroup @@ -219,7 +218,7 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') icon('trash'), ), ) - ), + ) ); $i ++; @@ -239,8 +238,9 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') ( set::name("plans[{$planProductID}][]"), set::items(isset($productPlans[$planProductID]) ? $productPlans[$planProductID] : array()), + set::value(isset($linkedProducts[$planProductID]) ? $linkedProducts[$planProductID]->plans : ''), set::multiple(true), - formHidden('products[]', $planProductID), + formHidden('products[0]', $planProductID), formHidden('branch[0][0]', 0), ) ), @@ -248,14 +248,14 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') } else { - $productsBox [] = formRow + $productsBox[] = formRow ( + set::hidden($hidden), set::className('productsBox'), formGroup ( set::width('1/2'), setClass('linkProduct'), - set::required(true), set::label($lang->project->manageProducts), picker ( @@ -275,7 +275,6 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') ( set::id('branch0'), set::name('branch[0][]'), - set::control('picker'), set::multiple(true), set::items(array()), on::change('branchChange') @@ -316,9 +315,10 @@ if($project->model != 'waterfall' && $project->model != 'waterfallplus') ); } } -else +elseif(!empty($project) && !empty($project->hasProduct)) { - if(!empty($project) && !empty($project->hasProduct)) + $i = 0; + foreach($linkedProducts as $product) { $hasBranch = $product->type != 'normal' and isset($branchGroups[$product->id]); $branches = isset($branchGroups[$product->id]) ? $branchGroups[$product->id] : array(); @@ -330,7 +330,7 @@ else ( set::width($hasBranch ? '1/4' : '1/2'), setClass('linkProduct'), - set::required(true), + set::required(in_array($project->model, array('waterfall', 'waterfallplus'))), $i == 0 ? set::label($lang->project->manageProducts) : set::label(''), inputGroup ( @@ -341,12 +341,12 @@ else ( set::id("products{$i}"), set::name("products[$i]"), - set::value($product->id), set::items($allProducts), + set::value($product->id), set::last($product->id), $hasBranch && $product->branches ? set::lastBranch(implode(',', $product->branches)) : null, - set::disabled($project->model == 'waterfall' || $project->model == 'waterfallplus'), - $project->model == 'waterfall' || $project->model == 'waterfallplus' ? formHidden("products[$i]", $product->id) : null, + set::disabled(in_array($project->model, array('waterfall', 'waterfallplus'))), + set::required(in_array($project->model, array('waterfall', 'waterfallplus'))), ) ), ) @@ -355,7 +355,7 @@ else ( set::width('1/4'), setClass('ml-px'), - $hasBranch ? null : setClass('hidden'), + set::hidden(!$hasBranch), inputGroup ( $lang->product->branchName['branch'], @@ -387,13 +387,22 @@ else set::multiple(true) ) ), - ), + ) ); $i ++; - $productsBox[] = formHidden('products[]', key($linkedProducts)); - $productsBox[] = formHidden('branch', json_encode(array_values($linkedBranches))); } + + if(empty($linkedProducts)) + { + $productsBox[] = formHidden('products[0]', array()); + $productsBox[] = formHidden('branch', ''); + } +} +else +{ + $productsBox[] = formHidden('products[0]', key($linkedProducts)); + $productsBox[] = formHidden('branch', json_encode(array_values($linkedBranches))); } if(helper::isAjaxRequest('modal')) modalHeader(set::title($lang->execution->edit)); diff --git a/module/execution/zen.php b/module/execution/zen.php index 0cad9f0d0b..14305963e8 100644 --- a/module/execution/zen.php +++ b/module/execution/zen.php @@ -2075,11 +2075,17 @@ class executionZen extends execution foreach($branches[$productID] as $branchID => $branch) { - $productPlans[$productID] += isset($plans[$productID][$branchID]) ? $plans[$productID][$branchID] : array(); + if(isset($plans[$productID][$branchID])) + { + foreach($plans[$productID][$branchID] as $plan) $productPlans[$productID][$plan->id] = $plan->title; + } $linkedBranchList[$branchID] = $branchID; $linkedBranches[$productID][$branchID] = $branchID; - if($branchID != BRANCH_MAIN && isset($plans[$productID][BRANCH_MAIN])) $productPlans[$productID] += $plans[$productID][BRANCH_MAIN]; + if($branchID != BRANCH_MAIN && isset($plans[$productID][BRANCH_MAIN])) + { + foreach($plans[$productID][BRANCH_MAIN] as $plan) $productPlans[$productID][$plan->id] = $plan->title; + } if(!empty($executionStories[$productID][$branchID])) { array_push($unmodifiableProducts, $productID);