easy-charts-admin.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. (function($) {
  2. 'use strict';
  3. $('document').ready(function() {
  4. var data = [
  5. ['', 'Kia', 'Nissan', 'Toyota', 'Honda'],
  6. ['2008', 10, 11, 12, 13],
  7. ['2009', 20, 11, 14, 13],
  8. ['2010', 30, 15, 12, 13]
  9. ];
  10. if (typeof(ec_chart) != 'undefined') {
  11. if (ec_chart.chart_data != null) {
  12. data = ec_chart.chart_data;
  13. }
  14. }
  15. $('.ec-color-picker').wpColorPicker();
  16. $(".ec-field-buttonset").buttonset();
  17. $('.ec-field-slider').each(function(index, el) {
  18. $(this).slider({
  19. range: "max",
  20. min: 0,
  21. max: 1,
  22. value: $($(this).data('attach')).val(),
  23. step: 0.1,
  24. slide: function(event, ui) {
  25. $($(this).data('attach')).val(ui.value);
  26. }
  27. });
  28. });
  29. $('.resp-tabs-container').pwstabs({
  30. tabsPosition: 'vertical',
  31. responsive: false,
  32. containerWidth: '100%',
  33. theme: 'pws_theme_orange',
  34. effect: 'slidedown'
  35. });
  36. function ec_save_chart_data_ajax(table) {
  37. $.ajax({
  38. url: ajaxurl,
  39. type: 'POST',
  40. dataType: 'json',
  41. data: {
  42. 'action': 'easy_charts_save_chart_data',
  43. 'chart_id': ec_chart.chart_id,
  44. '_nonce_check': ec_chart.ec_ajax_nonce,
  45. 'chart_data': JSON.stringify(table.getData())
  46. },
  47. })
  48. .done(function(updated_data) {
  49. $('.uv-div-' + ec_chart.chart_id).html('');
  50. var graphdef = {
  51. categories: updated_data.chart_categories,
  52. dataset: updated_data.chart_data,
  53. };
  54. var chartObject = uv.chart(updated_data.chart_type, graphdef, chartConfiguration);
  55. })
  56. .fail(function() {})
  57. .always(function() {});
  58. }
  59. var container = document.getElementById("handsontable");
  60. if (container != null) {
  61. var hot = new Handsontable(container, {
  62. data: data,
  63. stretchH: 'all',
  64. cell: [{
  65. row: 0,
  66. col: 0,
  67. readOnly: true
  68. }],
  69. fixedRowsTop: 1,
  70. fixedColumnsTop: 1,
  71. fixedColumnsLeft: 1,
  72. rowHeaders: true,
  73. colHeaders: true,
  74. manualColumnMove: true,
  75. manualRowMove: true,
  76. minSpareRows: 0,
  77. minSpareCols: 0,
  78. contextMenu: true,
  79. autoWrapCol: true,
  80. autoWrapRow: true,
  81. afterChange: function(change, source) {},
  82. afterColumnMove: function(startColumn, endColumn) {},
  83. afterRowMove: function(startColumn, endColumn) {}
  84. });
  85. }
  86. $('#ec-button-add-col').on('click', function(event) {
  87. event.preventDefault();
  88. hot.alter('insert_col', null);
  89. });
  90. $('#ec-button-remove-col').on('click', function(event) {
  91. event.preventDefault();
  92. hot.alter('remove_col', null);
  93. });
  94. $('#ec-button-add-row').on('click', function(event) {
  95. event.preventDefault();
  96. hot.alter('insert_row', null);
  97. });
  98. $('#ec-button-remove-row').on('click', function(event) {
  99. event.preventDefault();
  100. hot.alter('remove_row', null);
  101. });
  102. $('#ec-button-save-data').on('click', function(event) {
  103. event.preventDefault();
  104. if (hot.countEmptyCols() == 0 && hot.countEmptyRows() == 0) {
  105. ec_save_chart_data_ajax(hot);
  106. } else {
  107. $("#dialog-confirm").dialog({
  108. resizable: false,
  109. height: 400,
  110. modal: true,
  111. buttons: {
  112. "Ok": function() {
  113. $(this).dialog("close");
  114. }
  115. }
  116. });
  117. }
  118. });
  119. if (typeof(ec_chart_data) != 'undefined') {
  120. var graphdef = {
  121. categories: [],
  122. dataset: {}
  123. };
  124. var chartType = ec_chart_data.chart_type;
  125. var chartCategories = ec_chart_data.chart_categories;
  126. var chartDataset = ec_chart_data.chart_data;
  127. var chartConfiguration = ec_chart_data.chart_configuration;
  128. graphdef = {
  129. categories: chartCategories,
  130. dataset: chartDataset,
  131. };
  132. var chartObject = uv.chart(chartType, graphdef, chartConfiguration);
  133. }
  134. $('.uv-chart-div svg.uv-frame g.uv-download-options').bind('mouseenter', function(event) {
  135. var svg = $(this).parents('.uv-chart-div svg.uv-frame');
  136. svg[0].setAttribute('width', svg[0].getBoundingClientRect().width);
  137. svg[0].setAttribute('height', svg[0].getBoundingClientRect().height);
  138. });
  139. });
  140. })(jQuery);