dashboard.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup UnaStudio UNA Studio
  6. * @{
  7. */
  8. function BxDolStudioDashboard(oOptions) {
  9. this.sActionsUrl = oOptions.sActionUrl;
  10. this.sObjName = oOptions.sObjName == undefined ? 'oBxDolStudioDashboard' : oOptions.sObjName;
  11. this.sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
  12. this.iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  13. this.oData = [];
  14. var $this = this;
  15. $(document).ready(function() {
  16. $('.bx-dbd-block-content').bxProcessHtml();
  17. });
  18. }
  19. BxDolStudioDashboard.prototype.checkForUpgrade = function() {
  20. var $this = this;
  21. var oDate = new Date();
  22. var sDivId = 'bx-dbd-version';
  23. bx_loading(sDivId, true);
  24. $.get(
  25. this.sActionsUrl,
  26. {
  27. dbd_action: 'check_for_upgrade',
  28. _t: oDate.getTime()
  29. },
  30. function(oData) {
  31. bx_loading(sDivId, false);
  32. if(!oData.data)
  33. return;
  34. $('#' + sDivId + ' .bx-dbd-version-available').html(oData.data).show();
  35. },
  36. 'json'
  37. );
  38. };
  39. BxDolStudioDashboard.prototype.performUpgrade = function() {
  40. var $this = this;
  41. var oDate = new Date();
  42. var sDivId = 'bx-dbd-version';
  43. bx_loading(sDivId, true);
  44. $.get(
  45. this.sActionsUrl,
  46. {
  47. dbd_action: 'perform_upgrade',
  48. _t: oDate.getTime()
  49. },
  50. function(oData) {
  51. bx_loading(sDivId, false);
  52. if(!oData.message)
  53. return;
  54. $this.popup(oData.message);
  55. },
  56. 'json'
  57. );
  58. };
  59. BxDolStudioDashboard.prototype.getBlockContent = function(sType) {
  60. var $this = this;
  61. var oDate = new Date();
  62. var sDivId = 'bx-dbd-' + sType;
  63. bx_loading(sDivId, true);
  64. $.get(
  65. this.sActionsUrl,
  66. {
  67. dbd_action: 'get_block',
  68. dbd_value: sType,
  69. _t: oDate.getTime()
  70. },
  71. function(oData) {
  72. bx_loading(sDivId, false);
  73. if(!oData.data)
  74. return;
  75. $('#' + sDivId).replaceWith(oData.data);
  76. },
  77. 'json'
  78. );
  79. };
  80. BxDolStudioDashboard.prototype.initChart = function(sType, oData) {
  81. var $this = this;
  82. var sDivId = 'bx-dbd-' + sType;
  83. bx_loading(sDivId, true);
  84. google.load("visualization", "1", {packages:["corechart"], callback: function() {
  85. bx_loading(sDivId, false);
  86. $this.showChart(sType, oData);
  87. }});
  88. };
  89. BxDolStudioDashboard.prototype.showChart = function(sType, oData) {
  90. var oChart = $('#bx-dbd-' + sType + ' .bx-dbd-chart');
  91. oChart.html('');
  92. var oDataTable = new google.visualization.DataTable();
  93. oDataTable.addColumn('string', 'Label');
  94. oDataTable.addColumn('number', 'Size');
  95. if(oData != undefined)
  96. this.oData = oData;
  97. oDataTable.addRows(this.oData);
  98. var oChart = new google.visualization.PieChart(oChart[0]);
  99. oChart.draw(oDataTable, {
  100. chartArea: {
  101. left:10,
  102. top:10,
  103. width:'92%',
  104. height:'92%'
  105. }
  106. });
  107. };
  108. BxDolStudioDashboard.prototype.clearCache = function(sType) {
  109. var $this = this;
  110. var oDate = new Date();
  111. var sDivId = 'bx-dbd-cache';
  112. $('#' + sDivId).parents('.bx-page-block-container').find('.bx-db-header .bx-popup-applied:visible').dolPopupHide();
  113. bx_loading(sDivId, true);
  114. $.post(
  115. sUrlStudio + 'dashboard.php',
  116. {
  117. dbd_action: 'clear_cache',
  118. dbd_value: sType,
  119. _t: oDate.getTime()
  120. },
  121. function(oData) {
  122. bx_loading(sDivId, false);
  123. if(oData.message != undefined && oData.message.length > 0)
  124. $this.popup(oData.message);
  125. if(oData.data != undefined) {
  126. if(typeof oData.data == 'object')
  127. $this.showChart('cache', oData.data);
  128. else if(typeof oData.data == 'string')
  129. $('#' + sDivId).html(oData.data);
  130. }
  131. },
  132. 'json'
  133. );
  134. };
  135. BxDolStudioDashboard.prototype.permissions = function() {
  136. this.hostTools('permissions');
  137. };
  138. BxDolStudioDashboard.prototype.serverAudit = function() {
  139. this.hostTools('server_audit');
  140. };
  141. BxDolStudioDashboard.prototype.hostTools = function(sAction) {
  142. var $this = this;
  143. var oDate = new Date();
  144. var sDivId = 'bx-dbd-htools';
  145. $('#' + sDivId).parents('.bx-page-block-container').find('.bx-db-header .bx-popup-applied:visible').dolPopupHide();
  146. bx_loading(sDivId, true);
  147. $.get(
  148. this.sActionsUrl,
  149. {
  150. dbd_action: sAction,
  151. _t: oDate.getTime()
  152. },
  153. function(sData) {
  154. bx_loading(sDivId, false);
  155. if(!sData.length)
  156. return;
  157. $('#' + sDivId).hide().html(sData).bx_anim('show', 'fade', 'slow', function() {
  158. $(this).bxProcessHtml();
  159. });
  160. },
  161. 'html'
  162. );
  163. };
  164. BxDolStudioDashboard.prototype.popup = function(sValue) {
  165. var sId = 'bx-std-dbd-popup';
  166. $('#' + sId).remove();
  167. $('<div id="' + sId + '" style="display: none;"></div>').prependTo('body').html(sValue);
  168. $('#' + sId).dolPopup({});
  169. };
  170. /** @} */