nicewebpage.class.inc.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 NiceWebPage
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. require_once(APPROOT."/application/webpage.class.inc.php");
  25. /**
  26. * Web page with some associated CSS and scripts (jquery) for a fancier display
  27. */
  28. class NiceWebPage extends WebPage
  29. {
  30. var $m_aReadyScripts;
  31. var $m_sRootUrl;
  32. public function __construct($s_title)
  33. {
  34. parent::__construct($s_title);
  35. $this->m_aReadyScripts = array();
  36. $this->add_linked_script("../js/jquery-1.10.0.min.js");
  37. $this->add_linked_script("../js/jquery-migrate-1.2.1.min.js"); // Needed since many other plugins still rely on oldies like $.browser
  38. $this->add_linked_stylesheet('../css/ui-lightness/jquery-ui-1.10.3.custom.min.css');
  39. $this->add_linked_script('../js/jquery-ui-1.10.3.custom.min.js');
  40. $this->add_linked_script("../js/hovertip.js");
  41. // table sorting
  42. $this->add_linked_script("../js/jquery.tablesorter.js");
  43. $this->add_linked_script("../js/jquery.tablesorter.pager.js");
  44. $this->add_linked_script("../js/jquery.tablehover.js");
  45. $this->add_linked_script('../js/field_sorter.js');
  46. $this->add_linked_script('../js/datatable.js');
  47. $this->add_linked_script("../js/jquery.positionBy.js");
  48. $this->add_linked_script("../js/jquery.popupmenu.js");
  49. $this->add_ready_script(
  50. <<< EOF
  51. //add new widget called TruncatedList to properly display truncated lists when they are sorted
  52. $.tablesorter.addWidget({
  53. // give the widget a id
  54. id: "truncatedList",
  55. // format is called when the on init and when a sorting has finished
  56. format: function(table)
  57. {
  58. // Check if there is a "truncated" line
  59. this.truncatedList = false;
  60. if ($("tr td.truncated",table).length > 0)
  61. {
  62. this.truncatedList = true;
  63. }
  64. if (this.truncatedList)
  65. {
  66. $("tr td",table).removeClass('truncated');
  67. $("tr:last td",table).addClass('truncated');
  68. }
  69. }
  70. });
  71. $.tablesorter.addWidget({
  72. // give the widget a id
  73. id: "myZebra",
  74. // format is called when the on init and when a sorting has finished
  75. format: function(table)
  76. {
  77. // Replace the 'red even' lines by 'red_even' since most browser do not support 2 classes selector in CSS, etc..
  78. $("tbody tr:even",table).addClass('even');
  79. $("tbody tr.red:even",table).removeClass('red').removeClass('even').addClass('red_even');
  80. $("tbody tr.orange:even",table).removeClass('orange').removeClass('even').addClass('orange_even');
  81. $("tbody tr.green:even",table).removeClass('green').removeClass('even').addClass('green_even');
  82. // In case we sort again the table, we need to remove the added 'even' classes on odd rows
  83. $("tbody tr:odd",table).removeClass('even');
  84. $("tbody tr.red_even:odd",table).removeClass('even').removeClass('red_even').addClass('red');
  85. $("tbody tr.orange_even:odd",table).removeClass('even').removeClass('orange_even').addClass('orange');
  86. $("tbody tr.green_even:odd",table).removeClass('even').removeClass('green_even').addClass('green');
  87. }
  88. });
  89. $("table.listResults").tableHover(); // hover tables
  90. EOF
  91. );
  92. $this->add_linked_stylesheet("../css/light-grey.css");
  93. $this->m_sRootUrl = $this->GetAbsoluteUrlAppRoot();
  94. $sAbsURLAppRoot = addslashes($this->m_sRootUrl);
  95. $sAbsURLModulesRoot = addslashes($this->GetAbsoluteUrlModulesRoot());
  96. $sAppContext = addslashes($this->GetApplicationContext());
  97. $this->add_script(
  98. <<<EOF
  99. function GetAbsoluteUrlAppRoot()
  100. {
  101. return '$sAbsURLAppRoot';
  102. }
  103. function GetAbsoluteUrlModulesRoot()
  104. {
  105. return '$sAbsURLModulesRoot';
  106. }
  107. function AddAppContext(sURL)
  108. {
  109. var sContext = '$sAppContext';
  110. if (sContext.length > 0)
  111. {
  112. if (sURL.indexOf('?') == -1)
  113. {
  114. return sURL+'?'+sContext;
  115. }
  116. return sURL+'&'+sContext;
  117. }
  118. return sURL;
  119. }
  120. EOF
  121. );
  122. }
  123. public function SetRootUrl($sRootUrl)
  124. {
  125. $this->m_sRootUrl = $sRootUrl;
  126. }
  127. public function small_p($sText)
  128. {
  129. $this->add("<p style=\"font-size:smaller\">$sText</p>\n");
  130. }
  131. public function GetAbsoluteUrlAppRoot()
  132. {
  133. return utils::GetAbsoluteUrlAppRoot();
  134. }
  135. public function GetAbsoluteUrlModulesRoot()
  136. {
  137. return utils::GetAbsoluteUrlModulesRoot();
  138. }
  139. function GetApplicationContext()
  140. {
  141. $oAppContext = new ApplicationContext();
  142. return $oAppContext->GetForLink();
  143. }
  144. // By Rom, used by CSVImport and Advanced search
  145. public function MakeClassesSelect($sName, $sDefaultValue, $iWidthPx, $iActionCode = null)
  146. {
  147. // $aTopLevelClasses = array('bizService', 'bizContact', 'logInfra', 'bizDocument');
  148. // These are classes wich root class is cmdbAbstractObject !
  149. $this->add("<select id=\"select_$sName\" name=\"$sName\">");
  150. $aValidClasses = array();
  151. foreach(MetaModel::GetClasses('bizmodel') as $sClassName)
  152. {
  153. if (is_null($iActionCode) || UserRights::IsActionAllowed($sClassName, $iActionCode))
  154. {
  155. $sSelected = ($sClassName == $sDefaultValue) ? " SELECTED" : "";
  156. $sDescription = MetaModel::GetClassDescription($sClassName);
  157. $sDisplayName = MetaModel::GetName($sClassName);
  158. $aValidClasses[$sDisplayName] = "<option style=\"width: ".$iWidthPx." px;\" title=\"$sDescription\" value=\"$sClassName\"$sSelected>$sDisplayName</option>";
  159. }
  160. }
  161. ksort($aValidClasses);
  162. $this->add(implode("\n", $aValidClasses));
  163. $this->add("</select>");
  164. }
  165. // By Rom, used by Advanced search
  166. public function add_select($aChoices, $sName, $sDefaultValue, $iWidthPx)
  167. {
  168. $this->add("<select id=\"select_$sName\" name=\"$sName\">");
  169. foreach($aChoices as $sKey => $sValue)
  170. {
  171. $sSelected = ($sKey == $sDefaultValue) ? " SELECTED" : "";
  172. $this->add("<option style=\"width: ".$iWidthPx." px;\" value=\"".htmlspecialchars($sKey)."\"$sSelected>".htmlentities($sValue, ENT_QUOTES, 'UTF-8')."</option>");
  173. }
  174. $this->add("</select>");
  175. }
  176. public function add_ready_script($sScript)
  177. {
  178. $this->m_aReadyScripts[] = $sScript;
  179. }
  180. /**
  181. * Outputs (via some echo) the complete HTML page by assembling all its elements
  182. */
  183. public function output()
  184. {
  185. //$this->set_base($this->m_sRootUrl.'pages/');
  186. if (count($this->m_aReadyScripts)>0)
  187. {
  188. $this->add_script("\$(document).ready(function() {\n".implode("\n", $this->m_aReadyScripts)."\n});");
  189. }
  190. parent::output();
  191. }
  192. }
  193. ?>