Revision 236 (by ahitrov, 2012/08/30 20:19:18) Blog admin - first
Bugs
<& "/contenido/components/header.msn" &>
<& "/contenido/components/naviline.msn" &>

<script type="text/javascript">
<!--
function set_create_button( oSelect, sBtnID ) {
	if ( oSelect.value == '' ) {
		$('#'+sBtnID).attr('disabled','disabled');
	} else {
		$('#'+sBtnID).removeAttr('disabled');
	}
}
//-->
</script>

<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr valign="top">
<td width="35%">



</td>
<td width="2%">&nbsp;</td>
<td width="65%">


        <fieldset>
        <legend>Документы\
%       if ($class) {
 класса <% $class %>\
%               if ($use_section) {
 c учетом текущей секции\
%               }
%       } else {
 в разделе\
%       }
%       if ( $total > 0 )    {
 (всего: <% $total %>, показано с <% $first + 1 %> по <% ($first + $n > $total) ? $total : $first + $n %>)
%       }
        </legend>

%	if ($total || scalar @documents || defined($alpha) || defined($search) ) {
%

<& "/contenido/components/new_objects_form.msn", proto => 'documents',
	sect_id => ref $owner ? $owner->id : undef,
	default => 'blogs::Blog' &>

<div style="font-size:12px; font-family:Arial;">
<table border="0" cellspacing="0" cellpadding="2" width="100%" style="margin:4px 0 0; border:1px solid gray;">
<tr bgcolor="#e0e0e0"><th colspan="4">Поиск по букве:&nbsp;&nbsp;[<a href="?id=<% $id %>" style="font-weight:normal;">сброс фильтра</a>]</th></tr>
<tr><td style="font-size:12px; font-family:Arial; padding:2px 4px;">
<& /inc/alpha.msn, alpha=>$alpha, params=>\%ARGS, &>
</td></tr></table>

%		## Форма поиска. Работает при включенном фильтре класса
%		## и описанной для класса функции search_fields
%		########################################################
%		if ( $filter{class} ) {
%			my $document = $filter{class}->new ($keeper);
%			my @fields = $document->search_fields;
%			if ( @fields ) {
%				my @props = $document->required_properties;
<form action="sections.html">
<table border="0" cellspacing="0" cellpadding="2" width="100%" style="margin:4px 0; border:1px solid gray;">
<tr bgcolor="#e0e0e0"><th colspan="4">Поиск по полю:&nbsp;&nbsp;[<a href="?id=<% $id %>" style="font-weight:normal;">сброс фильтра</a>]</th></tr><tr>
<td width="1%" nowrap style="padding:2px 0 2px 4px;"><select name="search_by">
%			foreach my $field ( @fields ) {
%					my ($prop) = grep { $_->{'attr'} eq $field } @props;
%					my $selected = $field eq $search_by ? ' selected' : '';
<option value="<% $field %>"<% $selected %>><% ref $prop ? $prop->{'shortname'} || $prop->{'rusname'} : $field %>
%			}
</td><td width="0">:</td>
<td width="98%"><input type="text" name="search" value="<% $search %>" style="width:100%"></td>
<td width="1%" style="padding:2px 4px 2px 0;"><input type="submit" value=" &raquo; " style="border:1px solid gray;"></td>
</tr></table>
%				if ( $id ) {
<input type="hidden" name="id" value="<% $id %>">
%				}
%				if ( $class ) {
<input type="hidden" name="class" value="<% $class %>">
%				}
%				if ( $use_section ) {
<input type="hidden" name="use_section" value="<% $use_section %>">
%				}
</form>
%			}
%		}

<div style="height:5px"><spacer type="block" height="5"></div>
<& /inc/pages_.msn, p=>$p, n=>$n, total=>$total, href=>'sections.html', params=>\%ARGS, &>
</div>

<& /contenido/blogs/components/blogs_browse.msn, documents => \@documents, columns => \@columns, section => $owner, filter => \%filter_params, %ARGS &>

<div style="font-size:12px; font-family:Arial;">
<& /inc/pages_.msn, p=>$p, n=>$n, total=>$total, href=>'sections.html', params=>\%ARGS, &>
<div style="height:5px"><spacer type="block" height="5"></div>
</div>


%	} else {
<h4 align="center"><i>---- Нет документов -----</i></h4>
%	}
%

<& "/contenido/components/new_objects_form.msn", proto => 'documents',
	sect_id => ref $owner ? $owner->id : undef,
	default => 'blogs::Blog' &>

</fieldset>



</td>
</tr>
</table>


</body>
</html>
<%args>

	$id		=> undef
	$p		=> 1
	$class		=> 'blogs::Blog'
	$use_section	=> undef
	$alpha		=> undef
	$alpha_search	=> undef
	$search_by	=> undef
	$search		=> undef
	$update		=> undef
	$delete		=> undef

</%args>
<%init>

    $id = 0 if $id =~ /\D/;
    my $owner;

    if ( ref $project->s_alias && exists $project->s_alias->{blogs} ) {
	$owner = $keeper->get_section_by_id( $project->s_alias->{blogs} );
    } else {
	$owner = $keeper->get_section_by_id( $Contenido::Section::ROOT );
    }

    my %filter_params;
    $filter_params{class} = $class			if $class;
    $filter_params{alpha} = $alpha			if $alpha;
    $filter_params{alpha_search} = $alpha_search	if $alpha_search;
    $filter_params{search_by} = $search_by		if $search_by;
    $filter_params{search} = $search			if $search;
    $filter_params{p} = $p				if $p && $p > 1;

    # Фильтры работают в любом случае...
    my $filter = $m->comp('/contenido/components/context.msn', name => 'filter');
    my $profile = $m->comp('/contenido/components/context.msn', name => 'profile');

    my (@documents, $total);


    my %filter=();
    my $nothing_found = 0;
    my %order = (order => ['date','direct']);
    if (defined $alpha and $alpha ne '') {
	$filter{ilike}=1;
	$filter{ $alpha_search || 'name' }="$alpha%";
	$order{order}=['name','reverse'];
	delete $order{order_by};
    }
    $filter{class} = $class;

    if ( $search_by && defined $search ) {
	my $doc_class = $class;
	if ( $doc_class ) {
		my @props = $doc_class->new( $keeper )->structure();
		my ($prop) = grep { $_->{attr} eq $search_by } @props   if @props;
		if ( ref $prop && ($prop->{type} eq 'integer' || $prop->{type} eq 'checkbox' ||
			(($prop->{type} eq 'pickup' || $prop->{type} eq 'lookup') && $search =~ /^\d+$/) ||
			(exists $prop->{db_type} && $prop->{db_type} =~ /integer\[\]/)    )) {
				$filter{$search_by} = int($search);
		} elsif ( ref $prop && ($prop->{type} eq 'pickup' || $prop->{type} eq 'lookup') && $search =~ /\D/ ) {
			my $lookup_opts = $prop->{lookup_opts};
			if ( ref $lookup_opts && exists $lookup_opts->{class} ) {
				my $search_field = exists $lookup_opts->{search_by} ? $lookup_opts->{search_by} : 'name';
				my @ids = $keeper->get_documents (
						ids     => 1,
						class   => $lookup_opts->{class},
						ilike   => 1,
						$search_field   => '%'.$search.'%',
					);
				if ( @ids ) {
					$filter{$search_by} = \@ids;
				} else {
					$nothing_found = 1;
				}
			}
		} else {
			$filter{$search_by}='%'.$search.'%';
			$filter{ilike} = 1;
		}
	} else {
		$filter{$search_by}='%'.$search.'%';
		$filter{ilike} = 1;
	}
    }
    $total = $keeper->get_documents(%filter, count=>1);

    my $n = 40;
    my $first = $n * ($p - 1);
    ($first,$p)=(0,0)	if $first > $total;

    unless ( $nothing_found ) {
	@documents = $keeper->get_documents(%filter, %order, limit=>$n, offset=>$first);
    }

    # набор колонок таблицы документов...
    my @columns = ();

    # пытаемся найти колонки, которые документ сам пожелал показать (required_properties -> column)...
    if ($filter{class} or @documents and $documents[0]) {
	push @columns,
	sort {$a->{column} <=> $b->{column}}
	grep {$_->{column}} ($filter{class} ? $filter{class}->new($keeper)->structure : $documents[0]->structure);
    }

    # стандартная жопка таблицы...
    @columns = (@columns,
	{attr => '_act_',       rusname => 'Действия'},
    );

</%init>