Line # Revision Author
1 260 ahitrov <%once>
2
3 use JSON::XS;
4 my $json = JSON::XS->new->utf8;
5
6 </%once>
7 <%args>
8
9 $name => undef
10 $rusname => undef
11 $check => undef
12
13 </%args>
14 <%init>
15
16 my $fields = $check ? $json->decode($check) : {};
17 my @fields;
18 while ( my ($reg_id, $cost) = each %$fields ) {
19 push @fields, { region => $reg_id, cost => $cost };
20 }
21 @fields = sort { int($a->{cost}) <=> int($b->{cost}) } @fields;
22
23 my $regions = $keeper->get_documents (
24 class => 'webshop::Area',
25 status => 1,
26 order_by => 'name',
27 return_mode => 'array_ref',
28 );
29 my %pid = map { $_->pid => 1 } @$regions;
30 my @pid = keys %pid;
31 my $countries = @pid ? $keeper->get_documents (
32 id => \@pid,
33 class => 'webshop::Country',
34 return_mode => 'hash_ref',
35 ) : {};
36 $m->out('');
37 $m->out('<table width="95%" style="margin:5px 0;padding:5 6 5 6;border:1px solid #ccc;font-size:70%;font-family:Tahoma;background-color:#f5f5f5;color:#000;">');
38 $m->out('<tr bgcolor="silver" valign="top"><th width="40%"><h5 style="margin:0; padding:4px; font-size:11px; color:blue;">Регион:</h5></th>');
39 $m->out('<th width="60%"><h5 style="margin:0; padding:4px; font-size:11px; color:blue;">Стоимость доставки (число):</h5></th></tr>');
40
41 my $max = scalar @fields + 4;
42 for my $i ( 1..$max ) {
43 my $rusname = "$rusname N$i";
44 my $object = $fields[$i-1];
45 $m->comp('.field',
46 name => $name,
47 object => $object,
48 number => $i,
49 regions => $regions,
50 countries => $countries,
51 );
52 }
53 $m->out('</table>');
54
55 </%init>
56 <%def .field>
57 <%args>
58
59 $name => undef
60 $object => undef
61 $number => undef
62 $regions => []
63 $countries => {}
64
65 </%args>
66 <%init>
67 </%init>
68 <tr valign="top">
69 <td>
70 <select name="<% $name.'_area_'.$number %>" style="width:97%">
71 <option value="">--- не выбран ---</option>
72 % foreach my $region ( @$regions ) {
73 % my $selected = ref $object && $object->{region} == $region->id ? ' selected' : '';
74 % my $country = $region->pid && exists $countries->{$region->pid} ? $countries->{$region->pid} : undef;
75 <option value="<% $region->id %>"<% $selected %>><% $region->name.( ref $country ? ' ('.$country->name.')' : '' ) %></option>
76 % }
77 </select>
78 </td>
79 <td><input type="text" name="<% $name.'_cost_'.$number %>" value="<% (ref $object ? $object->{cost} : '') |h %>" style="width:97%;"></td>
80 </tr>
81 </%def>