nicewebpage.class.inc.php 6.9 KB

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