browse.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. $(document).ready(function()
  2. {
  3. /* Set drag event for save report sort. */
  4. $('#reportList').on('sort.sortable', function(e, data)
  5. {
  6. $.post(createLink('workflowreport', 'sort'), data.orders, function(response)
  7. {
  8. if(response.result == 'success')
  9. {
  10. return location.reload();
  11. }
  12. else
  13. {
  14. bootbox.alert(response.message);
  15. }
  16. }, 'json');
  17. });
  18. /* Click title to load chart. */
  19. $('#reportList tr').find("td:not(':first,:last')").click(function()
  20. {
  21. preview($(this).parent().data('id'));
  22. });
  23. if(window.reportSize == 0)
  24. {
  25. $('.existReport').hide();
  26. $('.noReport').show();
  27. }
  28. else
  29. {
  30. if(window.id)
  31. {
  32. preview(window.id);
  33. }
  34. else
  35. {
  36. $('#reportList tr:first td:eq(1)').click();
  37. }
  38. }
  39. $(document).on('change', "input[name='type'][type='radio']", function()
  40. {
  41. toggleSelect();
  42. });
  43. $(document).on('change', "input[name='countType'][type='radio']", function()
  44. {
  45. var countType = $("input[name='countType'][type='radio']:checked").val();
  46. $('#fieldsSelect').parent().parent().toggle(countType != 'count');
  47. });
  48. /* Display fields of current module when dimension selected. */
  49. $(document).on('change', '#dimension', function()
  50. {
  51. var dimension = $("#dimension").val();
  52. var module = dimension.substr(0, dimension.indexOf('_'));
  53. /* Display fields where belong to dimension's sub module and main table module if dimension is sub module. */
  54. if(module == window.moduleName)
  55. {
  56. $('#fields option').show();
  57. }
  58. else
  59. {
  60. $('#fields option').hide();
  61. $('#fields option[value^=' + window.moduleName + '_]').show();
  62. $('#fields option[value^=' + module + '_]').show();
  63. /* String is pie fields,object is line or bar fields. */
  64. fieldValue = $("#fields").val();
  65. if(typeof fieldValue == 'string')
  66. {
  67. if(fieldValue.indexOf(module + '_') != 0 && fieldValue.indexOf(window.moduleName + '_') != 0) $("#fields").val("");
  68. }
  69. else
  70. {
  71. var fieldsVal = [];
  72. $.each(fieldValue, function(i, val)
  73. {
  74. if(val.indexOf(window.moduleName + '_') == 0 || val.indexOf(module + '_') == 0) fieldsVal.push(val);
  75. });
  76. $("#fields").val(fieldsVal)
  77. }
  78. }
  79. $('#fields').trigger('chosen:updated');
  80. /* Display granularity if dimension control is date or datetime. */
  81. var isDate = window.controlPairs[dimension] == 'date' || window.controlPairs[dimension] == 'datetime';
  82. $('#granularity_chosen').toggle(isDate);
  83. $('#dimension_chosen a input').toggleClass('dimension-half-radius', isDate);
  84. $('#dimension_chosen a').toggleClass('dimension-all-radius dimension-half-radius');
  85. isDate ? $('#granularity').removeAttr("disabled") : $('#granularity').attr("disabled","disabled");
  86. });
  87. });
  88. /* Toggle which select to display. */
  89. function toggleSelect()
  90. {
  91. var type = $("input[name='type'][type='radio']:checked").val();
  92. if(type == 'pie')
  93. {
  94. $('#fields').removeAttr('multiple');
  95. }
  96. else
  97. {
  98. $('#fields').attr('multiple', 'multiple');
  99. }
  100. $('#fields').trigger('chosen:updated');
  101. }
  102. /* Load preview chart. */
  103. function preview(id)
  104. {
  105. let url = createLink('workflowreport', 'ajaxPreview', 'id=' + id);
  106. $('.existReport').load(url, function()
  107. {
  108. $('#reportList tr').removeClass('checked row-check-begin row-check-end');
  109. $('#reportList tr[data-id=' + id + ']').addClass('checked row-check-begin row-check-end');
  110. });
  111. }