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(''); $oOutput->AddHtml(''); if ($this->oField->GetLabel() != '') { $oOutput->AddHtml(''); } switch ($sFieldClass) { case 'Combodo\\iTop\\Form\\Field\\StringField': $oOutput->AddHtml(''); break; case 'Combodo\\iTop\\Form\\Field\\TextAreaField': $bRichEditor = ($this->oField->GetFormat() === TextAreaField::ENUM_FORMAT_HTML); $oOutput->AddHtml(''); break; case 'Combodo\\iTop\\Form\\Field\\SelectField': $oOutput->AddHtml(''); break; case 'Combodo\\iTop\\Form\\Field\\RadioField': $oOutput->AddHtml(''); break; case 'Combodo\\iTop\\Form\\Field\\DurationField': $oOutput->AddHtml(''); break; } $oOutput->AddHtml(''); $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(''); 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( <<oField->GetGlobalId()}').addClass('htmlEditor'); $('#{$this->oField->GetGlobalId()}').ckeditor(function(){}, {language: '$sEditorLanguage', contentsLanguage: '$sEditorLanguage'}); EOF ); if (($this->oField->GetObject() !== null) && ($this->oField->GetTransactionId() !== null)) { $oOutput->AddJs(InlineImage::EnableCKEditorImageUpload($this->oField->GetObject(), utils::GetUploadTempId($this->oField->GetTransactionId()))); } } } $oOutput->AddHtml(''); $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(''); 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("
\n"); } $idx++; } $oOutput->AddHtml('
'); $oOutput->AddHtml(""); } $oOutput->AddHtml(''); $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('
'); } switch ($sFieldClass) { case 'Combodo\\iTop\\Form\\Field\\StringField': case 'Combodo\\iTop\\Form\\Field\\TextAreaField': $oOutput->AddJs( <<oField->GetGlobalId()}").off("change keyup").on("change keyup", function(){ var me = this; $(this).closest(".field_set").trigger("field_change", { id: $(me).attr("id"), name: $(me).closest(".form_field").attr("data-field-id"), value: $(me).val() }) .closest('.form_handler').trigger('value_change'); }); EOF ); break; case 'Combodo\\iTop\\Form\\Field\\SelectField': case 'Combodo\\iTop\\Form\\Field\\RadioField': case 'Combodo\\iTop\\Form\\Field\\DurationField': $oOutput->AddJs( <<oField->GetGlobalId()}").off("change").on("change", function(){ var me = this; $(this).closest(".field_set").trigger("field_change", { id: $(me).attr("id"), name: $(me).closest(".form_field").attr("data-field-id"), value: $(me).val() }) .closest('.form_handler').trigger('value_change'); }); EOF ); break; } // JS Form field widget construct $aValidators = array(); foreach ($this->oField->GetValidators() as $oValidator) { $aValidators[$oValidator::GetName()] = array( 'reg_exp' => $oValidator->GetRegExp(), 'message' => Dict::S($oValidator->GetErrorMessage()) ); } $sValidators = json_encode($aValidators); $sFormFieldOptions = <<'); oValidationElement.tooltip({ items: 'span', tooltipClass: 'form_field_error', content: function() { return $(this).find('img').attr('data-tooltip'); // As opposed to the default 'content' handler, do not escape the contents of 'title' } }); } } } EOF ; $oOutput->AddJs( <<AddJs( <<