@@ -2141,7 +2141,7 @@ |
||
2141 | 2141 | } |
2142 | 2142 | |
2143 | 2143 | header("Content-type: application/json; charset=utf-8"); |
2144 | - echo $collection->output(); |
|
2145 | - die(); |
|
2144 | + echo $collection->output(); |
|
2145 | + die(); |
|
2146 | 2146 | } |
2147 | 2147 | } |
@@ -59,50 +59,50 @@ discard block |
||
59 | 59 | |
60 | 60 | function app_genericSetEditor(ORMRecordSet $set) |
61 | 61 | { |
62 | - $O = \bab_functionality::get('LibOrm'); |
|
63 | - $O->init(); |
|
64 | - $W = \bab_Widgets(); |
|
65 | - $layout = $W->VBoxLayout(); |
|
66 | - $layout->setVerticalSpacing(1, 'em'); |
|
67 | - |
|
68 | - |
|
69 | - $fields = $set->getFields(); |
|
70 | - |
|
71 | - foreach ($fields as $field) { |
|
72 | - $description = $field->getDescription(); |
|
73 | - if (empty($description)) { |
|
74 | - $description = $field->getName(); |
|
75 | - } |
|
76 | - $fieldLabel = $W->Label($description . ':'); |
|
77 | - |
|
78 | - if ($field instanceof ORMDateField) { |
|
79 | - $widget = $W->DatePicker(); |
|
80 | - } else if ($field instanceof ORMTimeField) { |
|
81 | - $widget = $W->LineEdit()->setMaxSize(5)->setSize(5)->addClass('widget-timepicker'); |
|
82 | - } else if ($field instanceof ORMStringField) { |
|
83 | - $widget = $W->LineEdit()->setSize(min(array(80, $field->getMaxLength()))); |
|
84 | - } else if ($field instanceof ORMEnumField) { |
|
85 | - $widget = $W->Select(); |
|
86 | - $widget->addOption('', ''); |
|
87 | - foreach ($field->getValues() as $key => $text) { |
|
88 | - $widget->addOption($key, $text); |
|
89 | - } |
|
90 | - } else if ($field instanceof ORMIntField) { |
|
91 | - $widget = $W->LineEdit()->setSize(9); |
|
92 | - } else if ($field instanceof ORMTextField) { |
|
93 | - $widget = $W->TextEdit()->setColumns(80)->setLines(5); |
|
94 | - } else if ($field instanceof ORMRecordSet) { |
|
95 | - $widget = app_genericSetEditor($field); |
|
96 | - $widget->addClass('sub-form'); |
|
97 | - } else { |
|
98 | - $widget = null; |
|
99 | - } |
|
100 | - if (isset($widget)) { |
|
101 | - $layout->addItem($W->VBoxLayout()->addItem($fieldLabel)->addItem($widget)); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - return $layout; |
|
62 | + $O = \bab_functionality::get('LibOrm'); |
|
63 | + $O->init(); |
|
64 | + $W = \bab_Widgets(); |
|
65 | + $layout = $W->VBoxLayout(); |
|
66 | + $layout->setVerticalSpacing(1, 'em'); |
|
67 | + |
|
68 | + |
|
69 | + $fields = $set->getFields(); |
|
70 | + |
|
71 | + foreach ($fields as $field) { |
|
72 | + $description = $field->getDescription(); |
|
73 | + if (empty($description)) { |
|
74 | + $description = $field->getName(); |
|
75 | + } |
|
76 | + $fieldLabel = $W->Label($description . ':'); |
|
77 | + |
|
78 | + if ($field instanceof ORMDateField) { |
|
79 | + $widget = $W->DatePicker(); |
|
80 | + } else if ($field instanceof ORMTimeField) { |
|
81 | + $widget = $W->LineEdit()->setMaxSize(5)->setSize(5)->addClass('widget-timepicker'); |
|
82 | + } else if ($field instanceof ORMStringField) { |
|
83 | + $widget = $W->LineEdit()->setSize(min(array(80, $field->getMaxLength()))); |
|
84 | + } else if ($field instanceof ORMEnumField) { |
|
85 | + $widget = $W->Select(); |
|
86 | + $widget->addOption('', ''); |
|
87 | + foreach ($field->getValues() as $key => $text) { |
|
88 | + $widget->addOption($key, $text); |
|
89 | + } |
|
90 | + } else if ($field instanceof ORMIntField) { |
|
91 | + $widget = $W->LineEdit()->setSize(9); |
|
92 | + } else if ($field instanceof ORMTextField) { |
|
93 | + $widget = $W->TextEdit()->setColumns(80)->setLines(5); |
|
94 | + } else if ($field instanceof ORMRecordSet) { |
|
95 | + $widget = app_genericSetEditor($field); |
|
96 | + $widget->addClass('sub-form'); |
|
97 | + } else { |
|
98 | + $widget = null; |
|
99 | + } |
|
100 | + if (isset($widget)) { |
|
101 | + $layout->addItem($W->VBoxLayout()->addItem($fieldLabel)->addItem($widget)); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + return $layout; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
@@ -115,50 +115,50 @@ discard block |
||
115 | 115 | */ |
116 | 116 | function app_genericSetFilterForm(ORMRecordSet $set) |
117 | 117 | { |
118 | - $O = \bab_functionality::get('LibOrm'); |
|
119 | - $O->init(); |
|
120 | - $W = \bab_Widgets(); |
|
121 | - $layout = $W->FlowLayout(); |
|
122 | - $layout->setVerticalSpacing(1, 'em')->setHorizontalSpacing(1, 'em'); |
|
123 | - |
|
124 | - |
|
125 | - $fields = $set->getFields(); |
|
126 | - |
|
127 | - foreach ($fields as $field) { |
|
128 | - $description = $field->getDescription(); |
|
129 | - if (empty($description)) { |
|
130 | - $description = $field->getName(); |
|
131 | - } |
|
132 | - $fieldLabel = $W->Label($description . ':'); |
|
133 | - |
|
134 | - if ($field instanceof ORMDateField) { |
|
135 | - $widget = $W->PeriodPicker(); |
|
136 | - } else if ($field instanceof ORMTimeField) { |
|
137 | - $widget = $W->TimePicker(); |
|
138 | - } else if ($field instanceof ORMStringField) { |
|
139 | - $widget = $W->LineEdit()->setSize(min(array(15, $field->getMaxLength()))); |
|
140 | - } else if ($field instanceof ORMEnumField) { |
|
141 | - $widget = $W->Select(); |
|
142 | - $widget->addOption('', ''); |
|
143 | - foreach ($field->getValues() as $key => $text) { |
|
144 | - $widget->addOption($key, $text); |
|
145 | - } |
|
146 | - } else if ($field instanceof ORMIntField) { |
|
147 | - $widget = $W->LineEdit()->setSize(9); |
|
148 | - } else if ($field instanceof ORMTextField) { |
|
149 | - $widget = $widget = $W->LineEdit()->setSize(15); |
|
150 | - } else if ($field instanceof ORMRecordSet) { |
|
151 | - $widget = app_genericSetFilterForm($field); |
|
152 | - $widget->addClass('sub-form'); |
|
153 | - } else { |
|
154 | - $widget = null; |
|
155 | - } |
|
156 | - if (isset($widget)) { |
|
157 | - $layout->addItem($W->VBoxLayout()->addItem($fieldLabel)->addItem($widget)); |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - return $layout; |
|
118 | + $O = \bab_functionality::get('LibOrm'); |
|
119 | + $O->init(); |
|
120 | + $W = \bab_Widgets(); |
|
121 | + $layout = $W->FlowLayout(); |
|
122 | + $layout->setVerticalSpacing(1, 'em')->setHorizontalSpacing(1, 'em'); |
|
123 | + |
|
124 | + |
|
125 | + $fields = $set->getFields(); |
|
126 | + |
|
127 | + foreach ($fields as $field) { |
|
128 | + $description = $field->getDescription(); |
|
129 | + if (empty($description)) { |
|
130 | + $description = $field->getName(); |
|
131 | + } |
|
132 | + $fieldLabel = $W->Label($description . ':'); |
|
133 | + |
|
134 | + if ($field instanceof ORMDateField) { |
|
135 | + $widget = $W->PeriodPicker(); |
|
136 | + } else if ($field instanceof ORMTimeField) { |
|
137 | + $widget = $W->TimePicker(); |
|
138 | + } else if ($field instanceof ORMStringField) { |
|
139 | + $widget = $W->LineEdit()->setSize(min(array(15, $field->getMaxLength()))); |
|
140 | + } else if ($field instanceof ORMEnumField) { |
|
141 | + $widget = $W->Select(); |
|
142 | + $widget->addOption('', ''); |
|
143 | + foreach ($field->getValues() as $key => $text) { |
|
144 | + $widget->addOption($key, $text); |
|
145 | + } |
|
146 | + } else if ($field instanceof ORMIntField) { |
|
147 | + $widget = $W->LineEdit()->setSize(9); |
|
148 | + } else if ($field instanceof ORMTextField) { |
|
149 | + $widget = $widget = $W->LineEdit()->setSize(15); |
|
150 | + } else if ($field instanceof ORMRecordSet) { |
|
151 | + $widget = app_genericSetFilterForm($field); |
|
152 | + $widget->addClass('sub-form'); |
|
153 | + } else { |
|
154 | + $widget = null; |
|
155 | + } |
|
156 | + if (isset($widget)) { |
|
157 | + $layout->addItem($W->VBoxLayout()->addItem($fieldLabel)->addItem($widget)); |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + return $layout; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | |
@@ -171,47 +171,47 @@ discard block |
||
171 | 171 | */ |
172 | 172 | function app_LabelledWidget($labelText, WidgetDisplayableInterface $widget) |
173 | 173 | { |
174 | - $W = \bab_Widgets(); |
|
175 | - |
|
176 | - $label = $W->Label($labelText); |
|
177 | - if ($widget instanceof WidgetInputWidget) { |
|
178 | - $label->setAssociatedWidget($widget); |
|
179 | - } |
|
180 | - |
|
181 | - if ($widget instanceof WidgetCheckBox) { |
|
182 | - $layout = $W->HBoxItems( |
|
183 | - $widget->setSizePolicy(WidgetSizePolicy::MINIMUM), |
|
184 | - $label |
|
185 | - )->setVerticalAlign('middle')->setHorizontalSpacing(0.5, 'em'); |
|
186 | - } else { |
|
187 | - $layout = $W->VBoxItems( |
|
188 | - $label, |
|
189 | - $widget |
|
190 | - )->setVerticalSpacing(0.5, 'em'); |
|
191 | - } |
|
192 | - |
|
193 | - return $layout; |
|
174 | + $W = \bab_Widgets(); |
|
175 | + |
|
176 | + $label = $W->Label($labelText); |
|
177 | + if ($widget instanceof WidgetInputWidget) { |
|
178 | + $label->setAssociatedWidget($widget); |
|
179 | + } |
|
180 | + |
|
181 | + if ($widget instanceof WidgetCheckBox) { |
|
182 | + $layout = $W->HBoxItems( |
|
183 | + $widget->setSizePolicy(WidgetSizePolicy::MINIMUM), |
|
184 | + $label |
|
185 | + )->setVerticalAlign('middle')->setHorizontalSpacing(0.5, 'em'); |
|
186 | + } else { |
|
187 | + $layout = $W->VBoxItems( |
|
188 | + $label, |
|
189 | + $widget |
|
190 | + )->setVerticalSpacing(0.5, 'em'); |
|
191 | + } |
|
192 | + |
|
193 | + return $layout; |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | |
197 | 197 | |
198 | 198 | function app_LabelledCheckbox($labelText, $checkboxName, $options = null) |
199 | 199 | { |
200 | - $W = \bab_Widgets(); |
|
200 | + $W = \bab_Widgets(); |
|
201 | 201 | |
202 | - $label = $W->Label($labelText)->colon(false); |
|
203 | - $checkbox = $W->Checkbox()->setName($checkboxName); |
|
204 | - $label->setAssociatedWidget($checkbox); |
|
205 | - if (isset($options)) { |
|
206 | - $label->setSizePolicy(WidgetSizePolicy::FIXED)->setCanvasOptions($options); |
|
207 | - } |
|
202 | + $label = $W->Label($labelText)->colon(false); |
|
203 | + $checkbox = $W->Checkbox()->setName($checkboxName); |
|
204 | + $label->setAssociatedWidget($checkbox); |
|
205 | + if (isset($options)) { |
|
206 | + $label->setSizePolicy(WidgetSizePolicy::FIXED)->setCanvasOptions($options); |
|
207 | + } |
|
208 | 208 | |
209 | - $layout = $W->HBoxItems( |
|
210 | - $checkbox->setSizePolicy(WidgetSizePolicy::MINIMUM), |
|
211 | - $label |
|
212 | - )->setVerticalAlign('middle')->setHorizontalSpacing(0.5, 'em'); |
|
209 | + $layout = $W->HBoxItems( |
|
210 | + $checkbox->setSizePolicy(WidgetSizePolicy::MINIMUM), |
|
211 | + $label |
|
212 | + )->setVerticalAlign('middle')->setHorizontalSpacing(0.5, 'em'); |
|
213 | 213 | |
214 | - return $layout; |
|
214 | + return $layout; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | |
@@ -219,42 +219,42 @@ discard block |
||
219 | 219 | |
220 | 220 | function app_LabelledOrmSelect(ORMMySqlIterator $iterator, $fieldName, $selectName, $label, $hidden = false, $groupFieldName = null) |
221 | 221 | { |
222 | - $W = \bab_Widgets(); |
|
223 | - |
|
224 | - if (isset($groupFieldName)) { |
|
225 | - $groupPathElements = explode('/', $groupFieldName); |
|
226 | - } |
|
227 | - |
|
228 | - $select = $W->Select()->setName($selectName); |
|
229 | - |
|
230 | - $select->addOption('', ''); |
|
231 | - |
|
232 | - $nbOptions = 0; |
|
233 | - foreach ($iterator as $record) { |
|
234 | - if (isset($record->code)) { |
|
235 | - $optionText = $record->code . ' - ' . $record->$fieldName; |
|
236 | - } else { |
|
237 | - $optionText = $record->$fieldName; |
|
238 | - } |
|
239 | - if (isset($groupFieldName)) { |
|
240 | - $group = $record; |
|
241 | - foreach ($groupPathElements as $groupPathElement) { |
|
242 | - $group = $group->$groupPathElement; |
|
243 | - } |
|
244 | - $select->addOption($record->id, $optionText, $group); |
|
245 | - } else { |
|
246 | - $select->addOption($record->id, $optionText); |
|
247 | - } |
|
248 | - $nbOptions++; |
|
249 | - $lastId = $record->id; |
|
250 | - } |
|
251 | - |
|
252 | - if ($nbOptions == 1) { |
|
253 | - $select->setValue($lastId); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - return app_LabelledWidget($label, $select); |
|
222 | + $W = \bab_Widgets(); |
|
223 | + |
|
224 | + if (isset($groupFieldName)) { |
|
225 | + $groupPathElements = explode('/', $groupFieldName); |
|
226 | + } |
|
227 | + |
|
228 | + $select = $W->Select()->setName($selectName); |
|
229 | + |
|
230 | + $select->addOption('', ''); |
|
231 | + |
|
232 | + $nbOptions = 0; |
|
233 | + foreach ($iterator as $record) { |
|
234 | + if (isset($record->code)) { |
|
235 | + $optionText = $record->code . ' - ' . $record->$fieldName; |
|
236 | + } else { |
|
237 | + $optionText = $record->$fieldName; |
|
238 | + } |
|
239 | + if (isset($groupFieldName)) { |
|
240 | + $group = $record; |
|
241 | + foreach ($groupPathElements as $groupPathElement) { |
|
242 | + $group = $group->$groupPathElement; |
|
243 | + } |
|
244 | + $select->addOption($record->id, $optionText, $group); |
|
245 | + } else { |
|
246 | + $select->addOption($record->id, $optionText); |
|
247 | + } |
|
248 | + $nbOptions++; |
|
249 | + $lastId = $record->id; |
|
250 | + } |
|
251 | + |
|
252 | + if ($nbOptions == 1) { |
|
253 | + $select->setValue($lastId); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + return app_LabelledWidget($label, $select); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | |
@@ -302,36 +302,36 @@ discard block |
||
302 | 302 | ->setMaxSize($field->getMaxLength()); |
303 | 303 | } else if ($field instanceof ORMTextField) { |
304 | 304 | $widget = $W->TextEdit() |
305 | - ->addClass('widget-autoresize'); |
|
305 | + ->addClass('widget-autoresize'); |
|
306 | 306 | } else if ($field instanceof ORMPkField) { |
307 | 307 | $widget = $W->Hidden(); |
308 | 308 | } else if ($field instanceof ORMFkField) { |
309 | 309 | |
310 | 310 | $fieldName = $field->getName(); |
311 | 311 | /** @var AppRecordSet $parentSet */ |
312 | - $parentSet = clone $field->getParentSet(); |
|
312 | + $parentSet = clone $field->getParentSet(); |
|
313 | 313 | $parentSet->join($fieldName); |
314 | 314 | $set = $parentSet->$fieldName; |
315 | 315 | $records = $set->select(); |
316 | - $pkName = $set->getPrimaryKey(); |
|
317 | - if($set->fieldExist("name")){ |
|
318 | - $displayField = $set->name->getName(); |
|
319 | - }else if(method_exists($set,"getDisplayNameField")){ |
|
320 | - $displayField = $set->getDisplayNameField()->getName(); |
|
321 | - }else{ |
|
322 | - $displayField = $pkName; |
|
323 | - } |
|
324 | - $records->orderAsc($set->$displayField); |
|
325 | - if($records->count() > 50){ |
|
326 | - $widget = bab_Widgets()->select2(); |
|
327 | - $widget->setDataSource($set->getController()->search()); |
|
328 | - }else{ |
|
329 | - $widget = $W->Select(); |
|
330 | - $widget->addOption('', ''); |
|
331 | - foreach ($records as $record) { |
|
332 | - $widget->addOption($record->$pkName, $record->$displayField); |
|
333 | - } |
|
334 | - } |
|
316 | + $pkName = $set->getPrimaryKey(); |
|
317 | + if($set->fieldExist("name")){ |
|
318 | + $displayField = $set->name->getName(); |
|
319 | + }else if(method_exists($set,"getDisplayNameField")){ |
|
320 | + $displayField = $set->getDisplayNameField()->getName(); |
|
321 | + }else{ |
|
322 | + $displayField = $pkName; |
|
323 | + } |
|
324 | + $records->orderAsc($set->$displayField); |
|
325 | + if($records->count() > 50){ |
|
326 | + $widget = bab_Widgets()->select2(); |
|
327 | + $widget->setDataSource($set->getController()->search()); |
|
328 | + }else{ |
|
329 | + $widget = $W->Select(); |
|
330 | + $widget->addOption('', ''); |
|
331 | + foreach ($records as $record) { |
|
332 | + $widget->addOption($record->$pkName, $record->$displayField); |
|
333 | + } |
|
334 | + } |
|
335 | 335 | } else if ($field instanceof ORMRecordSet) { |
336 | 336 | $widget = $W->Select(); |
337 | 337 | //// $widget = $W->MultiSelect()->setSingleSelect(); |
@@ -357,21 +357,21 @@ discard block |
||
357 | 357 | |
358 | 358 | function app_LabelledOrmWidget(ORMField $field, $label = null, $hidden = false) |
359 | 359 | { |
360 | - $W = \bab_Widgets(); |
|
360 | + $W = \bab_Widgets(); |
|
361 | 361 | |
362 | - if ($hidden) { |
|
363 | - $widget = $W->Hidden(); |
|
364 | - $widget->setName($field->getName()); |
|
365 | - return $widget; |
|
366 | - } |
|
362 | + if ($hidden) { |
|
363 | + $widget = $W->Hidden(); |
|
364 | + $widget->setName($field->getName()); |
|
365 | + return $widget; |
|
366 | + } |
|
367 | 367 | |
368 | - if (is_null($label)) { |
|
369 | - $label = $field->getDescription(); |
|
370 | - } |
|
368 | + if (is_null($label)) { |
|
369 | + $label = $field->getDescription(); |
|
370 | + } |
|
371 | 371 | |
372 | - $widget = app_OrmWidget($field); |
|
372 | + $widget = app_OrmWidget($field); |
|
373 | 373 | |
374 | - return app_LabelledWidget($label, $widget); |
|
374 | + return app_LabelledWidget($label, $widget); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | |
@@ -387,16 +387,16 @@ discard block |
||
387 | 387 | */ |
388 | 388 | function app_dateTime(ORMField $field, $value) { |
389 | 389 | |
390 | - $W = \bab_functionality::get('Widgets'); |
|
391 | - $name = $field->getName(); |
|
392 | - $label = $W->Label($field->getDescription()); |
|
390 | + $W = \bab_functionality::get('Widgets'); |
|
391 | + $name = $field->getName(); |
|
392 | + $label = $W->Label($field->getDescription()); |
|
393 | 393 | |
394 | - $frame = app_dateTimeField($name, $label, $value); |
|
394 | + $frame = app_dateTimeField($name, $label, $value); |
|
395 | 395 | |
396 | - return $W->VBoxItems( |
|
397 | - $label, |
|
398 | - $frame |
|
399 | - ); |
|
396 | + return $W->VBoxItems( |
|
397 | + $label, |
|
398 | + $frame |
|
399 | + ); |
|
400 | 400 | |
401 | 401 | } |
402 | 402 | |
@@ -410,24 +410,24 @@ discard block |
||
410 | 410 | */ |
411 | 411 | function app_dateTimeField($fieldName, WidgetLabel $label, $value = null) |
412 | 412 | { |
413 | - $W = \bab_functionality::get('Widgets'); |
|
413 | + $W = \bab_functionality::get('Widgets'); |
|
414 | 414 | |
415 | - $datepart = $W->DatePicker()->setAssociatedLabel($label)->setName('date'); |
|
416 | - $timepart = $W->TimePicker()->setName('time'); |
|
415 | + $datepart = $W->DatePicker()->setAssociatedLabel($label)->setName('date'); |
|
416 | + $timepart = $W->TimePicker()->setName('time'); |
|
417 | 417 | |
418 | - if (isset($value)) { |
|
418 | + if (isset($value)) { |
|
419 | 419 | |
420 | - $value = explode(' ', $value); |
|
420 | + $value = explode(' ', $value); |
|
421 | 421 | |
422 | - $datepart->setValue($value[0]); |
|
423 | - $timepart->setValue($value[1]); |
|
424 | - } |
|
422 | + $datepart->setValue($value[0]); |
|
423 | + $timepart->setValue($value[1]); |
|
424 | + } |
|
425 | 425 | |
426 | - $datetime = $W->Frame(null, $W->HBoxLayout())->setName($fieldName) |
|
427 | - ->addItem($datepart) |
|
428 | - ->addItem($timepart); |
|
426 | + $datetime = $W->Frame(null, $W->HBoxLayout())->setName($fieldName) |
|
427 | + ->addItem($datepart) |
|
428 | + ->addItem($timepart); |
|
429 | 429 | |
430 | - return $datetime; |
|
430 | + return $datetime; |
|
431 | 431 | } |
432 | 432 | |
433 | 433 |