dashboard.class.inc.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. require_once(APPROOT.'application/dashboardlayout.class.inc.php');
  3. require_once(APPROOT.'application/dashlet.class.inc.php');
  4. abstract class Dashboard
  5. {
  6. protected $sTitle;
  7. protected $sLayoutClass;
  8. protected $aWidgetsData;
  9. protected $oDOMNode;
  10. protected $sId;
  11. public function __construct($sId)
  12. {
  13. $this->sLayoutClass = null;
  14. $this->aDashlets = array();
  15. $this->oDOMNode = null;
  16. $this->sId = $sId;
  17. }
  18. public function FromXml($sXml)
  19. {
  20. $oDoc = new DOMDocument();
  21. $oDoc->loadXML($sXml);
  22. $this->oDOMNode = $oDoc->getElementsByTagName('dashboard')->item(0);
  23. $oLayoutNode = $this->oDOMNode->getElementsByTagName('layout')->item(0);
  24. $this->sLayoutClass = $oLayoutNode->textContent;
  25. $oTitleNode = $this->oDOMNode->getElementsByTagName('title')->item(0);
  26. $this->sTitle = $oTitleNode->textContent;
  27. $oDashletsNode = $this->oDOMNode->getElementsByTagName('dashlets')->item(0);
  28. $oDashletList = $oDashletsNode->getElementsByTagName('dashlet');
  29. foreach($oDashletList as $oDomNode)
  30. {
  31. $sDashletClass = $oDomNode->getAttribute('xsi:type');
  32. $sId = $oDomNode->getAttribute('id');
  33. $oNewDashlet = new $sDashletClass($sId);
  34. $oNewDashlet->FromDOMNode($oDomNode);
  35. $this->aDashlets[] = $oNewDashlet;
  36. }
  37. }
  38. public function FromParams($aParams)
  39. {
  40. }
  41. public function Save()
  42. {
  43. }
  44. public function GetLayout()
  45. {
  46. return $this->sLayoutClass;
  47. }
  48. public function SetLayout($sLayoutClass)
  49. {
  50. $this->sLayoutClass = $sLayoutClass;
  51. }
  52. public function GetTitle()
  53. {
  54. return $this->sTitle;
  55. }
  56. public function SetTitle($sTitle)
  57. {
  58. $this->sTitle = $sTitle;
  59. }
  60. public function AddDashlet()
  61. {
  62. }
  63. public function Render($oPage, $bEditMode = false, $aExtraParams = array())
  64. {
  65. $oPage->add('<h1>'.$this->sTitle.'</h1>');
  66. $oLayout = new $this->sLayoutClass;
  67. $oLayout->Render($oPage, $this->aDashlets, $bEditMode, $aExtraParams);
  68. if (!$bEditMode)
  69. {
  70. $oPage->add_linked_script('../js/dashlet.js');
  71. }
  72. }
  73. public function RenderProperties($oPage)
  74. {
  75. // menu to pick a layout and edit other properties of the dashboard
  76. $oPage->add('<div class="ui-widget-content ui-corner-all"><div class="ui-widget-header ui-corner-all" style="text-align:center; padding: 2px;">Dashboard Properties</div>');
  77. $sUrl = utils::GetAbsoluteUrlAppRoot();
  78. $oPage->add('<div style="text-align:center">Layout:</div>');
  79. $oPage->add('<div id="select_layout" style="text-align:center">');
  80. foreach( get_declared_classes() as $sLayoutClass)
  81. {
  82. if (is_subclass_of($sLayoutClass, 'DashboardLayout'))
  83. {
  84. $oReflection = new ReflectionClass($sLayoutClass);
  85. if (!$oReflection->isAbstract())
  86. {
  87. $aInfo = $sLayoutClass::GetInfo();
  88. $oPage->add('<input type="radio" name="layout_class" id="layout_'.$sLayoutClass.'"><label for="layout_'.$sLayoutClass.'"><img src="'.$sUrl.$aInfo['icon'].'" /></label>'); // title="" on either the img or the label does nothing !
  89. }
  90. }
  91. }
  92. $oPage->add('</div>');
  93. $oPage->add('</div>');
  94. $oPage->add_ready_script("$('#select_layout').buttonset();");
  95. }
  96. public function RenderDashletsSelection($oPage)
  97. {
  98. // Toolbox/palette to drag and drop dashlets
  99. $oPage->add('<div class="ui-widget-content ui-corner-all"><div class="ui-widget-header ui-corner-all" style="text-align:center; padding: 2px;">Available Dashlets</div>');
  100. $sUrl = utils::GetAbsoluteUrlAppRoot();
  101. $oPage->add('<div id="select_dashlet" style="text-align:center">');
  102. foreach( get_declared_classes() as $sDashletClass)
  103. {
  104. if (is_subclass_of($sDashletClass, 'Dashlet'))
  105. {
  106. $oReflection = new ReflectionClass($sDashletClass);
  107. if (!$oReflection->isAbstract())
  108. {
  109. $aInfo = $sDashletClass::GetInfo();
  110. $oPage->add('<span class="dashlet_icon ui-widget-content ui-corner-all" id="dashlet_'.$sDashletClass.'" title="'.$aInfo['label'].'" style="width:34px; height:34px; display:inline-block; margin:2px;"><img src="'.$sUrl.$aInfo['icon'].'" /></span>');
  111. }
  112. }
  113. }
  114. $oPage->add('</div>');
  115. $oPage->add('</div>');
  116. $oPage->add_ready_script("$('.dashlet_icon').draggable({helper: 'clone', appendTo: 'body', zIndex: 10000, revert:'invalid'});");
  117. $oPage->add_ready_script("$('.layout_cell').droppable({accept:'.dashlet_icon', hoverClass:'dragHover'});");
  118. }
  119. public function RenderDashletsProperties($oPage)
  120. {
  121. // Toolbox/palette to edit the properties of each dashlet
  122. $oPage->add('<div class="ui-widget-content ui-corner-all"><div class="ui-widget-header ui-corner-all" style="text-align:center; padding: 2px;">Dashlet Properties</div>');
  123. $oPage->add('<div id="dashlet_properties" style="text-align:center">');
  124. foreach($this->aDashlets as $oDashlet)
  125. {
  126. $oDashlet->RenderProperties($oPage);
  127. }
  128. $oPage->add('</div>');
  129. $oPage->add('</div>');
  130. }
  131. }
  132. class RuntimeDashboard extends Dashboard
  133. {
  134. public function Save()
  135. {
  136. }
  137. public function Render($oPage, $bEditMode = false, $aExtraParams = array())
  138. {
  139. parent::Render($oPage, $bEditMode, $aExtraParams);
  140. if (!$bEditMode)
  141. {
  142. $sEditBtn = addslashes('<div style="display: inline-block; height: 55px; width:200px;vertical-align:center;line-height:60px;text-align:left;"><button onclick="EditDashboard(\''.$this->sId.'\');">Edit This Page</button></div>');
  143. $oPage->add_ready_script("$('#top-bar').prepend('$sEditBtn');");
  144. $oPage->add_script(
  145. <<<EOF
  146. function EditDashboard(sId)
  147. {
  148. $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', {operation: 'dashboard_editor', id: sId},
  149. function(data)
  150. {
  151. $('body').append(data);
  152. }
  153. );
  154. return false;
  155. }
  156. EOF
  157. );
  158. }
  159. }
  160. public function RenderEditor($oPage)
  161. {
  162. $oPage->add('<div id="dashboard_editor">');
  163. $oPage->add('<div class="ui-layout-center">');
  164. $this->Render($oPage, true);
  165. $oPage->add('</div>');
  166. $oPage->add('<div class="ui-layout-east">');
  167. $this->RenderProperties($oPage);
  168. $this->RenderDashletsSelection($oPage);
  169. $this->RenderDashletsProperties($oPage);
  170. $oPage->add('</div>');
  171. $oPage->add('<div id="event_bus"/>'); // For exchanging messages between the panes, same as in the designer
  172. $oPage->add('</div>');
  173. $sDialogTitle = 'Dashboard Editor';
  174. $sOkButtonLabel = Dict::S('UI:Button:Ok');
  175. $sCancelButtonLabel = Dict::S('UI:Button:Cancel');
  176. $oPage->add_ready_script(
  177. <<<EOF
  178. $('#dashboard_editor').dialog({
  179. height: $('body').height() - 50,
  180. width: $('body').width() - 50,
  181. modal: true,
  182. title: '$sDialogTitle',
  183. buttons: [
  184. { text: "$sOkButtonLabel", click: function() {
  185. $(this).dialog( "close" ); $(this).remove();
  186. } },
  187. { text: "$sCancelButtonLabel", click: function() { $(this).dialog( "close" ); $(this).remove(); } },
  188. ],
  189. close: function() { $(this).remove(); }
  190. });
  191. $('#event_bus').bind('dashlet-selected', function(event, data){
  192. var sDashletId = data.dashlet_id;
  193. var sPropId = 'dashlet_properties_'+sDashletId;
  194. $('.dashlet_properties').each(function() {
  195. var sId = $(this).attr('id');
  196. var bShow = (sId == sPropId);
  197. if (bShow)
  198. {
  199. $(this).show();
  200. }
  201. else
  202. {
  203. $(this).hide();
  204. }
  205. });
  206. });
  207. EOF
  208. );
  209. $oPage->add_ready_script("$('#dashboard_editor').layout();");
  210. }
  211. }