managemembers.ui.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. * Set role when select an account.
  3. *
  4. * @param string $account
  5. * @param int $roleID
  6. * @access public
  7. * @return void
  8. */
  9. window.setRole = function(e, roleID)
  10. {
  11. const account = $(e.target).val();
  12. const role = roles[account];
  13. const $role = $('#role' + roleID);
  14. $role.val(role);
  15. resetAccountItems();
  16. }
  17. /**
  18. * Add item.
  19. *
  20. * @param object $obj
  21. * @access public
  22. * @return void
  23. */
  24. window.addItem = function(obj)
  25. {
  26. let item = $('#addItem > tbody').html().replace(/_i/g, itemIndex);
  27. const $currentTr = $(obj).closest('tr');
  28. $currentTr.after(item);
  29. const $newRow = $currentTr.next();
  30. $('#teamForm .table tbody tr .actions-list .btn-link').eq(1).removeClass('hidden');
  31. itemIndex ++;
  32. setTimeout(function()
  33. {
  34. let selectedAccounts = [];
  35. $('#teamForm [name^=account]').each(function()
  36. {
  37. if(!$(this).val()) return true;
  38. selectedAccounts.push($(this).val());
  39. });
  40. let $accountPicker = $newRow.find('input[name^=account]').zui('picker');
  41. if(typeof $accountPicker == 'undefined') return true;
  42. let userItems = $accountPicker.options.items;
  43. for(let key in userItems)
  44. {
  45. let disabled = selectedAccounts.includes(userItems[key].value) ? true : false;
  46. userItems[key].disabled = disabled;
  47. }
  48. $accountPicker.render({items: userItems});
  49. }, 100);
  50. }
  51. /**
  52. * Delete item.
  53. *
  54. * @param object $obj
  55. * @access public
  56. * @return void
  57. */
  58. window.deleteItem = function(obj)
  59. {
  60. let currentAccount = $(obj).closest('tr').find('input[name^=account]').val();
  61. $(obj).closest('tr').remove();
  62. if($('#teamForm .table tbody tr').length < 2) $('#teamForm .table tbody tr .actions-list .btn-link').eq(1).addClass('hidden');
  63. if(!currentAccount) return true;
  64. resetAccountItems();
  65. }
  66. /**
  67. * Set dept users.
  68. *
  69. * @param object $obj
  70. * @access public
  71. * @return void
  72. */
  73. window.setDeptUsers = function(e)
  74. {
  75. const dept = $(e.target).val(); // Get dept ID.
  76. const link = $.createLink('project', 'manageMembers', 'projectID=' + projectID + '&dept=' + dept + '&copyProjectID=' + copyProjectID); // Create manageMembers link.
  77. isInModal ? loadModal(link) : loadPage(link);
  78. }
  79. /**
  80. * Chose team to copy.
  81. *
  82. * @param object $obj
  83. * @access public
  84. * @return void
  85. */
  86. function choseTeam2Copy(e)
  87. {
  88. const copyProjectID = $(e.target).val();
  89. const dept = $('input[name=dept]').val();
  90. const link = $.createLink('project', 'manageMembers', 'projectID=' + projectID + '&dept=' + dept + '&copyProjectID=' + copyProjectID);
  91. isInModal ? loadModal(link) : loadPage(link);
  92. }
  93. window.changeProjectMembers = function()
  94. {
  95. let isDeleted = false;
  96. if(!noSprintProject)
  97. {
  98. let accountList = [];
  99. $("[name^='account']").each(function()
  100. {
  101. if($(this).val()) accountList.push($(this).val());
  102. });
  103. oldAccountList.forEach(function(account)
  104. {
  105. if(accountList.indexOf(account.toString()) < 0 && executionMembers.indexOf(account.toString()) !== -1)
  106. {
  107. isDeleted = true;
  108. return false;
  109. }
  110. });
  111. }
  112. if(!isDeleted)
  113. {
  114. const formData = new FormData($("#teamForm")[0]);
  115. const options = isInModal ? {url: $('#teamForm').attr('action'), data: formData, callback: `renderTaskAssignedTo(${projectID})`, 'load': false, 'closeModal': true} : {url: $('#teamForm').attr('action'), data: formData};
  116. $.ajaxSubmit(options);
  117. }
  118. else
  119. {
  120. zui.Modal.confirm({message: unlinkExecutionMembers}).then((res) =>
  121. {
  122. if(res) $('#removeExecution').val('yes');
  123. const formData = new FormData($("#teamForm")[0]);
  124. const options = isInModal ? {url: $('#teamForm').attr('action'), data: formData, callback: `renderTaskAssignedTo(${projectID})`, 'load': false, 'closeModal': true} : {url: $('#teamForm').attr('action'), data: formData};
  125. $.ajaxSubmit(options);
  126. });
  127. }
  128. return false;
  129. }
  130. function resetAccountItems()
  131. {
  132. let selectedAccounts = [];
  133. $('#teamForm [name^=account]').each(function()
  134. {
  135. if(!$(this).val()) return true;
  136. selectedAccounts.push($(this).val());
  137. });
  138. $('#teamForm [name^=account]').each(function()
  139. {
  140. let $accountPicker = $(this).closest('input[name^=account]').zui('picker');
  141. if(typeof $accountPicker == 'undefined') return true;
  142. let userItems = $accountPicker.options.items;
  143. let currentAccount = $(this).val();
  144. for(let key in userItems)
  145. {
  146. let disabled = selectedAccounts.includes(userItems[key].value) && userItems[key].value != currentAccount ? true : false;
  147. userItems[key].disabled = disabled;
  148. }
  149. $accountPicker.render({items: userItems});
  150. });
  151. }