nicewebpage.class.inc.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. // Copyright (C) 2010-2015 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-2015 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, $bPrintable = false)
  33. {
  34. parent::__construct($s_title, $bPrintable);
  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_saas("css/light-grey.scss");
  93. $this->m_sRootUrl = $this->GetAbsoluteUrlAppRoot();
  94. $sAbsURLAppRoot = addslashes($this->m_sRootUrl);
  95. $sAbsURLModulesRoot = addslashes($this->GetAbsoluteUrlModulesRoot());
  96. $sEnvironment = addslashes(utils::GetCurrentEnvironment());
  97. $sAppContext = addslashes($this->GetApplicationContext());
  98. $this->add_script(
  99. <<<EOF
  100. function GetAbsoluteUrlAppRoot()
  101. {
  102. return '$sAbsURLAppRoot';
  103. }
  104. function GetAbsoluteUrlModulesRoot()
  105. {
  106. return '$sAbsURLModulesRoot';
  107. }
  108. function GetAbsoluteUrlModulePage(sModule, sPage, aArguments)
  109. {
  110. // aArguments is optional, it default to an empty hash
  111. aArguments = typeof aArguments !== 'undefined' ? aArguments : {};
  112. var sUrl = '$sAbsURLAppRoot'+'pages/exec.php?exec_module='+sModule+'&exec_page='+sPage+'&exec_env='+'$sEnvironment';
  113. for (var sArgName in aArguments)
  114. {
  115. if (aArguments.hasOwnProperty(sArgName))
  116. {
  117. sUrl = sUrl + '&'+sArgName+'='+aArguments[sArgname];
  118. }
  119. }
  120. return sUrl;
  121. }
  122. function AddAppContext(sURL)
  123. {
  124. var sContext = '$sAppContext';
  125. if (sContext.length > 0)
  126. {
  127. if (sURL.indexOf('?') == -1)
  128. {
  129. return sURL+'?'+sContext;
  130. }
  131. return sURL+'&'+sContext;
  132. }
  133. return sURL;
  134. }
  135. EOF
  136. );
  137. }
  138. public function SetRootUrl($sRootUrl)
  139. {
  140. $this->m_sRootUrl = $sRootUrl;
  141. }
  142. public function small_p($sText)
  143. {
  144. $this->add("<p style=\"font-size:smaller\">$sText</p>\n");
  145. }
  146. public function GetAbsoluteUrlAppRoot()
  147. {
  148. return utils::GetAbsoluteUrlAppRoot();
  149. }
  150. public function GetAbsoluteUrlModulesRoot()
  151. {
  152. return utils::GetAbsoluteUrlModulesRoot();
  153. }
  154. function GetApplicationContext()
  155. {
  156. $oAppContext = new ApplicationContext();
  157. return $oAppContext->GetForLink();
  158. }
  159. // By Rom, used by CSVImport and Advanced search
  160. public function MakeClassesSelect($sName, $sDefaultValue, $iWidthPx, $iActionCode = null)
  161. {
  162. // $aTopLevelClasses = array('bizService', 'bizContact', 'logInfra', 'bizDocument');
  163. // These are classes wich root class is cmdbAbstractObject !
  164. $this->add("<select id=\"select_$sName\" name=\"$sName\">");
  165. $aValidClasses = array();
  166. foreach(MetaModel::GetClasses('bizmodel') as $sClassName)
  167. {
  168. if (is_null($iActionCode) || UserRights::IsActionAllowed($sClassName, $iActionCode))
  169. {
  170. $sSelected = ($sClassName == $sDefaultValue) ? " SELECTED" : "";
  171. $sDescription = MetaModel::GetClassDescription($sClassName);
  172. $sDisplayName = MetaModel::GetName($sClassName);
  173. $aValidClasses[$sDisplayName] = "<option style=\"width: ".$iWidthPx." px;\" title=\"$sDescription\" value=\"$sClassName\"$sSelected>$sDisplayName</option>";
  174. }
  175. }
  176. ksort($aValidClasses);
  177. $this->add(implode("\n", $aValidClasses));
  178. $this->add("</select>");
  179. }
  180. // By Rom, used by Advanced search
  181. public function add_select($aChoices, $sName, $sDefaultValue, $iWidthPx)
  182. {
  183. $this->add("<select id=\"select_$sName\" name=\"$sName\">");
  184. foreach($aChoices as $sKey => $sValue)
  185. {
  186. $sSelected = ($sKey == $sDefaultValue) ? " SELECTED" : "";
  187. $this->add("<option style=\"width: ".$iWidthPx." px;\" value=\"".htmlspecialchars($sKey)."\"$sSelected>".htmlentities($sValue, ENT_QUOTES, 'UTF-8')."</option>");
  188. }
  189. $this->add("</select>");
  190. }
  191. public function add_ready_script($sScript)
  192. {
  193. $this->m_aReadyScripts[] = $sScript;
  194. }
  195. /**
  196. * Outputs (via some echo) the complete HTML page by assembling all its elements
  197. */
  198. public function output()
  199. {
  200. //$this->set_base($this->m_sRootUrl.'pages/');
  201. if (count($this->m_aReadyScripts)>0)
  202. {
  203. $this->add_script("\$(document).ready(function() {\n".implode("\n", $this->m_aReadyScripts)."\n});");
  204. }
  205. parent::output();
  206. }
  207. }
  208. ?>