productview.ui.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. window.footerGenerator = function()
  2. {
  3. return [{children: summary, className: "text-dark"}, "flex", "pager"];
  4. }
  5. window.renderCellProductView = function(result, {col, row})
  6. {
  7. if(col.name === 'createdDate')
  8. {
  9. if(row.data.createdDate === '') return [''];
  10. }
  11. if(col.name === 'latestReleaseDate')
  12. {
  13. if(row.data.latestReleaseDate === '') return [''];
  14. }
  15. if(col.name == 'totalProjects' && row.data.type !== 'product') return [row.data.totalProjects];
  16. return result;
  17. }
  18. window.iconRenderProductView = function(value, row)
  19. {
  20. if(row.data.type === 'program') return {className: 'icon icon-cards-view text-gray'};
  21. if(row.data.type === 'productLine') return {className: 'icon icon-lane text-gray'};
  22. return '';
  23. }
  24. window.footerSummary = function(checkedIdList, pageSummary)
  25. {
  26. if(!checkedIdList.length) return {html: pageSummary, className: 'text-dark'};
  27. let totalProducts = 0;
  28. checkedIdList.forEach(function(id)
  29. {
  30. if(id.includes('-')) return;
  31. totalProducts++;
  32. });
  33. var summary = checkedSummary.replace('%total%', totalProducts);
  34. return {html: summary};
  35. };
  36. $(document).off('click', '[data-formaction]').on('click', '[data-formaction]', function()
  37. {
  38. const $this = $(this);
  39. const dtable = zui.DTable.query($('#productviews'));
  40. const checkedList = dtable.$.getChecks();
  41. if(!checkedList.length) return;
  42. const postData = new FormData();
  43. checkedList.forEach((id) => postData.append('productIDList[]', id));
  44. if($this.data('page') == 'batch') postAndLoadPage($this.data('formaction'), postData);
  45. });
  46. /**
  47. * 拖拽的项目集或者产品是否允许放下。
  48. * Is it allowed to drop the dragged program or project.
  49. *
  50. * @param from 拖动的行信息
  51. * @param to 被拖动到的行信息
  52. * @access public
  53. * @return bool
  54. */
  55. window.canSortTo = function(from, to)
  56. {
  57. if(!from || !to) return false;
  58. if(from.data.parent != to.data.parent) return false;
  59. if(from.data.type != to.data.type) return false;
  60. return true;
  61. };
  62. /**
  63. * 拖拽项目集或产品。
  64. * Drag program or project.
  65. *
  66. * @param from 拖动的行信息
  67. * @param to 被拖动到的行信息
  68. * @access public
  69. * @return bool
  70. */
  71. window.onSortEnd = function(from, to)
  72. {
  73. if(!canSortTo(from, to)) return false;
  74. const programIdList = [];
  75. const productIdList = [];
  76. const orders = this.state.rowOrders;
  77. for(id in orders)
  78. {
  79. if(id.includes('program'))
  80. {
  81. programID = id.slice(id.indexOf('-') + 1);
  82. programIdList[programID] = orders[id];
  83. }
  84. else
  85. {
  86. productIdList[id] = orders[id];
  87. }
  88. }
  89. const fromType = from.data.type;
  90. const url = $.createLink(fromType, 'updateOrder');
  91. const form = new FormData();
  92. if(fromType == 'program') form.append('programIdList', JSON.stringify(programIdList));
  93. if(fromType == 'product')
  94. {
  95. form.append('orderBy', 'order_asc');
  96. form.append('products', JSON.stringify(productIdList));
  97. }
  98. $.ajaxSubmit({url, data:form});
  99. return true;
  100. };