diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php
index 0176c0110..738537626 100644
--- a/application/cmdbabstract.class.inc.php
+++ b/application/cmdbabstract.class.inc.php
@@ -1520,24 +1520,39 @@ EOF
$iFieldSize = $oAttDef->GetMaxSize();
if ($aAllowedValues !== null)
{
- // Discrete list of values, use a SELECT
- $sHTMLValue = " {$sValidationField}\n";
- $aEventsList[] ='change';
}
else
{
diff --git a/application/ui.extkeywidget.class.inc.php b/application/ui.extkeywidget.class.inc.php
index c8fb0154c..c745640ff 100644
--- a/application/ui.extkeywidget.class.inc.php
+++ b/application/ui.extkeywidget.class.inc.php
@@ -73,8 +73,9 @@ class UIExtKeyWidget
$sTargetClass = $oAttDef->GetTargetClass();
$iMaxComboLength = $oAttDef->GetMaximumComboLength();
$bAllowTargetCreation = $oAttDef->AllowTargetCreation();
+ $sDisplayStyle = $oAttDef->GetDisplayStyle();
$oWidget = new UIExtKeyWidget($sTargetClass, $iInputId);
- return $oWidget->Display($oPage, $iMaxComboLength, $bAllowTargetCreation, $sTitle, $oAllowedValues, $value, $iInputId, $bMandatory, $sFieldName, $sFormPrefix, $aArgs, $bSearchMode);
+ return $oWidget->Display($oPage, $iMaxComboLength, $bAllowTargetCreation, $sTitle, $oAllowedValues, $value, $iInputId, $bMandatory, $sFieldName, $sFormPrefix, $aArgs, $bSearchMode, $sDisplayStyle);
}
public function __construct($sTargetClass, $iInputId)
@@ -89,13 +90,14 @@ class UIExtKeyWidget
* @param Hash $aArgs Extra context arguments
* @return string The HTML fragment to be inserted into the page
*/
- public function Display(WebPage $oPage, $iMaxComboLength, $bAllowTargetCreation, $sTitle, $oAllowedValues, $value, $iInputId, $bMandatory, $sFieldName, $sFormPrefix = '', $aArgs = array(), $bSearchMode = false)
+ public function Display(WebPage $oPage, $iMaxComboLength, $bAllowTargetCreation, $sTitle, $oAllowedValues, $value, $iInputId, $bMandatory, $sFieldName, $sFormPrefix = '', $aArgs = array(), $bSearchMode = false, $sDisplayStyle = 'select')
{
$sTitle = addslashes($sTitle);
$oPage->add_linked_script('../js/extkeywidget.js');
$oPage->add_linked_script('../js/forms-json-utils.js');
$bCreate = (!$bSearchMode) && (!MetaModel::IsAbstract($this->sTargetClass)) && (UserRights::IsActionAllowed($this->sTargetClass, UR_ACTION_BULK_MODIFY) && $bAllowTargetCreation);
+ $bExtensions = true;
$sMessage = Dict::S('UI:Message:EmptyList:UseSearchForm');
$sAttrFieldPrefix = ($bSearchMode) ? '' : 'attr_';
@@ -117,40 +119,60 @@ class UIExtKeyWidget
}
elseif ($oAllowedValues->Count() < $iMaxComboLength)
{
- // Few choices, use a normal 'select'
- $sSelectMode = 'true';
-
- $sHelpText = ''; //$this->oAttDef->GetHelpOnEdition();
-
- $sHTMLValue = "iId\">\n";
- if ($bSearchMode)
+ // Discrete list of values, use a SELECT or RADIO buttons depending on the config
+ switch($sDisplayStyle)
{
- $sDisplayValue = isset($aArgs['sDefaultValue']) ? $aArgs['sDefaultValue'] : Dict::S('UI:SearchValue:Any');
- $sHTMLValue .= "\n";
- }
- else
- {
- $sHTMLValue .= "\n";
- }
- $oAllowedValues->Rewind();
- while($oObj = $oAllowedValues->Fetch())
- {
- $key = $oObj->GetKey();
- $display_value = $oObj->Get('friendlyname');
-
- if (($oAllowedValues->Count() == 1) && ($bMandatory == 'true') )
+ case 'radio':
+ case 'radio_horizontal':
+ case 'radio_vertical':
+ $sHTMLValue = '';
+ $bVertical = ($sDisplayStyle != 'radio_horizontal');
+ $bExtensions = false;
+ $oAllowedValues->Rewind();
+ $aAllowedValues = array();
+ while($oObj = $oAllowedValues->Fetch())
{
- // When there is only once choice, select it by default
- $sSelected = ' selected';
+ $aAllowedValues[$oObj->GetKey()] = $oObj->Get('friendlyname');
+ }
+ $sHTMLValue = $oPage->GetRadioButtons($aAllowedValues, $value, $this->iId, "{$sAttrFieldPrefix}{$sFieldName}", $bMandatory, $bVertical, '' /* TODO: manage validation field */);
+ $aEventsList[] ='change';
+ break;
+
+ case 'select':
+ default:
+ $sSelectMode = 'true';
+
+ $sHelpText = ''; //$this->oAttDef->GetHelpOnEdition();
+
+ $sHTMLValue = "iId\">\n";
+ if ($bSearchMode)
+ {
+ $sDisplayValue = isset($aArgs['sDefaultValue']) ? $aArgs['sDefaultValue'] : Dict::S('UI:SearchValue:Any');
+ $sHTMLValue .= "\n";
}
else
{
- $sSelected = ($value == $key) ? ' selected' : '';
+ $sHTMLValue .= "\n";
}
- $sHTMLValue .= "\n";
- }
- $sHTMLValue .= "\n";
- $oPage->add_ready_script(
+ $oAllowedValues->Rewind();
+ while($oObj = $oAllowedValues->Fetch())
+ {
+ $key = $oObj->GetKey();
+ $display_value = $oObj->Get('friendlyname');
+
+ if (($oAllowedValues->Count() == 1) && ($bMandatory == 'true') )
+ {
+ // When there is only once choice, select it by default
+ $sSelected = ' selected';
+ }
+ else
+ {
+ $sSelected = ($value == $key) ? ' selected' : '';
+ }
+ $sHTMLValue .= "\n";
+ }
+ $sHTMLValue .= "\n";
+ $oPage->add_ready_script(
<<iId} = new ExtKeyWidget('{$this->iId}', '{$this->sTargetClass}', '$sFilter', '$sTitle', true, $sWizHelper);
oACWidget_{$this->iId}.emptyHtml = "
$sMessage
";
@@ -158,7 +180,8 @@ class UIExtKeyWidget
$('#$this->iId').bind('change', function() { $(this).trigger('extkeychange') } );
EOF
-);
+ );
+ } // Switch
}
else
{
@@ -200,7 +223,7 @@ EOF
EOF
);
}
- if (MetaModel::IsHierarchicalClass($this->sTargetClass) !== false)
+ if ($bExtensions && MetaModel::IsHierarchicalClass($this->sTargetClass) !== false)
{
$sHTMLValue .= "iId}.HKDisplay();\">iId}\" style=\"border:0;vertical-align:middle;\" src=\"../images/mini_tree.gif\" /> ";
$oPage->add_ready_script(
@@ -212,7 +235,7 @@ EOF
EOF
);
}
- if ($bCreate)
+ if ($bCreate && $bExtensions)
{
$sHTMLValue .= "iId}.CreateObject();\">iId}\" style=\"border:0;vertical-align:middle;\" src=\"../images/mini_add.gif\" /> ";
$oPage->add_ready_script(
diff --git a/application/webpage.class.inc.php b/application/webpage.class.inc.php
index b26583ec4..c98b8711f 100644
--- a/application/webpage.class.inc.php
+++ b/application/webpage.class.inc.php
@@ -275,6 +275,53 @@ class WebPage
$sHtml .= "\n";
return $sHtml;
}
+
+ /**
+ * Build a set of radio buttons suitable for editing a field/attribute of an object (including its validation)
+ * @param $aAllowedValues hash Array of value => display_value
+ * @param $value mixed Current value for the field/attribute
+ * @param $iId mixed Unique Id for the input control in the page
+ * @param $sFieldName string The name of the field, attr_<$sFieldName> will hold the value for the field
+ * @param $bMandatory bool Whether or not the field is mandatory
+ * @param $bVertical bool Disposition of the radio buttons vertical or horizontal
+ * @param $sValidationField string HTML fragment holding the validation field (exclamation icon...)
+ * @return string The HTML fragment corresponding to the radio buttons
+ */
+ public function GetRadioButtons($aAllowedValues, $value, $iId, $sFieldName, $bMandatory, $bVertical, $sValidationField)
+ {
+ $idx = 0;
+ $sHTMLValue = '';
+ foreach($aAllowedValues as $key => $display_value)
+ {
+ if ((count($aAllowedValues) == 1) && ($bMandatory == 'true') )
+ {
+ // When there is only once choice, select it by default
+ $sSelected = ' checked';
+ }
+ else
+ {
+ $sSelected = ($value == $key) ? ' checked' : '';
+ }
+ $sHTMLValue .= " ";
+ if ($bVertical)
+ {
+ if ($idx == 0)
+ {
+ // Validation icon at the end of the first line
+ $sHTMLValue .= " {$sValidationField}\n";
+ }
+ $sHTMLValue .= " \n";
+ }
+ $idx++;
+ }
+ $sHTMLValue .= "";
+ if (!$bVertical)
+ {
+ // Validation icon at the end of the line
+ $sHTMLValue .= " {$sValidationField}\n";
+ }
+ return $sHTMLValue;
+ }
/**
* Outputs (via some echo) the complete HTML page by assembling all its elements
diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php
index a33b11ee7..ea0f76c32 100644
--- a/core/attributedef.class.inc.php
+++ b/core/attributedef.class.inc.php
@@ -1109,6 +1109,11 @@ class AttributeString extends AttributeDBField
$sEscaped = str_replace($sFrom, $sTo, (string)$sValue);
return $sTextQualifier.$sEscaped.$sTextQualifier;
}
+
+ public function GetDisplayStyle()
+ {
+ return $this->GetOptional('display_style', 'select');
+ }
}
/**
@@ -2355,6 +2360,7 @@ class AttributeExternalKey extends AttributeDBFieldVoid
public function GetTargetClass($iType = EXTKEY_RELATIVE) {return $this->Get("targetclass");}
public function GetKeyAttDef($iType = EXTKEY_RELATIVE){return $this;}
public function GetKeyAttCode() {return $this->GetCode();}
+ public function GetDisplayStyle() { return $this->GetOptional('display_style', 'select'); }
public function GetDefaultValue() {return 0;}