N°2737 - RenderBlockTemplate enhancement, uilinkswidget UIBlock refactor

This commit is contained in:
Eric
2020-12-16 11:05:30 +01:00
parent d2bc651fc6
commit 1b115624a2
25 changed files with 612 additions and 286 deletions

View File

@@ -17,22 +17,17 @@
* You should have received a copy of the GNU Affero General Public License
*/
use Combodo\iTop\Application\UI\Base\iUIBlock;
use Combodo\iTop\Renderer\BlockRenderer;
/**
* Web page with some associated CSS and scripts (jquery) for a fancier display
*/
class NiceWebPage extends WebPage
{
const DEFAULT_PAGE_TEMPLATE_REL_PATH = 'pages/backoffice/nicewebpage/layout';
var $m_aReadyScripts;
var $m_sRootUrl;
public function __construct($s_title, $bPrintable = false)
{
parent::__construct($s_title, $bPrintable);
$this->m_aReadyScripts = array();
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.min.js');
if (utils::IsDevelopmentEnvironment()) // Needed since many other plugins still rely on oldies like $.browser
{
@@ -191,47 +186,16 @@ EOF
}
$this->add("</select>");
}
public function add_ready_script($sScript)
{
if (!empty(trim($sScript))) {
$this->m_aReadyScripts[] = $sScript;
}
}
/**
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
*
* @throws \ReflectionException
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function RenderInlineScriptsAndCSSRecursively(iUIBlock $oBlock): void
{
$oBlockRenderer = new BlockRenderer($oBlock);
$this->add_script($oBlockRenderer->RenderJsInline(iUIBlock::JS_TYPE_LIVE));
$this->add_ready_script($oBlockRenderer->RenderJsInline(iUIBlock::JS_TYPE_ON_INIT));
$this->add_ready_script($oBlockRenderer->RenderJsInline(iUIBlock::JS_TYPE_ON_READY));
$this->add_style($oBlockRenderer->RenderCssInline());
foreach ($oBlock->GetSubBlocks() as $oSubBlock) {
$this->RenderInlineScriptsAndCSSRecursively($oSubBlock);
}
foreach ($oBlock->GetDeferredBlocks() as $oSubBlock) {
$this->RenderInlineScriptsAndCSSRecursively($oSubBlock);
}
}
/**
* Outputs (via some echo) the complete HTML page by assembling all its elements
*/
public function output()
{
//$this->set_base($this->m_sRootUrl.'pages/');
if (count($this->m_aReadyScripts)>0)
if (count($this->a_ready_scripts)>0)
{
$this->add_script("\$(document).ready(function() {\n".implode("\n", $this->m_aReadyScripts)."\n});");
$this->add_script("\$(document).ready(function() {\n".implode("\n", $this->a_ready_scripts)."\n});");
}
parent::output();
}