managemembers.ui.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * Add item.
  3. *
  4. * @param object $obj
  5. * @access public
  6. * @return void
  7. */
  8. window.addItem = function(obj)
  9. {
  10. let item = $('#addItem > tbody').html().replace(/_i/g, itemIndex);
  11. const $currentTr = $(obj).closest('tr');
  12. $currentTr.after(item);
  13. const $newRow = $currentTr.next();
  14. itemIndex ++;
  15. setTimeout(function()
  16. {
  17. let selectedAccounts = [];
  18. $('#teamForm [name^=account]').each(function()
  19. {
  20. if(!$(this).val()) return true;
  21. selectedAccounts.push($(this).val());
  22. });
  23. let $accountPicker = $newRow.find('input[name^=account]').zui('picker');
  24. if(typeof $accountPicker == 'undefined') return true;
  25. let userItems = $accountPicker.options.items;
  26. for(let key in userItems)
  27. {
  28. let disabled = selectedAccounts.includes(userItems[key].value) ? true : false;
  29. userItems[key].disabled = disabled;
  30. }
  31. $accountPicker.render({items: userItems});
  32. }, 100);
  33. }
  34. /**
  35. * Delete item.
  36. *
  37. * @param object $obj
  38. * @access public
  39. * @return void
  40. */
  41. window.deleteItem = function(obj)
  42. {
  43. let currentAccount = $(obj).closest('tr').find('input[name^=account]').val();
  44. if($('#teamForm .table tbody').children().length < 2) return false;
  45. $(obj).closest('tr').remove();
  46. if(!currentAccount) return true;
  47. resetAccountItems();
  48. }
  49. /**
  50. * Set dept users.
  51. *
  52. * @param object $obj
  53. * @access public
  54. * @return void
  55. */
  56. window.setDeptUsers = function()
  57. {
  58. const dept = $('#featureBar input[name=dept]').val(); // Get dept ID.
  59. const link = $.createLink('execution', 'manageMembers', 'executionID=' + executionID + '&team2Import=' + team2Import + '&dept=' + dept); // Create manageMembers link.
  60. isInModal ? loadModal(link) : loadPage(link);
  61. }
  62. /**
  63. * Chose team to copy.
  64. *
  65. * @param object $obj
  66. * @access public
  67. * @return void
  68. */
  69. function choseTeam2Copy()
  70. {
  71. const team = $('#featureBar input[name=execution]').val();
  72. const dept = $('#featureBar input[name=dept]').val();
  73. const link = $.createLink('execution', 'manageMembers', 'executionID=' + executionID + '&team2Import=' + team + '&dept=' + dept);
  74. isInModal ? loadModal(link) : loadPage(link);
  75. }
  76. /**
  77. * Set role when select an account.
  78. *
  79. * @param string $account
  80. * @param int $roleID
  81. * @access public
  82. * @return void
  83. */
  84. window.setRole = function(roleID)
  85. {
  86. const account = $(`input[name='account\[${roleID}\]']`).val();
  87. const role = roles[account];
  88. const $role = $('#role' + roleID);
  89. $role.val(role);
  90. resetAccountItems();
  91. }
  92. function resetAccountItems()
  93. {
  94. let selectedAccounts = [];
  95. $('#teamForm [name^=account]').each(function()
  96. {
  97. if(!$(this).val()) return true;
  98. selectedAccounts.push($(this).val());
  99. });
  100. $('#teamForm [name^=account]').each(function()
  101. {
  102. let $accountPicker = $(this).closest('input[name^=account]').zui('picker');
  103. if(typeof $accountPicker == 'undefined') return true;
  104. let userItems = $accountPicker.options.items;
  105. let currentAccount = $(this).val();
  106. for(let key in userItems)
  107. {
  108. let disabled = selectedAccounts.includes(userItems[key].value) && userItems[key].value != currentAccount ? true : false;
  109. userItems[key].disabled = disabled;
  110. }
  111. $accountPicker.render({items: userItems});
  112. });
  113. }