mirror of
https://github.com/Combodo/iTop.git
synced 2026-08-22 14:18:18 +02:00
N°917: New AttributeClassState for triggers on state (entering or leaving a state)
This commit is contained in:
@@ -1677,6 +1677,13 @@ EOF
|
||||
{
|
||||
$iInputId = $oPage->GetUniqueId();
|
||||
}
|
||||
if (method_exists($oAttDef, 'SetTargetClass'))
|
||||
{
|
||||
if (isset($aArgs['this']))
|
||||
{
|
||||
$oAttDef->SetTargetClass($aArgs['this']);
|
||||
}
|
||||
}
|
||||
|
||||
$sHTMLValue = '';
|
||||
if (!$oAttDef->IsExternalField())
|
||||
@@ -2057,10 +2064,6 @@ EOF
|
||||
|
||||
$oPage->add_dict_entry('Core:AttributeTagSet:placeholder');
|
||||
|
||||
if (isset($aArgs['this']))
|
||||
{
|
||||
$oAttDef->SetTargetClass($aArgs['this']);
|
||||
}
|
||||
/** @var \ormSet $value */
|
||||
$sJson = $oAttDef->GetJsonForWidget($value);
|
||||
$sInputId = "attr_{$sFormPrefix}{$sAttCode}";
|
||||
@@ -2073,7 +2076,7 @@ EOF
|
||||
default:
|
||||
$aEventsList[] = 'validate';
|
||||
// #@# todo - add context information (depending on dimensions)
|
||||
$aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs);
|
||||
$aAllowedValues = $oAttDef->GetAllowedValues($aArgs);
|
||||
$iFieldSize = $oAttDef->GetMaxSize();
|
||||
if ($aAllowedValues !== null)
|
||||
{
|
||||
|
||||
@@ -3103,7 +3103,7 @@ class AttributeString extends AttributeDBField
|
||||
}
|
||||
|
||||
/**
|
||||
* An attibute that matches an object class
|
||||
* An attribute that matches an object class
|
||||
*
|
||||
* @package iTopORM
|
||||
*/
|
||||
@@ -3161,6 +3161,66 @@ class AttributeClass extends AttributeString
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An attribute that matches a class state
|
||||
*
|
||||
* @package iTopORM
|
||||
*/
|
||||
class AttributeClassState extends AttributeString
|
||||
{
|
||||
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_ENUM;
|
||||
|
||||
private $sTargetClass;
|
||||
|
||||
/**
|
||||
* @param \DBObject $oHostObj
|
||||
*
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function SetTargetClass($oHostObj)
|
||||
{
|
||||
if (!empty($oHostObj))
|
||||
{
|
||||
$sTargetClass = $this->Get('class_field');
|
||||
$sClass = $oHostObj->Get($sTargetClass);
|
||||
$this->sTargetClass = $sClass;
|
||||
}
|
||||
}
|
||||
|
||||
public function GetAllowedValues($aArgs = array(), $sContains = '')
|
||||
{
|
||||
if (!empty($this->sTargetClass))
|
||||
{
|
||||
$aAllowedStates = array();
|
||||
$aValues = MetaModel::EnumStates($this->sTargetClass);
|
||||
foreach(array_keys($aValues) as $sState)
|
||||
{
|
||||
$aAllowedStates[$sState] = MetaModel::GetStateLabel($this->sTargetClass, $sState);
|
||||
}
|
||||
return $aAllowedStates;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
|
||||
{
|
||||
if (empty($sValue))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
$this->SetTargetClass($oHostObject);
|
||||
if (!empty($this->sTargetClass))
|
||||
{
|
||||
return MetaModel::GetStateLabel($this->sTargetClass, $sValue);
|
||||
}
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An attibute that matches one of the language codes availables in the dictionnary
|
||||
*
|
||||
|
||||
@@ -289,7 +289,7 @@ abstract class TriggerOnStateChange extends TriggerOnObject
|
||||
);
|
||||
MetaModel::Init_Params($aParams);
|
||||
MetaModel::Init_InheritAttributes();
|
||||
MetaModel::Init_AddAttribute(new AttributeString("state", array("allowed_values" => null, "sql" => "state", "default_value" => null, "is_null_allowed" => false, "depends_on" => array())));
|
||||
MetaModel::Init_AddAttribute(new AttributeClassState("state", array("class_field" => 'target_class', "allowed_values" => null, "sql" => "state", "default_value" => null, "is_null_allowed" => false, "depends_on" => array('target_class'))));
|
||||
|
||||
// Display lists
|
||||
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'filter', 'state', 'action_list')); // Attributes to be displayed for the complete details
|
||||
|
||||
Reference in New Issue
Block a user