mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-08-16 07:18:09 +02:00
Forms: used templates should not be deleted
This commit is contained in:
parent
6f35e3cd11
commit
4e677dbc56
@ -530,6 +530,19 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function countDirectDescendants()
|
||||
{
|
||||
$db = $this->getDb();
|
||||
$table = $this->getTableName();
|
||||
$type = strtolower($this->getType());
|
||||
$query = $db->select()->from(
|
||||
array('oi' => $table . '_inheritance'),
|
||||
array('cnt' => 'COUNT(*)')
|
||||
)->where('oi.parent_' . $type . '_id = ?', (int) $this->id);
|
||||
|
||||
return $db->fetchOne($query);
|
||||
}
|
||||
|
||||
protected function resolve($what)
|
||||
{
|
||||
if ($this->hasResolveCached($what)) {
|
||||
|
@ -684,6 +684,8 @@ abstract class DirectorObjectForm extends QuickForm
|
||||
|
||||
protected function addDeleteButton($label = null)
|
||||
{
|
||||
$object = $this->object;
|
||||
|
||||
if ($label === null) {
|
||||
$label = $this->translate('Delete');
|
||||
}
|
||||
@ -694,6 +696,20 @@ abstract class DirectorObjectForm extends QuickForm
|
||||
//->removeDecorator('Label');
|
||||
|
||||
$this->deleteButtonName = $el->getName();
|
||||
|
||||
if ($object instanceof IcingaObject && $object->isTemplate()) {
|
||||
if ($cnt = $object->countDirectDescendants()) {
|
||||
$el->setAttrib('disabled', 'disabled');
|
||||
$el->setAttrib(
|
||||
'title',
|
||||
sprintf(
|
||||
$this->translate('This template is still in use by %d other objects'),
|
||||
$cnt
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->addElement($el);
|
||||
|
||||
return $this;
|
||||
|
@ -52,6 +52,12 @@ form input[type=submit] {
|
||||
.button();
|
||||
border-width: 1px;
|
||||
margin-top: 0.5em;
|
||||
|
||||
&:disabled {
|
||||
border-color: @gray-light;
|
||||
background-color: @gray-light;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
form input[type=submit]:first-of-type {
|
||||
|
Loading…
x
Reference in New Issue
Block a user