Um die Benutzung des Template Systems mal ein wenig zu foerdern.
[kivitendo-erp.git] / templates / webpages / generic / multibox.html
diff --git a/templates/webpages/generic/multibox.html b/templates/webpages/generic/multibox.html
new file mode 100644 (file)
index 0000000..5d8e863
--- /dev/null
@@ -0,0 +1,64 @@
+[%- 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.
+
+  call:  INCLUDE generic/multibox.html var = var, var2 = .... 
+
+  options and variables:
+    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.
+    limit      : defines the limit of entries, after which a textbox is generated. defaults to vclimit, or, failing to find that, 50.
+    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
+-%]
+[%- DEFAULT 
+  limit      = limit != ''   ? limit   : 50
+  id         = id    != ''   ? id      : name
+  default    = default != '' ? default : $name
+-%]
+[%- FOREACH row = DATA %]
+  [%-
+       row.id       = row.$id_key     != ''  ? row.$id_key    : $id_sub(row)
+       row.label    = row.$label_key  != ''  ? row.$label_key 
+                    : $label_sub(row) != ''  ? $label_sub(row) 
+                    :                          row.id
+       row.selected = default == row.id
+  -%]
+[%- END -%]
+[%- IF DATA.size and limit < DATA.size %]
+<input type="text" 
+ [%~ 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 ~%]
+>
+[%~ IF select %]
+  <button type="button" onclick="[% select %]">?</button>
+[% END ~%]
+[%- ELSE %]
+<select 
+ [%~ 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 ~%]
+>
+  [%- 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 %]