portalwebpage.class.inc.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 PortalWebPage
  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("../application/nicewebpage.class.inc.php");
  25. require_once("../application/applicationcontext.class.inc.php");
  26. require_once("../application/user.preferences.class.inc.php");
  27. /**
  28. * Web page with some associated CSS and scripts (jquery) for a fancier display
  29. * of the Portal web page
  30. */
  31. class PortalWebPage extends NiceWebPage
  32. {
  33. /**
  34. * Portal menu
  35. */
  36. protected $m_aMenuButtons;
  37. public function __construct($sTitle)
  38. {
  39. $this->m_aMenuButtons = array();
  40. parent::__construct($sTitle);
  41. $this->add_header("Content-type: text/html; charset=utf-8");
  42. $this->add_header("Cache-control: no-cache");
  43. $this->add_linked_stylesheet("../css/jquery.treeview.css");
  44. $this->add_linked_stylesheet("../css/jquery.autocomplete.css");
  45. $this->add_linked_stylesheet("../portal/portal.css");
  46. $this->add_linked_script('../js/jquery.layout.min.js');
  47. $this->add_linked_script('../js/jquery.ba-bbq.min.js');
  48. $this->add_linked_script("../js/jquery.tablehover.js");
  49. $this->add_linked_script("../js/jquery.treeview.js");
  50. $this->add_linked_script("../js/jquery.autocomplete.js");
  51. $this->add_linked_script("../js/jquery.bgiframe.js");
  52. $this->add_linked_script("../js/jquery.positionBy.js");
  53. $this->add_linked_script("../js/jquery.popupmenu.js");
  54. $this->add_linked_script("../js/date.js");
  55. $this->add_linked_script("../js/jquery.tablesorter.min.js");
  56. $this->add_linked_script("../js/jquery.blockUI.js");
  57. $this->add_linked_script("../js/utils.js");
  58. $this->add_linked_script("../js/forms-json-utils.js");
  59. $this->add_linked_script("../js/swfobject.js");
  60. $this->add_ready_script(
  61. <<<EOF
  62. try
  63. {
  64. //add new widget called TruncatedList to properly display truncated lists when they are sorted
  65. $.tablesorter.addWidget({
  66. // give the widget a id
  67. id: "truncatedList",
  68. // format is called when the on init and when a sorting has finished
  69. format: function(table)
  70. {
  71. // Check if there is a "truncated" line
  72. this.truncatedList = false;
  73. if ($("tr td.truncated",table).length > 0)
  74. {
  75. this.truncatedList = true;
  76. }
  77. if (this.truncatedList)
  78. {
  79. $("tr td",table).removeClass('truncated');
  80. $("tr:last td",table).addClass('truncated');
  81. }
  82. }
  83. });
  84. $.tablesorter.addWidget({
  85. // give the widget a id
  86. id: "myZebra",
  87. // format is called when the on init and when a sorting has finished
  88. format: function(table)
  89. {
  90. // Replace the 'red even' lines by 'red_even' since most browser do not support 2 classes selector in CSS, etc..
  91. $("tbody tr:even",table).addClass('even');
  92. $("tbody tr.red:even",table).removeClass('red').removeClass('even').addClass('red_even');
  93. $("tbody tr.orange:even",table).removeClass('orange').removeClass('even').addClass('orange_even');
  94. $("tbody tr.green:even",table).removeClass('green').removeClass('even').addClass('green_even');
  95. }
  96. });
  97. $("table.listResults").tableHover(); // hover tables
  98. $(".listResults").tablesorter( { widgets: ['myZebra', 'truncatedList']} ); // sortable and zebra tables
  99. $(".date-pick").datepicker({
  100. showOn: 'button',
  101. buttonImage: '../images/calendar.png',
  102. buttonImageOnly: true,
  103. dateFormat: 'yy-mm-dd',
  104. constrainInput: false,
  105. changeMonth: true,
  106. changeYear: true
  107. });
  108. $('.resizable').resizable(); // Make resizable everything that claims to be resizable !
  109. }
  110. catch(err)
  111. {
  112. // Do something with the error !
  113. alert(err);
  114. }
  115. EOF
  116. );
  117. $this->add_script(
  118. <<<EOF
  119. function CheckSelection(sMessage)
  120. {
  121. var bResult = ($('input:checked').length > 0);
  122. if (!bResult)
  123. {
  124. alert(sMessage);
  125. }
  126. return bResult;
  127. }
  128. function GoBack()
  129. {
  130. var form = $('#request_form');
  131. var step = $('input[name=step]');
  132. form.unbind('submit'); // De-activate validation
  133. step.val(step.val() -2); // To go Back one step: next step is x, current step is x-1, previous step is x-2
  134. form.submit(); // Go
  135. }
  136. EOF
  137. );
  138. }
  139. /**
  140. * Add a button to the portal's main menu
  141. */
  142. public function AddMenuButton($sId, $sLabel, $sHyperlink)
  143. {
  144. $this->m_aMenuButtons[] = array('id' => $sId, 'label' => $sLabel, 'hyperlink' => $sHyperlink);
  145. }
  146. public function output()
  147. {
  148. $this->AddMenuButton('logoff', 'Portal:Disconnect', '../pages/logoff.php?portal=1'); // This menu is always present and is the last one
  149. $sMenu = ' <div id="banner"><div id="portal_menu"><div id="logo"></div>';
  150. foreach($this->m_aMenuButtons as $aMenuItem)
  151. {
  152. $sMenu .= "<a class=\"button\" id=\"{$aMenuItem['id']}\" href=\"{$aMenuItem['hyperlink']}\"><span>".Dict::S($aMenuItem['label'])."</span></a>";
  153. }
  154. $this->s_content = '<div id="portal">'.$sMenu.'<div id="content">'.$this->s_content.'</div></div>';
  155. parent::output();
  156. }
  157. }
  158. ?>