nicewebpage.class.inc.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Class NiceWebPage
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  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_ready_script(
  45. <<< EOF
  46. //add new widget called TruncatedList to properly display truncated lists when they are sorted
  47. $.tablesorter.addWidget({
  48. // give the widget a id
  49. id: "truncatedList",
  50. // format is called when the on init and when a sorting has finished
  51. format: function(table)
  52. {
  53. // Check if there is a "truncated" line
  54. this.truncatedList = false;
  55. if ($("tr td.truncated",table).length > 0)
  56. {
  57. this.truncatedList = true;
  58. }
  59. if (this.truncatedList)
  60. {
  61. $("tr td",table).removeClass('truncated');
  62. $("tr:last td",table).addClass('truncated');
  63. }
  64. }
  65. });
  66. $.tablesorter.addWidget({
  67. // give the widget a id
  68. id: "myZebra",
  69. // format is called when the on init and when a sorting has finished
  70. format: function(table)
  71. {
  72. // Replace the 'red even' lines by 'red_even' since most browser do not support 2 classes selector in CSS, etc..
  73. $("tbody tr:even",table).addClass('even');
  74. $("tbody tr.red:even",table).removeClass('red').removeClass('even').addClass('red_even');
  75. $("tbody tr.orange:even",table).removeClass('orange').removeClass('even').addClass('orange_even');
  76. $("tbody tr.green:even",table).removeClass('green').removeClass('even').addClass('green_even');
  77. // In case we sort again the table, we need to remove the added 'even' classes on odd rows
  78. $("tbody tr:odd",table).removeClass('even');
  79. $("tbody tr.red_even:odd",table).removeClass('even').removeClass('red_even').addClass('red');
  80. $("tbody tr.orange_even:odd",table).removeClass('even').removeClass('orange_even').addClass('orange');
  81. $("tbody tr.green_even:odd",table).removeClass('even').removeClass('green_even').addClass('green');
  82. }
  83. });
  84. $("table.listResults").tableHover(); // hover tables
  85. EOF
  86. );
  87. $this->add_linked_stylesheet("../css/light-grey.css");
  88. $this->m_sRootUrl = $this->GetAbsoluteUrlAppRoot();
  89. $sAbsURLAppRoot = addslashes($this->m_sRootUrl);
  90. $sAbsURLModulesRoot = addslashes($this->GetAbsoluteUrlModulesRoot());
  91. $sAppContext = addslashes($this->GetApplicationContext());
  92. $this->add_script(
  93. <<<EOF
  94. function GetAbsoluteUrlAppRoot()
  95. {
  96. return '$sAbsURLAppRoot';
  97. }
  98. function GetAbsoluteUrlModulesRoot()
  99. {
  100. return '$sAbsURLModulesRoot';
  101. }
  102. function AddAppContext(sURL)
  103. {
  104. var sContext = '$sAppContext';
  105. if (sContext.length > 0)
  106. {
  107. if (sURL.indexOf('?') == -1)
  108. {
  109. return sURL+'?'+sContext;
  110. }
  111. return sURL+'&'+sContext;
  112. }
  113. return sURL;
  114. }
  115. EOF
  116. );
  117. }
  118. public function SetRootUrl($sRootUrl)
  119. {
  120. $this->m_sRootUrl = $sRootUrl;
  121. }
  122. public function small_p($sText)
  123. {
  124. $this->add("<p style=\"font-size:smaller\">$sText</p>\n");
  125. }
  126. public function GetAbsoluteUrlAppRoot()
  127. {
  128. return utils::GetAbsoluteUrlAppRoot();
  129. }
  130. public function GetAbsoluteUrlModulesRoot()
  131. {
  132. return utils::GetAbsoluteUrlModulesRoot();
  133. }
  134. function GetApplicationContext()
  135. {
  136. $oAppContext = new ApplicationContext();
  137. return $oAppContext->GetForLink();
  138. }
  139. // By Rom, used by CSVImport and Advanced search
  140. public function MakeClassesSelect($sName, $sDefaultValue, $iWidthPx, $iActionCode = null)
  141. {
  142. // $aTopLevelClasses = array('bizService', 'bizContact', 'logInfra', 'bizDocument');
  143. // These are classes wich root class is cmdbAbstractObject !
  144. $this->add("<select id=\"select_$sName\" name=\"$sName\">");
  145. $aValidClasses = array();
  146. foreach(MetaModel::GetClasses('bizmodel') as $sClassName)
  147. {
  148. if (is_null($iActionCode) || UserRights::IsActionAllowed($sClassName, $iActionCode))
  149. {
  150. $sSelected = ($sClassName == $sDefaultValue) ? " SELECTED" : "";
  151. $sDescription = MetaModel::GetClassDescription($sClassName);
  152. $sDisplayName = MetaModel::GetName($sClassName);
  153. $aValidClasses[$sDisplayName] = "<option style=\"width: ".$iWidthPx." px;\" title=\"$sDescription\" value=\"$sClassName\"$sSelected>$sDisplayName</option>";
  154. }
  155. }
  156. ksort($aValidClasses);
  157. $this->add(implode("\n", $aValidClasses));
  158. $this->add("</select>");
  159. }
  160. // By Rom, used by Advanced search
  161. public function add_select($aChoices, $sName, $sDefaultValue, $iWidthPx)
  162. {
  163. $this->add("<select id=\"select_$sName\" name=\"$sName\">");
  164. foreach($aChoices as $sKey => $sValue)
  165. {
  166. $sSelected = ($sKey == $sDefaultValue) ? " SELECTED" : "";
  167. $this->add("<option style=\"width: ".$iWidthPx." px;\" value=\"".htmlspecialchars($sKey)."\"$sSelected>".htmlentities($sValue, ENT_QUOTES, 'UTF-8')."</option>");
  168. }
  169. $this->add("</select>");
  170. }
  171. public function add_ready_script($sScript)
  172. {
  173. $this->m_aReadyScripts[] = $sScript;
  174. }
  175. /**
  176. * Outputs (via some echo) the complete HTML page by assembling all its elements
  177. */
  178. public function output()
  179. {
  180. $this->set_base($this->m_sRootUrl.'pages/');
  181. if (count($this->m_aReadyScripts)>0)
  182. {
  183. $this->add_script("\$(document).ready(function() {\n".implode("\n", $this->m_aReadyScripts)."\n});");
  184. }
  185. parent::output();
  186. }
  187. }
  188. ?>