/** * Class NiceWebPage * * @copyright Copyright (C) 2010-2016 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 */ require_once(APPROOT."/application/webpage.class.inc.php"); /** * Web page with some associated CSS and scripts (jquery) for a fancier display */ class NiceWebPage extends WebPage { var $m_aReadyScripts; var $m_sRootUrl; public function __construct($s_title, $bPrintable = false) { parent::__construct($s_title, $bPrintable); $this->m_aReadyScripts = array(); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery-3.3.1.min.js'); if(utils::IsDevelopmentEnvironment()) // Needed since many other plugins still rely on oldies like $.browser { $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery-migrate-3.0.1.dev.js'); } else { $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery-migrate-3.0.1.prod.min.js'); } $this->add_linked_stylesheet(utils::GetAbsoluteUrlAppRoot().'css/ui-lightness/jquery-ui-1.11.4.custom.css'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery-ui-1.11.4.custom.min.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/utils.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/hovertip.js'); // table sorting $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.tablesorter.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.tablesorter.pager.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.tablehover.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/table-selectable-lines.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/field_sorter.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/datatable.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.positionBy.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.popupmenu.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/searchformforeignkeys.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/latinise/latinise.min.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_handler.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_handler_history.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_criteria.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_criteria_raw.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_criteria_string.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_criteria_external_field.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_criteria_numeric.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_criteria_enum.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_criteria_tag_set.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_criteria_external_key.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_criteria_hierarchical_key.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_criteria_date_abstract.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_criteria_date.js'); $this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/search/search_form_criteria_date_time.js'); $this->add_dict_entries('UI:Combo'); $this->add_ready_script( <<< EOF //add new widget called TruncatedList to properly display truncated lists when they are sorted $.tablesorter.addWidget({ // give the widget a id id: "truncatedList", // format is called when the on init and when a sorting has finished format: function(table) { // Check if there is a "truncated" line this.truncatedList = false; if ($("tr td.truncated",table).length > 0) { this.truncatedList = true; } if (this.truncatedList) { $("tr td",table).removeClass('truncated'); $("tr:last td",table).addClass('truncated'); } } }); $.tablesorter.addWidget({ // give the widget a id id: "myZebra", // format is called when the on init and when a sorting has finished format: function(table) { // Replace the 'red even' lines by 'red_even' since most browser do not support 2 classes selector in CSS, etc.. $("tbody tr:even",table).addClass('even'); $("tbody tr.red:even",table).removeClass('red').removeClass('even').addClass('red_even'); $("tbody tr.orange:even",table).removeClass('orange').removeClass('even').addClass('orange_even'); $("tbody tr.green:even",table).removeClass('green').removeClass('even').addClass('green_even'); // In case we sort again the table, we need to remove the added 'even' classes on odd rows $("tbody tr:odd",table).removeClass('even'); $("tbody tr.red_even:odd",table).removeClass('even').removeClass('red_even').addClass('red'); $("tbody tr.orange_even:odd",table).removeClass('even').removeClass('orange_even').addClass('orange'); $("tbody tr.green_even:odd",table).removeClass('even').removeClass('green_even').addClass('green'); } }); $("table.listResults").tableHover(); // hover tables EOF ); $this->add_saas("css/light-grey.scss"); $this->m_sRootUrl = $this->GetAbsoluteUrlAppRoot(); $sAbsURLAppRoot = addslashes($this->m_sRootUrl); $sAbsURLModulesRoot = addslashes($this->GetAbsoluteUrlModulesRoot()); $sEnvironment = addslashes(utils::GetCurrentEnvironment()); $sAppContext = addslashes($this->GetApplicationContext()); $this->add_script( << 0) { if (sURL.indexOf('?') == -1) { return sURL+'?'+sContext; } return sURL+'&'+sContext; } return sURL; } EOF ); } public function SetRootUrl($sRootUrl) { $this->m_sRootUrl = $sRootUrl; } public function small_p($sText) { $this->add("

$sText

\n"); } public function GetAbsoluteUrlAppRoot() { return utils::GetAbsoluteUrlAppRoot(); } public function GetAbsoluteUrlModulesRoot() { return utils::GetAbsoluteUrlModulesRoot(); } function GetApplicationContext() { $oAppContext = new ApplicationContext(); return $oAppContext->GetForLink(); } // By Rom, used by CSVImport and Advanced search public function MakeClassesSelect($sName, $sDefaultValue, $iWidthPx, $iActionCode = null) { // $aTopLevelClasses = array('bizService', 'bizContact', 'logInfra', 'bizDocument'); // These are classes wich root class is cmdbAbstractObject ! $this->add(""); } // By Rom, used by Advanced search public function add_select($aChoices, $sName, $sDefaultValue, $iWidthPx) { $this->add(""); } public function add_ready_script($sScript) { $this->m_aReadyScripts[] = $sScript; } /** * Outputs (via some echo) the complete HTML page by assembling all its elements */ public function output() { //$this->set_base($this->m_sRootUrl.'pages/'); if (count($this->m_aReadyScripts)>0) { $this->add_script("\$(document).ready(function() {\n".implode("\n", $this->m_aReadyScripts)."\n});"); } parent::output(); } } ?>