Merge branch 'master' of ssh://lx-office/~/lx-office-erp
[kivitendo-erp.git] / templates / webpages / generic / multibox.html
1 [%- USE HTML %]
2 [%#-
3      Multibox
4
5   This template makes an input box for you,
6   decides wether it should be a text field or a drop down box,
7   generates the HTML code, and fixes everything just right.
8
9   call:  INCLUDE generic/multibox.html var = var, var2 = ....
10
11   options and variables:
12     name          : name of the select/textfield
13     id            : id of the select/textfield, optional, defaults to name
14     default       : entered/selected value. defaults to a dereference of name, since it is usually set to that for update mechanisms
15     id_key        : key that holds the id in each row.
16     id_sub        : name of a perl sub that calculates the id for each row. will be called with a hashref.
17     label_key     : key that holds the label in each row.
18     label_sub     : name of a perl sub that calculates the label for each row. will be called with a hashref.
19     DATA          : the actual data, expected to be arrayref of hashrefs, usually what's returned by the all_vc routines.
20     show_empty    : show an empty first line in select boxes. defaults to false
21     style         : additional style information
22     onChange      : java magic on change
23     select        : java function call for a selection popup or other magic
24     allow_textbox : allow to display a textbox instead of a drop down box if there are more entries than 'limit' entries.
25     limit         : defines the limit of entries, after which a textbox is generated. defaults to vclimit, or, failing to find that, 200.
26     readonly      : softly prevents modification
27 -%]
28 [%- DEFAULT
29   limit      = limit   != '' ? limit   : vclimit != '' ? vclimit : 200
30   id         = id      != '' ? id      : name
31   default    = default != '' ? default : $name
32 -%]
33 [%- FOREACH row = DATA %]
34   [%-
35        row.id       = row.$id_key     != ''  ? row.$id_key    : $id_sub(row)
36        row.label    = row.$label_key  != ''  ? row.$label_key
37                     : $label_sub(row) != ''  ? $label_sub(row)
38                     :                          row.id
39        row.selected = default == row.id
40   -%]
41 [%- END -%]
42 [%- IF allow_textbox and DATA.size and limit < DATA.size %]
43 <input type="text"
44  [%- IF name     %] name="[%     HTML.escape(name)     %]"[% END -%]
45  [%- IF id       %] id="[%       HTML.escape(id)       %]"[% END -%]
46  [%- IF default  %] value="[%    HTML.escape(default)  %]"[% END -%]
47  [%- IF style    %] style="[%    HTML.escape(style)    %]"[% END -%]
48  [%- IF readonly %] readonly[% END -%]
49 [%- -%]>
50 [%- IF select -%]
51   <input type="button" onclick="[% select %]" value="?">
52 [%- END -%]
53 [%- ELSE %]
54 <select
55  [%- IF name     %] name="[%     HTML.escape(name)     %]"[% END -%]
56  [%- IF id       %] id="[%       HTML.escape(id)       %]"[% END -%]
57  [%- IF style    %] style="[%    HTML.escape(style)    %]"[% END -%]
58  [%- IF onChange %] onChange="[% HTML.escape(onChange) %]"[% END -%]
59  [%- IF readonly %] disabled[% END -%]
60 [%- -%]>
61   [%- IF show_empty %]
62   <option value=""></option>
63   [%- END %]
64   [%- FOREACH row = DATA %]
65   <option value="[% row.id | html %]"[% IF row.selected %] selected[% END %]>[% HTML.escape(row.label) %]</option>
66   [%- END %]
67 </select>
68 [%- END %]