| 1 |
616 |
ahitrov |
<% $json %> |
| 2 |
|
|
<%once> |
| 3 |
|
|
|
| 4 |
|
|
use JSON::XS; |
| 5 |
|
|
|
| 6 |
|
|
</%once> |
| 7 |
|
|
<%args> |
| 8 |
|
|
|
| 9 |
|
|
$s => undef |
| 10 |
|
|
$id => undef |
| 11 |
|
|
$class => undef |
| 12 |
|
|
$status => undef |
| 13 |
618 |
ahitrov |
$toggle => undef |
| 14 |
616 |
ahitrov |
$params => undef |
| 15 |
|
|
|
| 16 |
|
|
</%args> |
| 17 |
|
|
<%init> |
| 18 |
|
|
|
| 19 |
|
|
my %result; |
| 20 |
|
|
|
| 21 |
618 |
ahitrov |
if ( $id && $id =~ /^\d+$/ && $class && $class =~ /--/ && ($toggle || defined $status) ) { |
| 22 |
|
|
$class =~ s/-/:/g; |
| 23 |
616 |
ahitrov |
my $section = $keeper->get_section_by_id( $s ) if $s; |
| 24 |
|
|
my $document = $keeper->get_document_by_id( $id, class => $class ); |
| 25 |
|
|
if ( ref $document ) { |
| 26 |
618 |
ahitrov |
if ( defined $status ) { |
| 27 |
|
|
$document->status( $status ); |
| 28 |
|
|
$document->store; |
| 29 |
|
|
} else { |
| 30 |
|
|
my ($prop) = grep { $_->{attr} eq 'status' } $document->structure; |
| 31 |
|
|
if ( ref $prop && exists $prop->{cases} && ref $prop->{cases} eq 'ARRAY' && scalar @{$prop->{cases}} == 2 ) { |
| 32 |
|
|
$document->status( $prop->{cases}[0][0] == $document->status ? $prop->{cases}[1][0] : $prop->{cases}[0][0] ); |
| 33 |
|
|
$document->store; |
| 34 |
|
|
} |
| 35 |
|
|
} |
| 36 |
621 |
ahitrov |
%result = $m->comp('/contenido/ajax/section_browse.html', return => 'hash', section => $section, params => $params ); |
| 37 |
|
|
delete $result{documents}; |
| 38 |
616 |
ahitrov |
} else { |
| 39 |
|
|
$result{error} = Encode::decode('utf-8', 'Документ не найден'); |
| 40 |
|
|
} |
| 41 |
|
|
} else { |
| 42 |
|
|
$result{error} = Encode::decode('utf-8', 'Переданы неверные параметры'); |
| 43 |
|
|
} |
| 44 |
|
|
|
| 45 |
|
|
my $json = encode_json \%result; |
| 46 |
|
|
|
| 47 |
|
|
</%init> |