manageproducts.ui.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. window.checkUnlink = function()
  2. {
  3. const $elem = $(this);
  4. if($elem.prop('checked')) return true;
  5. const productID = +$elem.val();
  6. if(unmodifiableProducts.includes(productID))
  7. {
  8. const $branch = $elem.closest('.product-block').find('[name^=branch]');
  9. if($branch.length)
  10. {
  11. const branchID = +$branch.val();
  12. if((branchID == BRANCH_MAIN && unmodifiableMainBranches[productID]) || (branchID != BRANCH_MAIN && $.inArray(branchID, unmodifiableBranches) != -1))
  13. {
  14. zui.Modal.confirm(unLinkProductTip.replace("%s", branchGroups[productID][branchID])).then((result) =>
  15. {
  16. if(!result) $elem.prop('checked', true);
  17. });
  18. }
  19. }
  20. else
  21. {
  22. zui.Modal.confirm(unLinkProductTip.replace("%s", allProducts[productID])).then((result) =>
  23. {
  24. if(!result) $elem.prop('checked', true);
  25. });
  26. }
  27. }
  28. }
  29. $(function()
  30. {
  31. $('#manageProducts [type="submit"]').on('click', function(){
  32. let checkedProducts = [];
  33. $('input[name^="products"]:checked').each(function()
  34. {
  35. let value = $(this).val();
  36. if(checkedProducts.indexOf(value) == -1) checkedProducts.push(value);
  37. })
  38. if(noticeSwitch && checkedProducts.length > 1)
  39. {
  40. notice();
  41. return false;
  42. }
  43. });
  44. $('#linkProduct [type="submit"]').on('click', function(){
  45. let checkedProducts = $('[name^="otherProducts"]').val();
  46. if(checkedProducts.length == 1 && checkedProducts[0] == '')
  47. {
  48. zui.Modal.alert(errorNoProduct);
  49. return false;
  50. }
  51. if(noticeSwitch && checkedProducts.length > 1)
  52. {
  53. notice('otherProducts');
  54. return false;
  55. }
  56. });
  57. })
  58. function notice(type)
  59. {
  60. zui.Modal.confirm(
  61. {
  62. 'message' : noticeDivsion,
  63. 'actions': [
  64. {text: stageBySwitchList['1'], key: 'confirm'},
  65. {text: stageBySwitchList['0'], key: 'cancel'},
  66. ],
  67. onResult: function(result)
  68. {
  69. let link;
  70. let formData;
  71. let stageBy = result ? 'product' : '';
  72. if(type == 'otherProducts')
  73. {
  74. link = $('#linkProduct form').attr('action');
  75. formData = {'otherProducts[]': $('[name^="otherProducts"]').val(), stageBy: stageBy};
  76. }
  77. else
  78. {
  79. let products = [];
  80. let branch = [];
  81. $('input[type="checkbox"][name^="products"]:checked').each(function() {
  82. if(products.indexOf($(this).val()) == -1) products.push($(this).val());
  83. });
  84. $('input[type="hidden"][name^="products"]').each(function() {
  85. if(products.indexOf($(this).val()) == -1) products.push($(this).val());
  86. });
  87. $('input[type="hidden"][name^="branch"]').each(function() {
  88. if(branch.indexOf($(this).val()) == -1) branch.push($(this).val());
  89. });
  90. $('select[name^="branch"]').each(function() {
  91. if(branch.indexOf($(this).val()) == -1) branch.push($(this).val());
  92. });
  93. link = $.createLink('project', 'manageproducts', 'projectID=' + projectID);
  94. formData = {"products[]": products, "branch[]": branch, stageBy: stageBy};
  95. }
  96. $.ajaxSubmit({url: link, data: formData});
  97. }
  98. }
  99. );
  100. }