Revision 260
- Date:
- 2012/12/05 20:52:56
- Files:
Legend:
- Added
- Removed
- Modified
-
utf8/plugins/webshop/comps/contenido/components/inputs/cost_region.msn
1 <%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> -
utf8/plugins/webshop/comps/contenido/components/outputs/cost_region.msn
1 <%once> 2 3 use JSON::XS; 4 my $json = JSON::XS->new; 5 6 </%once> 7 <%args> 8 9 $name => undef 10 $SETS => undef 11 12 </%args> 13 <%init> 14 15 return undef if (! ref($SETS)); 16 return undef if (! $name); 17 18 my $FIELDS = {}; 19 while (my ($element,$value) = each %{$SETS}) { 20 if ( $element =~ /^${name}_area_(\d+)$/ ) { 21 my $index = $1; 22 $value =~ s/^\s+//s; 23 $value =~ s/\s+$//s; 24 if ( defined $value && $value =~ /^\d+$/ ) { 25 $FIELDS->{$index}{area} = $value; 26 $FIELDS->{$index}{index} = $index; 27 } 28 } elsif ( $element =~ /^${name}_cost_(\d+)$/ ) { 29 my $index = $1; 30 $value =~ s/^\s+//s; 31 $value =~ s/\s+$//s; 32 if ( defined $value && ($value =~ /^\d+$/ || $value =~ /^\d+[\.\,]\d+$/) ) { 33 $value =~ s/\,/\./; 34 $FIELDS->{$index}{cost} = $value; 35 $FIELDS->{$index}{index} = $index; 36 } 37 } 38 } 39 my %FIELDS = map { $_->{area} => $_->{cost} } sort { int($a->{index}) <=> int($b->{index}) } grep { $_->{area} && defined $_->{cost} } values %$FIELDS; 40 return $json->encode(\%FIELDS); 41 42 </%init> -
utf8/plugins/webshop/sql/TOAST/regions.sql
1 CREATE TABLE webshop_regions ( 2 id integer DEFAULT nextval(('public.documents_id_seq'::text)::regclass) NOT NULL, 3 ctime timestamp without time zone DEFAULT now() NOT NULL, 4 mtime timestamp without time zone DEFAULT now() NOT NULL, 5 class text NOT NULL, 6 status smallint default 0 NOT NULL, 7 sections integer[], 8 pid integer default 0, 9 name text, 10 alias text, 11 price text, 12 data text 13 ); 14 15 CREATE INDEX webshop_regions_sections ON webshop_regions USING btree (sections); 16 CREATE INDEX webshop_regions_pid ON webshop_regions USING btree (pid);