namespace Combodo\iTop\Renderer\Console\FieldRenderer; use Combodo\iTop\Form\Validator\MandatoryValidator; use \Dict; use \DBObjectSet; use Combodo\iTop\Renderer\FieldRenderer; use Combodo\iTop\Renderer\RenderingOutput; use Combodo\iTop\Form\Field\SelectObjectField; class ConsoleSelectObjectFieldRenderer extends FieldRenderer { public function Render() { $oOutput = new RenderingOutput(); $oOutput->AddHtml('
'); } $oOutput->AddHtml(' | ');
$sEditType = 'none';
if ($this->oField->GetReadOnly())
{
$oSearch = $this->oField->GetSearch()->DeepClone();
$oSearch->AddCondition('id', $this->oField->GetCurrentValue());
$oSet = new DBObjectSet($oSearch);
$oObject = $oSet->Fetch();
if ($oObject)
{
$sCurrentLabel = $oObject->Get('friendlyname');
}
else
{
$sCurrentLabel = '';
}
$oOutput->AddHtml('');
$oOutput->AddHtml(''.htmlentities($sCurrentLabel, ENT_QUOTES, 'UTF-8').'');
}
else
{
$oSearch = $this->oField->GetSearch()->DeepClone();
$oSearch->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true);
$oSet = new \DBObjectSet($oSearch);
$oSet->OptimizeColumnLoad(array($oSearch->GetClassAlias() => array('friendlyname')));
$sTargetClass = $oSearch->GetClass();
$oAllowedValues = new DBObjectSet($oSearch);
$iMaxComboLength = $this->oField->GetMaximumComboLength();
$iCount = $oAllowedValues->Count();
if ($iCount > $iMaxComboLength)
{
// Auto-complete
//
$sEditType = 'autocomplete';
$aExtKeyParams = array();
$aExtKeyParams['iFieldSize'] = 10;
$aExtKeyParams['iMinChars'] = $this->oField->GetMinAutoCompleteChars();
$sFieldName = $this->oField->GetGlobalId();
$sFieldId = $sFieldName;
$sFormPrefix = '';
$oWidget = new \UIExtKeyWidget($sTargetClass, $sFieldId, '', true);
$aArgs = array();
$sDisplayStyle = 'select';
$sTitle = $this->oField->GetLabel();
require_once(APPROOT.'application/capturewebpage.class.inc.php');
$oPage = new \CaptureWebPage();
$sHTMLValue = $oWidget->Display($oPage, $iMaxComboLength, false /* $bAllowTargetCreation */, $sTitle, $oSet, $this->oField->GetCurrentValue(), $sFieldId, $this->oField->GetMandatory(), $sFieldName, $sFormPrefix, $aArgs, null, $sDisplayStyle);
$oOutput->AddHtml($sHTMLValue);
$oOutput->AddHtml($oPage->GetHtml());
$oOutput->AddJs($oPage->GetJS());
$oOutput->AddJs($oPage->GetReadyJS());
$oOutput->AddCss($oPage->GetCSS());
foreach ($oPage->GetJSFiles() as $sFile)
{
$oOutput->AddJsFile($sFile);
}
foreach ($oPage->GetCSSFiles() as $sFile)
{
$oOutput->AddCssFile($sFile);
}
}
elseif($this->oField->GetControlType() == SelectObjectField::CONTROL_RADIO_VERTICAL)
{
// Radio buttons (vertical)
//
$sEditType = 'radio';
$bVertical = true;
$idx = 0;
$bMandatory = $this->oField->GetMandatory();
$value = $this->oField->GetCurrentValue();
$sId = $this->oField->GetGlobalId();
$oOutput->AddHtml(' ');
while ($oObject = $oSet->Fetch())
{
$iObject = $oObject->GetKey();
$sLabel = $oObject->Get('friendlyname');
if (($iCount == 1) && $bMandatory)
{
// When there is only once choice, select it by default
$sSelected = ' checked';
}
else
{
$sSelected = ($value == $iObject) ? ' checked' : '';
}
$oOutput->AddHtml(" ");
if ($bVertical)
{
$oOutput->AddHtml(" ');
$oOutput->AddHtml("");
}
else
{
// Drop-down select
//
$sEditType = 'select';
$oOutput->AddHtml('');
}
$oOutput->AddJs(
<<\n"); } $idx++; } $oOutput->AddHtml(' | ');
$oOutput->AddHtml('