dashboard.class.inc.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. $oNewDashlet = new $sDashletClass;
  33. $oNewDashlet->FromDOMNode($oDomNode);
  34. $this->aDashlets[] = $oNewDashlet;
  35. }
  36. }
  37. public function FromParams($aParams)
  38. {
  39. }
  40. public function Save()
  41. {
  42. }
  43. public function GetLayout()
  44. {
  45. return $this->sLayoutClass;
  46. }
  47. public function SetLayout($sLayoutClass)
  48. {
  49. $this->sLayoutClass = $sLayoutClass;
  50. }
  51. public function GetTitle()
  52. {
  53. return $this->sTitle;
  54. }
  55. public function SetTitle($sTitle)
  56. {
  57. $this->sTitle = $sTitle;
  58. }
  59. public function AddDashlet()
  60. {
  61. }
  62. public function Render($oPage, $bEditMode = false, $aExtraParams = array())
  63. {
  64. $oPage->add('<h1>'.$this->sTitle.'</h1>');
  65. $oLayout = new $this->sLayoutClass;
  66. $oLayout->Render($oPage, $this->aDashlets, $bEditMode, $aExtraParams);
  67. }
  68. public function RenderProperties($oPage)
  69. {
  70. // menu to pick a layout and edit other properties of the dashboard
  71. $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>');
  72. $sUrl = utils::GetAbsoluteUrlAppRoot();
  73. $oPage->add('<div style="text-align:center">Layout:</div>');
  74. $oPage->add('<div id="select_layout" style="text-align:center">');
  75. foreach( get_declared_classes() as $sLayoutClass)
  76. {
  77. if (is_subclass_of($sLayoutClass, 'DashboardLayout'))
  78. {
  79. $oReflection = new ReflectionClass($sLayoutClass);
  80. if (!$oReflection->isAbstract())
  81. {
  82. $aInfo = $sLayoutClass::GetInfo();
  83. $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 !
  84. }
  85. }
  86. }
  87. $oPage->add('</div>');
  88. $oPage->add('</div>');
  89. $oPage->add_ready_script("$('#select_layout').buttonset();");
  90. }
  91. public function RenderDashletsSelection($oPage)
  92. {
  93. // Toolbox/palette to drag and drop dashlets
  94. $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>');
  95. $sUrl = utils::GetAbsoluteUrlAppRoot();
  96. $oPage->add('<div id="select_dashlet" style="text-align:center">');
  97. foreach( get_declared_classes() as $sDashletClass)
  98. {
  99. if (is_subclass_of($sDashletClass, 'Dashlet'))
  100. {
  101. $oReflection = new ReflectionClass($sDashletClass);
  102. if (!$oReflection->isAbstract())
  103. {
  104. $aInfo = $sDashletClass::GetInfo();
  105. $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>');
  106. }
  107. }
  108. }
  109. $oPage->add('</div>');
  110. $oPage->add('</div>');
  111. $oPage->add_ready_script("$('.dashlet_icon').draggable({helper: 'clone', appendTo: 'body', zIndex: 10000, revert:'invalid'});");
  112. $oPage->add_ready_script("$('.layout_cell').droppable({accept:'.dashlet_icon', hoverClass:'dragHover'});");
  113. }
  114. public function RenderDashletsProperties($oPage)
  115. {
  116. // Toolbox/palette to edit the properties of each dashlet
  117. $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>');
  118. $oPage->add('<div id="dashlet_properties" style="text-align:center">');
  119. $oPage->p('Not yet implemented');
  120. $oPage->add('</div>');
  121. $oPage->add('</div>');
  122. }
  123. }
  124. class RuntimeDashboard extends Dashboard
  125. {
  126. public function Save()
  127. {
  128. }
  129. public function Render($oPage, $bEditMode = false, $aExtraParams = array())
  130. {
  131. parent::Render($oPage, $bEditMode, $aExtraParams);
  132. if (!$bEditMode)
  133. {
  134. $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>');
  135. $oPage->add_ready_script("$('#top-bar').prepend('$sEditBtn');");
  136. $oPage->add_script(
  137. <<<EOF
  138. function EditDashboard(sId)
  139. {
  140. console.log('Ici');
  141. $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', {operation: 'dashboard_editor', id: sId},
  142. function(data)
  143. {
  144. $('body').append(data);
  145. }
  146. );
  147. return false;
  148. }
  149. EOF
  150. );
  151. }
  152. }
  153. public function RenderEditor($oPage)
  154. {
  155. $oPage->add('<div id="dashboard_editor">');
  156. $oPage->add('<div class="ui-layout-center">');
  157. $this->Render($oPage, true);
  158. $oPage->add('</div>');
  159. $oPage->add('<div class="ui-layout-east">');
  160. $this->RenderProperties($oPage);
  161. $this->RenderDashletsSelection($oPage);
  162. $this->RenderDashletsProperties($oPage);
  163. $oPage->add('</div>');
  164. $oPage->add('</div>');
  165. $sDialogTitle = 'Dashboard Editor';
  166. $sOkButtonLabel = Dict::S('UI:Button:Ok');
  167. $sCancelButtonLabel = Dict::S('UI:Button:Cancel');
  168. $oPage->add_ready_script(
  169. <<<EOF
  170. $('#dashboard_editor').dialog({
  171. height: $('body').height() - 50,
  172. width: $('body').width() - 50,
  173. modal: true,
  174. title: '$sDialogTitle',
  175. buttons: [
  176. { text: "$sOkButtonLabel", click: function() {
  177. $(this).dialog( "close" ); $(this).remove();
  178. } },
  179. { text: "$sCancelButtonLabel", click: function() { $(this).dialog( "close" ); $(this).remove(); } },
  180. ],
  181. close: function() { $(this).remove(); }
  182. });
  183. EOF
  184. );
  185. $oPage->add_ready_script("$('#dashboard_editor').layout();");
  186. }
  187. }