multibox part 2.
[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:  PROCESS 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     select_name   : if a select is displayed, use a different name. ex.: department for textinput, but department_id for selects
27     readonly      : softly prevents modification
28 -%]
29 [%-
30   Multibox__limit      = limit   != '' ? limit   : vclimit != '' ? vclimit : 200
31   Multibox__show_text  = allow_textbox and DATA.size and Multibox__limit < DATA.size ? 1 : 0
32   Multibox__id         = id      != '' ? id      : name
33   Multibox__default    = default != '' ? default : $name
34   Multibox__name       = (select_name != '' and ! Multibox__show_text) ? select_name : name
35 -%]
36 [%- IF Multibox__show_text %]
37 <input type="text"
38  [%- IF Multibox__name     %] name="[%  Multibox__name    | html %]"[% END -%]
39  [%- IF Multibox__id       %] id="[%    Multibox__id      | html %]"[% END -%]
40  [%- IF Multibox__default  %] value="[% Multibox__default | html %]"[% END -%]
41  [%- IF style              %] style="[% style             | html %]"[% END -%]
42  [%- IF readonly           %] readonly[% END -%]
43 [%- -%]>
44 [%- IF select -%]
45   <input type="button" onclick="[% select %]" value="?">
46 [%- END -%]
47 [%- ELSE %]
48 <select
49  [%- IF Multibox__name     %] name="[%     Multibox__name     | html %]"[% END -%]
50  [%- IF Multibox__id       %] id="[%       Multibox__id       | html %]"[% END -%]
51  [%- IF style              %] style="[%    style              | html %]"[% END -%]
52  [%- IF onChange           %] onChange="[% onChange           | html %]"[% END -%]
53  [%- IF readonly           %] disabled[% END -%]
54 [%- -%]>
55   [%- IF show_empty %]
56   <option value=""></option>
57   [%- END %]
58   [%- FOREACH row = DATA %]
59   [%-
60       Multibox__row_id       = row.$id_key     != ''  ? row.$id_key    : $id_sub(row)
61       Multibox__row_label    = row.$label_key  != ''  ? row.$label_key
62                              : $label_sub(row) != ''  ? $label_sub(row)
63                              :                          Multibox__row_id
64       Multibox__row_selected = Multibox__default == Multibox__row_id
65   %]
66   <option value="[% Multibox__row_id | html %]"[% IF Multibox__row_selected %] selected[% END %]>[% Multibox__row_label | html %]</option>
67   [%- END %]
68 </select>
69 [%- END %]