New implementation for displaying long lists: pagination

SVN:trunk[1295]
This commit is contained in:
Denis Flaven
2011-06-23 10:46:10 +00:00
parent 01a4a04364
commit dc3713f0ea
2 changed files with 128 additions and 6 deletions

View File

@@ -282,8 +282,16 @@ function DeleteObjects(WebPage $oP, $sClass, $aObjects, $bDeleteConfirmed)
else
{
$oP->p('<h1>'.Dict::Format('UI:Delect:Confirm_Count_ObjectsOf_Class', count($aObjects), MetaModel::GetName($sClass)).'</h1>');
$oSet = CMDBobjectSet::FromArray($sClass, $aObjects);
foreach($aObjects as $oObj)
{
$aKeys[] = $oObj->GetKey();
}
$oFilter = new DBObjectSearch($sClass);
$oFilter->AddCondition('id', $aKeys, 'IN');
$oSet = new CMDBobjectSet($oFilter);
$oP->add('<div id="0">');
CMDBAbstractObject::DisplaySet($oP, $oSet, array('display_limit' => false, 'menu' => false));
$oP->add("</div>\n");
$oP->add("<form method=\"post\">\n");
$oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::ReadParam('transaction_id')."\">\n");
$oP->add("<input type=\"hidden\" name=\"operation\" value=\"bulk_delete_confirmed\">\n");
@@ -715,7 +723,8 @@ try
case 'form_for_modify_all': // Form to modify multiple objects (bulk modify)
$sFilter = utils::ReadParam('filter', '');
$sClass = utils::ReadParam('class', '');
$aSelectedObj = utils::ReadParam('selectObject', array());
$oFullSetFilter = DBObjectSearch::unserialize($sFilter);
$aSelectedObj = ReadMultipleSelection($oFullSetFilter);
if (count($aSelectedObj) > 0)
{
$iAllowedCount = count($aSelectedObj);
@@ -1181,6 +1190,7 @@ EOF
$oP->add("<form method=\"post\">\n");
$oP->add("<input type=\"hidden\" name=\"operation\" value=\"bulk_delete\">\n");
$oP->add("<input type=\"hidden\" name=\"class\" value=\"".$oFilter->GetClass()."\">\n");
$oP->add("<input type=\"hidden\" name=\"filter\" value=\"".$oFilter->Serialize()."\">\n");
$oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::GetNewTransactionId()."\">\n");
$oBlock->Display($oP, 1, array('selection_type' => 'multiple', 'selection_mode' => true, 'display_limit' => false, 'menu' => false));
$oP->add("<input type=\"button\" value=\"".Dict::S('UI:Button:Cancel')."\" onClick=\"window.history.back()\">&nbsp;&nbsp;<input type=\"submit\" value=\"".Dict::S('UI:Button:Next')."\">\n");
@@ -1202,7 +1212,9 @@ EOF
case 'bulk_delete': // Actual bulk deletion (if confirmed)
$sClass = utils::ReadPostedParam('class', '');
$sClassLabel = MetaModel::GetName($sClass);
$aSelectObject = utils::ReadPostedParam('selectObject', '');
$sFilter = utils::ReadPostedParam('filter', '');
$oFullSetFilter = DBObjectSearch::unserialize($sFilter);
$aSelectObject = utils::ReadMultipleSelection($oFullSetFilter);
$aObjects = array();
if ( empty($sClass) || empty($aSelectObject)) // TO DO: check that the class name is valid !
{
@@ -1348,13 +1360,13 @@ EOF
$sFilter = utils::ReadParam('filter', '');
$sStimulus = utils::ReadParam('stimulus', '');
$sState = utils::ReadParam('state', '');
$aSelectObject = utils::ReadPostedParam('selectObject', array());
if (empty($sFilter) || empty($sStimulus) || empty($sState))
{
throw new ApplicationException(Dict::Format('UI:Error:3ParametersMissing', 'filter', 'stimulus', 'state'));
}
$oFilter = DBObjectSearch::unserialize($sFilter);
$sClass = $oFilter->GetClass();
$aSelectedObj = ReadMultipleSelection($oFilter);
if (count($aSelectObject) == 0)
{
// Nothing to do, no object was selected !

View File

@@ -50,6 +50,114 @@ try
switch($operation)
{
case 'pagination':
$sExtraParams = stripslashes(utils::ReadParam('extra_params', ''));
$aExtraParams = array();
if (!empty($sExtraParams))
{
$aExtraParams = json_decode(str_replace("'", '"', $sExtraParams), true /* associative array */);
}
if ($sEncoding == 'oql')
{
$oFilter = CMDBSearchFilter::FromOQL($sFilter);
}
else
{
$oFilter = CMDBSearchFilter::unserialize($sFilter);
}
$iStart = utils::ReadParam('start',0);
$iEnd = utils::ReadParam('end',1);
$iSortCol = utils::ReadParam('sort_col',null);
$sSelectMode = utils::ReadParam('select_mode', '');
$bDisplayKey = utils::ReadParam('display_key', 'true') == 'true';
$aList = utils::ReadParam('display_list', array());
$sClassName = $oFilter->GetClass();
//$aList = cmdbAbstractObject::FlattenZList(MetaModel::GetZListItems($sClassName, 'list'));
// Filter the list to removed linked set since we are not able to display them here
$aOrderBy = array();
$aConfig = array();
$iSortIndex = 0;
if ($sSelectMode != '')
{
$aConfig['form::select'] = array();
$iSortIndex++; // Take into account the extra (non-sortable) column for the checkbox/radio button.
}
if ($bDisplayKey)
{
$aConfig['key'] = array();
if ($iSortIndex == $iSortCol)
{
$aOrderBy['friendlyname'] = (utils::ReadParam('sort_order', 'asc') == 'asc');
}
$iSortIndex++;
}
foreach($aList as $sAttCode)
{
$aConfig[$sAttCode] = array();
}
foreach($aList as $index => $sAttCode)
{
$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
if ($oAttDef instanceof AttributeLinkedSet)
{
// Removed from the display list
unset($aList[$index]);
}
if ($iSortCol == $iSortIndex)
{
if ($oAttDef->IsExternalKey())
{
$sSortCol = $sAttCode.'_friendlyname';
}
else
{
$sSortCol = $sAttCode;
}
$aOrderBy[$sSortCol] = (utils::ReadParam('sort_order', 'asc') == 'asc');
}
$iSortIndex++;
}
// Load only the requested columns
$oSet = new DBObjectSet($oFilter, $aOrderBy, $aExtraParams, null, $iEnd-$iStart, $iStart);
$sClassAlias = $oSet->GetFilter()->GetClassAlias();
$oSet->OptimizeColumnLoad(array($sClassAlias => $aList));
while($oObj = $oSet->Fetch())
{
$aRow = array();
$sDisabled = '';
switch ($sSelectMode)
{
case 'single':
$aRow['form::select'] = "<input type=\"radio\" $sDisabled name=\"selectObject\" value=\"".$oObj->GetKey()."\"></input>";
break;
case 'multiple':
$aRow['form::select'] = "<input type=\"checkBox\" $sDisabled name=\"selectObject[]\" value=\"".$oObj->GetKey()."\"></input>";
break;
}
if ($bDisplayKey)
{
$aRow['key'] = $oObj->GetHyperLink();
}
$sHilightClass = $oObj->GetHilightClass();
if ($sHilightClass != '')
{
$aRow['@class'] = $sHilightClass;
}
foreach($aList as $sAttCode)
{
$aRow[$sAttCode] = $oObj->GetAsHTML($sAttCode);
}
$sRow = $oPage->GetTableRow($aRow, $aConfig);
$oPage->add($sRow);
}
break;
case 'addObjects':
require_once(APPROOT.'/application/uilinkswizard.class.inc.php');
$sClass = utils::ReadParam('class', '', 'get');
@@ -160,10 +268,10 @@ try
$sAttCode = utils::ReadParam('sAttCode', '');
$iInputId = utils::ReadParam('iInputId', '');
$sSuffix = utils::ReadParam('sSuffix', '');
$sRemoteClass = utils::ReadParam('sRemoteClass', '');
$bDuplicates = (utils::ReadParam('bDuplicates', 'false') == 'false') ? false : true;
$aLinkedObjectIds = utils::ReadParam('selectObject', array());
$oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix, $bDuplicates);
$oWidget->DoAddObjects($oPage, $aLinkedObjectIds);
$oWidget->DoAddObjects($oPage, $sRemoteClass);
break;
case 'wizard_helper_preview':
@@ -226,6 +334,8 @@ try
$oFilter = CMDBSearchFilter::unserialize($sFilter);
}
$oDisplayBlock = new DisplayBlock($oFilter, $sStyle, false);
$aExtraParams['display_limit'] = true;
$aExtraParams['truncated'] = true;
$oDisplayBlock->RenderContent($oPage, $aExtraParams);
}
else