manage.ui.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * 激活/关闭分支。
  3. * Change branch status.
  4. *
  5. * @param int branchID
  6. * @param string changeStatus
  7. * @access public
  8. * @return void
  9. */
  10. window.changeStatus = function(branchID, changeStatus)
  11. {
  12. const methodName = changeStatus == 'close' ? 'close' : 'activate';
  13. const confirmMsg = changeStatus == 'close' ? confirmclose : confirmactivate;
  14. zui.Modal.confirm({message: confirmMsg, icon:'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) =>
  15. {
  16. if(res) $.ajaxSubmit({url: $.createLink('branch', methodName, `branchID=${branchID}`)});
  17. });
  18. }
  19. $(document).on('click', '.batch-btn', function()
  20. {
  21. const dtable = zui.DTable.query($(this).target);
  22. const checkedList = dtable.$.getChecks();
  23. if(!checkedList.length) return;
  24. const form = new FormData();
  25. const url = $(this).data('url');
  26. checkedList.forEach((id) => form.append('branchIDList[]', id));
  27. postAndLoadPage(url, form);
  28. }).on('click', '#mergeBranch', function()
  29. {
  30. const dtable = zui.DTable.query($(this).target);
  31. const checkedList = dtable.$.getChecks();
  32. if(!checkedList.length) return false;
  33. $('#mergedBranchIDList').val(checkedList.join(','));
  34. let targetBranchItems = [];
  35. for(let branchName in branchNamePairs)
  36. {
  37. branchID = branchNamePairs[branchName];
  38. if(!checkedList.includes(String(branchID))) targetBranchItems.push({value: branchID, text: branchName});
  39. }
  40. let $targetBranchPicker = $('[name=targetBranch]').zui('picker');
  41. $targetBranchPicker.render({items: targetBranchItems});
  42. $targetBranchPicker.$.setValue('0');
  43. });
  44. /**
  45. * Set create branch form.
  46. *
  47. * @access public
  48. * @return void
  49. */
  50. function createBranch()
  51. {
  52. $('#createForm input, #createForm textarea').attr('disabled', true);
  53. $('input[name=targetBranch]').removeAttr('disabled');
  54. $('#createForm').addClass('hidden');
  55. const createNew = $(this).is(':checked');
  56. const $targetBranchPicker = $('[name=targetBranch]').zui('picker');
  57. if(createNew)
  58. {
  59. $targetBranchPicker.render({disabled: true});
  60. $('#createForm input, #createForm textarea').removeAttr('disabled');
  61. $('#createForm').removeClass('hidden');
  62. }
  63. else
  64. {
  65. $targetBranchPicker.render({disabled: false});
  66. }
  67. }
  68. window.clickSubmit = function()
  69. {
  70. let mergedBranchName = '';
  71. let targetBranchName = $('#mergeForm .picker-single-selection').text();
  72. $(".is-checked[data-col='name']").each(function()
  73. {
  74. mergedBranchName += ',' + $(this).find('.dtable-cell-content').attr('title');
  75. });
  76. mergedBranchName = mergedBranchName.substr(1);
  77. targetBranchName = $('#createBranch').prop('checked') ? $('#mergeForm input[name=name]').val() : targetBranchName;
  78. let confirmMergeMessage = confirmMerge.replace(/(.*)mergedBranch(.*)targetBranch(.*)/, "$1" + mergedBranchName + "$2" + targetBranchName + "$3");
  79. const formUrl = $('#mergeForm').attr('action');
  80. const formData = new FormData($("#mergeForm")[0]);
  81. if(targetBranchName && typeof branchNamePairs[targetBranchName] === 'undefined')
  82. {
  83. zui.Modal.confirm(confirmMergeMessage).then((res) => {
  84. if(res) $.ajaxSubmit({url: formUrl, data: formData})
  85. });
  86. return false;
  87. }
  88. }
  89. /**
  90. * 设置合并分支按钮是否显示。
  91. * Set merge btn display.
  92. *
  93. * @access public
  94. * @return void
  95. */
  96. window.checkedChange = function()
  97. {
  98. const dtable = zui.DTable.query($(this).target);
  99. const checkedList = dtable.$.getChecks();
  100. if(!checkedList.length) return;
  101. $('#mergeBranch').toggleClass('hidden', checkedList.includes('0'));
  102. }
  103. /**
  104. * 拖拽的分支是否允许放下。
  105. * Is it allowed to drop the dragged branch.
  106. *
  107. * @param from 被拿起的元素
  108. * @param to 放下时的目标元素
  109. * @access public
  110. * @return bool
  111. */
  112. window.canSortTo = function(from, to)
  113. {
  114. if(!from || !to) return false;
  115. if(from.id == '0' || to.id == '0') return false;
  116. return true;
  117. }
  118. /**
  119. * 拖拽分支。
  120. * Drag branch.
  121. *
  122. * @param from 被拿起的元素
  123. * @param to 放下时的目标元素
  124. * @param type 放在目标元素的上方还是下方
  125. * @access public
  126. * @return bool
  127. */
  128. window.onSortEnd = function(from, to, type)
  129. {
  130. if(!from || !to) return false;
  131. if(!canSortTo(from, to)) return false;
  132. const url = $.createLink('branch', 'sort');
  133. const form = new FormData();
  134. form.append('orderBy', orderBy);
  135. form.append('branches', JSON.stringify(this.state.rowOrders));
  136. $.ajaxSubmit({url, data: form});
  137. return true;
  138. }