From db2112c9f3bb955a7213f7a6038e32857e591fe0 Mon Sep 17 00:00:00 2001 From: hufangzhou Date: Wed, 6 Jul 2022 16:07:03 +0800 Subject: [PATCH] * Code for task #59535. --- module/execution/js/common.js | 67 +++++++++++++++++++++++++++++++++++ module/execution/js/create.js | 2 +- module/execution/js/edit.js | 5 ++- 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/module/execution/js/common.js b/module/execution/js/common.js index 8cb9bdc54c..6e3e90fabd 100644 --- a/module/execution/js/common.js +++ b/module/execution/js/common.js @@ -148,12 +148,21 @@ function loadBranches(product) if(data) { $inputgroup.addClass('has-branch').append(data); + $inputgroup.find('select:last').prepend(""); + $inputgroup.find('select:last').find('option:selected').removeAttr('selected'); + $inputgroup.find('select:last').val(''); + $inputgroup.find('select:last').each(nonClickableSelectedBranch); + $inputgroup.find('select:last').find('option:first').remove(); $inputgroup.find('select:last').attr('name', 'branch[' + index + ']').attr('id', 'branch' + index).attr('onchange', "loadPlans('#products" + index + "', this.value)").chosen(); + + nonClickableSelectedProduct(); } var branchID = $('#branch' + index).val(); loadPlans(product, branchID); }); + + if(!multiBranchProducts[$(product).val()]) nonClickableSelectedProduct(); } /** @@ -234,6 +243,11 @@ function nonClickableSelectedProduct() { var selectedProduct = $(this).val(); if(selectedProduct != 0 && $.inArray(selectedProduct, selectedVal) < 0 && !multiBranchProducts[selectedProduct]) selectedVal.push(selectedProduct); + if(multiBranchProducts[selectedProduct]) + { + var isDisabled = checkMultiProducts(this); + if(isDisabled) selectedVal.push(selectedProduct); + } }) $("select[id^='products']").each(function() @@ -249,6 +263,59 @@ function nonClickableSelectedProduct() $("select[id^=products]").trigger('chosen:updated'); } +function nonClickableSelectedBranch() +{ + var relatedProduct = $(this).siblings("select[id^='products']").val(); + + /* Get the products control of the same value and their branch control. */ + var sameProductControl = []; + var sameProductBranchControl = []; + $("select[id^='products']").each(function() + { + if($(this).val() == relatedProduct) + { + sameProductControl.push(this); + sameProductBranchControl.push($(this).siblings("select[id^='branch']")); + } + }); + + /* Get the selected branch of the related product. */ + var selectedVal = []; + $.each(sameProductControl, function() + { + var selectedBranch = $(this).siblings("select[id^='branch']").val(); + if($.inArray(selectedBranch, selectedVal) < 0) selectedVal.push(selectedBranch); + }); + + /* Make the selected value disabled. */ + $.each(sameProductBranchControl, function() + { + var selectedBranch = $(this).val(); + $(this).find('option').each(function() + { + var optionVal = $(this).attr('value'); + + if(optionVal != selectedBranch && $.inArray(optionVal, selectedVal) >= 0) $(this).attr('disabled', 'disabled'); + }) + }) + + $("select[id^=branch]").trigger('chosen:updated'); +} + +function checkMultiProducts(product) +{ + var disabledbranchList = []; + var optionLength = $(product).siblings("select[id^='branch']").find('option').length; + $(product).siblings("select[id^='branch']").find("option[disabled='disabled']").each(function() + { + disabledbranchList.push($(this).attr('value')); + }); + + if(optionLength - disabledbranchList.length == 1) return true; + + return false; +} + /* Auto compute the work days. */ $(function() { diff --git a/module/execution/js/create.js b/module/execution/js/create.js index 6dcd9c0483..026150e5f3 100644 --- a/module/execution/js/create.js +++ b/module/execution/js/create.js @@ -118,7 +118,7 @@ $(function() }); nonClickableSelectedProduct(); - $(document).on('change', "select[id^='products']", nonClickableSelectedProduct); + $(document).on('change', "select[id^='branch']", nonClickableSelectedBranch); }); function showLifeTimeTips() diff --git a/module/execution/js/edit.js b/module/execution/js/edit.js index d650459b98..edf640e8c3 100644 --- a/module/execution/js/edit.js +++ b/module/execution/js/edit.js @@ -72,7 +72,10 @@ $(function() }); nonClickableSelectedProduct(); - $(document).on('change', "select[id^='products']", nonClickableSelectedProduct); + + $("select[id^=branch]").each(nonClickableSelectedBranch); + + $(document).on('change', "select[id^='branch']", nonClickableSelectedBranch); }) var lastProjectID = $("#project").val();