Browse code

Add tom select dropdown for test purposes

Benjamin Roth authored on02/02/2023 13:15:02
Showing2 changed files
... ...
@@ -7,6 +7,17 @@
7 7
             <div class="widget widget-text">
8 8
                 <input type="text" name="filter_keywords" placeholder="Jobtitel" value="{{ formSetFilters.filter_keywords ?? '' }}">
9 9
             </div>
10
+            <div class="widget widget-autocomplete">
11
+                <input type="hidden" id="filter-city-label-{{ id }}" name="filter_city_label" value="{{ formSetFilters.filter_city_label }}">
12
+                <select id="filter-city-{{ id }}" name="filter_city" data-placeholder="{{ formSetFilters.filter_city_label ?? 'PLZ/Ort' }}" autocomplete="off">
13
+                    <option value="{{ formSetFilters.filter_city ?? '' }}">{{ formSetFilters.filter_city_label ?? 'PLZ/Ort' }}</option>
14
+                    <option value="49.44780,11.06830">Nürnberg</option>
15
+                    <option value="49.55000,10.88330">Herzogenaurach</option>
16
+                </select>
17
+            </div>
18
+            <div class="widget widget-text">
19
+                <input type="text" name="filter_radius" placeholder="Suchradius in km" value="{{ formSetFilters.filter_radius ?? '' }}">
20
+            </div>
10 21
             {% if filterVertragsarten is defined %}
11 22
                 <div class="widget widget-select">
12 23
                     <select name="filter_vertragsart">
... ...
@@ -33,6 +44,22 @@
33 44
         </div>
34 45
     </form>
35 46
 
47
+    <script>
48
+        document.addEventListener('DOMContentLoaded', function () {
49
+            new TomSelect("#filter-city-{{ id }}",{
50
+                allowEmptyOption: true,
51
+                create: false,
52
+                onChange: function (values) {
53
+                    let target = document.getElementById('filter-city-label-{{ id }}');
54
+                    if (target !== undefined && this.activeOption.innerText !== undefined)
55
+                    {
56
+                        target.value = this.activeOption.innerText
57
+                    }
58
+                }
59
+            });
60
+        }, false);
61
+    </script>
62
+
36 63
     {% if jobs is not defined %}
37 64
         <p>Es wurden keine Stellenangebote gefunden!</p>
38 65
     {% else %}
... ...
@@ -43,7 +43,14 @@ class JoblistModuleController extends AbstractFrontendModuleController
43 43
     {
44 44
         $strFormId = 'joblist-form-' . $model->id;
45 45
         $arrSearchParams = [];
46
-        $arrSetFilters = [];
46
+        $arrSetFilters = [
47
+            'filter_keywords' => null,
48
+            'filter_city' => null,
49
+            'filter_city_label' => null,
50
+            'filter_radius' => null,
51
+            'filter_vertragsart' => null,
52
+            'filter_abteilung' => null
53
+        ];
47 54
 
48 55
         // Prepare search parameters
49 56
         if (Input::get('FORM_SUBMIT') == $strFormId)
... ...
@@ -54,6 +61,18 @@ class JoblistModuleController extends AbstractFrontendModuleController
54 61
                 $arrSetFilters['filter_keywords'] = Input::get('filter_keywords');
55 62
             }
56 63
 
64
+            if (Input::get('filter_city'))
65
+            {
66
+                list($lat,$lon) = explode(',',Input::get('filter_city'));
67
+                $arrSearchParams['lat'] = floatval($lat);
68
+                $arrSearchParams['lon'] = floatval($lon);
69
+                $arrSearchParams['radius'] = max((intval(Input::get('filter_radius')) ?: 25),5);
70
+
71
+                $arrSetFilters['filter_city'] = Input::get('filter_city');
72
+                $arrSetFilters['filter_city_label'] = Input::get('filter_city_label');
73
+                $arrSetFilters['filter_radius'] = Input::get('filter_radius');
74
+            }
75
+
57 76
             if (Input::get('filter_vertragsart'))
58 77
             {
59 78
                 $value = Input::get('filter_vertragsart');
... ...
@@ -106,6 +125,10 @@ class JoblistModuleController extends AbstractFrontendModuleController
106 125
         $template->formSetFilters = $arrSetFilters;
107 126
 
108 127
 
128
+        // Add scripts
129
+        $GLOBALS['TL_BODY']['tomselect'] = Template::generateScriptTag('bundles/vossmedienalox/lib/tomselect/js/tom-select.base.js',false,null);
130
+        $GLOBALS['TL_CSS']['tomselect'] = 'bundles/vossmedienalox/lib/tomselect/css/tom-select.min.css';
131
+
109 132
         return $template->getResponse();
110 133
     }
111 134