Projekt

Allgemein

Profil

Herunterladen (2,93 KB) Statistiken
| Zweig: | Markierung: | Revision:
91ab1ef6 Sven Schöling
[%- USE HTML %]
[%#-
Multibox

This template makes an input box for you,
decides wether it should be a text field or a drop down box,
generates the HTML code, and fixes everything just right.

018e340a Moritz Bunkus
call: INCLUDE generic/multibox.html var = var, var2 = ....
91ab1ef6 Sven Schöling
options and variables:
018e340a Moritz Bunkus
name : name of the select/textfield
id : id of the select/textfield, optional, defaults to name
default : entered/selected value. defaults to a dereference of name, since it is usually set to that for update mechanisms
id_key : key that holds the id in each row.
id_sub : name of a perl sub that calculates the id for each row. will be called with a hashref.
label_key : key that holds the label in each row.
label_sub : name of a perl sub that calculates the label for each row. will be called with a hashref.
DATA : the actual data, expected to be arrayref of hashrefs, usually what's returned by the all_vc routines.
show_empty : show an empty first line in select boxes. defaults to false
style : additional style information
onChange : java magic on change
select : java function call for a selection popup or other magic
allow_textbox : allow to display a textbox instead of a drop down box if there are more entries than 'limit' entries.
limit : defines the limit of entries, after which a textbox is generated. defaults to vclimit, or, failing to find that, 200.
91ab1ef6 Sven Schöling
-%]
018e340a Moritz Bunkus
[%- DEFAULT
limit = limit != '' ? limit : vclimit != '' ? vclimit : 200
id = id != '' ? id : name
91ab1ef6 Sven Schöling
default = default != '' ? default : $name
-%]
[%- FOREACH row = DATA %]
[%-
row.id = row.$id_key != '' ? row.$id_key : $id_sub(row)
018e340a Moritz Bunkus
row.label = row.$label_key != '' ? row.$label_key
: $label_sub(row) != '' ? $label_sub(row)
91ab1ef6 Sven Schöling
: row.id
row.selected = default == row.id
-%]
[%- END -%]
018e340a Moritz Bunkus
[%- IF allow_textbox and DATA.size and limit < DATA.size %]
<input type="text"
f6de0aa9 Moritz Bunkus
[%- IF name %] name="[% HTML.escape(name) %]"[% END %]
[%- IF id %] id="[% HTML.escape(id) %]"[% END %]
[%- IF default %] value="[% HTML.escape(default) %]"[% END %]
[%- IF style %] style="[% HTML.escape(style) %]"[% END %]
91ab1ef6 Sven Schöling
>
f6de0aa9 Moritz Bunkus
[%- IF select %]
103dc24c Sven Schöling
<input type="button" onclick="[% select %]" value="?">
f6de0aa9 Moritz Bunkus
[% END %]
91ab1ef6 Sven Schöling
[%- ELSE %]
018e340a Moritz Bunkus
<select
f6de0aa9 Moritz Bunkus
[%- IF name %] name="[% HTML.escape(name) %]"[% END %]
[%- IF id %] id="[% HTML.escape(id) %]"[% END %]
[%- IF style %] style="[% HTML.escape(style) %]"[% END %]
[%- IF onChange %] onChange="[% HTML.escape(onChange) %]"[% END %]
91ab1ef6 Sven Schöling
>
[%- IF show_empty %]
<option value=""></option>
[%- END %]
[%- FOREACH row = DATA %]
<option value="[% row.id %]"[% IF row.selected %] selected[% END %]>[% HTML.escape(row.label) %]</option>
[%- END %]
</select>
[%- END %]