5 include( '/elements/selectlayers.html',
6 'field' => $key, # SELECT element NAME (passed as form field)
7 # also used as ID and a unique key for layers and
9 'curr_value' => $selected_layer,
10 'options' => [ 'option1', 'option2' ],
11 'labels' => { 'option1' => 'Option 1 Label',
12 'option2' => 'Option 2 Label',
15 #XXX put this handling it its own selectlayers-fields.html element?
16 'layer_prefix' => 'prefix_', #optional prefix for fieldnames
17 'layer_fields' => [ 'layer' => [ 'fieldname',
18 { label => 'fieldname2',
19 type => 'text', #implemented:
23 # select, select-agent,
25 # select-part_referral,
32 'layer2' => [ 'l2fieldname',
36 #current values for layer fields above
37 'layer_values' => { 'layer' => { 'fieldname' => 'current_value',
38 'fieldname2' => 'field2value',
41 'layer2' => { 'l2fieldname' => 'l2value',
47 #or manual control, instead of layer_fields and layer_values above
48 #called with args: my( $layer, $layer_fields, $layer_values, $layer_prefix )
51 'html_between => '', #optional HTML displayed between the SELECT and the
52 #layers, scalar or coderef ('field' passed as a param)
53 'onchange' => '', #javascript code run when the SELECT changes
54 # ("what" is the element)
55 'js_only' => 0, #set true to return only the JS portions
56 'html_only' => 0, #set true to return only the HTML portions
57 'select_only' => 0, #set true to return only the <SELECT> HTML
58 'layers_only' => 0, #set true to return only the layers <DIV> HTML
62 % unless ( grep $opt{$_}, qw(html_only js_only select_only layers_only) ) {
63 <SCRIPT TYPE="text/javascript">
65 % unless ( grep $opt{$_}, qw(html_only select_only layers_only) ) {
66 //alert('start function define');
67 function <% $key %>changed(what) {
69 <% $opt{'onchange'} %>
71 var <% $key %>layer = what.options[what.selectedIndex].value;
73 % foreach my $layer ( keys %$options ) {
75 if (<% $key %>layer == "<% $layer %>" ) {
77 % foreach my $not ( grep { $_ ne $layer } keys %$options ) {
78 % my $element = "document.getElementById('${key}d$not').style";
79 <% $element %>.display = "none";
80 <% $element %>.zIndex = 0;
83 % my $element = "document.getElementById('${key}d$layer').style";
84 <% $element %>.display = "";
85 <% $element %>.zIndex = 1;
90 //<% $opt{'onchange'} %>
93 //alert('end function define');
95 % unless ( grep $opt{$_}, qw(html_only js_only select_only layers_only) ) {
99 % unless ( grep $opt{$_}, qw(js_only layers_only) ) {
101 <SELECT NAME = "<% $key %>"
103 previousValue = "<% $selected %>"
104 previousText = "<% $options{$selected} %>"
105 onChange="<% $key %>changed(this);"
108 % foreach my $option ( keys %$options ) {
110 <OPTION VALUE="<% $option %>"
111 <% $option eq $selected ? ' SELECTED' : '' %>
112 ><% $options->{$option} %></OPTION>
119 % unless ( grep $opt{$_}, qw(js_only select_only layers_only) ) {
121 <% ref($between) ? &{$between}($key) : $between %>
125 % unless ( grep $opt{$_}, qw(js_only select_only) ) {
127 % foreach my $layer ( keys %$options ) {
129 <DIV ID="<% $key %>d<% $layer %>"
130 STYLE="<% $layer eq $selected
131 ? 'display: "" ; z-index: 1'
132 : 'display: none; z-index: 0'
136 <% &{$layer_callback}($layer, $layer_fields, $layer_values, $layer_prefix) %>
145 my $conf = new FS::Conf;
146 my $money_char = $conf->config('money_char') || '$';
156 my $key = $opt{field}; # || 'generate_one' #?
158 tie my %options, 'Tie::IxHash',
159 map { $_ => $opt{'labels'}->{$_} }
160 @{ $opt{'options'} }; #just arrayref for now
162 my $between = exists($opt{html_between}) ? $opt{html_between} : '';
163 my $options = \%options;
165 my $selected = exists($opt{curr_value}) ? $opt{curr_value} : '';
167 #XXX eek. also eek $layer_fields in the layer_callback() call...
168 my $layer_fields = $opt{layer_fields};
169 my $layer_values = $opt{layer_values};
170 my $layer_prefix = $opt{layer_prefix};
172 my $layer_callback = $opt{layer_callback} || \&layer_callback;
175 my( $layer, $layer_fields, $layer_values, $layer_prefix ) = @_;
177 return '' unless $layer && exists $layer_fields->{$layer};
178 tie my %fields, 'Tie::IxHash', @{ $layer_fields->{$layer} };
180 #XXX this should become an element itself... (false laziness w/edit.html)
181 # but at least all the elements inside are the shared mason elements now
183 return '' unless keys %fields;
184 my $html = "<TABLE>";
186 foreach my $field ( keys %fields ) {
188 my $lf = ref($fields{$field})
190 : { 'label'=>$fields{$field} };
192 my $value = $layer_values->{$layer}{$field};
194 my $type = $lf->{type} || 'text';
197 $include = "input-$include" if $include =~ /^(text|money)$/;
198 $include = "tr-$include" unless $include eq 'hidden';
200 $html .= include( "/elements/$include.html",
202 'field' => "$layer_prefix$field",
203 'id' => "$layer_prefix$field", #separate?
204 #don't want field0_label0...?
205 'label_id' => $layer_prefix.$field."_label",
207 'value' => ( $lf->{'value'} || $value ), #hmm.
208 'curr_value' => $value,