diff --git a/module/execution/js/create.js b/module/execution/js/create.js index 3ee176db92..1f8537bf40 100644 --- a/module/execution/js/create.js +++ b/module/execution/js/create.js @@ -87,33 +87,29 @@ $(function() /* Determine whether the products of the same branch are linked. */ $("#productsBox select[name^='products']").each(function() { - var productID = $(this).val(); - products[productID] = new Array(); + var productID = $(this).val(); + if(typeof(products[productID]) == 'undefined') products[productID] = new Array(); if(multiBranchProducts[productID]) { - $("#productsBox select[name^='branch']").each(function() + var branchID = $(this).closest('.input-group').find("select[id^=branch]").val(); + if(products[productID][branchID]) { - var branchID = $(this).val(); - if(products[productID][branchID]) - { - existedBranch = true; - return false; - } - else - { - products[productID][branchID] = branchID; - } - }) + existedBranch = true; + } + else + { + products[productID][branchID] = branchID; + } if(existedBranch) return false; } - }) + }); if(existedBranch) { bootbox.alert(errorSameBranches); return false; } - }) + }); }); function showLifeTimeTips() diff --git a/module/execution/js/edit.js b/module/execution/js/edit.js index 81039a601b..0c09b6bfe8 100644 --- a/module/execution/js/edit.js +++ b/module/execution/js/edit.js @@ -10,33 +10,29 @@ $().ready(function() /* Determine whether the products of the same branch are linked. */ $("#productsBox select[name^='products']").each(function() { - var productID = $(this).val(); - products[productID] = new Array(); + var productID = $(this).val(); + if(typeof(products[productID]) == 'undefined') products[productID] = new Array(); if(multiBranchProducts[productID]) { - $("#productsBox select[name^='branch']").each(function() + var branchID = $(this).closest('.input-group').find("select[id^=branch]").val(); + if(products[productID][branchID]) { - var branchID = $(this).val(); - if(products[productID][branchID]) - { - existedBranch = true; - return false; - } - else - { - products[productID][branchID] = branchID; - } - }) + existedBranch = true; + } + else + { + products[productID][branchID] = branchID; + } if(existedBranch) return false; } - }) + }); if(existedBranch) { bootbox.alert(errorSameBranches); return false; } - }) + }); }); $(function() diff --git a/module/project/js/create.js b/module/project/js/create.js index a4aedf2d0d..84088976fc 100644 --- a/module/project/js/create.js +++ b/module/project/js/create.js @@ -34,33 +34,29 @@ $(function() /* Determine whether the products of the same branch are linked. */ $("#productsBox select[name^='products']").each(function() { - var productID = $(this).val(); - products[productID] = new Array(); + var productID = $(this).val(); + if(typeof(products[productID]) == 'undefined') products[productID] = new Array(); if(multiBranchProducts[productID]) { - $("#productsBox select[name^='branch']").each(function() + var branchID = $(this).closest('.input-group').find("select[id^=branch]").val(); + if(products[productID][branchID]) { - var branchID = $(this).val(); - if(products[productID][branchID]) - { - existedBranch = true; - return false; - } - else - { - products[productID][branchID] = branchID; - } - }) + existedBranch = true; + } + else + { + products[productID][branchID] = branchID; + } if(existedBranch) return false; } - }) + }); if(existedBranch) { bootbox.alert(errorSameBranches); return false; } - }) + }); }); /** diff --git a/module/project/js/edit.js b/module/project/js/edit.js index 5b143b401c..77100f6632 100644 --- a/module/project/js/edit.js +++ b/module/project/js/edit.js @@ -102,33 +102,29 @@ $(function() /* Determine whether the products of the same branch are linked. */ $("#productsBox select[name^='products']").each(function() { - var productID = $(this).val(); - products[productID] = new Array(); + var productID = $(this).val(); + if(typeof(products[productID]) == 'undefined') products[productID] = new Array(); if(multiBranchProducts[productID]) { - $("#productsBox select[name^='branch']").each(function() + var branchID = $(this).closest('.input-group').find("select[id^=branch]").val(); + if(products[productID][branchID]) { - var branchID = $(this).val(); - if(products[productID][branchID]) - { - existedBranch = true; - return false; - } - else - { - products[productID][branchID] = branchID; - } - }) + existedBranch = true; + } + else + { + products[productID][branchID] = branchID; + } if(existedBranch) return false; } - }) + }); if(existedBranch) { bootbox.alert(errorSameBranches); return false; } - }) + }); }); /**