|
1 |
package SL::Presenter::CustomVariable;
|
|
2 |
|
|
3 |
use strict;
|
|
4 |
|
|
5 |
use SL::Presenter::Tag qw(hidden_tag checkbox_tag textarea_tag input_tag input_number_tag date_tag select_tag);
|
|
6 |
use SL::Presenter::EscapedText qw(escape);
|
|
7 |
use SL::Presenter::CustomerVendor qw(customer_picker vendor_picker);
|
|
8 |
use SL::Locale::String qw(t8);
|
|
9 |
|
|
10 |
use Exporter qw(import);
|
|
11 |
our @EXPORT_OK = qw(custom_variable_input_field custom_variable_label);
|
|
12 |
|
|
13 |
sub table_cell {
|
|
14 |
$_[0]->value_as_text
|
|
15 |
}
|
|
16 |
|
|
17 |
sub input_field {
|
|
18 |
my ($cvar, %params) = @_;
|
|
19 |
|
|
20 |
$params{name_prefix} //= 'cvar_';
|
|
21 |
$params{name_postfix} //= '';
|
|
22 |
|
|
23 |
my $config = $cvar->config;
|
|
24 |
my $name = $params{name} // join '', $params{name_prefix}, 'cvar_', $config->name, $params{name_postfix};
|
|
25 |
|
|
26 |
if ($params{hidden}) {
|
|
27 |
return hidden_tag($name, $cvar->value);
|
|
28 |
}
|
|
29 |
|
|
30 |
if (!$config->has_flag('editable')) {
|
|
31 |
if ($params{hide_non_editable}) {
|
|
32 |
return hidden_tag($name, $cvar->value);
|
|
33 |
} else {
|
|
34 |
return escape($cvar->value_as_text);
|
|
35 |
}
|
|
36 |
}
|
|
37 |
|
|
38 |
if (!$cvar->is_valid) {
|
|
39 |
if ($params{show_disabled_message}) {
|
|
40 |
return escape(t8('Element disabled'));
|
|
41 |
} else {
|
|
42 |
return '';
|
|
43 |
}
|
|
44 |
}
|
|
45 |
|
|
46 |
for my $type ($config->type) {
|
|
47 |
return checkbox_tag($name, checked => $cvar->value) if $type eq 'bool';
|
|
48 |
return textarea_tag($name, $cvar->value, $config->textarea_options) if $type eq 'textfield';
|
|
49 |
return date_tag($name, $cvar->value) if $type eq 'date';
|
|
50 |
return input_tag($name, $cvar->value) if $type eq 'timestamp';
|
|
51 |
return vendor_picker($name, $cvar->value) if $type eq 'vendor';
|
|
52 |
return customer_picker($name, $cvar->value) if $type eq 'customer';
|
|
53 |
return part_picker($name, $cvar->value) if $type eq 'part';
|
|
54 |
return select_tag($name, $config->processed_options, default => $cvar->value) if $type eq 'select';
|
|
55 |
return input_number_tag($name, $cvar->value_as_text, $config->number_options) if $type eq 'number';
|
|
56 |
return input_tag($name, $cvar->value, $config->text_options);
|
|
57 |
}
|
|
58 |
}
|
|
59 |
|
|
60 |
sub input_with_label {
|
|
61 |
&label . &input_field;
|
|
62 |
}
|
|
63 |
|
|
64 |
sub label {
|
|
65 |
$_[0]->config->description
|
|
66 |
}
|
|
67 |
|
|
68 |
sub custom_variable_input_field { goto &input_field }
|
|
69 |
sub custom_variable_label { goto &label }
|
|
70 |
|
|
71 |
1;
|
|
72 |
|
|
73 |
__END__
|
|
74 |
|
|
75 |
to do:
|
|
76 |
|
|
77 |
from oe/_sales_order.html - row2:
|
|
78 |
|
|
79 |
<table class='row2-cvars-table'>
|
|
80 |
<tr>
|
|
81 |
[%- FOREACH row2 = row.ROW2 %]
|
|
82 |
my $options = $row1->{render_options};
|
|
83 |
my $show = ($options.var.flag_editable || !$options.hide_non_editable) && $options.valid && !$options.partsgroup_filtered) %]
|
|
84 |
if ($row2.cvar && $show) {
|
|
85 |
[%- IF row2.line_break %]
|
|
86 |
</tr><tr>
|
|
87 |
[%- END %]
|
|
88 |
<th>
|
|
89 |
[% row2.description %]
|
|
90 |
</th>
|
|
91 |
<td>
|
|
92 |
[% PROCESS cvar_inputs cvar = row2.render_options %]
|
|
93 |
</td>
|
|
94 |
}
|
|
95 |
[%- END %]
|
|
96 |
</tr>
|
|
97 |
</table>
|
|
98 |
|
|
99 |
[%# process non editable cvars extra to not disturb the table layout (this will be hidden inputs) %]
|
|
100 |
[%- FOREACH row2 = row.ROW2 %]
|
|
101 |
[%- SET hide = (!row2.render_options.var.flag_editable && row2.render_options.hide_non_editable) %]
|
|
102 |
[%- IF row2.cvar && hide %]
|
|
103 |
[% PROCESS cvar_inputs cvar = row2.render_options %]
|
|
104 |
[%- END %]
|
|
105 |
[%- END %]
|
|
106 |
|
|
107 |
that in turn calls cvar_inputs which is included from amcvar/render_inputs_block and looks like render_input
|
Presenter::CustomVariables