فهرست منبع

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

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4092 a333f486-631f-4898-b8df-5754b55c2be0
glajarige 9 سال پیش
والد
کامیت
c5380e3e6a

+ 7 - 3
datamodels/2.x/itop-portal-base/portal/src/views/bricks/object/mode_create.html.twig

@@ -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)

+ 3 - 0
js/field_set.js

@@ -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()
 		{

+ 4 - 2
sources/renderer/bootstrap/fieldrenderer/bslinkedsetfieldrenderer.class.inc.php

@@ -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

+ 21 - 0
sources/renderer/bootstrap/fieldrenderer/bssubformfieldrenderer.class.inc.php

@@ -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();