Revision 621 (by ahitrov, 2016/11/10 14:16:02) During inline status modifying now all records are reloaded.
'/contenido/ajax/section_browse.html' now can be used as document digging component.

<% $json %>
<%once>

    use JSON::XS;

</%once>
<%args>

	$s	=> undef
	$id	=> undef
	$class	=> undef
	$status	=> undef
	$toggle	=> undef
	$params	=> undef

</%args>
<%init>

    my %result;

    if ( $id && $id =~ /^\d+$/ && $class && $class =~ /--/ && ($toggle || defined $status) ) {
	$class =~ s/-/:/g;
	my $section = $keeper->get_section_by_id( $s )	if $s;
	my $document = $keeper->get_document_by_id( $id, class => $class );
	if ( ref $document ) {
		if ( defined $status ) {
			$document->status( $status );
			$document->store;
		} else {
			my ($prop) = grep { $_->{attr} eq 'status' } $document->structure;
			if ( ref $prop && exists $prop->{cases} && ref $prop->{cases} eq 'ARRAY' && scalar @{$prop->{cases}} == 2 ) {
				$document->status( $prop->{cases}[0][0] == $document->status ? $prop->{cases}[1][0] : $prop->{cases}[0][0] );
				$document->store;
			}
		}
		%result = $m->comp('/contenido/ajax/section_browse.html', return => 'hash', section => $section, params => $params );
		delete $result{documents};
	} else {
		$result{error} = Encode::decode('utf-8', 'Документ не найден');
	}
    } else {
	$result{error} = Encode::decode('utf-8', 'Переданы неверные параметры');
    }

    my $json = encode_json \%result;

</%init>