- Search forms now display the subclasses of the specified class...

SVN:trunk[389]
This commit is contained in:
Denis Flaven
2010-05-02 18:28:18 +00:00
parent c95df7a42c
commit fe44e447ce
4 changed files with 73 additions and 88 deletions

View File

@@ -636,7 +636,6 @@ abstract class cmdbAbstractObject extends CMDBObject
$oAppContext = new ApplicationContext();
$sHtml = '';
$numCols=4;
$iSearchFormId++;
$sClassName = $oSet->GetFilter()->GetClass();
// Romain: temporarily removed the tab "OQL query" because it was not finalized
@@ -648,10 +647,46 @@ abstract class cmdbAbstractObject extends CMDBObject
</ul></div>\n";
*/
// Simple search form
$sHtml .= "<div id=\"SimpleSearchForm{$iSearchFormId}\" class=\"mini_tab{$iSearchFormId}\">\n";
$sHtml .= "<h1>".Dict::Format('UI:SearchFor_Class_Objects', $sClassName)."</h1>\n";
if (isset($aExtraParams['currentId']))
{
$sSearchFormId = $aExtraParams['currentId'];
$iSearchFormId++;
}
else
{
$iSearchFormId++;
$sSearchFormId = 'SimpleSearchForm'.$iSearchFormId;
$sHtml .= "<div id=\"$sSearchFormId\" class=\"mini_tab{$iSearchFormId}\">\n";
}
// Check if the current class has some sub-classes
if (isset($aExtraParams['baseClass']))
{
$sRootClass = $aExtraParams['baseClass'];
}
else
{
$sRootClass = $sClassName;
}
$aSubClasses = MetaModel::GetSubclasses($sRootClass);
if (count($aSubClasses) > 0)
{
$aOptions = array();
$aOptions[MetaModel::GetName($sRootClass)] = "<option value=\"$sRootClass\">".MetaModel::GetName($sRootClass)."</options>\n";
foreach($aSubClasses as $sSubclassName)
{
$aOptions[MetaModel::GetName($sSubclassName)] = "<option value=\"$sSubclassName\">".MetaModel::GetName($sSubclassName)."</options>\n";
}
$aOptions[MetaModel::GetName($sClassName)] = "<option selected value=\"$sClassName\">".MetaModel::GetName($sClassName)."</options>\n";
ksort($aOptions);
$sClassesCombo = "<select name=\"class\" onChange=\"ReloadSearchForm('$sSearchFormId', this.value, '$sRootClass')\">\n".implode('', $aOptions)."</select>\n";
}
else
{
$sClassesCombo = MetaModel::GetName($sClassName);
}
$oUnlimitedFilter = new DBObjectSearch($sClassName);
$sHtml .= "<form id=\"form{$iSearchFormId}\">\n";
$sHtml .= "<h1>".Dict::Format('UI:SearchFor_Class_Objects', $sClassesCombo)."</h1>\n";
$index = 0;
$sHtml .= "<table>\n";
$aFilterCriteria = $oSet->GetFilter()->GetCriteria();
@@ -738,7 +773,10 @@ abstract class cmdbAbstractObject extends CMDBObject
$sHtml .= "<input type=\"hidden\" name=\"operation\" value=\"search_form\" />\n";
$sHtml .= $oAppContext->GetForForm();
$sHtml .= "</form>\n";
$sHtml .= "</div><!-- Simple search form -->\n";
if (!isset($aExtraParams['currentId']))
{
$sHtml .= "</div><!-- Simple search form -->\n";
}
// OQL query builder
$sHtml .= "<div id=\"OQLQuery{$iSearchFormId}\" style=\"display:none\" class=\"mini_tab{$iSearchFormId}\">\n";

View File

@@ -74,7 +74,9 @@ class UILinksWizard
$oP->add("<h1>Manage ".MetaModel::GetName($this->m_sLinkedClass)."s linked with ".MetaModel::GetName(get_class($oTargetObj)).": <span class=\"hilite\">".$oTargetObj->GetHyperlink()."</span></h1>\n");
$oP->add("</div>\n");
$oP->add("<script type=\"text/javascript\">\n");
$oP->add("function OnSelectChange()
$oP->add(
<<<EOF
function OnSelectChange()
{
var nbChecked = $('.selection:checked').length;
if (nbChecked > 0)
@@ -132,7 +134,10 @@ class UILinksWizard
'linkedClass': '{$this->m_sLinkedClass}',
'objectId': '{$this->m_iObjectId}'
}
if ($('#'+currentFormId+' :input[name=class]').val() != undefined)
{
theMap.linkedClass = $('#'+currentFormId+' :input[name=class]').val();
}
// Gather the parameters from the search form
$('#'+currentFormId+' :input').each(
function(i)
@@ -230,7 +235,15 @@ class UILinksWizard
$('#btnRemove').attr('disabled','disabled');
$('#linksToRemove').val('');
}
");
function SubmitHook()
{
var the_form = this;
SearchObjectsToAdd(the_form.id);
return false;
}
EOF
);
$oP->Add("</script>\n");
$oP->add_ready_script("InitForm();");
$oFilter = $oContext->NewFilter($this->m_sClass);
@@ -358,7 +371,7 @@ class UILinksWizard
$oP->add("<input type=\"button\" value=\"Cancel\" onClick=\"$('#ModalDlg').jqmHide();\">&nbsp;&nbsp;<input type=\"submit\" value=\" Add \">");
$oP->Add("</div>\n");
$oP->Add("</form>\n");
$oP->add_ready_script("$('div#SearchFormToAdd form').bind('submit', function() {var the_form = this; SearchObjectsToAdd(the_form.id); return false;});");
$oP->add_ready_script("$('div#SearchFormToAdd form').bind('submit.uilinksWizard', SubmitHook);");
}
public function SearchObjectsToAdd(WebPage $oP, UserContext $oContext)

View File

@@ -18,7 +18,8 @@ $oP = new iTopWebPage("iTop - Universal search", $currentOrganization);
// From now on the context is limited to the the selected organization ??
// Now render the content of the page
$sOQLClass = utils::ReadParam('oql_class', 'bizOrganization');
$sClass = utils::ReadParam('class', 'bizOrganization');
$sOQLClass = utils::ReadParam('oql_class', $sClass);
$sOQLClause = utils::ReadParam('oql_clause', '');
$sClassName = $sOQLClass; //utils::ReadParam('class', $sOQLClass);
$sFilter = utils::ReadParam('filter', '');
@@ -85,85 +86,8 @@ if ($oFilter != null)
// Menu node
$sFilter = $oFilter->ToOQL();
$sMenuNodeContent = <<<EOF
<div id="TopPane">
<itopblock BlockClass="DisplayBlock" type="search" asynchronous="false" encoding="text/oql">$sFilter</itopblock>
</div>
<div id="BottomPane">
<p></p>
<itopblock BlockClass="DisplayBlock" type="list" asynchronous="false" encoding="text/oql">$sFilter</itopblock>
</div>
EOF;
if ($sOperation == "add_menu")
{
$oMenuNode = MetaModel::NewObject('menuNode');
$sClass = utils::ReadPostedParam('class', '');
$sLabel = utils::ReadPostedParam('label', '');
$sDescription = utils::ReadPostedParam('description', '');
$iPreviousNodeId = utils::ReadPostedParam('previous_node_id', 1);
$bChildItem = utils::ReadPostedParam('child_item', false);
$oMenuNode->Set('label', $sDescription);
$oMenuNode->Set('name', $sLabel);
$oMenuNode->Set('icon_path', '../images/std_view.gif');
$oMenuNode->Set('template', $sMenuNodeContent);
$oMenuNode->Set('hyperlink', 'UI.php');
$oMenuNode->Set('type', 'user');
$oMenuNode->Set('user_id', UserRights::GetUserId());
$oPreviousNode = MetaModel::GetObject('menuNode', $iPreviousNodeId);
if ($bChildItem)
{
// Insert the new item as a child of the previous one
$oMenuNode->Set('parent_id', $iPreviousNodeId);
$oMenuNode->Set('rank', 1); // A new child item is the first one, so let's start the numbering at 1
// If there are already child nodes, shift their rank by one
// to make room for the newly inserted child node
$oNextNodeSet = $oPreviousNode->GetChildNodesSet(null); // null => don't limit ourselves to the user context
// since we need to update all children in order to keep
// the database consistent
while($oNextNode = $oNextNodeSet->Fetch())
{
$oNextNode->Set('rank', 1 + $oNextNode->Get('rank'));
$oNextNode->DBUpdate();
}
}
else
{
// Insert the new item as the next sibling of the previous one
$oMenuNode->Set('parent_id', $oPreviousNode->Get('parent_id'));
$oMenuNode->Set('rank', 1 + $oPreviousNode->Get('rank')); // the new item comes immediatly after the selected one
// Add 1 to the rank of all the nodes currently following the 'selected' one
// to make room for the newly inserted node
$oNextNodeSet = $oPreviousNode->GetNextNodesSet(null); // null => don't limit ourselves to the user context
// since we need to update all children in order to keep
// the database consistent
while($oNextNode = $oNextNodeSet->Fetch())
{
$oNextNode->Set('rank', 1 + $oNextNode->Get('rank'));
$oNextNode->DBUpdate();
}
}
list($bRes, $aIssues) = $oMenuNode->CheckToInsert();
if ($bRes)
{
$oMenuNode->DBInsert();
$oP->add("<form method=\"get\">");
$oP->add("<p>Menu item created !</p>");
$oP->add("<input type=\"hidden\" name=\"filter\" value=\"$sFilter\">");
$oP->add("<input type=\"hidden\" name=\"class\" value=\"$sClassName\">");
$oP->add("<input type=\"submit\" name=\"\" value=\"Reload Page\">");
$oP->add("<form>");
}
}
$oP->add("</div>\n");
$oP->add("\n<!-- $sFilter -->\n");
}
else
{
$oP->add("</div>\n");
}
$oP->add("</div>\n");
$oP->output();
?>

View File

@@ -287,6 +287,16 @@ switch($operation)
DownloadDocument($oPage, $oContext, $sClass, $id, $sField, 'attachement');
}
break;
case 'search_form':
$sClass = utils::ReadParam('className', '', 'get');
$sRootClass = utils::ReadParam('baseClass', '', 'get');
$currentId = utils::ReadParam('currentId', '', 'get');
$oFilter = $oContext->NewFilter($sClass);
$oSet = new CMDBObjectSet($oFilter);
$sHtml = cmdbAbstractObject::GetSearchForm($oPage, $oSet, array('currentId' => $currentId, 'baseClass' => $sRootClass));
$oPage->add($sHtml);
break;
default:
$oPage->p("Invalid query.");