N°4813 - Remove DataTable class and file

This commit is contained in:
Anne-Cath
2025-07-30 15:29:15 +02:00
parent c9f88a16ef
commit 4d794fe656
7 changed files with 0 additions and 3239 deletions

View File

@@ -1,880 +0,0 @@
<?php
use Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableSettings;
use Combodo\iTop\Application\WebPage\WebPage;
use Combodo\iTop\Renderer\Console\ConsoleBlockRenderer;
/**
* Copyright (C) 2013-2024 Combodo SAS
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*
* @deprecated 3.0.0 use Combodo\iTop\Application\UI\Base\Component\DataTable\Datatable
*/
class DataTable
{
protected $iListId; // Unique ID inside the web page
/** @var string */
private $sDatatableContainerId;
protected $sTableId; // identifier for saving the settings (combined with the class aliases)
protected $oSet; // The set of objects to display
protected $aClassAliases; // The aliases (alias => class) inside the set
protected $iNbObjects; // Total number of objects in the set
protected $bUseCustomSettings; // Whether or not the current display uses custom settings
protected $oDefaultSettings; // the default settings for displaying such a list
protected $bShowObsoleteData;
/**
* @param string $iListId Unique ID for this div/table in the page
* @param DBObjectSet $oSet The set of data to display
* @param array$aClassAliases The list of classes/aliases to be displayed in this set $sAlias => $sClassName
* @param string $sTableId A string (or null) identifying this table in order to persist its settings
*
* @throws \CoreException
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
*/
public function __construct($iListId, $oSet, $aClassAliases, $sTableId = null)
{
DeprecatedCallsLog::NotifyDeprecatedPhpMethod('use Combodo\iTop\Application\UI\Base\Component\DataTable\Datatable');
$this->iListId = utils::GetSafeId($iListId); // Make a "safe" ID for jQuery
$this->sDatatableContainerId = 'datatable_'.utils::GetSafeId($iListId);
$this->oSet = $oSet;
$this->aClassAliases = $aClassAliases;
$this->sTableId = $sTableId;
$this->iNbObjects = $oSet->Count();
$this->bUseCustomSettings = false;
$this->oDefaultSettings = null;
$this->bShowObsoleteData = $oSet->GetShowObsoleteData();
}
/**
* @param WebPage $oPage
* @param DataTableSettings $oSettings
* @param $bActionsMenu
* @param $sSelectMode
* @param $bViewLink
* @param $aExtraParams
*
* @return string
* @throws \CoreException
* @throws \MySQLException
*/
public function Display(WebPage $oPage, DataTableSettings $oSettings, $bActionsMenu, $sSelectMode, $bViewLink, $aExtraParams)
{
$this->oDefaultSettings = $oSettings;
// Identified tables can have their own specific settings
$oCustomSettings = DataTableSettings::GetTableSettings($this->aClassAliases, $this->sTableId);
if ($oCustomSettings != null)
{
// Custom settings overload the default ones
$this->bUseCustomSettings = true;
if ($this->oDefaultSettings->iDefaultPageSize == 0)
{
$oCustomSettings->iDefaultPageSize = 0;
}
}
else
{
$oCustomSettings = $oSettings;
}
if ($oCustomSettings->iDefaultPageSize > 0)
{
$this->oSet->SetLimit($oCustomSettings->iDefaultPageSize);
}
$this->oSet->SetOrderBy($oCustomSettings->GetSortOrder());
// Load only the requested columns
$aColumnsToLoad = array();
foreach($oCustomSettings->aColumns as $sAlias => $aColumnsInfo)
{
foreach($aColumnsInfo as $sAttCode => $aData)
{
if ($sAttCode != '_key_')
{
if ($aData['checked'])
{
$aColumnsToLoad[$sAlias][] = $sAttCode;
}
else
{
// See if this column is a must to load
$sClass = $this->aClassAliases[$sAlias];
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
if ($oAttDef->AlwaysLoadInTables()) {
$aColumnsToLoad[$sAlias][] = $sAttCode;
}
}
}
}
}
$this->oSet->OptimizeColumnLoad($aColumnsToLoad);
$bToolkitMenu = true;
if (isset($aExtraParams['toolkit_menu']))
{
$bToolkitMenu = (bool) $aExtraParams['toolkit_menu'];
}
if (UserRights::IsPortalUser())
{
// Portal users have a limited access to data, for now they can only see what's configured for them
$bToolkitMenu = false;
}
return $this->GetAsHTML($oPage, $oCustomSettings->iDefaultPageSize, $oCustomSettings->iDefaultPageSize, 0, $oCustomSettings->aColumns, $bActionsMenu, $bToolkitMenu, $sSelectMode, $bViewLink, $aExtraParams);
}
/**
* @param WebPage $oPage
* @param $iPageSize
* @param $iDefaultPageSize
* @param $iPageIndex
* @param $aColumns
* @param $bActionsMenu
* @param $bToolkitMenu
* @param $sSelectMode
* @param $bViewLink
* @param $aExtraParams
*
* @return string
* @throws \ArchivedObjectException
* @throws \CoreException
*/
public function GetAsHTML(WebPage $oPage, $iPageSize, $iDefaultPageSize, $iPageIndex, $aColumns, $bActionsMenu, $bToolkitMenu, $sSelectMode, $bViewLink, $aExtraParams)
{
$sObjectsCount = $this->GetObjectCount($oPage, $sSelectMode);
$sPager = $this->GetPager($oPage, $iPageSize, $iDefaultPageSize, $iPageIndex);
$sActionsMenu = '';
$sToolkitMenu = '';
if ($bActionsMenu) {
$sActionsMenu = $this->GetActionsMenu($oPage, $aExtraParams);
}
// if ($bToolkitMenu)
// {
// $sToolkitMenu = $this->GetToolkitMenu($oPage, $aExtraParams);
// }
$sDataTable = $this->GetHTMLTable($oPage, $aColumns, $sSelectMode, $iPageSize, $bViewLink, $aExtraParams);
$sConfigDlg = $this->GetTableConfigDlg($oPage, $aColumns, $bViewLink, $iDefaultPageSize);
$sHtml = "<table id=\"{$this->sDatatableContainerId}\" class=\"datatable\">";
$sHtml .= "<tr><td>";
$sHtml .= "<table style=\"width:100%;\">";
$sHtml .= "<tr><td class=\"pagination_container\">$sObjectsCount</td><td class=\"menucontainer\">$sToolkitMenu $sActionsMenu</td></tr>";
$sHtml .= "<tr>$sPager</tr>";
$sHtml .= "</table>";
$sHtml .= "</td></tr>";
$sHtml .= "<tr><td class=\"datacontents\">$sDataTable</td></tr>";
$sHtml .= "</table>\n";
$oPage->add_at_the_end($sConfigDlg);
$aExtraParams['show_obsolete_data'] = $this->bShowObsoleteData;
$aOptions = array(
'sPersistentId' => '',
'sFilter' => $this->oSet->GetFilter()->serialize(),
'oColumns' => $aColumns,
'sSelectMode' => $sSelectMode,
'sViewLink' => ($bViewLink ? 'true' : 'false'),
'iNbObjects' => $this->iNbObjects,
'iDefaultPageSize' => $iDefaultPageSize,
'iPageSize' => $iPageSize,
'iPageIndex' => $iPageIndex,
'oClassAliases' => $this->aClassAliases,
'sTableId' => $this->sTableId,
'oExtraParams' => $aExtraParams,
'sRenderUrl' => utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php',
'oRenderParameters' => array('str' => ''), // Forces JSON to encode this as a object...
'oDefaultSettings' => array('str' => ''), // Forces JSON to encode this as a object...
'oLabels' => array('moveup' => Dict::S('UI:Button:MoveUp'), 'movedown' => Dict::S('UI:Button:MoveDown')),
);
if($this->oDefaultSettings != null)
{
$aOptions['oDefaultSettings'] = $this->GetAsHash($this->oDefaultSettings);
}
$sJSOptions = json_encode($aOptions);
$oPage->add_ready_script("$('#{$this->sDatatableContainerId}').datatable($sJSOptions);");
return $sHtml;
}
/**
* When refreshing the body of a paginated table, get the rows of the table (inside the TBODY)
* return string The HTML rows to insert inside the <tbody> node
*/
public function GetAsHTMLTableRows(WebPage $oPage, $iPageSize, $aColumns, $sSelectMode, $bViewLink, $aExtraParams)
{
if ($iPageSize < 1)
{
$iPageSize = -1; // convention: no pagination
}
$aAttribs = $this->GetHTMLTableConfig($aColumns, $sSelectMode, $bViewLink);
$aValues = $this->GetHTMLTableValues($aColumns, $sSelectMode, $iPageSize, $bViewLink, $aExtraParams);
$sHtml = '';
foreach($aValues as $aRow)
{
$sHtml .= $oPage->GetTableRow($aRow, $aAttribs);
}
return $sHtml;
}
/**
* @param WebPage $oPage
* @param $sSelectMode
*
* @return string
*/
protected function GetObjectCount(WebPage $oPage, $sSelectMode)
{
if (($sSelectMode == 'single') || ($sSelectMode == 'multiple'))
{
$sHtml = '<div class="pagination_objcount">'.Dict::Format('UI:Pagination:HeaderSelection', '<span id="total">'.$this->iNbObjects.'</span>', '<span class="selectedCount">0</span>').'</div>';
}
else
{
$sHtml = '<div class="pagination_objcount">'.Dict::Format('UI:Pagination:HeaderNoSelection', '<span id="total">'.$this->iNbObjects.'</span>').'</div>';
}
return $sHtml;
}
/**
* @param WebPage $oPage
* @param $iPageSize
* @param $iDefaultPageSize
* @param $iPageIndex
*
* @return string
*/
protected function GetPager(WebPage $oPage, $iPageSize, $iDefaultPageSize, $iPageIndex)
{
$sHtml = '';
if ($iPageSize < 1) // Display all
{
$sPagerStyle = 'style="display:none"'; // no limit: display the full table, so hide the "pager" UI
// WARNING: mPDF does not take the "display" style into account
// when applied to a <td> or a <table> tag, so make sure you apply this to a div
}
else
{
$sPagerStyle = '';
}
$sCombo = '<select class="pagesize">';
if($iPageSize < 1)
{
$sCombo .= "<option selected=\"selected\" value=\"-1\">".Dict::S('UI:Pagination:All')."</option>";
}
else
{
for($iPage = 1; $iPage < 5; $iPage++)
{
$iNbItems = $iPage * $iDefaultPageSize;
$sSelected = ($iNbItems == $iPageSize) ? 'selected="selected"' : '';
$sCombo .= "<option $sSelected value=\"$iNbItems\">$iNbItems</option>";
}
$sCombo .= "<option value=\"-1\">".Dict::S('UI:Pagination:All')."</option>";
}
$sCombo .= '</select>';
$sPages = Dict::S('UI:Pagination:PagesLabel');
$sPageSizeCombo = Dict::Format('UI:Pagination:PageSize', $sCombo);
$iNbPages = ($iPageSize < 1) ? 1 : ceil($this->iNbObjects / $iPageSize);
if ($iNbPages == 1)
{
// No need to display the pager
$sPagerStyle = 'style="display:none"';
}
$aPagesToDisplay = array();
for($idx = 0; $idx <= min(4, $iNbPages-1); $idx++)
{
if ($idx == 0)
{
$aPagesToDisplay[$idx] = '<span page="0" class="curr_page">1</span>';
}
else
{
$aPagesToDisplay[$idx] = "<span id=\"gotopage_$idx\" class=\"gotopage\" page=\"$idx\">".(1+$idx)."</span>";
}
}
$iLastPageIdx = $iNbPages - 1;
if (!isset($aPagesToDisplay[$iLastPageIdx]))
{
unset($aPagesToDisplay[$idx - 1]); // remove the last page added to make room for the very last page
$aPagesToDisplay[$iLastPageIdx] = "<span id=\"gotopage_$iLastPageIdx\" class=\"gotopage\" page=\"$iLastPageIdx\">... $iNbPages</span>";
}
$sPagesLinks = implode('', $aPagesToDisplay);
$sPagesList = '['.implode(',', array_keys($aPagesToDisplay)).']';
$sAppRootUrl = utils::GetAbsoluteUrlAppRoot();
$sSelectionMode = ($iNbPages == 1) ? '' : 'positive';
$sHtml =
<<<EOF
<td colspan="2">
<div $sPagerStyle>
<table id="pager{$this->iListId}" class="pager"><tr>
<td>$sPages</td>
<td><img src="{$sAppRootUrl}images/first.png" class="first"/>AAAA</td>
<td><img src="{$sAppRootUrl}images/prev.png" class="prev"/></td>
<td><span id="index">$sPagesLinks</span></td>
<td><img src="{$sAppRootUrl}images/next.png" class="next"/></td>
<td><img src="{$sAppRootUrl}images/last.png" class="last"/></td>
<td>$sPageSizeCombo</td>
<td><span id="loading">&nbsp;</span><input type="hidden" name="selectionMode" value="$sSelectionMode"></input>
</td>
</tr>
</table>
</div>
</td>
EOF;
return $sHtml;
}
/**
* @param WebPage $oPage
* @param $aExtraParams
*
* @return string
* @throws \ApplicationException
* @throws \ArchivedObjectException
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \DictExceptionMissingString
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
* @throws \OQLException
* @throws \ReflectionException
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
protected function GetActionsMenu(WebPage $oPage, $aExtraParams)
{
$oMenuBlock = new MenuBlock($this->oSet->GetFilter(), 'list');
$oBlock = $oMenuBlock->GetRenderContent($oPage, $aExtraParams, $this->iListId);
return ConsoleBlockRenderer::RenderBlockTemplateInPage($oPage, $oBlock);
}
/**
* @param WebPage $oPage
* @param $aExtraParams
*
* @return string
* @throws \Exception
*/
protected function GetToolkitMenu(WebPage $oPage, $aExtraParams)
{
if (!$oPage->IsPrintableVersion())
{
$sMenuTitle = Dict::S('UI:ConfigureThisList');
$sHtml = '<div class="itop_popup toolkit_menu" id="tk_'.$this->iListId.'"><ul><li aria-label="'.Dict::S('UI:Menu:Toolkit').'"><i class="fas fa-tools"></i><i class="fas fa-caret-down"></i><ul>';
$oMenuItem1 = new JSPopupMenuItem('iTop::ConfigureList', $sMenuTitle, "$('#datatable_dlg_".$this->iListId."').dialog('open');");
$aActions = array(
$oMenuItem1->GetUID() => $oMenuItem1->GetMenuItem(),
);
$this->oSet->Rewind();
utils::GetPopupMenuItems($oPage, iPopupMenuExtension::MENU_OBJLIST_TOOLKIT, $this->oSet, $aActions, $this->sTableId, $this->iListId);
$this->oSet->Rewind();
$sHtml .= $oPage->RenderPopupMenuItems($aActions);
}
else
{
$sHtml = '';
}
return $sHtml;
}
/**
* @param WebPage $oPage
* @param $aColumns
* @param $bViewLink
* @param $iDefaultPageSize
*
* @return string
*/
protected function GetTableConfigDlg(WebPage $oPage, $aColumns, $bViewLink, $iDefaultPageSize)
{
$sHtml = "<div id=\"datatable_dlg_{$this->iListId}\" style=\"display: none;\">";
$sHtml .= "<form onsubmit=\"return false\">";
$sChecked = ($this->bUseCustomSettings) ? '' : 'checked';
$sHtml .= "<p><input id=\"dtbl_dlg_settings_{$this->iListId}\" type=\"radio\" name=\"settings\" $sChecked value=\"defaults\"><label for=\"dtbl_dlg_settings_{$this->iListId}\">&nbsp;".Dict::S('UI:UseDefaultSettings').'</label></p>';
$sHtml .= "<fieldset>";
$sChecked = ($this->bUseCustomSettings) ? 'checked': '';
$sHtml .= "<legend class=\"transparent\"><input id=\"dtbl_dlg_specific_{$this->iListId}\" type=\"radio\" class=\"specific_settings\" name=\"settings\" $sChecked value=\"specific\"><label for=\"dtbl_dlg_specific_{$this->iListId}\">&nbsp;".Dict::S('UI:UseSpecificSettings')."</label></legend>";
$sHtml .= Dict::S('UI:ColumnsAndSortOrder').'<br/><ul class="sortable_field_list" id="sfl_'.$this->iListId.'"></ul>';
$sHtml .= '<p>'.Dict::Format('UI:Display_X_ItemsPerPage', '<input type="text" size="4" name="page_size" value="'.$iDefaultPageSize.'">').'</p>';
$sHtml .= "</fieldset>";
$sHtml .= "<fieldset>";
$sSaveChecked = ($this->sTableId != null) ? 'checked' : '';
$sCustomDisabled = ($this->sTableId == null) ? 'disabled="disabled" stay-disabled="true" ' : '';
$sCustomChecked = ($this->sTableId != null) ? 'checked' : '';
$sGenericChecked = ($this->sTableId == null) ? 'checked' : '';
$sHtml .= "<legend class=\"transparent\"><input id=\"dtbl_dlg_save_{$this->iListId}\" type=\"checkbox\" $sSaveChecked name=\"save_settings\"><label for=\"dtbl_dlg_save_{$this->iListId}\">&nbsp;".Dict::S('UI:UseSavetheSettings')."</label></legend>";
$sHtml .= "<p><input id=\"dtbl_dlg_this_list_{$this->iListId}\" type=\"radio\" name=\"scope\" $sCustomChecked $sCustomDisabled value=\"this_list\"><label for=\"dtbl_dlg_this_list_{$this->iListId}\">&nbsp;".Dict::S('UI:OnlyForThisList').'</label>&nbsp;&nbsp;&nbsp;&nbsp;';
$sHtml .= "<input id=\"dtbl_dlg_all_{$this->iListId}\" type=\"radio\" name=\"scope\" $sGenericChecked value=\"defaults\"><label for=\"dtbl_dlg_all_{$this->iListId}\">&nbsp;".Dict::S('UI:ForAllLists').'</label></p>';
$sHtml .= "</fieldset>";
$sHtml .= '<table style="width:100%"><tr><td style="text-align:center;">';
$sHtml .= '<button type="button" onclick="$(\'#'.$this->sDatatableContainerId.'\').datatable(\'onDlgCancel\'); $(\'#datatable_dlg_'.$this->iListId.'\').dialog(\'close\')">'.Dict::S('UI:Button:Cancel').'</button>';
$sHtml .= '</td><td style="text-align:center;">';
$sHtml .= '<button type="submit" onclick="$(\'#'.$this->sDatatableContainerId.'\').datatable(\'onDlgOk\');$(\'#datatable_dlg_'.$this->iListId.'\').dialog(\'close\');">'.Dict::S('UI:Button:Ok').'</button>';
$sHtml .= '</td></tr></table>';
$sHtml .= "</form>";
$sHtml .= "</div>";
$sDlgTitle = addslashes(Dict::S('UI:ListConfigurationTitle'));
$oPage->add_ready_script("$('#datatable_dlg_{$this->iListId}').dialog({autoOpen: false, title: '$sDlgTitle', width: 500, close: function() { $('#{$this->sDatatableContainerId}').datatable('onDlgCancel'); } });");
return $sHtml;
}
/**
* @param $oSetting
*
* @return array
*/
public function GetAsHash($oSetting)
{
$aSettings = array('iDefaultPageSize' => $oSetting->iDefaultPageSize, 'oColumns' => $oSetting->aColumns);
return $aSettings;
}
/**
* @param array $aColumns
* @param string $sSelectMode
* @param bool $bViewLink
*
* @return array
* @throws \CoreException
* @throws \DictExceptionMissingString
* @throws \Exception
*/
protected function GetHTMLTableConfig($aColumns, $sSelectMode, $bViewLink)
{
$aAttribs = array();
if ($sSelectMode == 'multiple')
{
$aAttribs['form::select'] = array(
'label' => "<input type=\"checkbox\" onClick=\"CheckAll('.selectList{$this->iListId}:not(:disabled)', this.checked);\" class=\"checkAll\"></input>",
'description' => Dict::S('UI:SelectAllToggle+'),
'metadata' => array(),
);
}
else if ($sSelectMode == 'single')
{
$aAttribs['form::select'] = array('label' => '', 'description' => '', 'metadata' => array());
}
foreach($this->aClassAliases as $sAlias => $sClassName)
{
foreach($aColumns[$sAlias] as $sAttCode => $aData)
{
if ($aData['checked'])
{
if ($sAttCode == '_key_')
{
$sAttLabel = MetaModel::GetName($sClassName);
$aAttribs['key_'.$sAlias] = array(
'label' => $sAttLabel,
'description' => '',
'metadata' => array(
'object_class' => $sClassName,
'attribute_label' => $sAttLabel,
),
);
}
else
{
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
$sAttDefClass = get_class($oAttDef);
$sAttLabel = MetaModel::GetLabel($sClassName, $sAttCode);
$aAttribs[$sAttCode.'_'.$sAlias] = array(
'label' => $sAttLabel,
'description' => $oAttDef->GetOrderByHint(),
'metadata' => array(
'object_class' => $sClassName,
'attribute_code' => $sAttCode,
'attribute_type' => $sAttDefClass,
'attribute_label' => $sAttLabel,
),
);
}
}
}
}
return $aAttribs;
}
/**
* @param $aColumns
* @param $sSelectMode
* @param $iPageSize
* @param $bViewLink
* @param $aExtraParams
*
* @return array
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
* @throws \Exception
*/
protected function GetHTMLTableValues($aColumns, $sSelectMode, $iPageSize, $bViewLink, $aExtraParams)
{
$bLocalize = true;
if (isset($aExtraParams['localize_values']))
{
$bLocalize = (bool) $aExtraParams['localize_values'];
}
$aValues = array();
$aAttDefsCache = array();
$this->oSet->Seek(0);
$iMaxObjects = $iPageSize;
while (($aObjects = $this->oSet->FetchAssoc()) && ($iMaxObjects != 0))
{
$bFirstObject = true;
$aRow = array();
foreach($this->aClassAliases as $sAlias => $sClassName)
{
if (is_object($aObjects[$sAlias]))
{
$sHilightClass = MetaModel::GetHilightClass($sClassName, $aObjects[$sAlias]);
if ($sHilightClass != '')
{
$aRow['@class'] = $sHilightClass;
}
if ((($sSelectMode == 'single') || ($sSelectMode == 'multiple')) && $bFirstObject)
{
if (array_key_exists('selection_enabled', $aExtraParams) && isset($aExtraParams['selection_enabled'][$aObjects[$sAlias]->GetKey()]))
{
$sDisabled = ($aExtraParams['selection_enabled'][$aObjects[$sAlias]->GetKey()]) ? '' : ' disabled="disabled"';
}
else
{
$sDisabled = '';
}
if ($sSelectMode == 'single')
{
$aRow['form::select'] = "<input type=\"radio\" $sDisabled class=\"selectList{$this->iListId}\" name=\"selectObject\" value=\"".$aObjects[$sAlias]->GetKey()."\"></input>";
}
else
{
$aRow['form::select'] = "<input type=\"checkbox\" $sDisabled class=\"selectList{$this->iListId}\" name=\"selectObject[]\" value=\"".$aObjects[$sAlias]->GetKey()."\"></input>";
}
}
foreach($aColumns[$sAlias] as $sAttCode => $aData)
{
if ($aData['checked'])
{
if ($sAttCode == '_key_')
{
$aRow['key_'.$sAlias] = array(
'value_raw' => $aObjects[$sAlias]->GetKey(),
'value_html' => $aObjects[$sAlias]->GetHyperLink(),
);
}
else
{
// Prepare att. def. classes cache to avoid retrieving AttDef for each row
if(!isset($aAttDefsCache[$sClassName][$sAttCode]))
{
$aAttDefClassesCache[$sClassName][$sAttCode] = get_class(MetaModel::GetAttributeDef($sClassName, $sAttCode));
}
// Only retrieve raw (stored) value for simple fields
$bExcludeRawValue = false;
foreach (cmdbAbstractObject::GetAttDefClassesToExcludeFromMarkupMetadataRawValue() as $sAttDefClassToExclude)
{
if (is_a($aAttDefClassesCache[$sClassName][$sAttCode], $sAttDefClassToExclude, true))
{
$bExcludeRawValue = true;
break;
}
}
if($bExcludeRawValue)
{
$aRow[$sAttCode.'_'.$sAlias] = $aObjects[$sAlias]->GetAsHTML($sAttCode, $bLocalize);
}
else
{
$aRow[$sAttCode.'_'.$sAlias] = array(
'value_raw' => $aObjects[$sAlias]->Get($sAttCode),
'value_html' => $aObjects[$sAlias]->GetAsHTML($sAttCode, $bLocalize),
);
}
}
}
}
}
else
{
foreach($aColumns[$sAlias] as $sAttCode => $aData)
{
if ($aData['checked'])
{
if ($sAttCode == '_key_')
{
$aRow['key_'.$sAlias] = '';
}
else
{
$aRow[$sAttCode.'_'.$sAlias] = '';
}
}
}
}
$bFirstObject = false;
}
$aValues[] = $aRow;
$iMaxObjects--;
}
return $aValues;
}
/**
* @param WebPage $oPage
* @param $aColumns
* @param $sSelectMode
* @param $iPageSize
* @param $bViewLink
* @param $aExtraParams
*
* @return string
* @throws \ArchivedObjectException
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \DictExceptionMissingString
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
* @throws \Exception
*/
public function GetHTMLTable(WebPage $oPage, $aColumns, $sSelectMode, $iPageSize, $bViewLink, $aExtraParams)
{
$iNbPages = ($iPageSize < 1) ? 1 : ceil($this->iNbObjects / $iPageSize);
if ($iPageSize < 1)
{
$iPageSize = -1; // convention: no pagination
}
$aAttribs = $this->GetHTMLTableConfig($aColumns, $sSelectMode, $bViewLink);
$aValues = $this->GetHTMLTableValues($aColumns, $sSelectMode, $iPageSize, $bViewLink, $aExtraParams);
$sHtml = '<table class="listContainer object-list">';
foreach($this->oSet->GetFilter()->GetInternalParams() as $sName => $sValue)
{
$aExtraParams['query_params'][$sName] = $sValue;
}
$aExtraParams['show_obsolete_data'] = $this->bShowObsoleteData;
$sHtml .= "<tr><td>";
$sHtml .= $oPage->GetTable($aAttribs, $aValues);
$sHtml .= '</td></tr>';
$sHtml .= '</table>';
$iCount = $this->iNbObjects;
$aArgs = $this->oSet->GetArgs();
$sExtraParams = addslashes(str_replace('"', "'", json_encode(array_merge($aExtraParams, $aArgs)))); // JSON encode, change the style of the quotes and escape them
$sSelectModeJS = '';
$sHeaders = '';
if (($sSelectMode == 'single') || ($sSelectMode == 'multiple'))
{
$sSelectModeJS = $sSelectMode;
$sHeaders = 'headers: { 0: {sorter: false}},';
}
$sDisplayKey = ($bViewLink) ? 'true' : 'false';
// Protect against duplicate elements in the Zlist
$aUniqueOrderedList = array();
foreach($this->aClassAliases as $sAlias => $sClassName)
{
foreach($aColumns[$sAlias] as $sAttCode => $aData)
{
if ($aData['checked'])
{
$aUniqueOrderedList[$sAttCode] = true;
}
}
}
$aUniqueOrderedList = array_keys($aUniqueOrderedList);
$sJSColumns = json_encode($aColumns);
$sJSClassAliases = json_encode($this->aClassAliases);
$sCssCount = isset($aExtraParams['cssCount']) ? ", cssCount: '{$aExtraParams['cssCount']}'" : '';
$this->oSet->ApplyParameters();
// Display the actual sort order of the table
$aRealSortOrder = $this->oSet->GetRealSortOrder();
$aDefaultSort = array();
$iColOffset = 0;
if (($sSelectMode == 'single') || ($sSelectMode == 'multiple'))
{
$iColOffset += 1;
}
if ($bViewLink)
{
// $iColOffset += 1;
}
foreach($aRealSortOrder as $sColCode => $bAscending)
{
$iPos = array_search($sColCode, $aUniqueOrderedList);
if ($iPos !== false)
{
$aDefaultSort[] = "[".($iColOffset+$iPos).",".($bAscending ? '0' : '1')."]";
}
else if (($iPos = array_search(preg_replace('/_friendlyname$/', '', $sColCode), $aUniqueOrderedList)) !== false)
{
// if sorted on the friendly name of an external key, then consider it sorted on the column that shows the links
$aDefaultSort[] = "[".($iColOffset+$iPos).",".($bAscending ? '0' : '1')."]";
}
else if($sColCode == 'friendlyname' && $bViewLink)
{
$aDefaultSort[] = "[".($iColOffset).",".($bAscending ? '0' : '1')."]";
}
}
$sFakeSortList = '';
if (count($aDefaultSort) > 0)
{
$sFakeSortList = '['.implode(',', $aDefaultSort).']';
}
$sOQL = addslashes($this->oSet->GetFilter()->serialize());
$oPage->add_ready_script(
<<<JS
var oTable = $('#{$this->sDatatableContainerId} table.listResults');
oTable.tableHover();
oTable
.tablesorter({ $sHeaders widgets: ['myZebra', 'truncatedList']})
.tablesorterPager({
container: $('#pager{$this->iListId}'),
totalRows:$iCount,
size: $iPageSize,
filter: '$sOQL',
extra_params: '$sExtraParams',
select_mode: '$sSelectModeJS',
displayKey: $sDisplayKey,
table_id: '{$this->sDatatableContainerId}',
columns: $sJSColumns,
class_aliases: $sJSClassAliases $sCssCount
});
JS
);
if ($sFakeSortList != '')
{
$oPage->add_ready_script("oTable.trigger(\"fakesorton\", [$sFakeSortList]);");
}
return $sHtml;
}
/**
* @param WebPage $oPage
* @param $iDefaultPageSize
* @param $iStart
*/
public function UpdatePager(WebPage $oPage, $iDefaultPageSize, $iStart)
{
$iPageSize = $iDefaultPageSize;
$iPageIndex = 0;
$sHtml = $this->GetPager($oPage, $iPageSize, $iDefaultPageSize, $iPageIndex);
$oPage->add_ready_script("$('#pager{$this->iListId}').html('".json_encode($sHtml)."');");
if ($iDefaultPageSize < 1)
{
$oPage->add_ready_script("$('#pager{$this->iListId}').parent().hide()");
}
else
{
$oPage->add_ready_script("$('#pager{$this->iListId}').parent().show()");
}
}
}
/**
* Simplified version of the data table with less "decoration" (and no paging)
* which is optimized for printing
*/
class PrintableDataTable extends DataTable
{
/**
* @param WebPage $oPage
* @param $iPageSize
* @param $iDefaultPageSize
* @param $iPageIndex
* @param $aColumns
* @param $bActionsMenu
* @param $bToolkitMenu
* @param $sSelectMode
* @param $bViewLink
* @param $aExtraParams
*
* @return string
* @throws \ArchivedObjectException
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \DictExceptionMissingString
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
*/
public function GetAsHTML(WebPage $oPage, $iPageSize, $iDefaultPageSize, $iPageIndex, $aColumns, $bActionsMenu, $bToolkitMenu, $sSelectMode, $bViewLink, $aExtraParams)
{
return $this->GetHTMLTable($oPage, $aColumns, $sSelectMode, -1, $bViewLink, $aExtraParams);
}
/**
* @param WebPage $oPage
* @param $aColumns
* @param $sSelectMode
* @param $iPageSize
* @param $bViewLink
* @param $aExtraParams
*
* @return string
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \DictExceptionMissingString
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
*/
public function GetHTMLTable(WebPage $oPage, $aColumns, $sSelectMode, $iPageSize, $bViewLink, $aExtraParams)
{
$iNbPages = ($iPageSize < 1) ? 1 : ceil($this->iNbObjects / $iPageSize);
if ($iPageSize < 1)
{
$iPageSize = -1; // convention: no pagination
}
$aAttribs = $this->GetHTMLTableConfig($aColumns, $sSelectMode, $bViewLink);
$aValues = $this->GetHTMLTableValues($aColumns, $sSelectMode, $iPageSize, $bViewLink, $aExtraParams);
$sHtml = $oPage->GetTable($aAttribs, $aValues);
return $sHtml;
}
}

View File

@@ -1,351 +0,0 @@
// jQuery UI style "widget" for selecting and sorting "fields"
//@deprecated
$(function()
{
// the widget definition, where "itop" is the namespace,
// "datatable" the widget name
$.widget( "itop.datatable",
{
// default options
options:
{
sPersistentId: '',
sFilter: '',
oColumns: {},
sSelectMode: '',
sViewLink: 'true',
iNbObjects: 0,
iDefaultPageSize: -1,
iPageSize: -1,
iPageIndex: 0,
oClassAliases: {},
sTableId : null,
oExtraParams: {},
sRenderUrl: 'index.php',
oRenderParameters: {},
oDefaultSettings: {},
oLabels: { moveup: 'Move Up', movedown: 'Move Down' }
},
// the constructor
_create: function()
{
this.aDlgStateParams = ['iDefaultPageSize', 'oColumns'];
this.element
.addClass('itop-datatable');
var me = this;
var sId = new String(this.element.attr('id'));
var sListId = sId.replace('datatable_', '');
var bViewLink = (this.options.sViewLink == 'true');
$('#sfl_'+sListId).fieldsorter({hasKeyColumn: bViewLink, labels: this.options.oLabels, fields: this.options.oColumns, onChange: function() { me._onSpecificSettings(); } });
$('#datatable_dlg_'+sListId).find('input[name=page_size]').on('click', function() { me._onSpecificSettings(); });
$('#datatable_dlg_'+sListId).find('input[name=save_settings]').on('click', function() { me._updateSaveScope(); });
this._updateSaveScope();
this._saveDlgState();
},
// called when created, and later when changing options
_refresh: function()
{
oParams = this.options.oRenderParameters;
oParams.operation = 'datatable';
oParams.filter = this.options.sFilter;
oParams.extra_param = JSON.stringify(this.options.oExtraParams);
oParams.start = 0;
oParams.end = this.options.iPageSize;
oParams.select_mode = this.options.sSelectMode;
oParams.display_key = this.options.sViewLink;
oParams.class_aliases = this.options.oClassAliases;
oParams.columns = this.options.oColumns;
var iSortCol = 0;
var aCurrentSort = [];
for(var k1 in oParams.columns) //Aliases
{
for(var k2 in oParams.columns[k1]) //Attribute codes
{
if (oParams.columns[k1][k2].sort != 'none')
{
oParams.sort_col = iSortCol;
oParams.sort_order = oParams.columns[k1][k2].sort;
aCurrentSort.push([iSortCol, (oParams.columns[k1][k2].sort == 'asc') ? 0 : 1]);
break; //TODO make this more generic, Sort on just one column for now
}
iSortCol++;
}
break; //TODO: DBObjectSet supports only sorting on the first alias of the set
}
var sId = new String(this.element.attr('id'));
var sListId = sId.replace('datatable_', '');
oParams.list_id = sListId;
var me = this;
this.element.block();
$.post(this.options.sRenderUrl, oParams, function(data) {
// Nasty workaround to clear the pager's state for paginated lists !!!
// See jquery.tablesorter.pager.js / saveParams / restoreParams
if (window.pager_params)
{
window.pager_params['pager'+sListId] = undefined;
}
// End of workaround
try {
me.element.find('.datacontents').html(data);
// restore the sort order on columns
me.element.find('table.listResults').trigger('fakesorton', [aCurrentSort]);
} catch (e) {
// ugly hacks for IE 8/9 first...
if (!window.console) console.error = {};
if (!window.console.error) {
console.error = function () {
};
}
console.error("Can not inject data : "+data);
}
me.element.unblock();
}, 'html' );
},
_useDefaultSettings: function(bResetAll)
{
var oParams = this.options.oRenderParameters;
oParams.operation = 'datatable_reset_settings';
oParams.table_id = this.options.sTableId;
oParams.defaults = bResetAll;
oParams.class_aliases = this.options.oClassAliases;
var me = this;
$.post(this.options.sRenderUrl, oParams, function(data) {
// Do nothing...
}, 'html' );
},
_saveSettings: function(bSaveAsDefaults)
{
var oParams = this.options.oRenderParameters;
oParams.operation = 'datatable_save_settings';
oParams.page_size = this.options.iPageSize;
oParams.table_id = this.options.sTableId;
oParams.defaults = bSaveAsDefaults;
oParams.class_aliases = this.options.oClassAliases;
oParams.columns = this.options.oColumns;
var iSortCol = 0;
var sSortOrder = '';
for(var i in this.options.oColumns)
{
if (this.options.oColumns[i].checked)
{
if (this.options.oColumns[i].sort != 'none')
{
sSortOrder = this.options.oColumns[i].sort;
}
else
{
iSortCol++;
}
}
}
if ((this.options.sSelectMode != '') && (this.options.sSelectMode != 'none'))
{
iSortCol++;
}
oParams.sort_col = iSortCol;
oParams.sort_order = sSortOrder;
var me = this;
$.post(this.options.sRenderUrl, oParams, function(data) {
// Do nothing...
}, 'html' );
},
onDlgOk: function()
{
var oOptions = {};
var sId = new String(this.element.attr('id'));
var sListId = sId.replace('datatable_', '');
oSettings = $('#datatable_dlg_'+sListId).find('input[name=settings]:checked');
if (oSettings.val() == 'defaults')
{
oOptions = { iPageSize: this.options.oDefaultSettings.iDefaultPageSize,
oColumns: this.options.oDefaultSettings.oColumns
};
}
else
{
var oDisplayColumns = {};
var iColIdx = 0;
var iSortIdx = 0;
var sSortDirection = 'asc';
var oColumns = $('#datatable_dlg_'+sListId).find(':itop-fieldsorter').fieldsorter('get_params');
var iPageSize = parseInt($('#datatable_dlg_'+sListId+' input[name=page_size]').val(), 10);
oOptions = {oColumns: oColumns, iPageSize: iPageSize, iDefaultPageSize: iPageSize };
}
this._setOptions(oOptions);
// Check if we need to save the settings or not...
var oSaveCheck = $('#datatable_dlg_'+sListId).find('input[name=save_settings]');
var oSaveScope = $('#datatable_dlg_'+sListId).find('input[name=scope]:checked');
if (oSaveCheck.prop('checked'))
{
if (oSettings.val() == 'defaults')
{
this._useDefaultSettings((oSaveScope.val() == 'defaults'));
}
else
{
this._saveSettings((oSaveScope.val() == 'defaults'));
}
}
this._saveDlgState();
},
onDlgCancel: function()
{
this._restoreDlgState();
},
_onSpecificSettings: function()
{
var sId = new String(this.element.attr('id'));
var sListId = sId.replace('datatable_', '');
$('#datatable_dlg_'+sListId).find('input.specific_settings').prop('checked', true);
},
_updateSaveScope: function()
{
var sId = new String(this.element.attr('id'));
var sListId = sId.replace('datatable_', '');
var oSaveCheck = $('#datatable_dlg_'+sListId).find('input[name=save_settings]');
if (oSaveCheck.prop('checked'))
{
$('#datatable_dlg_'+sListId).find('input[name=scope]').each(function() {
if ($(this).attr('stay-disabled') != 'true')
{
$(this).prop('disabled', false);
}
});
}
else
{
$('#datatable_dlg_'+sListId).find('input[name=scope]').prop('disabled', true);
}
},
// events bound via _bind are removed automatically
// revert other modifications here
_destroy: function()
{
this.element
.removeClass('itop-datatable');
var sId = new String(this.element.attr('id'));
var sListId = sId.replace('datatable_', '');
$('#sfl_'+sListId).remove();
$('#datatable_dlg_'+sListId).remove();
},
// _setOptions is called with a hash of all options that are changing
_setOptions: function()
{
// in 1.9 would use _superApply
this._superApply(arguments);
this._refresh();
},
// _setOption is called for each individual option that is changing
_setOption: function( key, value )
{
// in 1.9 would use _super
this._superApply(arguments);
},
UpdateState: function( config )
{
var iPageSize = config.page_size;
if (iPageSize == -1)
{
iPageSize = 0;
}
this.options.iPageSize = iPageSize;
var iPos = 0;
for (alias in this.options.oColumns)
{
for (attcode in this.options.oColumns[alias])
{
this.options.oColumns[alias][attcode]['sort'] = 'none';
if (this.options.oColumns[alias][attcode]['checked'])
{
if (iPos == config.sort_index)
{
this.options.oColumns[alias][attcode]['sort'] = config.sort_order;
}
iPos++;
}
}
}
var sId = new String(this.element.attr('id'));
var sListId = sId.replace('datatable_', '');
var dlgElement = $('#datatable_dlg_'+sListId);
dlgElement.find('input[name=page_size]').val(iPageSize);
dlgElement.find(':itop-fieldsorter').fieldsorter('option', { fields: this.options.oColumns });
},
_saveDlgState: function()
{
this.originalState = {};
for(k in this.aDlgStateParams)
{
this.originalState[this.aDlgStateParams[k]] = this.options[this.aDlgStateParams[k]];
}
var sId = new String(this.element.attr('id'));
var sListId = sId.replace('datatable_', '');
this.originalState.oFields = $('#datatable_dlg_'+sListId).find(':itop-fieldsorter').fieldsorter('get_params');
},
_restoreDlgState: function()
{
var sId = new String(this.element.attr('id'));
var sListId = sId.replace('datatable_', '');
var dlgElement = $('#datatable_dlg_'+sListId);
for(k in this.aDlgStateParams)
{
this._setOption(this.aDlgStateParams[k], this.originalState[this.aDlgStateParams[k]]);
}
dlgElement.find('input[name=page_size]').val(this.originalState.iDefaultPageSize);
dlgElement.find(':itop-fieldsorter').fieldsorter('option', { fields: this.originalState.oFields });
},
IsDialogOpen: function()
{
var sId = new String(this.element.attr('id'));
var sListId = sId.replace('datatable_', '');
var oDlgOpen = $('#datatable_dlg_'+sListId+' :visible');
return (oDlgOpen.length > 0);
},
DoRefresh: function()
{
this._refresh();
},
GetMultipleSelectionParams: function()
{
var oRes = {};
oRes.selectionMode = '';
if (this.element.find(':input[name=selectionMode]').length > 0)
{
oRes.selectionMode = this.element.find(':input[name=selectionMode]').val();
}
oRes.selectObject = [];
this.element.find(':input[name^=selectObject]:checked').each(function() {
oRes.selectObject.push($(this).val());
});
oRes.storedSelection = [];
this.element.find(':input[name^=storedSelection]').each(function() {
oRes.storedSelection.push($(this).val());
});
return oRes;
}
});
});

View File

@@ -1,426 +0,0 @@
/*
* jQuery tableHover plugin
* Version: 0.1.3
*
* Copyright (c) 2007 Roman Weich
* http://p.sohei.org
*
* Dual licensed under the MIT and GPL licenses
* (This means that you can choose the license that best suits your project, and use it accordingly):
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Changelog:
* v 0.1.3 - 2007-09-04
* - fix: highlight did not work when the hovered table cell had child elements inside
* v 0.1.2 - 2007-08-13
* - fix/change: changed event binding routine, as is got really slow with jquery 1.1.3.1
* -change: added new option "ignoreCols", through which columns can be excluded from the highlighting process
* v 0.1.1 - 2007-06-05
* - fix: errors when using the plugin on a table not having a theader or tfoot
* v 0.1.0 - 2007-05-31
*/
(function($)
{
/**
* Calculates the actual cellIndex value of all cells in the table and stores it in the realCell property of each cell.
* Thats done because the cellIndex value isn't correct when colspans or rowspans are used.
* Originally created by Matt Kruse for his table library - Big Thanks! (see http://www.javascripttoolbox.com/)
* @param {element} table The table element.
*/
var fixCellIndexes = function(table)
{
var rows = table.rows;
var len = rows.length;
var matrix = [];
for ( var i = 0; i < len; i++ )
{
var cells = rows[i].cells;
var clen = cells.length;
for ( var j = 0; j < clen; j++ )
{
var c = cells[j];
var rowSpan = c.rowSpan || 1;
var colSpan = c.colSpan || 1;
var firstAvailCol = -1;
if ( !matrix[i] )
{
matrix[i] = [];
}
var m = matrix[i];
// Find first available column in the first row
while ( m[++firstAvailCol] ) {}
c.realIndex = firstAvailCol;
for ( var k = i; k < i + rowSpan; k++ )
{
if ( !matrix[k] )
{
matrix[k] = [];
}
var matrixrow = matrix[k];
for ( var l = firstAvailCol; l < firstAvailCol + colSpan; l++ )
{
matrixrow[l] = 1;
}
}
}
}
};
/**
* Sets the rowIndex of each row in the table.
* Opera seems to get that wrong using document order instead of logical order on the tfoot-tbody part.
* @param {element} table The table element.
*/
var fixRowIndexes = function(tbl)
{
var v = 0, i, k, r = ( tbl.tHead ) ? tbl.tHead.rows : 0;
if ( r )
{
for ( i = 0; i < r.length; i++ )
{
r[i].realRIndex = v++;
}
}
for ( k = 0; k < tbl.tBodies.length; k++ )
{
r = tbl.tBodies[k].rows;
if ( r )
{
for ( i = 0; i < r.length; i++ )
{
r[i].realRIndex = v++;
}
}
}
r = ( tbl.tFoot ) ? tbl.tFoot.rows : 0;
if ( r )
{
for ( i = 0; i < r.length; i++ )
{
r[i].realRIndex = v++;
}
}
};
/**
* Highlights table rows and/or columns on mouse over.
* Fixes the highlight of the currently highlighted rows/columns on click.
* Works on tables with rowspans and colspans.
*
* @param {map} options An object for optional settings (options described below).
*
* @option {boolean} allowHead Allow highlighting when hovering over the table header.
* Default value: true
* @option {boolean} allowBody Allow highlighting when hovering over the table body.
* Default value: true
* @option {boolean} allowFoot Allow highlighting when hovering over the table footer.
* Default value: true
*
* @option {boolean} headRows If true the rows in the table header will be highlighted when hovering over them.
* Default value: false
* @option {boolean} bodyRows If true the rows in the table body will be highlighted when hovering over them.
* Default value: true
* @option {boolean} footRows If true the rows in the table footer will be highlighted when hovering over them.
* Default value: false
* @option {boolean} spanRows When hovering over a cell spanning over more than one row, highlight all spanned rows.
* Default value: true
*
* @option {boolean} headCols If true the cells in the table header (matching the currently hovered column) will be highlighted.
* Default value: false
* @option {boolean} bodyCols If true the cells in the table body (matching the currently hovered column) will be highlighted.
* Default value: true
* @option {boolean} footCols If true the cells in the table footer (matching the currently hovered column) will be highlighted.
* Default value: false
* @option {boolean} spanCols When hovering over a cell spanning over more than one column, highlight all spanned columns.
* Default value: true
* @option {array} ignoreCols An array of numbers. Each column with the matching column index won't be included in the highlighting process.
* Index starting at 1!
* Default value: [] (empty array)
*
* @option {boolean} headCells Set a special highlight class to the cell the mouse pointer is currently pointing at (inside the table header only).
* Default value: false
* @option {boolean} bodyCells Set a special highlight class to the cell the mouse pointer is currently pointing at (inside the table body only).
* Default value: true
* @option {boolean} footCells Set a special highlight class to the cell the mouse pointer is currently pointing at (inside the table footer only).
* Default value: false
*
* @option {string} rowClass The css class set to the currently highlighted row.
* Default value: 'hover'
* @option {string} colClass The css class set to the currently highlighted column.
* Default value: '' (empty string)
* @option {string} cellClass The css class set to the currently highlighted cell.
* Default value: '' (empty string)
* @option {string} clickClass The css class set to the currently highlighted row and column on mouse click.
* Default value: '' (empty string)
*
* @example $('#table').tableHover({});
* @desc Add simple row highlighting to #table with default settings.
*
* @example $('#table').tableHover({rowClass: "someclass", colClass: "someotherclass"});
* @desc Add row and columnhighlighting to #table and set the specified css classes to the highlighted cells.
*
* @example $('#table').tableHover({clickClass: "someclickclass"});
* @desc Add simple row highlighting to #table and set the specified css class on the cells when clicked.
*
* @example $('#table').tableHover({allowBody: false, allowFoot: false, allowHead: true, colClass: "someclass"});
* @desc Add column highlighting on #table only highlighting the cells when hovering over the table header.
*
* @example $('#table').tableHover({bodyCols: false, footCols: false, headCols: true, colClass: "someclass"});
* @desc Add column highlighting on #table only for the cells in the header.
*
* @type jQuery
*
* @name tableHover
* @cat Plugins/tableHover
* @author Roman Weich (http://p.sohei.org)
*/
$.fn.tableHover = function(options)
{
var settings = $.extend({
allowHead : true,
allowBody : true,
allowFoot : true,
headRows : false,
bodyRows : true,
footRows : false,
spanRows : true,
headCols : false,
bodyCols : true,
footCols : false,
spanCols : true,
ignoreCols : [],
headCells : false,
bodyCells : true,
footCells : false,
//css classes,,
rowClass : 'hover',
colClass : '',
cellClass : '',
clickClass : ''
}, options);
return this.each(function()
{
var colIndex = [], rowIndex = [], tbl = this, r, rCnt = 0, lastClick = [-1, -1];
if ( !tbl.tBodies || !tbl.tBodies.length )
{
return;
}
/**
* Adds all rows and each of their cells to the row and column indexes.
* @param {array} rows An array of table row elements to add.
* @param {string} nodeName Defines whether the rows are in the header, body or footer of the table.
*/
var addToIndex = function(rows, nodeName)
{
var c, row, rowI, cI, rI, s;
//loop through the rows
for ( rowI = 0; rowI < rows.length; rowI++, rCnt++ )
{
row = rows[rowI];
//each cell
for ( cI = 0; cI < row.cells.length; cI++ )
{
c = row.cells[cI];
//add to rowindex
if ( (nodeName == 'TBODY' && settings.bodyRows)
|| (nodeName == 'TFOOT' && settings.footRows)
|| (nodeName == 'THEAD' && settings.headRows) )
{
s = c.rowSpan;
while ( --s >= 0 )
{
rowIndex[rCnt + s].push(c);
}
}
//add do colindex
if ( (nodeName == 'TBODY' && settings.bodyCols)
|| (nodeName == 'THEAD' && settings.headCols)
|| (nodeName == 'TFOOT' && settings.footCols) )
{
s = c.colSpan;
while ( --s >= 0 )
{
rI = c.realIndex + s;
if ( $.inArray(rI + 1, settings.ignoreCols) > -1 )
{
break;//dont highlight the columns in the ignoreCols array
}
if ( !colIndex[rI] )
{
colIndex[rI] = [];
}
colIndex[rI].push(c);
}
}
//allow hover for the cell?
if ( (nodeName == 'TBODY' && settings.allowBody)
|| (nodeName == 'THEAD' && settings.allowHead)
|| (nodeName == 'TFOOT' && settings.allowFoot) )
{
c.thover = true;
}
}
}
};
/**
* Mouseover event handling. Set the highlight to the rows/cells.
*/
var over = function(e)
{
var p = e.target;
while ( p != this && p.thover !== true )
{
p = p.parentNode;
}
if ( p.thover === true )
{
highlight(p, true);
}
};
/**
* Mouseout event handling. Remove the highlight from the rows/cells.
*/
var out = function(e)
{
var p = e.target;
while ( p != this && p.thover !== true )
{
p = p.parentNode;
}
if ( p.thover === true )
{
highlight(p, false);
}
};
/**
* Mousedown event handling. Sets or removes the clickClass css style to the currently highlighted rows/cells.
*/
var click = function(e)
{
if ( e.target.thover && settings.clickClass != '' )
{
var x = e.target.realIndex, y = e.target.parentNode.realRIndex, s = '';
//unclick
$('td.' + settings.clickClass + ', th.' + settings.clickClass, tbl).removeClass(settings.clickClass);
if ( x != lastClick[0] || y != lastClick[1] )
{
//click..
if ( settings.rowClass != '' )
{
s += ',.' + settings.rowClass;
}
if ( settings.colClass != '' )
{
s += ',.' + settings.colClass;
}
if ( settings.cellClass != '' )
{
s += ',.' + settings.cellClass;
}
if ( s != '' )
{
$('td, th', tbl).filter(s.substring(1)).addClass(settings.clickClass);
}
lastClick = [x, y];
}
else
{
lastClick = [-1, -1];
}
}
};
/**
* Adds or removes the highlight to/from the columns and rows.
* @param {element} cell The cell with the mouseover/mouseout event.
* @param {boolean} on Defines whether the style will be set or removed.
*/
var highlight = function(cell, on)
{
if ( on ) //create dummy funcs - dont want to test for on==true all the time
{
$.fn.tableHoverHover = $.fn.addClass;
}
else
{
$.fn.tableHoverHover = $.fn.removeClass;
}
//highlight columns
var h = colIndex[cell.realIndex] || [], rH = [], i = 0, rI, nn;
if ( settings.colClass != '' )
{
while ( settings.spanCols && ++i < cell.colSpan && colIndex[cell.realIndex + i] )
{
h = h.concat(colIndex[cell.realIndex + i]);
}
$(h).tableHoverHover(settings.colClass);
}
//highlight rows
if ( settings.rowClass != '' )
{
rI = cell.parentNode.realRIndex;
if ( rowIndex[rI] )
{
rH = rH.concat(rowIndex[rI]);
}
i = 0;
while ( settings.spanRows && ++i < cell.rowSpan )
{
if ( rowIndex[rI + i] )
{
rH = rH.concat(rowIndex[rI + i]);
}
}
$(rH).tableHoverHover(settings.rowClass);
}
//highlight cell
if ( settings.cellClass != '' )
{
nn = cell.parentNode.parentNode.nodeName.toUpperCase();
if ( (nn == 'TBODY' && settings.bodyCells)
|| (nn == 'THEAD' && settings.headCells)
|| (nn == 'TFOOT' && settings.footCells) )
{
$(cell).tableHoverHover(settings.cellClass);
}
}
};
fixCellIndexes(tbl);
fixRowIndexes(tbl);
//init rowIndex
for ( r = 0; r < tbl.rows.length; r++ )
{
rowIndex[r] = [];
}
//add header cells to index
if ( tbl.tHead )
{
addToIndex(tbl.tHead.rows, 'THEAD');
}
//create index - loop through the bodies
for ( r = 0; r < tbl.tBodies.length; r++ )
{
addToIndex(tbl.tBodies[r].rows, 'TBODY');
}
//add footer cells to index
if ( tbl.tFoot )
{
addToIndex(tbl.tFoot.rows, 'TFOOT');
}
$(this).bind('mouseover', over).bind('mouseout', out).click(click);
});
};
})(jQuery);

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -1,542 +0,0 @@
function sprintf(format, etc) {
var arg = arguments;
var i = 1;
return format.replace(/%((%)|s)/g, function (m) { return m[2] || arg[i++] })
}
(function($) {
$.extend({
tablesorterPager: new function() {
function updatePageDisplay(c) {
var s = $(c.cssPageDisplay,c.container).val((c.page+1) + c.seperator + c.totalPages);
}
function setPageSize(table,size, bReload) {
var c = table.config;
if (c != undefined)
{
c.selectedSize = size;
if (size == -1)
{
size = c.totalRows;
}
c.size = size;
c.totalPages = Math.ceil(c.totalRows / c.size);
c.pagerPositionSet = false;
if (bReload)
{
moveToPage(table);
}
fixPosition(table);
}
}
function fixPosition(table) {
var c = table.config;
if(!c.pagerPositionSet && c.positionFixed) {
var c = table.config, o = $(table);
if(o.offset) {
c.container.css({
top: o.offset().top + o.height() + 'px',
position: 'absolute'
});
}
c.pagerPositionSet = true;
}
}
function moveToFirstPage(table) {
var c = table.config;
c.page = 0;
moveToPage(table);
}
function moveToLastPage(table) {
var c = table.config;
c.page = (c.totalPages-1);
moveToPage(table);
}
function moveToNextPage(table) {
var c = table.config;
c.page++;
if(c.page >= (c.totalPages-1)) {
c.page = (c.totalPages-1);
}
moveToPage(table);
}
function moveToPrevPage(table) {
var c = table.config;
c.page--;
if(c.page <= 0) {
c.page = 0;
}
moveToPage(table);
}
function moveToPage(table) {
var c = table.config;
if(c.page < 0 || c.page > (c.totalPages-1)) {
c.page = 0;
}
renderTable(table,c.rowsCopy);
}
function checkAll(table, pager, value)
{
// Mark all the displayed items as check or unchecked depending on the value
$(table).find(':checkbox[name^=selectObj]:not([disabled])').each(function (index, element) {
var $currentCheckbox = $(this);
$currentCheckbox.prop('checked', value);
$currentLine = $currentCheckbox.closest("tr");
(value) ? $currentLine.addClass("selected") : $currentLine.removeClass("selected");
});
// Set the 'selectionMode' for the future objects to load
if (value)
{
table.config.selectionMode = 'negative';
}
else
{
table.config.selectionMode = 'positive';
}
$(pager).find(':input[name=selectionMode]').val(table.config.selectionMode);
// Reset the list of saved selection...
resetStoredSelection(pager);
$(table).find(':checkbox[name^=selectObj]').trigger("change");
updateCounter(table, pager);
return true;
}
function resetStoredSelection(pager)
{
$(':input[name^=storedSelection]', pager).remove();
}
function storeSelection(table, pager, id, value, disabled)
{
if(disabled == undefined)
{
disabled = false;
}
var valueToStore = value;
if (table.config.selectionMode == 'negative')
{
valueToStore = !(valueToStore);
}
if (valueToStore)
{
if (table.config.select_mode == 'single')
{
$(':input[name^=storedSelection]', pager).remove(); // Remove any previous selection
}
if ($('#'+id, pager).length ==0)
{
$(pager).append($('<input type="hidden" id="'+id+'" name="storedSelection[]" value="'+id+'"'+ (disabled ? ' disabled ' : '') +'/>'));
}
}
else
{
if ($('#'+id, pager).length !=0)
{
$('#'+id, pager).remove();
}
}
updateCounter(table, pager);
}
function loadSelection(table, pager)
{
table.config.selectionMode = $(pager).find(':input[name=selectionMode]').val();
updateCounter(table, pager);
}
function updateCounter(table, pager)
{
var ex = $(':input[name^=storedSelection]', pager).length;
var s = ex;
if (table.config.selectionMode == 'negative')
{
s = table.config.totalRows - ex;
}
pager.parent().closest('table').find('.selectedCount').text(s);
if (table.config.cssCount != '')
{
$(table.config.cssCount).val(s);
$(table.config.cssCount).trigger('change');
}
}
function getData(table, start, end)
{
if (table.ajax_request)
{
table.ajax_request.abort();
table.ajax_request = null;
}
var c = table.config;
var s = c.sortList[0];
var s_col = null;
var s_order = null;
if (s != undefined)
{
s_col = s[0];
s_order = (s[1] == 0) ? 'asc' : 'desc';
}
var oDataTable = $(table).closest('table.itop-datatable');
var oConfig = {
sort_index: s_col,
sort_order: s_order,
page_size: table.config.selectedSize
};
oDataTable.datatable('UpdateState', oConfig);
$('#loading', table.config.container).html('<img src="../images/indicator.gif" />');
table.ajax_request = $.post(AddAppContext(GetAbsoluteUrlAppRoot()+"pages/ajax.render.php"),
{ operation: 'pagination',
filter: c.filter,
extra_param: c.extra_params,
start: start,
end: end,
sort_col: s_col,
sort_order: s_order,
select_mode: c.select_mode,
list_id: c.table_id,
display_key: c.displayKey,
columns: c.columns,
class_aliases: c.class_aliases
},
function(data)
{
table.ajax_request = null; // Ajax request completed
oData = $(data);
var tableBody = $(table.tBodies[0]);
// clear the table body
$.tablesorter.clearTableBody(table);
for(var i = 0; i < end-start; i++) {
//tableBody.append(rows[i]);
//var o = rows[i];
var r = $(oData[i]);
var l = r.length;
for(var j=0; j < l; j++) {
//tableBody[0].appendChild(r);
tableBody[0].appendChild(r[j]);
}
}
fixPosition(table,tableBody);
applySelection(table);
$(table).trigger("applyWidgets");
if( c.page >= c.totalPages ) {
moveToLastPage(table);
}
updatePageDisplay(c);
updateCounter(table, table.config.container);
renderPager(table, table.config.container);
$('#loading', table.config.container).empty();
saveParams(table.config);
});
}
function applySelection(table)
{
var c = table.config;
if (c == undefined) return;
if (c.selectionMode == 'negative')
{
$(table).find(':checkbox[name^=selectObj]:not([disabled])').prop('checked', true);
}
if (table.config.select_mode == 'multiple')
{
$(table).find(':checkbox[name^=selectObj]:not([disabled])').each(function() {
var id = parseInt(this.value, 10);
if ($('#'+id, table.config.container).length > 0)
{
if (c.selectionMode == 'positive')
{
$(this).prop('checked', true);
}
else
{
$(this).prop('checked', false);
}
}
});
$(table).find(':checkbox[name^=selectObj]').on("change init-selection", function () {
storeSelection(table, table.config.container, this.value, this.checked, this.disabled);
}).trigger("init-selection"); // don't need to trigger the very generic change event !
}
else if (table.config.select_mode == 'single')
{
$(table).find('input[name^=selectObject]:radio:not([disabled])').each(function() {
var id = parseInt(this.value, 10);
if ($('#'+id, table.config.container).length > 0)
{
if (c.selectionMode == 'positive')
{
$(this).prop('checked', true);
}
else
{
$(this).prop('checked', false);
}
}
});
$(table).find('input[name^=selectObject]:radio').change(function() {
storeSelection(table, table.config.container, this.value, this.checked);
});
}
}
function renderPager(table, pager)
{
var c = table.config;
var aPages = [0]; // first page
var s = c.page - 1;
var nb = Math.ceil(c.totalRows / c.size);
if (s < 1)
{
s = 1;
}
var e = s +3;
if (e >= nb)
{
e = nb;
if ((e - 4) > 1)
{
s = e - 4;
}
}
for(var i=s; i<e; i++)
{
aPages.push(i);
}
if ((nb > 1) && (nb > i))
{
aPages.push(nb - 1); // very last page
}
txt = '';
for(i=0; i<aPages.length; i++)
{
var page = 1+aPages[i];
var link = '';
var sDotsAfter = '';
var sDotsBefore = '';
if ((i == 0) && (aPages.length > 1) && (aPages[i+1] != aPages[i]+1))
{
sDotsAfter = '...'; // Gap between the last 2 page numbers
}
if ((i == aPages.length-1) && (aPages.length > 1) && (aPages[i-1] != aPages[i]-1))
{
sDotsBefore = '...'; // Gap between the first 2 page numbers
}
if (aPages[i] != c.page)
{
link = ' <span page="'+aPages[i]+'" id="gotopage_'+aPages[i]+'">'+sDotsBefore+page+sDotsAfter+'</span> ';
}
else
{
link = ' <span class="curr_page" page="'+aPages[i]+'">'+sDotsBefore+page+sDotsAfter+'</span> ';
}
txt += link;
}
txt += '';
$('#total', pager).text(c.totalRows);
$('#index', pager).html(txt);
for(i=0; i<aPages.length; i++)
{
$('#gotopage_'+aPages[i], pager).click(function(){
var idx = $(this).attr('page');
table.config.page = idx;
moveToPage(table);
});
}
}
function renderTable(table) {
var c = table.config;
//var l = rows.length;
var s = (c.page * c.size);
var e = (s + c.size);
if(e > c.totalRows ) {
e = c.totalRows;
}
getData(table, s, e);
}
this.appender = function(table,rows) {
var c = table.config;
if (c.totalRows == 0)
{
c.totalRows = rows.length;
}
c.totalPages = Math.ceil(c.totalRows / c.size);
renderTable(table,rows);
};
function saveParams(config) {
var sPagerId = config.container.attr('id');
var params = { size: config.selectedSize, page: config.page, sortList: config.sortList };
if (window.pager_params == undefined)
{
window.pager_params = {};
}
window.pager_params[sPagerId] = params;
};
function restoreParams(table) {
var sPagerId = config.container.attr('id');
if (window.pager_params != undefined)
{
params = window.pager_params[sPagerId];
if (params != undefined)
{
$(table.config.cssPageSize, table.config.container).val(params.size);
setPageSize(table, params.size, false); // false => don't trigger a reload
if (table.config.sortList != params.sortList)
{
$(table).trigger("sorton", [params.sortList]); // triggers a reload anyway
}
}
}
};
this.defaults = {
size: 10,
offset: 0,
page: 0,
totalRows: 0,
totalPages: 0,
container: null,
cssNext: '.next',
cssPrev: '.prev',
cssFirst: '.first',
cssLast: '.last',
cssPageDisplay: '.pagedisplay',
cssPageSize: '.pagesize',
cssCount: '',
seperator: "/",
positionFixed: false,
appender: this.appender,
filter: '',
extra_params: '',
select_mode: '',
table_id: 0,
totalSelected: 0,
selectionMode: 'positive',
displayKey: true,
columns: {},
class_aliases: {}
};
this.construct = function(settings) {
return this.each(function() {
try
{
config = $.extend(this.config, $.tablesorterPager.defaults, settings);
var table = this, pager = config.container;
this.ajax_request = null;
config.selectedSize = parseInt($(".pagesize",pager).val());
setPageSize(table,config.selectedSize, false);
restoreParams(table, config);
//$(this).trigger("appendCache"); // Load the data
//console.log($.tablesorterPager);
applySelection(table);
$('.gotopage',pager).click(function() {
var idx = $(this).attr('page');
table.config.page = idx;
moveToPage(table);
});
$(config.cssFirst,pager).click(function() {
moveToFirstPage(table);
return false;
});
$(config.cssNext,pager).click(function() {
moveToNextPage(table);
return false;
});
$(config.cssPrev,pager).click(function() {
moveToPrevPage(table);
return false;
});
$(config.cssLast,pager).click(function() {
moveToLastPage(table);
return false;
});
$(config.cssPageSize,pager).change(function() {
setPageSize(table,parseInt($(this).val()), true);
return false;
});
$(table).find(':checkbox.checkAll').removeAttr('onclick').click(function() {
return checkAll(table, pager, this.checked);
});
$(table).bind('load_selection', function() {
loadSelection(table, pager);
applySelection(table);
});
$(table).bind('check_all', function() {
// update header checkbox
$(table).find("thead>tr>th>input:checkbox").prop("checked", true);
checkAll(table, pager, true);
});
}
catch(err)
{
if (console && console.log)
{
console.log(err);
}
}
});
};
}
});
// extend plugin scope
$.fn.extend({
tablesorterPager: $.tablesorterPager.construct
});
})(jQuery);

View File

@@ -64,11 +64,6 @@ class NiceWebPage extends WebPage
protected const COMPATIBILITY_DEPRECATED_LINKED_SCRIPTS_REL_PATH = [
/** @deprecated 3.0.0 Not used in the backoffice since the introduction of the new tooltip lib. */
'js/hovertip.js',
/** @deprecated 3.0.0 N°2737 - Migrate table to DataTables plugin to be iso with the end-users portal, will be removed in 3.x */
'js/datatable.js',
'js/jquery.tablesorter.js',
'js/jquery.tablesorter.pager.js',
'js/jquery.tablehover.js',
];
const DEFAULT_PAGE_TEMPLATE_REL_PATH = 'pages/backoffice/nicewebpage/layout';