mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-21 17:48:43 +02:00
- First (partial) implementation of context and default values.
SVN:trunk[223]
This commit is contained in:
@@ -14,6 +14,7 @@ class ApplicationContext
|
||||
{
|
||||
protected $aNames;
|
||||
protected $aValues;
|
||||
protected static $aDefaultValues; // Cache shared among all instances
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -29,16 +30,20 @@ class ApplicationContext
|
||||
*/
|
||||
protected function ReadContext()
|
||||
{
|
||||
$this->aValues = array();
|
||||
foreach($this->aNames as $sName)
|
||||
if (empty(self::$aDefaultValues))
|
||||
{
|
||||
$sValue = utils::ReadParam($sName, '');
|
||||
// TO DO: check if some of the context parameters are mandatory (or have default values)
|
||||
if (!empty($sValue))
|
||||
self::$aDefaultValues = array();
|
||||
foreach($this->aNames as $sName)
|
||||
{
|
||||
$this->aValues[$sName] = $sValue;
|
||||
$sValue = utils::ReadParam($sName, '');
|
||||
// TO DO: check if some of the context parameters are mandatory (or have default values)
|
||||
if (!empty($sValue))
|
||||
{
|
||||
self::$aDefaultValues[$sName] = $sValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->aValues = self::$aDefaultValues;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,5 +82,18 @@ class ApplicationContext
|
||||
{
|
||||
return $this->aValues;
|
||||
}
|
||||
/**
|
||||
* Removes the specified parameter from the context, for example when the same parameter
|
||||
* is already a search parameter
|
||||
* @param string $sParamName Name of the parameter to remove
|
||||
* @return none
|
||||
*/
|
||||
public function Reset($sParamName)
|
||||
{
|
||||
if (isset($this->aValues[$sParamName]))
|
||||
{
|
||||
unset($this->aValues[$sParamName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -507,12 +507,13 @@ abstract class cmdbAbstractObject extends CMDBObject
|
||||
public static function GetSearchForm(web_page $oPage, CMDBObjectSet $oSet, $aExtraParams = array())
|
||||
{
|
||||
static $iSearchFormId = 0;
|
||||
$oAppContext = new ApplicationContext();
|
||||
$sHtml = '';
|
||||
$numCols=4;
|
||||
$iSearchFormId++;
|
||||
$sClassName = $oSet->GetFilter()->GetClass();
|
||||
|
||||
// Romain: temporariy removed the tab "OQL query" because it was not finalized
|
||||
// Romain: temporarily removed the tab "OQL query" because it was not finalized
|
||||
// (especially when used to add a link)
|
||||
/*
|
||||
$sHtml .= "<div class=\"mini_tabs\" id=\"mini_tabs{$iSearchFormId}\"><ul>
|
||||
@@ -536,6 +537,7 @@ abstract class cmdbAbstractObject extends CMDBObject
|
||||
$aList = MetaModel::GetZListItems($sClassName, 'standard_search');
|
||||
foreach($aList as $sFilterCode)
|
||||
{
|
||||
$oAppContext->Reset($sFilterCode); // Make sure the same parameter will not be passed twice
|
||||
if (($index % $numCols) == 0)
|
||||
{
|
||||
if ($index != 0)
|
||||
@@ -608,6 +610,7 @@ abstract class cmdbAbstractObject extends CMDBObject
|
||||
$sHtml .= "<input type=\"hidden\" name=\"class\" value=\"$sClassName\" />\n";
|
||||
$sHtml .= "<input type=\"hidden\" name=\"dosearch\" value=\"1\" />\n";
|
||||
$sHtml .= "<input type=\"hidden\" name=\"operation\" value=\"search_form\" />\n";
|
||||
$sHtml .= $oAppContext->GetForForm();
|
||||
$sHtml .= "</form>\n";
|
||||
$sHtml .= "</div><!-- Simple search form -->\n";
|
||||
|
||||
@@ -634,6 +637,7 @@ abstract class cmdbAbstractObject extends CMDBObject
|
||||
$sHtml .= "<input type=\"hidden\" name=\"$sName\" value=\"$sValue\" />\n";
|
||||
}
|
||||
$sHtml .= "<input type=\"hidden\" name=\"operation\" value=\"search_oql\" />\n";
|
||||
$sHtml .= $oAppContext->GetForForm();
|
||||
$sHtml .= "</table></form>\n";
|
||||
$sHtml .= "</div><!-- OQL query form -->\n";
|
||||
return $sHtml;
|
||||
@@ -642,6 +646,12 @@ abstract class cmdbAbstractObject extends CMDBObject
|
||||
public static function GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value = '', $sDisplayValue = '', $iId = '', $sNameSuffix = '', $iFlags = 0, $aArgs = array())
|
||||
{
|
||||
static $iInputId = 0;
|
||||
if (isset($aArgs[$sAttCode]) && empty($value))
|
||||
{
|
||||
// default value passed by the context (either the app context of the operation)
|
||||
$value = $aArgs[$sAttCode];
|
||||
}
|
||||
|
||||
if (!empty($iId))
|
||||
{
|
||||
$iInputId = $iId;
|
||||
@@ -797,7 +807,7 @@ abstract class cmdbAbstractObject extends CMDBObject
|
||||
$oPage->add("</form>\n");
|
||||
}
|
||||
|
||||
public static function DisplayCreationForm(web_page $oPage, $sClass, $oObjectToClone = null)
|
||||
public static function DisplayCreationForm(web_page $oPage, $sClass, $oObjectToClone = null, $aArgs = array())
|
||||
{
|
||||
static $iCreationFormId = 0;
|
||||
|
||||
@@ -835,7 +845,7 @@ abstract class cmdbAbstractObject extends CMDBObject
|
||||
$sDisplayValue = ($oObjectToClone == null) ? '' : $oObjectToClone->GetDisplayValue($sAttCode);
|
||||
$iOptions = isset($aStates[$sTargetState]['attribute_list'][$sAttCode]) ? $aStates[$sTargetState]['attribute_list'][$sAttCode] : 0;
|
||||
|
||||
$sHTMLValue = self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, '', '', $iOptions);
|
||||
$sHTMLValue = self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, '', '', $iOptions, $aArgs);
|
||||
$aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,10 +257,12 @@ class DisplayBlock
|
||||
}
|
||||
$sFilter = urlencode($this->m_oFilter->serialize());
|
||||
$aData = array();
|
||||
$oAppContext = new ApplicationContext();
|
||||
$sParams = $oAppContext->GetForLink();
|
||||
foreach($aGroupBy as $sValue => $iCount)
|
||||
{
|
||||
$aData[] = array ( 'group' => $sValue,
|
||||
'value' => "<a href=\"./UI.php?operation=search&dosearch=1&filter=$sFilter&$sGroupByField=".urlencode($sValue)."\">$iCount</a>"); // TO DO: add the context information
|
||||
'value' => "<a href=\"./UI.php?operation=search&dosearch=1&$sParams&filter=$sFilter&$sGroupByField=".urlencode($sValue)."\">$iCount</a>"); // TO DO: add the context information
|
||||
}
|
||||
$sHtml .= $oPage->GetTable(array('group' => array('label' => MetaModel::GetLabel($this->m_oFilter->GetClass(), $sGroupByField), 'description' => ''), 'value' => array('label'=>'Count', 'description' => 'Number of elements')), $aData);
|
||||
}
|
||||
@@ -287,7 +289,9 @@ class DisplayBlock
|
||||
{
|
||||
if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES)
|
||||
{
|
||||
$sHtml .= $oPage->GetP("<a href=\"./UI.php?operation=new&class=$sClass\">Click here to create a new ".Metamodel::GetName($sClass)."</a>\n");
|
||||
$oAppContext = new ApplicationContext();
|
||||
$sParams = $oAppContext->GetForLink();
|
||||
$sHtml .= $oPage->GetP("<a href=\"./UI.php?operation=new&class=$sClass&$sParams\">Click here to create a new ".Metamodel::GetName($sClass)."</a>\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -312,7 +316,9 @@ class DisplayBlock
|
||||
{
|
||||
if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES)
|
||||
{
|
||||
$sHtml .= $oPage->GetP("<a href=\"../pages/UI.php?operation=modify_links&class=$sClass&link_attr=".$aExtraParams['link_attr']."&id=".$aExtraParams['object_id']."&target_class=$sTargetClass&addObjects=true\">Click here to add new ".Metamodel::GetName($sTargetClass)."s</a>\n");
|
||||
$oAppContext = new ApplicationContext();
|
||||
$sParams = $oAppContext->GetForLink();
|
||||
$sHtml .= $oPage->GetP("<a href=\"../pages/UI.php?operation=modify_links&class=$sClass&sParams&link_attr=".$aExtraParams['link_attr']."&id=".$aExtraParams['object_id']."&target_class=$sTargetClass&addObjects=true\">Click here to add new ".Metamodel::GetName($sTargetClass)."s</a>\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class UIWizard
|
||||
/**
|
||||
* Displays one step of the wizard
|
||||
*/
|
||||
public function DisplayWizardStep($aStep, $iStepIndex, &$iMaxInputId, &$aFieldsMap, $bFinishEnabled = false)
|
||||
public function DisplayWizardStep($aStep, $iStepIndex, &$iMaxInputId, &$aFieldsMap, $bFinishEnabled = false, $aArgs = array())
|
||||
{
|
||||
if ($iStepIndex == 1) // one big form that contains everything, to make sure that the uploaded files are posted too
|
||||
{
|
||||
@@ -60,7 +60,7 @@ class UIWizard
|
||||
|
||||
$sFieldFlag = ($iOptions & (OPT_ATT_MANDATORY | OPT_ATT_MUSTCHANGE)) ? ' <span class="hilite">*</span>' : '';
|
||||
$oDefaultValuesSet = $oAttDef->GetDefaultValue(); // @@@ TO DO: get the object's current value if the object exists
|
||||
$sHTMLValue = cmdbAbstractObject::GetFormElementForField($this->m_oPage, $this->m_sClass, $sAttCode, $oAttDef, $oDefaultValuesSet, '', "att_$iMaxInputId", '', $iOptions);
|
||||
$sHTMLValue = cmdbAbstractObject::GetFormElementForField($this->m_oPage, $this->m_sClass, $sAttCode, $oAttDef, $oDefaultValuesSet, '', "att_$iMaxInputId", '', $iOptions, $aArgs);
|
||||
$aFieldsMap[$iMaxInputId] = $sAttCode;
|
||||
$aDetails[] = array('label' => $oAttDef->GetLabel().$sFieldFlag, 'value' => "<div id=\"field_$iMaxInputId\">$sHTMLValue</div>");
|
||||
if ($oAttDef->GetValuesDef() != null)
|
||||
@@ -108,6 +108,7 @@ $sJSHandlerCode
|
||||
*/
|
||||
public function DisplayFinalStep($iStepIndex, $aFieldsMap)
|
||||
{
|
||||
$oAppContext = new ApplicationContext();
|
||||
$this->m_oPage->add("<div class=\"wizContainer\" id=\"wizStep$iStepIndex\" style=\"display:none;\">\n");
|
||||
$this->m_oPage->add("<a name=\"step$iStepIndex\" />\n");
|
||||
$this->m_oPage->P("Final step: confirmation");
|
||||
@@ -126,6 +127,7 @@ $sJSHandlerCode
|
||||
$this->m_oPage->add("</script>\n");
|
||||
$this->m_oPage->add("<div id=\"object_preview\">\n");
|
||||
$this->m_oPage->add("</div>\n");
|
||||
$this->m_oPage->add($oAppContext->GetForForm());
|
||||
$this->m_oPage->add("<input type=\"submit\" value=\"Create ".MetaModel::GetName($this->m_sClass)."\" />\n");
|
||||
$this->m_oPage->add("</div>\n");
|
||||
$this->m_oPage->add("</form>\n");
|
||||
|
||||
@@ -350,6 +350,8 @@ switch($operation)
|
||||
$oP->add_linked_script("../js/linkswidget.js");
|
||||
$oP->add_linked_script("../js/jquery.blockUI.js");
|
||||
$oWizard = new UIWizard($oP, $sClass, $sStateCode);
|
||||
$oContext = new UserContext();
|
||||
$aArgs = array_merge($oAppContext->GetAsHash(), utils::ReadParam('default', array()));
|
||||
$sStateCode = $oWizard->GetTargetState(); // Will computes the default state if none was supplied
|
||||
$sClassLabel = MetaModel::GetName($sClass);
|
||||
$oP->add("<h2>Creation of a new $sClassLabel</h2>");
|
||||
@@ -367,21 +369,19 @@ switch($operation)
|
||||
foreach($aWizardSteps['mandatory'] as $aSteps)
|
||||
{
|
||||
$oP->SetCurrentTab("Step $iStepIndex *");
|
||||
$oWizard->DisplayWizardStep($aSteps, $iStepIndex, $iMaxInputId, $aFieldsMap);
|
||||
$oWizard->DisplayWizardStep($aSteps, $iStepIndex, $iMaxInputId, $aFieldsMap, false /* no finish button */, $aArgs);
|
||||
//$oP->add("</div>\n");
|
||||
$iStepIndex++;
|
||||
}
|
||||
foreach($aWizardSteps['optional'] as $aSteps)
|
||||
{
|
||||
$oP->SetCurrentTab("Step $iStepIndex *");
|
||||
$oWizard->DisplayWizardStep($aSteps, $iStepIndex, $iMaxInputId, $aFieldsMap, true); // true means enable the finish button
|
||||
$oWizard->DisplayWizardStep($aSteps, $iStepIndex, $iMaxInputId, $aFieldsMap, true, $aArgs); // true means enable the finish button
|
||||
//$oP->add("</div>\n");
|
||||
$iStepIndex++;
|
||||
}
|
||||
$oWizard->DisplayFinalStep($iStepIndex, $aFieldsMap);
|
||||
|
||||
$oAppContext = new ApplicationContext();
|
||||
$oContext = new UserContext();
|
||||
$oObj = null;
|
||||
if (!empty($id))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user