From 3f2b98e71c80bbf6d269b134fca4372a77491b79 Mon Sep 17 00:00:00 2001 From: hufangzhou Date: Mon, 11 Jul 2022 15:03:40 +0800 Subject: [PATCH] * Move the functions to my.full.js file. --- module/execution/js/common.js | 115 ---------------------------------- module/project/js/common.js | 115 ---------------------------------- www/js/my.full.js | 115 ++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 230 deletions(-) diff --git a/module/execution/js/common.js b/module/execution/js/common.js index 2108083f47..0e8071a6f9 100644 --- a/module/execution/js/common.js +++ b/module/execution/js/common.js @@ -225,121 +225,6 @@ function adjustPlanBoxMargin() } } -/** - * Make the selected product non clickable. - * - * @return void - */ -function disableSelectedProduct() -{ - $("select[id^='products'] option[disabled='disabled']").removeAttr('disabled'); - - var selectedVal = []; - $("select[id^='products']").each(function() - { - 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() - { - var selectedProduct = $(this).val(); - $(this).find('option').each(function() - { - var optionVal = $(this).attr('value'); - if(optionVal != selectedProduct && $.inArray(optionVal, selectedVal) >= 0) $(this).attr('disabled', 'disabled'); - }) - }) - - $("select[id^=products]").trigger('chosen:updated'); -} - -/** - * Make the selected branch non clickable. - * - * @return void - */ -function disableSelectedBranch() -{ - 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) - { - $(this).siblings("select[id^='branch']").find("option[disabled='disabled']").removeAttr('disabled'); - - sameProductControl.push(this); - sameProductBranchControl.push($(this).siblings("select[id^='branch']")); - } - }); - - /* Get the selected branch of the related product. */ - var preSelectedVal = []; - $.each(sameProductControl, function() - { - var selectedBranch = $(this).siblings("select[id^='branch']").val(); - if($.inArray(selectedBranch, preSelectedVal) < 0) preSelectedVal.push(selectedBranch); - }); - - var selectedVal = []; - $.each(sameProductControl, function() - { - var selectedBranch = $(this).siblings("select[id^='branch']").val(); - if($.inArray(selectedBranch, selectedVal) >= 0) - { - $(this).siblings("select[id^='branch']").find('option').removeAttr('selected'); - for(i in preSelectedVal) $(this).siblings("select[id^='branch']").find('option[value=' + preSelectedVal[i] + ']').attr('disabled', 'disabled'); - - $(this).siblings("select[id^='branch']").find('option').not('[disabled=disabled]').eq(0).attr('selected', 'selected'); - 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'); -} - -/** - * Determine whether multi-branch products should be disabled. - * - * @param object product - * @return bool - */ -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/project/js/common.js b/module/project/js/common.js index 47c050ff3a..b524edb7ce 100644 --- a/module/project/js/common.js +++ b/module/project/js/common.js @@ -97,121 +97,6 @@ function computeWorkDays(currentID) } } -/** - * Make the selected product non clickable. - * - * @return void - */ -function disableSelectedProduct() -{ - $("select[id^='products'] option[disabled='disabled']").removeAttr('disabled'); - - var selectedVal = []; - $("select[id^='products']").each(function() - { - 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() - { - var selectedProduct = $(this).val(); - $(this).find('option').each(function() - { - var optionVal = $(this).attr('value'); - if(optionVal != selectedProduct && $.inArray(optionVal, selectedVal) >= 0) $(this).attr('disabled', 'disabled'); - }) - }) - - $("select[id^=products]").trigger('chosen:updated'); -} - -/** - * Make the selected branch non clickable. - * - * @return void - */ -function disableSelectedBranch() -{ - 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) - { - $(this).siblings("select[id^='branch']").find("option[disabled='disabled']").removeAttr('disabled'); - - sameProductControl.push(this); - sameProductBranchControl.push($(this).siblings("select[id^='branch']")); - } - }); - - /* Get the selected branch of the related product. */ - var preSelectedVal = []; - $.each(sameProductControl, function() - { - var selectedBranch = $(this).siblings("select[id^='branch']").val(); - if($.inArray(selectedBranch, preSelectedVal) < 0) preSelectedVal.push(selectedBranch); - }); - - var selectedVal = []; - $.each(sameProductControl, function() - { - var selectedBranch = $(this).siblings("select[id^='branch']").val(); - if($.inArray(selectedBranch, selectedVal) >= 0) - { - $(this).siblings("select[id^='branch']").find('option').removeAttr('selected'); - for(i in preSelectedVal) $(this).siblings("select[id^='branch']").find('option[value=' + preSelectedVal[i] + ']').attr('disabled', 'disabled'); - - $(this).siblings("select[id^='branch']").find('option').not('[disabled=disabled]').eq(0).attr('selected', 'selected'); - 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'); -} - -/** - * Determine whether multi-branch products should be disabled. - * - * @param object product - * @return bool - */ -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; -} - /** * Compute the end date for project. * diff --git a/www/js/my.full.js b/www/js/my.full.js index 154aa2bcbb..3e4a7cd790 100644 --- a/www/js/my.full.js +++ b/www/js/my.full.js @@ -1032,3 +1032,118 @@ $(document).ready(function() $(this).removeClass('dropdown-hover'); }); }); + +/** + * Make the selected product non clickable. + * + * @return void + */ +function disableSelectedProduct() +{ + $("select[id^='products'] option[disabled='disabled']").removeAttr('disabled'); + + var selectedVal = []; + $("select[id^='products']").each(function() + { + 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() + { + var selectedProduct = $(this).val(); + $(this).find('option').each(function() + { + var optionVal = $(this).attr('value'); + if(optionVal != selectedProduct && $.inArray(optionVal, selectedVal) >= 0) $(this).attr('disabled', 'disabled'); + }) + }) + + $("select[id^=products]").trigger('chosen:updated'); +} + +/** + * Make the selected branch non clickable. + * + * @return void + */ +function disableSelectedBranch() +{ + 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) + { + $(this).siblings("select[id^='branch']").find("option[disabled='disabled']").removeAttr('disabled'); + + sameProductControl.push(this); + sameProductBranchControl.push($(this).siblings("select[id^='branch']")); + } + }); + + /* Get the selected branch of the related product. */ + var preSelectedVal = []; + $.each(sameProductControl, function() + { + var selectedBranch = $(this).siblings("select[id^='branch']").val(); + if($.inArray(selectedBranch, preSelectedVal) < 0) preSelectedVal.push(selectedBranch); + }); + + var selectedVal = []; + $.each(sameProductControl, function() + { + var selectedBranch = $(this).siblings("select[id^='branch']").val(); + if($.inArray(selectedBranch, selectedVal) >= 0) + { + $(this).siblings("select[id^='branch']").find('option').removeAttr('selected'); + for(i in preSelectedVal) $(this).siblings("select[id^='branch']").find('option[value=' + preSelectedVal[i] + ']').attr('disabled', 'disabled'); + + $(this).siblings("select[id^='branch']").find('option').not('[disabled=disabled]').eq(0).attr('selected', 'selected'); + 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'); +} + +/** + * Determine whether multi-branch products should be disabled. + * + * @param object product + * @return bool + */ +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; +}