Overview
Comment: | Split parameters and attributes, implement list inputs |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | dev |
Files: | files | file ages | folders |
SHA1: |
cd293e7c1077d9aedb7b96c7fcee7b36 |
User & Date: | bohwaz on 2020-09-09 21:15:37 |
Other Links: | branch diff | manifest | tags |
Context
2020-09-09
| ||
21:15 | Add ability to open dialogs check-in: 2e91cecaaa user: bohwaz tags: dev | |
21:15 | Split parameters and attributes, implement list inputs check-in: cd293e7c10 user: bohwaz tags: dev | |
21:15 | type_parent can take any type value now check-in: 7f458dbc19 user: bohwaz tags: dev | |
Changes
Modified src/include/lib/Garradin/Template.php from [b844a01740] to [a5a8d51011].
︙ | ︙ | |||
176 177 178 179 180 181 182 | protected function widgetLinkButton(array $params): string { return sprintf('<a class="icn-btn" data-icon="%s" href="%s">%s</a>', Utils::iconUnicode($params['shape']), $this->escape(ADMIN_URL . $params['href']), $this->escape($params['label'])); } protected function formInput(array $params) { | > | > > > < | | 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | protected function widgetLinkButton(array $params): string { return sprintf('<a class="icn-btn" data-icon="%s" href="%s">%s</a>', Utils::iconUnicode($params['shape']), $this->escape(ADMIN_URL . $params['href']), $this->escape($params['label'])); } protected function formInput(array $params) { static $params_list = ['value', 'default', 'type', 'help', 'label', 'name', 'options']; // Extract params and keep attributes separated $attributes = array_diff_key($params, array_flip($params_list)); $params = array_intersect_key($params, array_flip($params_list)); extract($params, \EXTR_SKIP); if (!isset($name, $type)) { throw new \InvalidArgumentException('Missing name or type'); } $current_value = null; if (isset($value)) { $current_value = $value; } elseif (isset($_POST[$name])) { $current_value = $_POST[$name]; } elseif (isset($default)) { $current_value = $default; } $attributes['id'] = 'f_' . $name; if ($type == 'radio' || $type == 'checkbox') { $attributes['id'] .= '_' . $value; } // Create attributes string if (array_key_exists('required', $attributes)) { $attributes['required'] = 'required'; } $attributes_string = $attributes; array_walk($attributes_string, function (&$v, $k) { $v = sprintf('%s="%s"', $k, $v); |
︙ | ︙ | |||
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | } $input .= '</select>'; } elseif ($type == 'textarea') { $input = sprintf('<textarea %s>%s</textarea>', $attributes_string, $this->escape($current_value)); } else { $input = sprintf('<input type="%s" %s value="%s" />', $type, $attributes_string, $this->escape($current_value)); } // No label? then we only want the input without the widget if (empty($label)) { return $input; } | > > > | | 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | } $input .= '</select>'; } elseif ($type == 'textarea') { $input = sprintf('<textarea %s>%s</textarea>', $attributes_string, $this->escape($current_value)); } elseif ($type == 'list') { $input = sprintf('<span id="%s_container" class="input-list"><input type="hidden" name="%s" value="%s" /><span class="value">%3$s</span><button id="%1$s" data-icon="%s" name="list_selector[%2$s]" class="icn-btn" value="%s">%s</button></span>', $this->escape($attributes['id']), $this->escape($name), $this->escape($current_value), Utils::iconUnicode('menu'), $this->escape($attributes['target']), 'Sélectionner'); } else { $input = sprintf('<input type="%s" %s value="%s" />', $type, $attributes_string, $this->escape($current_value)); } // No label? then we only want the input without the widget if (empty($label)) { return $input; } $required_label = array_key_exists('required', $attributes) ? ' <b title="Champ obligatoire">(obligatoire)</b>' : ''; $out = '<dt>'; if ($type == 'radio' || $type == 'checkbox') { $out .= $input . ' '; } |
︙ | ︙ |