create.ui.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. $(function()
  2. {
  3. if(productID == 'all') $('#manageModule').addClass('hidden');
  4. })
  5. window.addNewLine = function(e)
  6. {
  7. const obj = e.target;
  8. const newLine = $(obj).closest('.customerBox').clone();
  9. /* 将已有组件的最大name属性的值加1赋值给新行. */
  10. let index = 0;
  11. $(".customerBox [name^='customer']").each(function()
  12. {
  13. let id = $(this).attr('name').replace(/[^\d]/g, '');
  14. id = parseInt(id);
  15. id ++;
  16. index = id > index ? id : index;
  17. });
  18. /* 重新初始化新一行的下拉控件. */
  19. newLine.find('.form-control.customerInput').val('').attr('name', 'customer[' + index + ']').attr('id', 'customer[' + index + ']');
  20. newLine.find('.form-control.contactInput').val('').attr('name', 'contact[' + index + ']').attr('id', 'contact[' + index + ']');
  21. newLine.find('.form-control.notifyEmailInput').val('').attr('name', 'notifyEmail[' + index + ']').attr('id', 'notifyEmail[' + index + ']');
  22. newLine.addClass('pt-4');
  23. newLine.find('.removeLine').removeClass('hidden');
  24. $(obj).closest('.customerBox').after(newLine.zuiInit());
  25. }
  26. window.removeLine = function(e)
  27. {
  28. $(e.target).closest('.customerBox').remove();
  29. }
  30. window.loadAll = function()
  31. {
  32. const productID = $('#ticketCreateForm [name=product]').val();
  33. loadModules(productID);
  34. loadBuilds(productID);
  35. }
  36. function loadModules(productID)
  37. {
  38. const moduleLink = $.createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=ticket&branch=all&rootModuleID=0&returnType=items');
  39. const moduleID = $('#ticketCreateForm [name=module]').val();
  40. $.getJSON(moduleLink, function(modules)
  41. {
  42. const $modulePicker = $('#ticketCreateForm [name=module]').zui('picker');
  43. $modulePicker.render({items: modules});
  44. $modulePicker.$.setValue(moduleID);
  45. const hidenModule = (modules.length != 1) || (!isAdmin && !authedProducts.includes(productID));
  46. $('#moduleBox #manageModule').toggleClass('hidden', hidenModule);
  47. if(modules.length == 1) $('#moduleBox #manageModule').attr('href', $.createLink('tree', 'browse', `rootID=${productID}&viewType=ticket`));
  48. })
  49. }
  50. function loadBuilds(productID)
  51. {
  52. const openedBuild = $('#ticketCreateForm [name^=openedBuild]').val() ? $('#ticketCreateForm [name^=openedBuild]').val().toString() : 0;
  53. const buildLink = $.createLink('build', 'ajaxGetProductBuilds', 'productID=' + productID + '&varName=openedBuilds&build=' + openedBuild);
  54. $.getJSON(buildLink, function(data)
  55. {
  56. const $buildPicker = $('#ticketCreateForm [name^=openedBuild]').zui('picker');
  57. $buildPicker.render({items: data});
  58. $buildPicker.$.setValue(openedBuild);
  59. })
  60. }
  61. renderModulePicker = function(rootID, viewType)
  62. {
  63. if(config.debug) console.log('[ZIN] Rendering module picker');
  64. const link = $.createLink('tree', 'ajaxGetOptionMenu', 'rootID=' + rootID + '&viewtype=' + viewType + '&branch=&rootModuleID=0&returnType=items');
  65. $.getJSON(link, function(data)
  66. {
  67. $('#moduleBox [name=module]').zui('picker').render({items: data});
  68. $('#moduleBox #manageModule').addClass('hidden');
  69. });
  70. }