| 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 |
|
|
my %filter; |
| 26 |
|
|
map { if ( $_ =~ /(.+?)=(.*)/ ) { $filter{$1} = $2 } } split(/\&/, $params); |
| 27 |
|
|
my $params_unclassed = join ('&', map { $_.'='.$filter{$_} } grep { $_ ne 'class' } keys %filter ); |
| 28 |
|
|
my $params_unsection = join ('&', map { $_.'='.$filter{$_} } grep { $_ ne 's' } keys %filter ); |
| 29 |
|
|
if ( ref $document ) { |
| 30 |
|
|
# набор колонок таблицы документов... |
| 31 |
|
|
my @columns = ref $section && $section->_sorted ? ({attr => '_sort_', name => 'N'}) : (); |
| 32 |
|
|
|
| 33 |
|
|
# пытаемся найти колонки, которые документ сам пожелал показать (required_properties -> column)... |
| 34 |
|
|
push @columns, |
| 35 |
|
|
sort {$a->{column} <=> $b->{column}} |
| 36 |
|
|
grep {$_->{column}} $document->structure; |
| 37 |
|
|
|
| 38 |
|
|
# стандартная жопка таблицы... |
| 39 |
|
|
push @columns, {attr => '_act_', rusname => 'Действия'}; |
| 40 |
|
|
|
| 41 |
618 |
ahitrov |
if ( defined $status ) { |
| 42 |
|
|
$document->status( $status ); |
| 43 |
|
|
$document->store; |
| 44 |
|
|
} else { |
| 45 |
|
|
my ($prop) = grep { $_->{attr} eq 'status' } $document->structure; |
| 46 |
|
|
if ( ref $prop && exists $prop->{cases} && ref $prop->{cases} eq 'ARRAY' && scalar @{$prop->{cases}} == 2 ) { |
| 47 |
|
|
$document->status( $prop->{cases}[0][0] == $document->status ? $prop->{cases}[1][0] : $prop->{cases}[0][0] ); |
| 48 |
|
|
$document->store; |
| 49 |
|
|
} |
| 50 |
|
|
} |
| 51 |
|
|
|
| 52 |
616 |
ahitrov |
my $html = $m->scomp('/contenido/components/section_browse_row.msn', no_tr => 1, |
| 53 |
|
|
document => $document, columns => \@columns, section => $section, |
| 54 |
|
|
lookup_elemets => {}, filter => \%filter, params_unsection => $params_unsection, params_unclassed => $params_unclassed |
| 55 |
|
|
); |
| 56 |
|
|
$result{success} = 1; |
| 57 |
|
|
$result{html} = Encode::decode('utf-8', $html); |
| 58 |
|
|
} else { |
| 59 |
|
|
$result{error} = Encode::decode('utf-8', 'Документ не найден'); |
| 60 |
|
|
} |
| 61 |
|
|
} else { |
| 62 |
|
|
$result{error} = Encode::decode('utf-8', 'Переданы неверные параметры'); |
| 63 |
|
|
} |
| 64 |
|
|
|
| 65 |
|
|
my $json = encode_json \%result; |
| 66 |
|
|
|
| 67 |
|
|
</%init> |