-
parent.msn
385 386 1 1 <select name="<% $name %>" class="selects"> 2 % select_index_tree( $root_sect, 0, $level, $check, $CACHE ); 2 % select_index_tree( $root_sect, 0, $level, $check, \$color, $tree ); 3 3 </select> 4 5 4 <%args> 6 5 7 6 $name => undef … … 12 11 13 12 </%args> 14 13 <%init> 15 sub select_index_tree 16 { 17 use locale; 18 my ($sect, $offset, $count_offset, $selected, $CACHE) = @_; 19 14 20 my $spacer = ''; 21 for(my $c=0; $c<$offset; $c++) 22 { 23 $spacer = $spacer.(($c == $offset-1) ? ' >> ' : ' '); 15 my $tree; 16 if ( exists $request->{"_section_tree_$root"} ) { 17 $tree = $request->{"_section_tree_$root"}; 18 } else { 19 $tree = $keeper->get_section_tree( root_id => $root ); 20 $request->{"_section_tree_$root"} = $tree; 21 } 22 my $root_sect = $tree->{root}; 23 my $color = 0; 24 25 sub select_index_tree { 26 my ($sect, $offset, $count_offset, $selected, $cb, $TREE) = @_; 27 return unless ref $sect; 28 my $padding = 'padding-left:'.int($offset * 15).'px;'; 29 my $color = $$cb ? 'background:#f0f0f0;' : ''; 30 $$cb = $$cb ? 0 : 1; 31 my $style = $sect->id == 1 ? ' style="background-color:#606060;color:#ffffff;'.$padding.$color.'"' : ' style="'.$padding.$color.'"'; 32 my $sel = $selected && $selected == $sect->id ? ' selected' : ''; 33 $m->out ('<option value="'.$sect->id.'"'.$style.$sel.'>» '.$sect->name.'</option>'."\n"); 34 if ( exists $sect->{children} && $offset < $count_offset ) { 35 $offset++; 36 foreach my $child ( @{$sect->{children}} ) { 37 select_index_tree( $child, $offset, $count_offset, $selected, $cb, $TREE ); 24 38 } 25 if( $sect->id() ) 26 { 27 $m->out('<option value="'.$sect->id.'" '.(($selected == $sect->id) ? ' selected' : '').'>'.$spacer.$sect->name.'</option>'); 28 } 29 elsif( $sect->id() && $sect->id() == 1 ) 30 { 31 32 $m->out('<option style="background-color:#606060;color:#ffffff;" value="'.$sect->id.'" '.(($selected == $sect->id) ? ' selected' : '').'>'.$sect->name.'</option>'); 33 } 34 my @childs = $sect->childs(); 35 if( @childs && $offset < $count_offset ) 36 { 37 $offset++; 38 foreach my $child_id (@childs) 39 { 40 my $child = $CACHE->{$child_id}; 41 select_index_tree( $child, $offset, $count_offset, $selected, $CACHE); 42 } 43 $offset--; 44 } 45 39 } 40 } 46 41 47 48 my $CACHE = {}; 49 my @cacher = $keeper->get_sections( light => 1 ); 50 for my $c (@cacher) 51 { 52 $CACHE->{$c->id()} = $c; 53 } 54 55 my $root_sect = $CACHE->{$root} || $CACHE->{1}; 56 57 42 </%init>