Benjamin Roth authored on12/07/2024 14:13:18
Showing2 changed files
... ...
@@ -12,16 +12,20 @@
12 12
     </div>
13 13
     <form id="tl_slot_assistant" class="tl_form tl_edit_form" method="post" enctype="application/x-www-form-urlencoded">
14 14
         <div class="tl_formbody_edit">
15
+            <input type="hidden" name="FORM_SUBMIT" value="wa_slotassistant">
15 16
             <input type="hidden" name="REQUEST_TOKEN" value="{{ request_token }}">
16 17
 
17 18
             {% for legend, widgets in fields %}
18 19
                 <fieldset id="pal_{{ legend }}" class="tl_tbox">
19 20
                     <legend onclick="AjaxRequest.toggleFieldset(this,{{ legend }},'wa_slotassistant')">{{ ('wa_slotassistant.'~legend)|trans([], 'contao_default') }}</legend>
20
-                {% for field in widgets %}
21
-                    <div class="{{ field.class is defined and field.class|length ? field.class ~ ' ' : '' }}widget">
22
-                        {{ field.widget.parse()|raw }}
23
-                    </div>
24
-                {% endfor %}
21
+                    {% for field in widgets %}
22
+                        <div class="{{ field.class is defined and field.class|length ? field.class ~ ' ' : '' }}widget">
23
+                            {{ field.widget.parse()|raw }}{{ field.widget.wizard is defined ? field.widget.wizard : '' }}
24
+                            {% if not field.widget.hasErrors() and field.help is defined and field.help|length %}
25
+                                <p class="tl_help tl_tip">{{ field.help }}</p>
26
+                            {% endif %}
27
+                        </div>
28
+                    {% endfor %}
25 29
                 </fieldset>
26 30
             {% endfor %}
27 31
 
... ...
@@ -12,16 +12,19 @@ declare(strict_types=1);
12 12
 
13 13
 namespace vonRotenberg\WeinanlieferungBundle\Controller\Backend;
14 14
 
15
+use Contao\Config;
15 16
 use Contao\CoreBundle\Controller\AbstractController;
16 17
 use Contao\CoreBundle\Csrf\ContaoCsrfTokenManager;
17 18
 use Contao\Date;
18 19
 use Contao\Environment;
19 20
 use Contao\FrontendUser;
21
+use Contao\Image;
20 22
 use Contao\Input;
21 23
 use Contao\SelectMenu;
22 24
 use Contao\StringUtil;
23 25
 use Contao\System;
24 26
 use Contao\TextField;
27
+use Contao\Widget;
25 28
 use Doctrine\DBAL\Connection;
26 29
 use Symfony\Component\HttpFoundation\RequestStack;
27 30
 use Symfony\Component\HttpFoundation\Response;
... ...
@@ -62,16 +65,17 @@ class WeinanlieferungSlotAssistantController extends AbstractController
62 65
         $session[$strRefererId]['current'] = substr(Environment::get('requestUri'), \strlen(Environment::get('path')) + 1);
63 66
         $objSession->set($strKey, $session);
64 67
     }
68
+
65 69
     public function __invoke(): Response
66 70
     {
67 71
         $GLOBALS['TL_CSS']['cirrus'] = 'bundles/vonrotenbergweinanlieferung/css/backend.css|static';
68 72
         $arrData = [
69 73
             'request_token' => $this->tokenManager->getDefaultTokenValue(),
70
-            'ref' => $this->request->attributes->get('_contao_referer_id')
74
+            'ref'           => $this->request->attributes->get('_contao_referer_id')
71 75
         ];
72 76
         System::loadLanguageFile('default');
73 77
 
74
-        dump($this->getWidgets());
78
+//        dump($this->getWidgets());
75 79
 
76 80
         $arrData['fields'] = $this->getWidgets();
77 81
 
... ...
@@ -91,26 +95,112 @@ class WeinanlieferungSlotAssistantController extends AbstractController
91 95
         }
92 96
 
93 97
         $arrWidgets = [
94
-          'base_legend' => [
95
-              [
96
-                  'class' => 'w50',
97
-                  'widget' => new SelectMenu([
98
-                      'name' => 'slotType',
99
-                      'mandatory' => true,
100
-                      'label' => 'Zeitslot-Typ'
101
-                  ])
102
-              ],
103
-              [
104
-                  'class' => 'w50',
105
-                  'widget' => new TextField([
106
-                      'name' => 'buffer',
107
-                      'mandatory' => true,
108
-                      'label' => 'Pufferzeit in min.'
109
-                  ])
110
-              ]
111
-          ]
98
+            'base_legend' => [
99
+                [
100
+                    'class'  => 'w50',
101
+                    'help'   => 'Legen Sie hier den Zeitslot-Typ/Annahmestelle fest.',
102
+                    'widget' => new SelectMenu([
103
+                        'name'      => 'slotType',
104
+                        'mandatory' => true,
105
+                        'options'   => [
106
+                            ['value' => 'eins', 'label' => 'eins'],
107
+                            ['value' => 'zwei', 'label' => 'zwei']
108
+                        ],
109
+                        'label'     => 'Zeitslot-Typ'
110
+                    ])
111
+                ],
112
+                [
113
+                    'class'  => 'w50',
114
+                    'help'   => 'Die Pufferzeit zwischen den Slots.',
115
+                    'widget' => new TextField([
116
+                        'name'      => 'buffer',
117
+                        'mandatory' => true,
118
+                        'label'     => 'Pufferzeit in min.',
119
+                        'rgxp'      => 'natural'
120
+                    ])
121
+                ]
122
+            ],
123
+            'time_legend' => [
124
+                [
125
+                    'class'  => 'w50 wizard',
126
+                    'help'   => 'Zeitslot-Typ/Annahmestelle fest.',
127
+                    'widget' => new TextField([
128
+                        'name'       => 'date_start[1]',
129
+                        'mandatory'  => true,
130
+                        'label'      => 'Pufferzeit in min.',
131
+                        'rgxp'       => 'datim',
132
+                        'datepicker' => true,
133
+                    ])
134
+                ]
135
+            ]
112 136
         ];
113 137
 
138
+
139
+        foreach ($arrWidgets as $group => $fields)
140
+        {
141
+            foreach ($fields as $field)
142
+            {
143
+                if (empty($field['widget']->id))
144
+                {
145
+                    $field['widget']->id = $field['widget']->name;
146
+                }
147
+
148
+                $wizard = '';
149
+
150
+                // Date picker
151
+                if ($field['widget']->datepicker ?? null)
152
+                {
153
+                    $rgxp = $field['widget']->rgxp ?? 'date';
154
+                    $format = Date::formatToJs(Config::get($rgxp . 'Format'));
155
+
156
+                    switch ($rgxp)
157
+                    {
158
+                        case 'datim':
159
+                            $time = ",\n        timePicker: true";
160
+                            break;
161
+
162
+                        case 'time':
163
+                            $time = ",\n        pickOnly: \"time\"";
164
+                            break;
165
+
166
+                        default:
167
+                            $time = '';
168
+                            break;
169
+                    }
170
+
171
+                    $strOnSelect = '';
172
+
173
+                    // Trigger the auto-submit function (see #8603)
174
+                    if ($field['widget']->submitOnChange ?? null)
175
+                    {
176
+                        $strOnSelect = ",\n        onSelect: function() { Backend.autoSubmit(\"wa_slotassistant\"); }";
177
+                    }
178
+
179
+                    $wizard .= ' ' . Image::getHtml('assets/datepicker/images/icon.svg', '', 'title="' . StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['datepicker']) . '" id="toggle_' . $field['widget']->id . '" style="cursor:pointer"') . '
180
+  <script>
181
+    window.addEvent("domready", function() {
182
+      new Picker.Date($("ctrl_' . $field['widget']->id . '"), {
183
+        draggable: false,
184
+        toggle: $("toggle_' . $field['widget']->id . '"),
185
+        format: "' . $format . '",
186
+        positionOffset: {x:-211,y:-209}' . $time . ',
187
+        pickerClass: "datepicker_bootstrap",
188
+        useFadeInOut: !Browser.ie' . $strOnSelect . ',
189
+        startDay: ' . $GLOBALS['TL_LANG']['MSC']['weekOffset'] . ',
190
+        titleFormat: "' . $GLOBALS['TL_LANG']['MSC']['titleFormat'] . '"
191
+      });
192
+    });
193
+  </script>';
194
+                    $field['widget']->wizard = $wizard;
195
+                }
196
+
197
+                if (Input::post('FORM_SUBMIT') == 'wa_slotassistant')
198
+                {
199
+                    dump($field['widget']->validate());
200
+                }
201
+            }
202
+        }
203
+
114 204
         $this->fields = $arrWidgets;
115 205
         return $this->fields;
116 206
     }