Forms: transform addHtmlHint into ipl-aware code

This commit is contained in:
Thomas Gelf 2017-08-25 18:12:39 +02:00
parent 84b6196e79
commit 75fb983622
4 changed files with 73 additions and 81 deletions

View File

@ -9,12 +9,15 @@ use Icinga\Module\Director\Web\Form\DirectorObjectForm;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaService;
use Icinga\Module\Director\Objects\IcingaServiceSet;
use ipl\Html\Html;
use ipl\Html\Link;
class IcingaServiceForm extends DirectorObjectForm
{
/** @var IcingaHost */
private $host;
/** @var IcingaServiceSet */
private $set;
private $apply;
@ -80,10 +83,7 @@ class IcingaServiceForm extends DirectorObjectForm
return;
}
$this->addHtmlHint(
$this->getOverrideHint(),
array('name' => 'inheritance_hint')
);
$this->addOverrideHint();
$group = $this->getDisplayGroup('custom_fields');
@ -142,91 +142,78 @@ class IcingaServiceForm extends DirectorObjectForm
->setButtons();
}
protected function getOverrideHint()
protected function addOverrideHint()
{
$view = $this->getView();
if ($this->object && $this->object->usesVarOverrides()) {
return $this->translate(
$hint = $this->translate(
'This service has been generated in an automated way, but still'
. ' allows you to override the following properties in a safe way.'
);
}
if ($this->applyGenerated) {
return $view->escape(sprintf(
} elseif ($this->applyGenerated) {
$hint = Html::sprintf(
$this->translate(
'This service has been generated using an apply rule, assigned where %s'
),
Filter::fromQueryString($this->applyGenerated->assign_filter)
));
}
if ($this->host && $this->set) {
return $this->translate(
(string) Filter::fromQueryString($this->applyGenerated->assign_filter)
);
} elseif ($this->host && $this->set) {
$hint = $this->translate(
'This service belongs to a Service Set. Still, you might want'
. ' to override the following properties for this host only.'
);
}
if ($this->inheritedFrom) {
$msg = $view->escape($this->translate(
} elseif ($this->inheritedFrom) {
$msg = $this->translate(
'This service has been inherited from %s. Still, you might want'
. ' to change the following properties for this host only.'
));
$name = $this->inheritedFrom;
$link = $view->qlink(
$name,
'director/service',
array(
'host' => $name,
'name' => $this->object->object_name,
),
array('data-base-target' => '_next')
);
return sprintf($msg, $link);
$name = $this->inheritedFrom;
$link = Link::create(
$name,
'director/service',
[
'host' => $name,
'name' => $this->object->getObjectName(),
],
['data-base-target' => '_next']
);
$hint = Html::sprintf($msg, $link);
}
$this->setSubmitLabel(
$this->translate('Override vars')
);
$this->setSubmitLabel($this->translate('Override vars'));
$this->addHtmlHint($hint, ['name' => 'inheritance_hint']);
}
protected function setupOnHostForSet()
{
$view = $this->getView();
$msg = $view->escape($this->translate(
$msg = $this->translate(
'This service belongs to the service set "%s". Still, you might want'
. ' to change the following properties for this host only.'
));
);
$name = $this->set->getObjectName();
$link = $view->qlink(
$link = Link::create(
$name,
'director/serviceset',
array(
'name' => $name,
),
array('data-base-target' => '_next')
['name' => $name],
['data-base-target' => '_next']
);
$this->addHtmlHint(
sprintf($msg, $link),
array('name' => 'inheritance_hint')
Html::sprintf($msg, $link),
['name' => 'inheritance_hint']
);
$this->addElementsToGroup(
array('inheritance_hint'),
['inheritance_hint'],
'custom_fields',
50,
$this->translate('Custom properties')
);
$this->setSubmitLabel(
$this->translate('Override vars')
);
$this->setSubmitLabel($this->translate('Override vars'));
}
protected function addAssignmentElements()

View File

@ -86,9 +86,7 @@ class IcingaServiceSetForm extends DirectorObjectForm
if (count($object->get('imports'))) {
$this->addHtmlHint(
$this->getView()->escape(
$object->getResolvedProperty('description')
)
$object->getResolvedProperty('description')
);
}

View File

@ -10,7 +10,8 @@ use Icinga\Module\Director\Db\Migrations;
use Icinga\Module\Director\Objects\IcingaEndpoint;
use Icinga\Module\Director\KickstartHelper;
use Icinga\Module\Director\Web\Form\DirectorForm;
use Icinga\Module\Director\Web\Form\QuickForm;
use ipl\Html\Html;
use ipl\Html\Link;
class KickstartForm extends DirectorForm
{
@ -60,16 +61,17 @@ class KickstartForm extends DirectorForm
}
if (! $this->endpoint && $this->getDb()->hasDeploymentEndpoint()) {
$hint = sprintf($this->translate(
'Your database looks good, you are ready to %s'
), $this->getView()->qlink(
'start working with the Icinga Director',
'director',
null,
array('data-base-target' => '_main')
));
$hint = Html::sprintf(
$this->translate('Your database looks good, you are ready to %s'),
Link::create(
'start working with the Icinga Director',
'director',
null,
['data-base-target' => '_main']
)
);
$this->addHtmlHint($hint, array('name' => 'HINT_ready'));
$this->addHtmlHint($hint, ['name' => 'HINT_ready']);
$this->getDisplayGroup('config')->addElements(
array($this->getElement('HINT_ready'))
);
@ -233,14 +235,15 @@ class KickstartForm extends DirectorForm
$this->translate('This has to be a MySQL or PostgreSQL database')
);
$hint = $this->translate('Please click %s to create new DB resources');
$link = $this->getView()->qlink(
$this->translate('here'),
'config/resource',
null,
array('data-base-target' => '_main')
);
$this->addHtmlHint(sprintf($hint, $link));
$this->addHtmlHint(Html::sprintf(
$this->translate('Please click %s to create new DB resources'),
Link::create(
$this->translate('here'),
'config/resource',
null,
['data-base-target' => '_main']
)
));
}
$this->setSubmitLabel($this->storeConfigLabel);
@ -308,7 +311,7 @@ class KickstartForm extends DirectorForm
)
);
$this->addHtmlHint(
'<pre>' . $config . '</pre>',
Html::tag('pre', null, $config),
array('name' => 'HINT_config_store')
);

View File

@ -7,7 +7,8 @@ use Icinga\Data\ResourceFactory;
use Icinga\Module\Director\Web\Form\QuickForm;
use Icinga\Exception\NotImplementedError;
use Icinga\Exception\ProgrammingError;
use Icinga\Web\Url;
use ipl\Html\Html;
use ipl\Html\Link;
use Zend_Db_Expr;
class Util
@ -173,14 +174,17 @@ class Util
'required' => true,
));
if (true && empty($list)) {
if (empty($list)) {
if (self::hasPermission('config/application/resources')) {
$hint = $form->translate('Please click %s to create new resources');
$link = sprintf(
'<a href="' . Url::fromPath('config/resource') . '" data-base-target="_main">%s</a>',
$form->translate('here')
);
$form->addHtmlHint(sprintf($hint, $link));
$form->addHtmlHint(Html::sprintf(
$form->translate('Please click %s to create new resources'),
Link::create(
$form->translate('here'),
'config/resource',
null,
['data-base-target' => '_main']
)
));
$msg = sprintf($form->translate('No %s resource available'), $type);
} else {
$msg = $form->translate('Please ask an administrator to grant you access to resources');