Add UIBlocks to twig (Use sub-blocks for alerts and fields)

This commit is contained in:
Eric
2021-01-14 13:56:51 +01:00
parent d8316a090a
commit 2aae6cd744
7 changed files with 62 additions and 59 deletions

View File

@@ -30,11 +30,8 @@ class UIAlertNode extends Node
->subcompile($oParams)
->raw(";\n")
->write("\$sTitle = \$aParams['title'] ?? '';\n")
->write("\$sId = \$aParams['id'] ?? null;\n")
->write("ob_start();\n")
->subcompile($this->getNode('body'))
->write("\$sContent = ob_get_contents();\n")
->write("ob_end_clean();\n");
->write("\$sContent = \$aParams['content'] ?? '';\n")
->write("\$sId = \$aParams['id'] ?? null;\n");
$sType = $this->getAttribute('type');
switch ($sType) {
@@ -47,7 +44,17 @@ class UIAlertNode extends Node
case 'WithBrandingPrimaryColor':
case 'WithBrandingSecondaryColor':
$compiler
->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Alert\\AlertFactory::Make{$sType}(\$sTitle, \$sContent, \$sId);\n");
->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Alert\\AlertFactory::Make{$sType}(\$sTitle, \$sContent, \$sId);\n")
->write("if (!\$aParams['is_collapsible'] ?? true) {\n")
->indent()
->write("\${$sBlockVar}->SetIsCollapsible(false);\n")
->outdent()
->write("}\n")
->write("if (!\$aParams['is_closable'] ?? true) {\n")
->indent()
->write("\${$sBlockVar}->SetIsClosable(false);\n")
->outdent()
->write("}\n");
break;
// TODO 3.0 add other Factory methods
@@ -55,7 +62,11 @@ class UIAlertNode extends Node
throw new SyntaxError(sprintf('%s: Bad type "%s" for %s at line %d', $this->getTemplateName(), $sType, $this->tag, $this->lineno), $this->lineno, $this->getSourceContext());
}
$compiler->write(UIBlockHelper::AddToParentBlock($sBlockVar));
$compiler
->write(UIBlockHelper::AddToParentBlock($sBlockVar))
->write(UIBlockHelper::PushParentBlock($sBlockVar))
->subcompile($this->getNode('body'))
->write(UIBlockHelper::PopParentBlock());
}
}

View File

@@ -36,11 +36,8 @@ class UIFieldNode extends Node
case 'Large':
$compiler
->write("\$sLabel = \$aParams['label'] ?? '';\n")
->write("\$sValue = \$aParams['value'] ?? '';\n")
->write("\$sValueId = \$aParams['value_id'] ?? null;\n")
->write("ob_start();\n")
->subcompile($this->getNode('body'))
->write("\$sValue = ob_get_contents();\n")
->write("ob_end_clean();\n")
->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Field\\FieldFactory::Make{$sType}(\$sLabel, \$sValue);\n")
->write("\${$sBlockVar}->SetValueId(\$sValueId);\n");
break;
@@ -50,7 +47,11 @@ class UIFieldNode extends Node
throw new SyntaxError(sprintf('%s: Bad type "%s" for %s at line %d', $this->getTemplateName(), $sType, $this->tag, $this->lineno), $this->lineno, $this->getSourceContext());
}
$compiler->write(UIBlockHelper::AddToParentBlock($sBlockVar));
$compiler
->write(UIBlockHelper::AddToParentBlock($sBlockVar))
->write(UIBlockHelper::PushParentBlock($sBlockVar))
->subcompile($this->getNode('body'))
->write(UIBlockHelper::PopParentBlock());
}
}

View File

@@ -37,7 +37,7 @@ class UIInputNode extends Node
->write("\$sName = \$aParams['name'] ?? '';\n")
->write("\$sValue = \$aParams['value'] ?? '';\n")
->write("\$sId = \$aParams['id'] ?? null;\n")
->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\InputFactory::Make{$sFactoryType}(\$sName, \$sValue, \$sId);\n");
->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\InputFactory::MakeForHidden(\$sName, \$sValue, \$sId);\n");
break;
case 'Standard':
@@ -46,7 +46,7 @@ class UIInputNode extends Node
->write("\$sName = \$aParams['name'] ?? '';\n")
->write("\$sValue = \$aParams['value'] ?? '';\n")
->write("\$sId = \$aParams['id'] ?? null;\n")
->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\InputFactory::Make{$sFactoryType}(\$sType, \$sName, \$sValue, \$sId);\n")
->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\InputFactory::MakeStandard(\$sType, \$sName, \$sValue, \$sId);\n")
->write("if (\$aParams['checked'] ?? false) {\n")
->indent()
->write("\${$sBlockVar}->SetChecked(true);\n")
@@ -54,20 +54,6 @@ class UIInputNode extends Node
->write("}\n");
break;
case 'WithLabel':
$compiler
->write("\$sLabel = \$aParams['label'] ?? '';\n")
->write("\$sType = \$aParams['type'] ?? '';\n")
->write("\$sName = \$aParams['name'] ?? '';\n")
->write("\$sValue = \$aParams['value'] ?? '';\n")
->write("\$sId = \$aParams['id'] ?? null;\n")
->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\InputFactory::Make{$sFactoryType}(\$sType, \$sLabel, \$sName, \$sValue, \$sId);\n")
->write("if (\$aParams['checked'] ?? false) {\n")
->indent()
->write("\${$sBlockVar}->GetInput()->SetChecked(true);\n")
->outdent()
->write("}\n");
break;
// TODO 3.0 add other Factory methods
default: