column.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. $(function()
  2. {
  3. $(document).on('click', '.add-column', addColumn);
  4. });
  5. function renderColumns()
  6. {
  7. var form = $('#step2Content').find('form#columnForm');
  8. form.empty();
  9. var pivot = DataStorage.clone('pivot');
  10. var fieldSettings = DataStorage.fieldSettings;
  11. var langs = DataStorage.langs;
  12. if(!pivot.settings.columns) pivot.settings.columns = [{field: '', stat: '', slice: 'noSlice', showMode: 'default', monopolize: '' , showTotal: 'noShow'}];
  13. DataStorage.pivot = pivot;
  14. $.post(createLink('pivot', 'ajaxGetColumnForm', 'pivotID=' + pivot.id), {fieldSettings: fieldSettings, columns: pivot.settings.columns, langs: langs}, function(resp)
  15. {
  16. resp = JSON.parse(resp);
  17. pivot.settings.columns.forEach(function(column, index)
  18. {
  19. form.append(columnRow(resp, index));
  20. });
  21. setDeleteColumnHidden(form, pivot.settings.columns.length);
  22. $('#columnTotal').data('zui.picker').setValue(pivot.settings.columnTotal);
  23. });
  24. }
  25. function columnRow(resp, index)
  26. {
  27. var tpl = $('#step2Content').find('#columnTpl').html();
  28. var showOrigin = resp[index].showOrigin;
  29. var data =
  30. {
  31. index: index,
  32. columnIndex: resp[index].columnIndex,
  33. fieldSelect: resp[index].fieldSelect,
  34. sliceField: resp[index].sliceField,
  35. calcMode: resp[index].calcMode,
  36. showMode: resp[index].showMode,
  37. monopolize: resp[index].monopolize,
  38. monopolizeHide: resp[index].monopolizeHide,
  39. showTotal: resp[index].showTotal,
  40. fieldHide: resp[index].fieldHide,
  41. columnHidden: showOrigin ? 'hidden' : '',
  42. maskHidden: showOrigin ? '' : 'hidden'
  43. };
  44. var html = $($.zui.formatString(tpl, data))
  45. initPicker(html);
  46. html.find('#column').next().css('width', '180');
  47. html.find('.showOrigin input#showOrigin0').prop('checked', showOrigin);
  48. return html;
  49. }
  50. /**
  51. * Judge whether the element can be deleted in #columnForm.
  52. *
  53. * @param object form
  54. * @param int length
  55. * @access public
  56. * @return void
  57. */
  58. function setDeleteColumnHidden(form, length)
  59. {
  60. if(length == 1)
  61. {
  62. form.find('.column-delete').addClass('hidden');
  63. }
  64. else
  65. {
  66. form.find('.column-delete').removeClass('hidden');
  67. }
  68. }
  69. /**
  70. * Add a column.
  71. *
  72. * @access public
  73. * @return void
  74. */
  75. function addColumn()
  76. {
  77. var column = {field: '', stat: '', slice: 'noSlice', showMode: 'default', showTotal: 'noShow'};
  78. var pivot = DataStorage.clone('pivot');
  79. pivot.settings.columns.push(column);
  80. DataStorage.pivot = pivot;
  81. renderColumns();
  82. }
  83. /**
  84. * Remove a column.
  85. *
  86. * @param int index
  87. * @access public
  88. * @return void
  89. */
  90. function removeColumn(index)
  91. {
  92. bootbox.confirm(pivotLang.deleteColumn, function(res)
  93. {
  94. if(res)
  95. {
  96. var pivot = DataStorage.clone('pivot');
  97. pivot.settings.columns.splice(index, 1);
  98. DataStorage.pivot = pivot;
  99. renderColumns();
  100. }
  101. });
  102. }