Support multiple option for the widget.

This commit is contained in:
David Molineus
2017-11-13 10:54:20 +01:00
parent c4517b2dec
commit 047cc7b7cf
5 changed files with 50 additions and 18 deletions

View File

@@ -2,6 +2,13 @@
Changelog Changelog
========= =========
Version 1.2.0 (2017-11-13)
--------------------------
[Full Changelog](https://github.com/netzmacht/contao-leaflet-geocode-widget/compare/1.1.0...1.2.0)
- Allow multiple elements
Version 1.1.0 Version 1.1.0
------------- -------------

View File

@@ -42,8 +42,8 @@
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.0.x-dev", "dev-master": "1.2.x-dev",
"dev-develop": "1.1.x-dev" "dev-develop": "1.3.x-dev"
}, },
"contao-manager-plugin": "Netzmacht\\Contao\\Leaflet\\GeocodeWidget\\ContaoManager\\Plugin" "contao-manager-plugin": "Netzmacht\\Contao\\Leaflet\\GeocodeWidget\\ContaoManager\\Plugin"
} }

View File

@@ -15,7 +15,8 @@ namespace Netzmacht\Contao\Leaflet\GeocodeWidget;
/** /**
* Class GeocodeWidget * Class GeocodeWidget
* *
* @package Netzmacht\Contao\Leaflet\GeocodeWidget * @property int size
* @property bool multiple
*/ */
class GeocodeWidget extends \Widget class GeocodeWidget extends \Widget
{ {
@@ -87,20 +88,39 @@ class GeocodeWidget extends \Widget
*/ */
public function generate() public function generate()
{ {
$template = new \BackendTemplate($this->widgetTemplate); $wrapperClass = 'wizard';
$template->setData(
[
'widget' => $this,
'value' => specialchars($this->value),
'class' => $this->strClass ? ' ' . $this->strClass : '',
'id' => $this->strId,
'name' => $this->strName,
'attributes' => $this->getAttributes(),
'wizard' => $this->wizard,
'label' => $this->strLabel
]
);
return $template->parse(); if (!$this->multiple || !$this->size) {
$this->size = 1;
} else {
$wrapperClass .= ' wizard_' . $this->size;
}
if (!is_array($this->value)) {
$this->value = [$this->value];
}
$buffer = '';
for ($index = 0; $index < $this->size; $index++) {
$template = new \BackendTemplate($this->widgetTemplate);
$template->setData(
[
'wrapperClass' => $wrapperClass,
'widget' => $this,
'value' => \StringUtil::specialchars($this->value[$index]),
'class' => $this->strClass ? ' ' . $this->strClass : '',
'id' => $this->strId . (($this->size > 1) ? '_' . $index : ''),
'name' => $this->strName . (($this->size > 1) ? '[]' : ''),
'attributes' => $this->getAttributes(),
'wizard' => $this->wizard,
'label' => $this->strLabel,
]
);
$buffer .= $template->parse();
}
return $buffer;
} }
} }

View File

@@ -2,6 +2,7 @@
$GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/leaflet/leaflet.css'; $GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/leaflet/leaflet.css';
$GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.css'; $GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.css';
$GLOBALS['TL_CSS'][] = 'bundles/leafletgeocodewidget/css/backend.css';
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/leaflet/leaflet.js'; $GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/leaflet/leaflet.js';
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.js'; $GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.js';
@@ -9,7 +10,7 @@ $GLOBALS['TL_JAVASCRIPT'][] = 'bundles/leafletgeocodewidget/js/geocode.widget.js
?> ?>
<div class="wizard"> <div class="<?= $this->wrapperClass ?>">
<input type="text" <input type="text"
name="<?= $this->name ?>" name="<?= $this->name ?>"
id="ctrl_<?= $this->id ?>" id="ctrl_<?= $this->id ?>"

View File

@@ -0,0 +1,4 @@
.wizard_2 {
width: 325px;
display: inline-block;
}