namespace Combodo\iTop\Renderer\Console\FieldRenderer; use \Dict; use Combodo\iTop\Renderer\FieldRenderer; use Combodo\iTop\Renderer\RenderingOutput; use Combodo\iTop\Form\Field\TextAreaField; use \InlineImage; use \UserRights; use \AttributeDuration; class ConsoleSimpleFieldRenderer extends FieldRenderer { public function Render() { $oOutput = new RenderingOutput(); $sFieldClass = get_class($this->oField); if ($sFieldClass == 'Combodo\\iTop\\Form\\Field\\HiddenField') { $oOutput->AddHtml(''); } else { $oOutput->AddHtml('
'); } switch ($sFieldClass) { case 'Combodo\\iTop\\Form\\Field\\StringField': $oOutput->AddHtml(' | '); if ($this->oField->GetReadOnly()) { $oOutput->AddHtml(''); $oOutput->AddHtml(''.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8').''); } else { $oOutput->AddHtml(''); } $oOutput->AddHtml(''); $oOutput->AddHtml(' | '); break; case 'Combodo\\iTop\\Form\\Field\\TextAreaField': $bRichEditor = ($this->oField->GetFormat() === TextAreaField::ENUM_FORMAT_HTML); $oOutput->AddHtml('');
if ($this->oField->GetReadOnly())
{
$oOutput->AddHtml('');
}
else
{
$oOutput->AddHtml('');
// Some additional stuff if we are displaying it with a rich editor
if ($bRichEditor)
{
$sEditorLanguage = strtolower(trim(UserRights::GetUserLanguage()));
$oOutput->AddJs(
<< | ');
break;
case 'Combodo\\iTop\\Form\\Field\\SelectField':
$oOutput->AddHtml(''); if ($this->oField->GetReadOnly()) { $aChoices = $this->oField->GetChoices(); $sCurrentLabel = isset($aChoices[$this->oField->GetCurrentValue()]) ? $aChoices[$this->oField->GetCurrentValue()] : '' ; $oOutput->AddHtml(''); $oOutput->AddHtml(''.htmlentities($sCurrentLabel, ENT_QUOTES, 'UTF-8').''); } else { $oOutput->AddHtml(''); } $oOutput->AddHtml(''); $oOutput->AddHtml(' | '); break; case 'Combodo\\iTop\\Form\\Field\\RadioField': $oOutput->AddHtml('');
if ($this->oField->GetReadOnly())
{
$aChoices = $this->oField->GetChoices();
$sCurrentLabel = isset($aChoices[$this->oField->GetCurrentValue()]) ? $aChoices[$this->oField->GetCurrentValue()] : '' ;
$oOutput->AddHtml('');
$oOutput->AddHtml(''.htmlentities($sCurrentLabel, ENT_QUOTES, 'UTF-8').'');
}
else
{
$bVertical = true;
$idx = 0;
$bMandatory = $this->oField->GetMandatory();
$value = $this->oField->GetCurrentValue();
$sId = $this->oField->GetGlobalId();
$oOutput->AddHtml(' ');
$aChoices = $this->oField->GetChoices();
foreach ($aChoices as $sChoice => $sLabel)
{
if ((count($aChoices)== 1) && $bMandatory)
{
// When there is only once choice, select it by default
$sSelected = ' checked';
}
else
{
$sSelected = ($value == $sChoice) ? ' checked' : '';
}
$oOutput->AddHtml(" ");
if ($bVertical)
{
$oOutput->AddHtml(" ');
$oOutput->AddHtml("");
}
$oOutput->AddHtml('');
$oOutput->AddHtml('\n"); } $idx++; } $oOutput->AddHtml(' | ');
break;
case 'Combodo\\iTop\\Form\\Field\\DurationField':
$oOutput->AddHtml(''); $value = $this->oField->GetCurrentValue(); if ($this->oField->GetReadOnly()) { $oOutput->AddHtml(''); $oOutput->AddHtml(''.htmlentities(\AttributeDuration::FormatDuration($value), ENT_QUOTES, 'UTF-8').''); } else { $sId = $this->oField->GetGlobalId(); $aVal = AttributeDuration::SplitDuration($value); $sDays = ""; $sHours = ""; $sMinutes = ""; $sSeconds = ""; $oOutput->AddHtml(Dict::Format('UI:DurationForm_Days_Hours_Minutes_Seconds', $sDays, $sHours, $sMinutes, $sSeconds)); $oOutput->AddHtml(""); $oOutput->AddJs("$('#{$sId}_d').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$sId'); });"); $oOutput->AddJs("$('#{$sId}_h').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$sId'); });"); $oOutput->AddJs("$('#{$sId}_m').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$sId'); });"); $oOutput->AddJs("$('#{$sId}_s').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$sId'); });"); $oOutput->AddJs("$('#{$sId}').bind('update', function(evt, sFormId) { return ToggleDurationField('$sId'); });"); } $oOutput->AddHtml(''); $oOutput->AddHtml(' | '); break; } $oOutput->AddHtml('