N°3819 - Input: Migrate request templates input to new UIBlock system

This commit is contained in:
acognet
2021-05-04 11:55:20 +02:00
parent a7040a911d
commit 16c9599739
8 changed files with 236 additions and 146 deletions

View File

@@ -2251,17 +2251,9 @@ HTML;
break;
case 'CustomFields':
$sHTMLValue = '<table>';
$sHTMLValue .= '<tr>';
$sHTMLValue .= '<td>';
$sHTMLValue .= '<div id="'.$iId.'_console_form">';
$sHTMLValue .= '<div id="'.$iId.'_field_set">';
$sHTMLValue .= '</div>';
$sHTMLValue .= '</div>';
$sHTMLValue .= '</td>';
$sHTMLValue .= '<td>'.$sReloadSpan.'</td>'; // No validation span for this one: it does handle its own validation!
$sHTMLValue .= '</tr>';
$sHTMLValue .= '</table>';
$sHTMLValue .= '<div>'.$sReloadSpan.'</div>'; // No validation span for this one: it does handle its own validation!
$sHTMLValue .= "<input name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" type=\"hidden\" id=\"$iId\" value=\"\"/>\n";
$oForm = $value->GetForm($sFormPrefix);

View File

@@ -49,6 +49,14 @@ $ibo-field--value-decoration--spacing-x: 0.5rem !default;
max-width: initial;
width: 100%;
}
.ibo-field-small .ibo-field--label {
display: table-cell;
vertical-align: top;
padding-right: 10px;
min-width: 100px;
max-width: 145px;
width: 30%;
}
}
.ibo-field-small {
display: table;

View File

@@ -19,11 +19,20 @@
namespace Combodo\iTop\Renderer\Console\FieldRenderer;
use CaptureWebPage;
use Combodo\iTop\Application\UI\Base\Component\Field\FieldUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
use Combodo\iTop\Application\UI\Base\Component\Input\InputUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\Select\SelectOptionUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\SelectUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlockUIBlockFactory;
use Combodo\iTop\Form\Validator\MandatoryValidator;
use Combodo\iTop\Renderer\BlockRenderer;
use \Dict;
use \DBObjectSet;
use Combodo\iTop\Renderer\FieldRenderer;
use Combodo\iTop\Form\Field\SelectObjectField;
use UIExtKeyWidget;
/**
* Class ConsoleSelectObjectFieldRenderer
@@ -39,16 +48,14 @@ class ConsoleSelectObjectFieldRenderer extends FieldRenderer
{
$oOutput = parent::Render();
$oOutput->AddHtml('<table class="form-field-container">');
$oOutput->AddHtml('<tr>');
if ($this->oField->GetLabel() != '')
{
$oOutput->AddHtml('<td class="form-field-label label"><span><label for="'.$this->oField->GetGlobalId().'">'.$this->oField->GetLabel().'</label></span></td>');
}
$oOutput->AddHtml('<td class="form-field-content">');
$oBlock = FieldUIBlockFactory::MakeStandard($this->oField->GetLabel());
$oBlock->SetValueId($this->oField->GetGlobalId());
$oBlock->AddDataAttribute("input-id",$this->oField->GetGlobalId());
$sEditType = 'none';
if ($this->oField->GetReadOnly())
{
$oBlock->AddDataAttribute("input-type","Combodo\\iTop\\Form\\Field\\SelectObjectField\readonly");
$oSearch = $this->oField->GetSearch()->DeepClone();
$oSearch->AddCondition('id', $this->oField->GetCurrentValue());
$oSet = new DBObjectSet($oSearch);
@@ -61,15 +68,17 @@ class ConsoleSelectObjectFieldRenderer extends FieldRenderer
{
$sCurrentLabel = '';
}
$oOutput->AddHtml('<input type="hidden" id="'.$this->oField->GetGlobalId().'" value="' . htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8') . '"/>');
$oOutput->AddHtml('<span class="form-field-data">'.htmlentities($sCurrentLabel, ENT_QUOTES, 'UTF-8').'</span>');
$oValue = UIContentBlockUIBlockFactory::MakeStandard();
$oValue->AddSubBlock(InputUIBlockFactory::MakeForHidden("",$this->oField->GetCurrentValue(),$this->oField->GetGlobalId()));
$oValue->AddSubBlock(new Html($sCurrentLabel));
$oBlock->SetValue($oValue);
}
else
{
$oSearch = $this->oField->GetSearch()->DeepClone();
$oSearch->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', true);
$oSet = new \DBObjectSet($oSearch);
$oSet = new DBObjectSet($oSearch);
$oSet->ApplyParameters();
$oSet->OptimizeColumnLoad(array($oSearch->GetClassAlias() => array('friendlyname')));
@@ -82,6 +91,7 @@ class ConsoleSelectObjectFieldRenderer extends FieldRenderer
{
// Auto-complete
//
$oBlock->AddDataAttribute("input-type","Combodo\\iTop\\Form\\Field\\SelectObjectField\\Autocomplete");
$sEditType = 'autocomplete';
$aExtKeyParams = array();
$aExtKeyParams['iFieldSize'] = 10;
@@ -89,14 +99,17 @@ class ConsoleSelectObjectFieldRenderer extends FieldRenderer
$sFieldName = $this->oField->GetGlobalId();
$sFieldId = $sFieldName;
$sFormPrefix = '';
$oWidget = new \UIExtKeyWidget($sTargetClass, $sFieldId, '', true);
$oWidget = new UIExtKeyWidget($sTargetClass, $sFieldId, '', true);
$aArgs = array();
$sTitle = $this->oField->GetLabel();
require_once(APPROOT.'application/capturewebpage.class.inc.php');
$oPage = new \CaptureWebPage();
$oPage = new CaptureWebPage();
$sHTMLValue = $oWidget->DisplaySelect($oPage, $iMaxComboLength, false /* $bAllowTargetCreation */, $sTitle, $oSet, $this->oField->GetCurrentValue(), $this->oField->GetMandatory(), $sFieldName, $sFormPrefix, $aArgs);
$oOutput->AddHtml($sHTMLValue);
$oOutput->AddHtml($oPage->GetHtml());
$oValue = UIContentBlockUIBlockFactory::MakeStandard();
$oValue->AddSubBlock(new Html($sHTMLValue));
$oValue->AddSubBlock(new Html($oPage->GetHtml()));
$oBlock->AddSubBlock($oValue);
$oOutput->AddJs($oPage->GetJS());
$oOutput->AddJs($oPage->GetReadyJS());
foreach ($oPage->GetCSS() as $sCss)
@@ -114,6 +127,7 @@ class ConsoleSelectObjectFieldRenderer extends FieldRenderer
}
elseif($this->oField->GetControlType() == SelectObjectField::CONTROL_RADIO_VERTICAL)
{
$oBlock->AddDataAttribute("input-type","Combodo\\iTop\\Form\\Field\\SelectObjectField\\Radio");
// Radio buttons (vertical)
//
$sEditType = 'radio';
@@ -122,6 +136,10 @@ class ConsoleSelectObjectFieldRenderer extends FieldRenderer
$bMandatory = $this->oField->GetMandatory();
$value = $this->oField->GetCurrentValue();
$sId = $this->oField->GetGlobalId();
$oValue = UIContentBlockUIBlockFactory::MakeStandard();
$oBlock->SetValue($oValue);
$oOutput->AddHtml('<div>');
while ($oObject = $oSet->Fetch())
{
@@ -137,32 +155,42 @@ class ConsoleSelectObjectFieldRenderer extends FieldRenderer
{
$sSelected = ($value == $iObject) ? 'checked' : '';
}
$oOutput->AddHtml("<input type=\"radio\" id=\"{$sId}_{$iObject}\" name=\"radio_$sId\" onChange=\"$('#{$sId}').val(this.value).trigger('change');\" value=\"$iObject\" $sSelected><label class=\"radio\" for=\"{$sId}_{$iObject}\">&nbsp;".htmlentities($sLabel, ENT_QUOTES, 'UTF-8')."</label>&nbsp;");
$oRadioCustom = InputUIBlockFactory::MakeForInputWithLabel($sLabel, "radio_$sId", $iObject, "{$sId}_{$iObject}", "radio");
$oRadioCustom->GetInput()->SetIsChecked($sSelected);
$oRadioCustom->SetBeforeInput(false);
$oRadioCustom->GetInput()->AddCSSClass('ibo-input-checkbox');
$oValue->AddSubBlock($oRadioCustom);
$oOutput->AddJs(
<<<EOF
$("#{$sId}_{$iObject}").off("change").on("change", function(){
$('#{$sId}').val(this.value).trigger('change');
});
EOF
);
if ($bVertical)
{
$oOutput->AddHtml("<br>\n");
$oValue->AddSubBlock(new Html("<br>"));
}
$idx++;
}
$oOutput->AddHtml('</div>');
$oOutput->AddHtml("<input type=\"hidden\" id=\"$sId\" name=\"$sId\" value=\"$value\"/>");
$oValue->AddSubBlock(InputUIBlockFactory::MakeForHidden($sId,$value,$sId));
}
else
{
// Drop-down select
//
$oBlock->AddDataAttribute("input-type","Combodo\\iTop\\Form\\Field\\SelectObjectField\\Select");
$sEditType = 'select';
$oOutput->AddHtml('<select class="form-field-data" id="'.$this->oField->GetGlobalId().'">');
$oOutput->AddHtml('<option value="">'.Dict::S('UI:SelectOne').'</option>');
$oSelect = SelectUIBlockFactory::MakeForSelect("",$this->oField->GetGlobalId());
$oBlock->AddSubBlock($oSelect);
$oSelect->AddOption(SelectOptionUIBlockFactory::MakeForSelectOption('',Dict::S('UI:SelectOne') ));
while ($oObject = $oSet->Fetch())
{
$iObject = $oObject->GetKey();
$sLabel = $oObject->Get('friendlyname');
// Note : The test is a double equal on purpose as the type of the value received from the XHR is not always the same as the type of the allowed values. (eg : string vs int)
$sSelectedAtt = ($this->oField->GetCurrentValue() == $iObject) ? 'selected' : '';
$oOutput->AddHtml('<option value="'.$iObject.'" '.$sSelectedAtt.' >'.htmlentities($sLabel, ENT_QUOTES, 'UTF-8').'</option>');
$oSelect->AddOption(SelectOptionUIBlockFactory::MakeForSelectOption($iObject,$sLabel, ($this->oField->GetCurrentValue() == $iObject)));
}
$oOutput->AddHtml('</select>');
}
$oOutput->AddJs(
<<<EOF
@@ -179,12 +207,7 @@ class ConsoleSelectObjectFieldRenderer extends FieldRenderer
EOF
);
}
$oOutput->AddHtml('<span class="form_validation"></span>');
$oOutput->AddHtml('</td>');
$oOutput->AddHtml('</tr>');
$oOutput->AddHtml('</table>');
$oOutput->AddHtml((BlockRenderer::RenderBlockTemplates($oBlock)));
// JS Form field widget construct
$aValidators = array();
foreach ($this->oField->GetValidators() as $oValidator)

View File

@@ -22,7 +22,16 @@ namespace Combodo\iTop\Renderer\Console\FieldRenderer;
use AttributeDate;
use AttributeDateTime;
use AttributeDuration;
use Combodo\iTop\Application\UI\Base\Component\Field\FieldUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
use Combodo\iTop\Application\UI\Base\Component\Input\InputUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\Select\SelectOptionUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\SelectUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\TextArea;
use Combodo\iTop\Application\UI\Base\Component\Text\Text;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlockUIBlockFactory;
use Combodo\iTop\Form\Field\TextAreaField;
use Combodo\iTop\Renderer\BlockRenderer;
use Combodo\iTop\Renderer\FieldRenderer;
use DateTimeFormat;
use Dict;
@@ -47,59 +56,68 @@ class ConsoleSimpleFieldRenderer extends FieldRenderer
}
else
{
$oOutput->AddHtml('<table class="form-field-container">');
$oOutput->AddHtml('<tr>');
if ($this->oField->GetLabel() != '')
{
$oOutput->AddHtml('<td class="form-field-label label"><span><label for="'.$this->oField->GetGlobalId().'">'.$this->oField->GetLabel().'</label></span></td>');
}
$oBlock = FieldUIBlockFactory::MakeStandard($this->oField->GetLabel());
$oBlock->AddDataAttribute("input-id",$this->oField->GetGlobalId());
$oBlock->AddDataAttribute("input-type",$sFieldClass);
switch ($sFieldClass)
{
case 'Combodo\\iTop\\Form\\Field\\DateTimeField':
$oValue = UIContentBlockUIBlockFactory::MakeStandard("",["form-field-content"]);
$sDateTimeFormat = $this->oField->GetPHPDateTimeFormat();
$oFormat = new DateTimeFormat($sDateTimeFormat);
$sPlaceHolder = $oFormat->ToPlaceholder();
$oOutput->AddHtml('<td class="form-field-content">');
if ($this->oField->GetReadOnly())
{
$oOutput->AddHtml('<input type="hidden" id="'.$this->oField->GetGlobalId().'" value="' . htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8') . '"/>');
$oOutput->AddHtml('<span class="form-field-data">'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8').'</span>');
} else {
$oOutput->AddHtml('<input class="form-field-data datetime-pick" size="15" type="text" placeholder="'.htmlentities($sPlaceHolder, ENT_QUOTES, 'UTF-8').'" id="'.$this->oField->GetGlobalId().'" value="'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES,
'UTF-8').'" size="30"/>');
$oValue->AddSubBlock(InputUIBlockFactory::MakeForHidden("",$this->oField->GetCurrentValue(),$this->oField->GetGlobalId()));
$oValue->AddSubBlock(new Html($this->oField->GetCurrentValue()));
}
$oOutput->AddHtml('<span class="form_validation"></span>');
$oOutput->AddHtml('</td>');
break;
else
{
$oField = UIContentBlockUIBlockFactory::MakeStandard("",["field_input_zone", "field_input_datetime", "ibo-input-wrapper", "ibo-input-datetime-wrapper"]);
$oValue->AddSubBlock($oField);
$oField->AddSubBlock(new Html('<input class="date-pick ibo-input ibo-input-date" type="text" placeholder="'.htmlentities($sPlaceHolder, ENT_QUOTES, 'UTF-8').'" id="'.$this->oField->GetGlobalId().'" value="'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8').'" autocomplete="off"/>'));
$oField->AddSubBlock(new Html('<span class="form_validation"></span>'));
}
$oBlock->AddSubBlock($oValue);
break;
case 'Combodo\\iTop\\Form\\Field\\LabelField':
$oOutput->AddHtml('<td class="form-field-content">');
$oOutput->AddHtml('<span class="form-field-data">'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8').'</span>');
$oOutput->AddHtml('<span class="form_validation"></span>');
$oOutput->AddHtml('</td>');
$oValue = UIContentBlockUIBlockFactory::MakeStandard("",[""]);
$oBlock->AddSubBlock($oValue);
$oValue->AddSubBlock(new Text($this->oField->GetCurrentValue()));
$oValue->AddSubBlock(new Html('<span class="form_validation"></span>'));
break;
case 'Combodo\\iTop\\Form\\Field\\StringField':
$oOutput->AddHtml('<td class="form-field-content">');
if ($this->oField->GetReadOnly()) {
$oOutput->AddHtml('<input type="hidden" id="'.$this->oField->GetGlobalId().'" value="'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8').'"/>');
$oOutput->AddHtml('<span class="form-field-data">'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8').'</span>');
} else {
$oOutput->AddHtml('<input class="form-field-data" type="text" id="'.$this->oField->GetGlobalId().'" value="'.htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8').'" size="30"/>');
$oValue = UIContentBlockUIBlockFactory::MakeStandard("",[""]);
if ($this->oField->GetReadOnly())
{
$oValue->AddSubBlock(InputUIBlockFactory::MakeForHidden("",$this->oField->GetCurrentValue(),$this->oField->GetGlobalId()));
$oValue->AddSubBlock(new Html($this->oField->GetCurrentValue()));
}
$oOutput->AddHtml('<span class="form_validation"></span>');
$oOutput->AddHtml('</td>');
else
{
$oValue->AddSubBlock(InputUIBlockFactory::MakeStandard("text","", $this->oField->GetCurrentValue(),$this->oField->GetGlobalId()));
$oValue->AddSubBlock(new Html('<span class="form_validation"></span>'));
}
$oBlock->AddSubBlock($oValue);
break;
case 'Combodo\\iTop\\Form\\Field\\TextAreaField':
$oValue = UIContentBlockUIBlockFactory::MakeStandard("",["form-field-content"]);
$bRichEditor = ($this->oField->GetFormat() === TextAreaField::ENUM_FORMAT_HTML);
$oOutput->AddHtml('<td class="form-field-content">');
if ($this->oField->GetReadOnly()) {
$oOutput->AddHtml('<textarea disabled="disabled" id="'.$this->oField->GetGlobalId().'" class="form-field-data resizable" rows="8" cols="40">'.$this->oField->GetCurrentValue().'</textarea>');
} else
$oText = new TextArea("",$this->oField->GetCurrentValue(),$this->oField->GetGlobalId(),40,8);
$oValue->AddSubBlock($oText);
if ($this->oField->GetReadOnly())
{
$oText->SetIsDisabled(true);
}
else
{
$oOutput->AddHtml('<textarea id="' . $this->oField->GetGlobalId() . '" class="form-field-data resizable" rows="8" cols="40">' . $this->oField->GetCurrentValue() . '</textarea>');
// Some additional stuff if we are displaying it with a rich editor
if ($bRichEditor)
{
@@ -110,7 +128,7 @@ class ConsoleSimpleFieldRenderer extends FieldRenderer
$oOutput->AddJs(
<<<EOF
$('#{$this->oField->GetGlobalId()}').addClass('htmlEditor');
$('#{$this->oField->GetGlobalId()}').ckeditor(function(){}, $sJsConfig);
$('#{$this->oField->GetGlobalId()}').ckeditor(function(){}, $sJsConfig);
EOF
);
if (($this->oField->GetObject() !== null) && ($this->oField->GetTransactionId() !== null))
@@ -118,43 +136,45 @@ EOF
$oOutput->AddJs(InlineImage::EnableCKEditorImageUpload($this->oField->GetObject(), utils::GetUploadTempId($this->oField->GetTransactionId())));
}
}
$oValue->AddSubBlock(new Html('<span class="form_validation"></span>'));
}
$oOutput->AddHtml('<span class="form_validation"></span>');
$oOutput->AddHtml('</td>');
$oBlock->AddSubBlock($oValue);
break;
case 'Combodo\\iTop\\Form\\Field\\SelectField':
$oOutput->AddHtml('<td class="form-field-content">');
$oValue = UIContentBlockUIBlockFactory::MakeStandard("",["form-field-content"]);
if ($this->oField->GetReadOnly())
{
$aChoices = $this->oField->GetChoices();
$sCurrentLabel = isset($aChoices[$this->oField->GetCurrentValue()]) ? $aChoices[$this->oField->GetCurrentValue()] : '' ;
$oOutput->AddHtml('<input type="hidden" id="'.$this->oField->GetGlobalId().'" value="' . htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8') . '"/>');
$oOutput->AddHtml('<span class="form-field-data">'.htmlentities($sCurrentLabel, ENT_QUOTES, 'UTF-8').'</span>');
$oValue->AddSubBlock(InputUIBlockFactory::MakeForHidden("",$this->oField->GetCurrentValue(),$this->oField->GetGlobalId()));
$oValue->AddSubBlock(new Html($sCurrentLabel));
}
else
{
$oOutput->AddHtml('<select class="form-field-data" id="'.$this->oField->GetGlobalId().'" '.(($this->oField->GetMultipleValuesEnabled()) ? 'multiple' : '').'>');
$oSelect = SelectUIBlockFactory::MakeForSelect("",$this->oField->GetGlobalId());
if ($this->oField->GetMultipleValuesEnabled()) {
$oSelect->SetIsMultiple(true);
}
foreach ($this->oField->GetChoices() as $sChoice => $sLabel)
{
// Note : The test is a double equal on purpose as the type of the value received from the XHR is not always the same as the type of the allowed values. (eg : string vs int)
$sSelectedAtt = ($this->oField->GetCurrentValue() == $sChoice) ? 'selected' : '';
$oOutput->AddHtml('<option value="'.htmlentities($sChoice, ENT_QUOTES, 'UTF-8').'" '.$sSelectedAtt.' >'.htmlentities($sLabel, ENT_QUOTES, 'UTF-8').'</option>');
$oSelect->AddOption(SelectOptionUIBlockFactory::MakeForSelectOption($sChoice,$sLabel, ($this->oField->GetCurrentValue() == $sChoice)));
}
$oOutput->AddHtml('</select>');
$oValue->AddSubBlock($oSelect);
$oValue->AddSubBlock(new Html('<span class="form_validation"></span>'));
}
$oOutput->AddHtml('<span class="form_validation"></span>');
$oOutput->AddHtml('</td>');
$oBlock->AddSubBlock($oValue);
break;
case 'Combodo\\iTop\\Form\\Field\\RadioField':
$oOutput->AddHtml('<td class="form-field-content">');
$oValue = UIContentBlockUIBlockFactory::MakeStandard("",["form-field-content"]);
if ($this->oField->GetReadOnly())
{
$aChoices = $this->oField->GetChoices();
$sCurrentLabel = isset($aChoices[$this->oField->GetCurrentValue()]) ? $aChoices[$this->oField->GetCurrentValue()] : '' ;
$oOutput->AddHtml('<input type="hidden" id="'.$this->oField->GetGlobalId().'" value="' . htmlentities($this->oField->GetCurrentValue(), ENT_QUOTES, 'UTF-8') . '"/>');
$oOutput->AddHtml('<span class="form-field-data">'.htmlentities($sCurrentLabel, ENT_QUOTES, 'UTF-8').'</span>');
$oValue->AddSubBlock(InputUIBlockFactory::MakeForHidden("",$this->oField->GetCurrentValue(),$this->oField->GetGlobalId()));
$oValue->AddSubBlock(new Html($sCurrentLabel));
}
else
{
@@ -163,7 +183,6 @@ EOF
$bMandatory = $this->oField->GetMandatory();
$value = $this->oField->GetCurrentValue();
$sId = $this->oField->GetGlobalId();
$oOutput->AddHtml('<div>');
$aChoices = $this->oField->GetChoices();
foreach ($aChoices as $sChoice => $sLabel)
{
@@ -177,30 +196,32 @@ EOF
{
$sSelected = ($value == $sChoice) ? 'checked' : '';
}
$oOutput->AddHtml("<input type=\"radio\" id=\"{$sId}_{$idx}\" name=\"radio_$sId\" onChange=\"$('#{$sId}').val(this.value).trigger('change');\" value=\"".htmlentities($sChoice, ENT_QUOTES, 'UTF-8')."\" $sSelected><label class=\"radio\" for=\"{$sId}_{$idx}\">&nbsp;".htmlentities($sLabel, ENT_QUOTES, 'UTF-8')."</label>&nbsp;");
$oRadio=InputUIBlockFactory::MakeForInputWithLabel($sLabel,"radio_".$sId, $sChoice,"{$sId}_{$idx}","radio" );;
$oRadio->GetInput()->SetIsChecked($sSelected);
$oRadio->SetBeforeInput(false);
$oRadio->GetInput()->AddCSSClass('ibo-input-checkbox');
$oValue->AddSubBlock($oRadio);
if ($bVertical)
{
$oOutput->AddHtml("<br>\n");
$oValue->AddSubBlock(new Html("<br>"));
}
$idx++;
}
$oOutput->AddHtml('</div>');
$oOutput->AddHtml("<input type=\"hidden\" id=\"$sId\" name=\"$sId\" value=\"$value\"/>");
$oValue->AddSubBlock(InputUIBlockFactory::MakeForHidden("",$value,$sId));
$oValue->AddSubBlock(new Html('<span class="form_validation"></span>'));
}
$oOutput->AddHtml('<span class="form_validation"></span>');
$oOutput->AddHtml('</td>');
$oBlock->AddSubBlock($oValue);
break;
case 'Combodo\\iTop\\Form\\Field\\DurationField':
$oOutput->AddHtml('<td class="form-field-content">');
$oValue = UIContentBlockUIBlockFactory::MakeStandard("",["form-field-content"]);
$value = $this->oField->GetCurrentValue();
if ($this->oField->GetReadOnly())
{
$oOutput->AddHtml('<input type="hidden" id="'.$this->oField->GetGlobalId().'" value="' . htmlentities($value, ENT_QUOTES, 'UTF-8') . '"/>');
$oOutput->AddHtml('<span class="form-field-data">'.htmlentities(\AttributeDuration::FormatDuration($value), ENT_QUOTES, 'UTF-8').'</span>');
$oValue->AddSubBlock(InputUIBlockFactory::MakeForHidden("",$value,$this->oField->GetGlobalId()));
$oValue->AddSubBlock(new Html(AttributeDuration::FormatDuration($value)));
}
else
{
else {
$sId = $this->oField->GetGlobalId();
$aVal = AttributeDuration::SplitDuration($value);
@@ -208,21 +229,22 @@ EOF
$sHours = "<input type=\"text\" size=\"2\" name=\"{$sId}[h]\" value=\"{$aVal['hours']}\" id=\"{$sId}_h\"/>";
$sMinutes = "<input type=\"text\" size=\"2\" name=\"{$sId}[m]\" value=\"{$aVal['minutes']}\" id=\"{$sId}_m\"/>";
$sSeconds = "<input type=\"text\" size=\"2\" name=\"{$sId}[s]\" value=\"{$aVal['seconds']}\" id=\"{$sId}_s\"/>";
$oOutput->AddHtml(Dict::Format('UI:DurationForm_Days_Hours_Minutes_Seconds', $sDays, $sHours, $sMinutes, $sSeconds));
$oOutput->AddHtml("<input type=\"hidden\" id=\"{$sId}\" value=\"".htmlentities($value, ENT_QUOTES, 'UTF-8')."\"/>");
$oTime = UIContentBlockUIBlockFactory::MakeStandard("",["pt-2"]);
$oTime->AddSubBlock(new Html(Dict::Format('UI:DurationForm_Days_Hours_Minutes_Seconds', $sDays, $sHours, $sMinutes, $sSeconds)));
$oValue->AddSubBlock($oTime);
$oValue->AddSubBlock(InputUIBlockFactory::MakeForHidden("",$value,$sId));
$oOutput->AddJs("$('#{$sId}_d').on('keyup change', function(evt, sFormId) { return UpdateDuration('$sId'); });");
$oOutput->AddJs("$('#{$sId}_h').on('keyup change', function(evt, sFormId) { return UpdateDuration('$sId'); });");
$oOutput->AddJs("$('#{$sId}_m').on('keyup change', function(evt, sFormId) { return UpdateDuration('$sId'); });");
$oOutput->AddJs("$('#{$sId}_s').on('keyup change', function(evt, sFormId) { return UpdateDuration('$sId'); });");
$oOutput->AddJs("$('#{$sId}').on('update', function(evt, sFormId) { return ToggleDurationField('$sId'); });");
$oValue->AddSubBlock(new Html('<span class="form_validation"></span>'));
}
$oOutput->AddHtml('<span class="form_validation"></span>');
$oOutput->AddHtml('</td>');
$oBlock->AddSubBlock($oValue);
break;
}
$oOutput->AddHtml('</tr>');
$oOutput->AddHtml('</table>');
$oOutput->AddHtml(BlockRenderer::RenderBlockTemplates($oBlock));
}
switch ($sFieldClass)
@@ -239,22 +261,25 @@ EOF
$oTimeFormat = new DateTimeFormat($sTimeFormat);
$sJSTimeFormat = json_encode($oTimeFormat->ToDatePicker());
$sJSOk = json_encode(Dict::S('UI:Button:Ok'));
if ($this->oField->IsDateOnly())
{
$oOutput->AddJs(
<<<EOF
$("#{$this->oField->GetGlobalId()}").datepicker({
showOn: 'button',
buttonImage: '../images/calendar.png',
buttonImageOnly: true,
dateFormat: $sJSDateFormat,
constrainInput: false,
changeMonth: true,
changeYear: true,
dayNamesMin: $sJSDaysMin,
monthNamesShort: $sJSMonthsShort,
firstDay: $iFirstDayOfWeek
});
var oInput = "#{$this->oField->GetGlobalId()}";
$(oInput).addClass('is-widget-ready');
$(oInput).datepicker({
"showOn":"button",
"buttonText":"<i class=\"fas fa-calendar-alt\"><\/i>",
"format": $sJSDateFormat,
"constrainInput":false,
"changeMonth":true,
"changeYear":true,
"dayNamesMin":$sJSDaysMin,
"monthNamesShort": $sJSMonthsShort,
"firstDay":$iFirstDayOfWeek}).next("img").wrap("<span>");
EOF
);
}
@@ -262,40 +287,38 @@ EOF
{
$oOutput->AddJs(
<<<EOF
$("#{$this->oField->GetGlobalId()}").datetimepicker({
showOn: 'button',
buttonImage: '../images/calendar.png',
buttonImageOnly: true,
dateFormat: $sJSDateFormat,
constrainInput: false,
changeMonth: true,
changeYear: true,
dayNamesMin: $sJSDaysMin,
monthNamesShort: $sJSMonthsShort,
firstDay: $iFirstDayOfWeek,
// time picker options
timeFormat: $sJSTimeFormat,
controlType: 'select',
closeText: $sJSOk
var oInput = "#{$this->oField->GetGlobalId()}";
$(oInput).addClass('is-widget-ready');
$('<div class="ibo-input-datetime--action-button"><i class="fas fa-calendar-alt"></i></i>')
.insertAfter($(oInput))
.on('click', function(){
$(oInput)
.datetimepicker({
showOn: 'button',
buttonText: "<i class=\"fas fa-calendar-alt\"><\/i>",
dateFormat: $sJSDateFormat,
constrainInput: false,
changeMonth: true,
changeYear: true,
dayNamesMin: $sJSDaysMin,
monthNamesShort: $sJSMonthsShort,
firstDay: $iFirstDayOfWeek,
// time picker options
timeFormat: $sJSTimeFormat,
controlType: 'select',
closeText: $sJSOk
})
.datetimepicker('show')
.datetimepicker('option', 'onClose', function(dateText,inst){
$(oInput).datetimepicker('destroy');
})
.on('click keypress', function(){
$(oInput).datetimepicker('hide');
});
});
EOF
);
}
$oOutput->AddJs(
<<<EOF
$("#{$this->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;
break;

View File

@@ -22,11 +22,14 @@ class Select extends UIContentBlock
protected $sValue;
/** @var bool */
protected $bSubmitOnChange = false;
/** @var bool */
protected $bIsMultiple = false;
public function __construct(?string $sId = null)
{
parent::__construct($sId);
$this->bIsMultiple = false;
}
public function AddOption(SelectOption $oOption)
@@ -84,7 +87,25 @@ class Select extends UIContentBlock
public function SetSubmitOnChange(bool $bSubmitOnChange)
{
$this->bSubmitOnChange = $bSubmitOnChange;
return $this;
}
/**
* @return bool
*/
public function IsMultiple(): bool
{
return $this->bIsMultiple;
}
/**
* @param bool $bIsMultiple
*/
public function SetIsMultiple(bool $bIsMultiple): void
{
$this->bIsMultiple = $bIsMultiple;
}
}

View File

@@ -20,6 +20,8 @@ class TextArea extends AbstractInput
protected $iCols;
/** @var int */
protected $iRows;
/** @var bool */
protected $bIsDisabled;
public function __construct(string $sName, ?string $sValue, ?string $sId = null, ?int $iCols = null, ?int $iRows = null)
{
@@ -29,6 +31,7 @@ class TextArea extends AbstractInput
$this->sValue = $sValue;
$this->iCols = $iCols;
$this->iRows = $iRows;
$this->bIsDisabled = false;
}
public function GetCols(): ?int
@@ -64,4 +67,22 @@ class TextArea extends AbstractInput
return $this;
}
/**
* @return bool
*/
public function IsDisabled(): bool
{
return $this->bIsDisabled;
}
/**
* @param bool $bIsDisabled
*/
public function SetIsDisabled(bool $bIsDisabled): void
{
$this->bIsDisabled = $bIsDisabled;
}
}

View File

@@ -11,5 +11,6 @@
{% endif %}
{% if oUIBlock.GetAdditionalCSSClassesAsString() %} class="{{ oUIBlock.GetAdditionalCSSClassesAsString() }}"{% endif %}
{% if oUIBlock.GetPlaceHolder() %} placeholder="{{ oUIBlock.GetPlaceHolder() }}" {% endif %}
{% if oUIBlock.IsDisabled() %} disabled="disabled" {% endif %}
>{{ oUIBlock.GetValue()|raw }}</textarea>
{% endblock %}

View File

@@ -4,6 +4,7 @@
{% block iboInput %}
<select id="{{ oUIBlock.GetId() }}" name="{{ oUIBlock.GetName() }}"
{% if oUIBlock.GetSubmitOnChange() %}onChange="this.form.submit();"{% endif %}
{% if oUIBlock.IsMultiple() %}multiple{% endif %}
class="{% if oUIBlock.IsHidden() %}ibo-is-hidden{% endif %}"
>
{% for oSubBlock in oUIBlock.GetSubBlocks() %}