add_post_js = $add_post_js; $this->setAttribute('name', $name); $this->setId(uniqid('input-secret-')); if ($value !== null) { $this->setAttribute('value', $value); } } /** * Get content of all Javascript code. * * @return string Javascript code. */ public function getPostJS(): string { return 'jQuery("#'.$this->getId().'").inputSecret();'; } public function toString($destroy = true) { $node = (new CDiv()) ->setId($this->getId()) ->addClass(self::ZBX_STYLE_CLASS); $name = $this->getAttribute('name'); $value = $this->getAttribute('value'); $maxlength = ($this->getAttribute('maxlength') === null) ? 255 : $this->getAttribute('maxlength'); if ($value === null) { $node->addItem([ (new CPassBox($name, ZBX_SECRET_MASK, $maxlength))->setAttribute('disabled', 'disabled'), (new CSimpleButton(_('Set new value'))) ->setId(zbx_formatDomId($name.'[btn]')) ->addClass(self::ZBX_STYLE_BTN_CHANGE) ->setAttribute('disabled', $this->getAttribute('disabled')) ]); } else { $pass_box = new CPassBox($name, $value, $maxlength); if ($this->getAttribute('placeholder')) { $pass_box->setAttribute('placeholder', $this->getAttribute('placeholder')); } $node->addItem($pass_box); } if ($this->add_post_js) { zbx_add_post_js($this->getPostJS()); } return $node->toString(true); } }