applicationextension.inc.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Class iPlugin
  20. * Management of application plugin
  21. *
  22. * @copyright Copyright (C) 2010-2012 Combodo SARL
  23. * @license http://opensource.org/licenses/AGPL-3.0
  24. */
  25. interface iApplicationUIExtension
  26. {
  27. public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false);
  28. public function OnDisplayRelations($oObject, WebPage $oPage, $bEditMode = false);
  29. public function OnFormSubmit($oObject, $sFormPrefix = '');
  30. public function OnFormCancel($sTempId); // temp id is made of session_id and transaction_id, it identifies the object in a unique way
  31. public function EnumUsedAttributes($oObject); // Not yet implemented
  32. public function GetIcon($oObject); // Not yet implemented
  33. public function GetHilightClass($oObject);
  34. public function EnumAllowedActions(DBObjectSet $oSet);
  35. }
  36. interface iApplicationObjectExtension
  37. {
  38. public function OnIsModified($oObject);
  39. public function OnCheckToWrite($oObject);
  40. public function OnCheckToDelete($oObject);
  41. public function OnDBUpdate($oObject, $oChange = null);
  42. public function OnDBInsert($oObject, $oChange = null);
  43. public function OnDBDelete($oObject, $oChange = null);
  44. }
  45. /**
  46. * New extension to add menu items in the "popup" menus inside iTop. Provides a greater flexibility than
  47. * iApplicationUIExtension::EnumAllowedActions.
  48. *
  49. * To add some menus into iTop, declare a class that implements this interface, it will be called automatically
  50. * by the application, as long as the class definition is included somewhere in the code
  51. */
  52. interface iPopupMenuExtension
  53. {
  54. // Possible types of menu into which new items can be added
  55. const MENU_OBJLIST_ACTIONS = 1; // $param is a DBObjectSet containing the list of objects
  56. const MENU_OBJLIST_TOOLKIT = 2; // $param is a DBObjectSet containing the list of objects
  57. const MENU_OBJDETAILS_ACTIONS = 3; // $param is a DBObject instance: the object currently displayed
  58. const MENU_DASHBOARD_ACTIONS = 4; // $param is a Dashboard instance: the dashboard currently displayed
  59. const MENU_USER_ACTIONS = 5; // $param is a null ??
  60. /**
  61. * Get the list of items to be added to a menu. The items will be inserted in the menu in the order of the returned array
  62. * @param int $iMenuId The identifier of the type of menu, as listed by the constants MENU_xxx above
  63. * @param mixed $param Depends on $iMenuId, see the constants defined above
  64. * @return Array An array of ApplicationPopupMenuItem or an empty array if no action is to be added to the menu
  65. */
  66. public static function EnumItems($iMenuId, $param);
  67. }
  68. /**
  69. * Each menu items is defined by an instance of an object derived from the class
  70. * ApplicationPopupMenu below
  71. *
  72. */
  73. abstract class ApplicationPopupMenuItem
  74. {
  75. protected $sUID;
  76. protected $sLabel;
  77. public function __construct($sUID, $sLabel)
  78. {
  79. $this->sUID = $sUID;
  80. $this->sLabel = $sLabel;
  81. }
  82. public function GetUID()
  83. {
  84. return $this->sUID;
  85. }
  86. public function GetLabel()
  87. {
  88. return $this->sLabel;
  89. }
  90. /**
  91. * Returns the components to create a popup menu item in HTML
  92. * @return Hash A hash array: array('label' => , 'url' => , 'target' => , 'onclick' => )
  93. */
  94. abstract public function GetMenuItem();
  95. public function GetLinkedScripts()
  96. {
  97. return array();
  98. }
  99. }
  100. /**
  101. * Class for adding an item into a popup menu that browses to the given URL
  102. */
  103. class URLPopupMenuItem extends ApplicationPopupMenuItem
  104. {
  105. protected $sURL;
  106. protected $sTarget;
  107. /**
  108. * Class for adding an item that browses to the given URL
  109. * @param string $sUID The unique identifier of this menu in iTop... make sure you pass something unique enough
  110. * @param string $sLabel The display label of the menu (must be localized)
  111. * @param string $sURL If the menu is an hyperlink, provide the absolute hyperlink here
  112. * @param string $sTarget In case the menu is an hyperlink and a specific target is needed (_blank for example), pass it here
  113. */
  114. public function __construct($sUID, $sLabel, $sURL, $sTarget = '_top')
  115. {
  116. parent::__construct($sUID, $sLabel);
  117. $this->sURL = $sURL;
  118. $this->sTarget = $sTarget;
  119. }
  120. public function GetMenuItem()
  121. {
  122. return array ('label' => $this->GetLabel(), 'url' => $this->sURL, 'target' => $this->sTarget);
  123. }
  124. }
  125. /**
  126. * Class for adding an item into a popup menu that triggers some Javascript code
  127. */
  128. class JSPopupMenuItem extends ApplicationPopupMenuItem
  129. {
  130. protected $sJSCode;
  131. protected $aIncludeJSFiles;
  132. /**
  133. * Class for adding an item that triggers some Javascript code
  134. * @param string $sUID The unique identifier of this menu in iTop... make sure you pass something unique enough
  135. * @param string $sLabel The display label of the menu (must be localized)
  136. * @param string $sJSCode In case the menu consists in executing some havascript code inside the page, pass it here. If supplied $sURL ans $sTarget will be ignored
  137. * @param array $aIncludeJSFiles An array of file URLs to be included (once) to provide some JS libraries for the page.
  138. */
  139. public function __construct($sUID, $sLabel, $sJSCode, $aIncludeJSFiles = array())
  140. {
  141. parent::__construct($sUID, $sLabel);
  142. $this->sJSCode = $sJSCode;
  143. $this->aIncludeJSFiles = $aIncludeJSFiles;
  144. }
  145. public function GetMenuItem()
  146. {
  147. return array ('label' => $this->GetLabel(), 'onclick' => $this->sJSCode, 'url' => '#');
  148. }
  149. public function GetLinkedScripts()
  150. {
  151. return $this->aIncludeJSFiles;
  152. }
  153. }
  154. /**
  155. * Class for adding a separator (horizontal line, not selectable) the output
  156. * will automatically reduce several consecutive separators to just one
  157. */
  158. class SeparatorPopupMenuItem extends ApplicationPopupMenuItem
  159. {
  160. /**
  161. * Class for inserting a separator into a popup menu
  162. */
  163. public function __construct()
  164. {
  165. parent::__construct('', '');
  166. }
  167. public function GetMenuItem()
  168. {
  169. return array ('label' => '<hr class="menu-separator">', 'url' => '');
  170. }
  171. }