Customer portal : Form - Hiding templates when there is none in order to optimize form space (Actually hiding SubForm when there is only HiddenField)

SVN:trunk[4092]
This commit is contained in:
Guillaume Lajarige
2016-05-15 08:46:24 +00:00
parent 72b4c549c7
commit 7790f770a7
4 changed files with 35 additions and 5 deletions

View File

@@ -85,7 +85,7 @@
oStickyRegularButtons_{{ sFormIdSanitized }}.removeClass('closed');
}
};
// - Event binding
// - Event binding for scroll
$({% if tIsModal == true %}'.modal.in'{% else %}window{% endif %}).off('scroll').on('scroll', function () {
if (oScrollTimeout) {
// Clear the timeout, if one is pending
@@ -94,11 +94,15 @@
}
oScrollTimeout = setTimeout(scrollHandler_{{ sFormIdSanitized }}, 50);
});
// - Event binding for linkedset collapse
$({% if tIsModal == true %}'.modal.in'{% else %}window{% endif %}).off('shown.bs.collapse hidden.bs.collapse').on('shown.bs.collapse hidden.bs.collapse', function () {
scrollHandler_{{ sFormIdSanitized }}();
});
// - First time call
scrollHandler_{{ sFormIdSanitized }}();
// - Event binding for form building / updating
// Note : We do not want to 'off' the event or it will remove listeners from the widget
oFieldSet_{{ sFormIdSanitized }}.on('form_built', function(oEvent){
scrollHandler_{{ sFormIdSanitized }}();
});
{% if tIsModal == true %}
// Scroll top (because sometimes when several modals have been opened)

View File

@@ -317,6 +317,9 @@ $(function()
this.options.style_element.text(this.buildData.style_code);
eval(this.options.script_element.text());
// Sending event to let know that form is built
this.element.trigger('form_built');
},
hasTouchedFields: function()
{

View File

@@ -362,8 +362,10 @@ EOF
<<<EOF
<div class="row">
<div class="col-xs-12">
<button type="button" class="btn btn-sm btn-danger" id="{$sButtonRemoveId}" title="{$sLabelRemove}" disabled><span class="glyphicon glyphicon-minus"></span></button>
<button type="button" class="btn btn-sm btn-default" id="{$sButtonAddId}" title="{$sLabelAdd}"><span class="glyphicon glyphicon-plus"></span></button>
<div class="btn-group" role="group">
<button type="button" class="btn btn-sm btn-danger" id="{$sButtonRemoveId}" title="{$sLabelRemove}" disabled><span class="glyphicon glyphicon-minus"></span></button>
<button type="button" class="btn btn-sm btn-default" id="{$sButtonAddId}" title="{$sLabelAdd}"><span class="glyphicon glyphicon-plus"></span></button>
</div>
</div>
</div>
EOF

View File

@@ -29,6 +29,23 @@ class BsSubFormFieldRenderer extends FieldRenderer
{
$oOutput = new RenderingOutput();
// Checking if subform has visible fields
$bHasVisibleFields = false;
foreach ($this->oField->GetForm()->GetFields() as $oSubFormField)
{
$sSubFormFieldClass = get_class($oSubFormField);
// Note : This is a dirty hack for templates. As they show a label when there is no template, we have to detect it...
if (($sSubFormFieldClass !== 'Combodo\iTop\Form\Field\HiddenField') && ($oSubFormField->GetId() !== '_no_template_'))
{
$bHasVisibleFields = true;
}
}
// Showing subform if there are visible fields
if (!$bHasVisibleFields)
{
$oOutput->AddHtml('<div class="hidden">');
}
if (($this->oField->GetLabel() !== null) && ($this->oField->GetLabel() !== ''))
{
$oOutput->AddHtml('<fieldset><legend>' . $this->oField->GetLabel() . '</legend>');
@@ -39,6 +56,10 @@ class BsSubFormFieldRenderer extends FieldRenderer
{
$oOutput->AddHtml('</fieldset>');
}
if (!$bHasVisibleFields)
{
$oOutput->AddHtml('</div>');
}
$oRenderer = new BsFormRenderer($this->oField->GetForm());
$aRenderRes = $oRenderer->Render();