Overview
Comment: | Autoriser les widgets input à ne pas avoir de label etc., ajouter un widget de type bouton avec icône |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | dev |
Files: | files | file ages | folders |
SHA1: |
3af48380f7163d29b4c6233a79852f68 |
User & Date: | bohwaz on 2020-09-04 22:23:13 |
Other Links: | branch diff | manifest | tags |
Context
2020-09-08
| ||
19:03 | Liste des comptes, objets pour les plans comptables et exercices check-in: 6987513f8d user: bohwaz tags: dev | |
2020-09-04
| ||
22:23 | Autoriser les widgets input à ne pas avoir de label etc., ajouter un widget de type bouton avec icône check-in: 3af48380f7 user: bohwaz tags: dev | |
22:20 | Liste simplifiée des comptes check-in: 4463ba110d user: bohwaz tags: dev | |
Changes
Modified src/include/lib/Garradin/Template.php from [e69b34a2ee] to [b844a01740].
︙ | ︙ | |||
70 71 72 73 74 75 76 77 78 79 80 81 82 83 | $this->register_function('format_droits', [$this, 'formatDroits']); $this->register_function('csrf_field', function ($params) { return Form::tokenHTML($params['key']); }); $this->register_function('icon', [$this, 'widgetIcon']); $this->register_modifier('strlen', 'strlen'); $this->register_modifier('dump', ['KD2\ErrorManager', 'dump']); $this->register_modifier('get_country_name', ['Garradin\Utils', 'getCountryName']); $this->register_modifier('format_sqlite_date_to_french', ['Garradin\Utils', 'sqliteDateToFrench']); $this->register_modifier('format_bytes', ['Garradin\Utils', 'format_bytes']); $this->register_modifier('format_tel', [$this, 'formatPhoneNumber']); | > | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | $this->register_function('format_droits', [$this, 'formatDroits']); $this->register_function('csrf_field', function ($params) { return Form::tokenHTML($params['key']); }); $this->register_function('icon', [$this, 'widgetIcon']); $this->register_function('button', [$this, 'widgetLinkButton']); $this->register_modifier('strlen', 'strlen'); $this->register_modifier('dump', ['KD2\ErrorManager', 'dump']); $this->register_modifier('get_country_name', ['Garradin\Utils', 'getCountryName']); $this->register_modifier('format_sqlite_date_to_french', ['Garradin\Utils', 'sqliteDateToFrench']); $this->register_modifier('format_bytes', ['Garradin\Utils', 'format_bytes']); $this->register_modifier('format_tel', [$this, 'formatPhoneNumber']); |
︙ | ︙ | |||
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | { if (empty($params['href'])) { return sprintf('<b class="icn">%s</b>', Utils::iconUnicode($params['shape'])); } return sprintf('<a href="%s" class="icn" title="%s">%s</a>', $this->escape(ADMIN_URL . $params['href']), $this->escape($params['label']), Utils::iconUnicode($params['shape'])); } protected function formInput(array $params) { static $keep_attributes = ['pattern', 'max', 'min', 'step', 'title', 'name', 'cols', 'rows', 'maxlength']; extract($params, \EXTR_SKIP); if (!isset($name, $type)) { throw new \InvalidArgumentException('Missing name or type'); } $current_value = null; | > > > > > > > > | < | < | < < | | < | > > > | | < < | | | | | | | | | | > > > > > > > > > > | > > > > > > > > > > > | 168 169 170 171 172 173 174 175 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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 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 272 273 274 275 276 277 278 279 280 281 | { if (empty($params['href'])) { return sprintf('<b class="icn">%s</b>', Utils::iconUnicode($params['shape'])); } return sprintf('<a href="%s" class="icn" title="%s">%s</a>', $this->escape(ADMIN_URL . $params['href']), $this->escape($params['label']), Utils::iconUnicode($params['shape'])); } 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 $keep_attributes = ['pattern', 'max', 'min', 'step', 'title', 'name', 'cols', 'rows', 'maxlength']; 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 = array_intersect_key($params, array_flip($keep_attributes)); $attributes['id'] = 'f_' . $name; if ($type == 'radio' || $type == 'checkbox') { $attributes['id'] .= '_' . $value; } // Create attributes string if (array_key_exists('required', $params)) { $attributes['required'] = 'required'; } $attributes_string = $attributes; array_walk($attributes_string, function (&$v, $k) { $v = sprintf('%s="%s"', $k, $v); }); $attributes_string = implode(' ', $attributes_string); if ($type == 'select') { $input = sprintf('<select %s>', $attributes_string); foreach ($options as $_key => $_value) { $input .= sprintf('<option value="%s"%s>%s</option>', $_key, $current_value == $_key ? ' selected="selected"' : '', $this->escape($_value)); } $input .= '</select>'; } elseif ($type == 'select_groups') { $input = sprintf('<select %s>', $attributes_string); foreach ($options as $optgroup => $suboptions) { $input .= sprintf('<optgroup label="%s">', $this->escape($optgroup)); foreach ($suboptions as $_key => $_value) { $input .= sprintf('<option value="%s"%s>%s</option>', $_key, $current_value == $_key ? ' selected="selected"' : '', $this->escape($_value)); } $input .= '</optgroup>'; } $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; } $required_label = array_key_exists('required', $params) ? ' <b title="Champ obligatoire">(obligatoire)</b>' : ''; $out = '<dt>'; if ($type == 'radio' || $type == 'checkbox') { $out .= $input . ' '; } $out .= sprintf('<label for="%s">%s</label>%s</dt>', $attributes['id'], $this->escape($label), $required_label); if (isset($help)) { $out .= sprintf('<dd class="help">%s</dd>', $this->escape($help)); } if ($type != 'radio' && $type != 'checkbox') { $out .= sprintf('<dd>%s</dd>', $input); } return $out; } protected function formField(array $params, $escape = true) { if (!isset($params['name'])) |
︙ | ︙ |