• sections.html

    130 131  
    293 293 }
    294 294
    295 295 my %filter=();
    296 my $nothing_found = 0;
    296 297 my %order = (not $class and $owner->order_by) ? (order_by => $owner->order_by) : (order => ['date','direct']);
    297 298 if (defined $alpha and $alpha ne '') {
    298 299 $filter{ilike}=1;
     
    313 314 if ( $doc_class ) {
    314 315 my @props = $doc_class->new( $keeper )->structure();
    315 316 my ($prop) = grep { $_->{attr} eq $search_by } @props if @props;
    316 if ( ref $prop && ($prop->{type} eq 'integer' || $prop->{type} eq 'checkbox') ) {
    317 if ( ref $prop && ($prop->{type} eq 'integer' || $prop->{type} eq 'checkbox' ||
    318 (($prop->{type} eq 'pickup' || $prop->{type} eq 'lookup') && $search =~ /^\d+$/) ) ) {
    317 319 $filter{$search_by} = int($search);
    320 } elsif ( ref $prop && ($prop->{type} eq 'pickup' || $prop->{type} eq 'lookup') && $search =~ /\D/ ) {
    321 my $lookup_opts = $prop->{lookup_opts};
    322 if ( ref $lookup_opts && exists $lookup_opts->{class} ) {
    323 my $search_field = exists $lookup_opts->{search_by} ? $lookup_opts->{search_by} : 'name';
    324 my @ids = $keeper->get_documents (
    325 ids => 1,
    326 class => $lookup_opts->{class},
    327 ilike => 1,
    328 $search_field => '%'.$search.'%',
    329 );
    330 if ( @ids ) {
    331 $filter{$search_by} = \@ids;
    332 } else {
    333 $nothing_found = 1;
    334 }
    335 }
    318 336 } else {
    319 337 $filter{$search_by}='%'.$search.'%';
    320 338 $filter{ilike} = 1;
     
    325 343 }
    326 344 }
    327 345
    328 # Дополнительные фильтры раздела
    329 if ($owner->filters) {
    330 no strict 'vars';
    331 my $filters = eval($owner->filters);
    332 if ($@) {
    333 warn "Bad filter: " . $owner->filters . " in section " . $owner->id;
    334 } elsif (ref $filters eq 'HASH') {
    335 map { $filter{$_} = $filters->{$_} } keys %$filters;
    336 }
    337 }
    346 # Дополнительные фильтры раздела
    347 if ($owner->filters) {
    348 no strict 'vars';
    349 my $filters = eval($owner->filters);
    350 if ($@) {
    351 warn "Bad filter: " . $owner->filters . " in section " . $owner->id;
    352 } elsif (ref $filters eq 'HASH') {
    353 while ( my ($key, $val) = each %$filters ) {
    354 $filter{$key} = $val;
    355 }
    356 }
    357 }
    338 358
    339 359 $total = $keeper->get_documents(%filter, count=>1) unless $owner->no_count;
    340 360
     
    342 362 my $first = $n * ($p - 1);
    343 363 ($first,$p)=(0,0) if (!$owner->no_count && $first>$total);
    344 364
    345 if ($class && !$use_section) {
    346 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first);
    347 } elsif ($sorted) {
    348 @documents = $keeper->get_sorted_documents(%filter, limit=>$n, offset=>$first);
    349 } else {
    350 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first);
    365 unless ( $nothing_found ) {
    366 if ($class && !$use_section) {
    367 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first);
    368 } elsif ($sorted) {
    369 @documents = $keeper->get_sorted_documents(%filter, limit=>$n, offset=>$first);
    370 } else {
    371 @documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first);
    372 }
    351 373 }
    352 374
    353 375 # набор колонок таблицы документов...
    354 my @columns = $sorted ? ({attr => '_sort_', name => 'N'}) : ();
    376 my @columns = $sorted ? ({attr => '_sort_', name => 'N'}) : ();
    355 377
    356 # пытаемся найти колонки, которые документ сам пожелал показать (required_properties -> column)...
    357 if ($filter{class} or @documents and $documents[0]) {
    358 push @columns,
    359 sort {$a->{column} <=> $b->{column}}
    360 grep {$_->{column}} ($filter{class} ? $filter{class}->new($keeper)->structure : $documents[0]->structure);
    361 }
    378 # пытаемся найти колонки, которые документ сам пожелал показать (required_properties -> column)...
    379 if ($filter{class} or @documents and $documents[0]) {
    380 push @columns,
    381 sort {$a->{column} <=> $b->{column}}
    382 grep {$_->{column}} ($filter{class} ? $filter{class}->new($keeper)->structure : $documents[0]->structure);
    383 }
    362 384
    363 # стандартная жопка таблицы...
    364 @columns = (@columns,
    365 {attr => '_act_', rusname => 'Действия'},
    366 );
    385 # стандартная жопка таблицы...
    386 @columns = (@columns,
    387 {attr => '_act_', rusname => 'Действия'},
    388 );
    389
    367 390 </%init>