importfromlib.ui.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. window.renderModuleItem = function(result, info)
  2. {
  3. if(info.col.name == 'branch') result[0].children.props.items = info.row.data.branchItems;
  4. if(info.col.name == 'module') result[0].children.props.items = info.row.data.moduleItems;
  5. return result;
  6. }
  7. $(document).off('change', '[name^=branch]').on('change', '[name^=branch]', function()
  8. {
  9. const branchID = $(this).val();
  10. const caseID = $(this).attr('name').match(/\d+/)[0];
  11. const libID = $('input[name="fromlib"]').val();
  12. const link = $.createLink('testcase', 'ajaxGetCanImportModuleItems', 'productID=' + productID + '&libID=' + libID + '&branch=' + branchID + '&caseID=' + caseID);
  13. $.getJSON(link, function(data)
  14. {
  15. modulePicker = $('input[name="module[' + caseID + ']"]').zui('picker');
  16. if(modulePicker)
  17. {
  18. modulePicker.render({items: data});
  19. }
  20. else
  21. {
  22. new zui.Picker($('div[data-col="module"][data-row="' + caseID + '"]').closest('div[data-col="module"]'), {items: data, name: 'module[' + caseID + ']', defaultValue: ''});
  23. }
  24. });
  25. });
  26. window.getModuleCellProps = function(cell)
  27. {
  28. const caseID = cell.row.data.id;
  29. const branchID = this.getFormData(`branch[${cell.row.data.id}]`) != undefined ? this.getFormData(`branch[${cell.row.data.id}]`) : cell.row.data.branch;
  30. const modules = canImportModules[branchID] != undefined && canImportModules[branchID][caseID] != undefined ? canImportModules[branchID][caseID] : {};
  31. return {items: modules, required: true};
  32. }
  33. window.toggleLib = function(event)
  34. {
  35. const libID = $(event.target).val();
  36. const link = $.createLink('testcase','importFromLib','productID=' + productID + '&branch=' + branch + '&libID=' + libID);
  37. loadPage(link);
  38. }
  39. $(document).off('click', '.import-btn').on('click', '.import-btn', function()
  40. {
  41. const dtable = zui.DTable.query($(this).target);
  42. const checkedList = dtable.$.getChecks();
  43. if(!checkedList.length) return false;
  44. const url = $('#importFromLibForm').attr('action');
  45. const formData = new FormData($("#importFromLibForm")[0]);
  46. const dtableData = dtable.$.getFormData();
  47. checkedList.forEach((id) =>
  48. {
  49. formData.append(`caseIdList[${id}]`, id);
  50. formData.append(`branch[${id}]`, typeof dtableData[`branch[${id}]`] == 'undefined' ? 0 : dtableData[`branch[${id}]`]);
  51. formData.append(`module[${id}]`, dtableData[`module[${id}]`]);
  52. });
  53. $.ajaxSubmit({url: url, data: formData});
  54. return false;
  55. });
  56. function updateModules()
  57. {
  58. var branchID = $(this).val();
  59. var itemRow = $(this).closest('.dtable-row');
  60. if(branchID == 'ditto')
  61. {
  62. itemRow.preAll().each(function()
  63. {
  64. var preSelectedBranch = $(this).find('#branch option:checked').val();
  65. if(preSelectedBranch != 'ditto')
  66. {
  67. branchID = preSelectedBranch;
  68. return false;
  69. }
  70. })
  71. }
  72. const moduleLink = $.createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=case&branch=' + branchID + '&rootModuleID=0&returnType=html&fieldID=');
  73. $.get(moduleLink, function(data)
  74. {
  75. var currentModuleItem = itemRow.find('[name^=module]');
  76. currentModuleItem.parent().html(data);
  77. itemRow.find('[name^=module]').css({'width': '176px'});
  78. var caseID = itemRow.attr('data-id');
  79. if(canImportModules[branchID][caseID] != undefined && Object.keys(canImportModules[branch][caseID]).length > 0)
  80. {
  81. currentModuleItem.children().each(function()
  82. {
  83. moduleID = $(this).val();
  84. if(canImportModules[branch][caseID][moduleID] == undefined) $(this).remove();
  85. });
  86. }
  87. currentModuleItem.attr({"name": 'module[' + caseID + ']'});
  88. itemRow.nextAll().each(function()
  89. {
  90. var nextSelectedBranch = $(this).find('#branch option:checked').val();
  91. if(nextSelectedBranch != 'ditto') return;
  92. var moduleItem = $(this).find('[name^=module]');
  93. moduleItem.html(itemRow.find('[name^=module]').html());
  94. moduleItem.attr({"name": 'module[' + caseID + ']'});
  95. })
  96. })
  97. }