summaryrefslogtreecommitdiffstats
path: root/library/Reporting/Web/Flatpickr.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:46:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:46:47 +0000
commit4ada86876033fa171e2896d7e3d3c5645d8062db (patch)
treef0d1fee61877df200ccfb1c0af58a39cd551fb46 /library/Reporting/Web/Flatpickr.php
parentInitial commit. (diff)
downloadicingaweb2-module-reporting-upstream/0.10.0.tar.xz
icingaweb2-module-reporting-upstream/0.10.0.zip
Adding upstream version 0.10.0.upstream/0.10.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Reporting/Web/Flatpickr.php')
-rw-r--r--library/Reporting/Web/Flatpickr.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/library/Reporting/Web/Flatpickr.php b/library/Reporting/Web/Flatpickr.php
new file mode 100644
index 0000000..5f6605d
--- /dev/null
+++ b/library/Reporting/Web/Flatpickr.php
@@ -0,0 +1,77 @@
+<?php
+// Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2
+
+namespace Icinga\Module\Reporting\Web;
+
+use Icinga\Application\Version;
+use ipl\Html\Html;
+use ipl\Web\Compat\CompatDecorator;
+
+class Flatpickr extends CompatDecorator
+{
+ protected $allowInput = true;
+
+ /**
+ * Set whether to allow manual input
+ *
+ * @param bool $state
+ *
+ * @return $this
+ */
+ public function setAllowInput(bool $state): self
+ {
+ $this->allowInput = $state;
+
+ return $this;
+ }
+
+ protected function assembleElement()
+ {
+ if (version_compare(Version::VERSION, '2.9.0', '>=')) {
+ $element = parent::assembleElement();
+ } else {
+ $element = $this->formElement;
+ }
+
+ if (version_compare(Version::VERSION, '2.10.0', '<')) {
+ $element->getAttributes()->set('data-use-flatpickr-fallback', true);
+ } else {
+ $element->getAttributes()->set('data-use-datetime-picker', true);
+ }
+
+ if (! $this->allowInput) {
+ return $element;
+ }
+
+ $element->getAttributes()
+ ->set('data-input', true)
+ ->set('data-flatpickr-wrap', true)
+ ->set('data-flatpickr-allow-input', true)
+ ->set('data-flatpickr-click-opens', 'false');
+
+ return [
+ $element,
+ Html::tag('button', ['type' => 'button', 'class' => 'icon-calendar', 'data-toggle' => true]),
+ Html::tag('button', ['type' => 'button', 'class' => 'icon-cancel', 'data-clear' => true])
+ ];
+ }
+
+ protected function assemble()
+ {
+ if (version_compare(Version::VERSION, '2.9.0', '>=')) {
+ parent::assemble();
+ return;
+ }
+
+ if ($this->formElement->hasBeenValidated() && ! $this->formElement->isValid()) {
+ $this->getAttributes()->add('class', 'has-error');
+ }
+
+ $this->add(array_filter([
+ $this->assembleLabel(),
+ $this->assembleElement(),
+ $this->assembleDescription(),
+ $this->assembleErrors()
+ ]));
+ }
+}