| 1 |
609 |
ahitrov |
<% $json %> |
| 2 |
|
|
<%once> |
| 3 |
|
|
|
| 4 |
|
|
use JSON::XS; |
| 5 |
|
|
|
| 6 |
|
|
</%once> |
| 7 |
|
|
<%args> |
| 8 |
|
|
|
| 9 |
|
|
$id => undef |
| 10 |
|
|
$aid => undef |
| 11 |
|
|
$s => undef |
| 12 |
|
|
$move => undef |
| 13 |
|
|
|
| 14 |
|
|
</%args> |
| 15 |
|
|
<%init> |
| 16 |
|
|
|
| 17 |
|
|
my %result; |
| 18 |
|
|
|
| 19 |
|
|
if ( $id && $id =~ /^\d+$/ && $s && $s =~ /^\d+$/ && $move && $move =~ /^(up|down|first|last|before|after)$/ && (!$aid || $aid && $aid =~ /^\d+$/) ) { |
| 20 |
|
|
my $section = $keeper->get_section_by_id( $s ); |
| 21 |
|
|
if ( ref $section ) { |
| 22 |
|
|
if ( $section->_sorted ) { |
| 23 |
|
|
if ( $section->dmove( $id, $move, $aid ) ) { |
| 24 |
|
|
my $position = $section->_get_document_pos( $id ); |
| 25 |
|
|
warn Dumper( $position ); |
| 26 |
|
|
if ( ref $position && exists $position->{index} ) { |
| 27 |
|
|
if ( exists $position->{before} ) { |
| 28 |
|
|
$result{before} = $position->{before}; |
| 29 |
|
|
$result{success} = 1; |
| 30 |
|
|
} |
| 31 |
|
|
if ( exists $position->{after} ) { |
| 32 |
|
|
$result{after} = $position->{after}; |
| 33 |
|
|
$result{success} = 1; |
| 34 |
|
|
} |
| 35 |
|
|
if ( exists $position->{first} ) { |
| 36 |
|
|
$result{first} = 1; |
| 37 |
|
|
$result{success} = 1; |
| 38 |
|
|
} |
| 39 |
|
|
if ( exists $position->{last} ) { |
| 40 |
|
|
$result{last} = 1; |
| 41 |
|
|
$result{success} = 1; |
| 42 |
|
|
} |
| 43 |
|
|
unless ( exists $result{success} ) { |
| 44 |
|
|
$result{error} = Encode::decode('utf-8', 'Ошибка индексации. Для разбора полетов обратитесь к разработчикам'); |
| 45 |
|
|
} |
| 46 |
|
|
} else { |
| 47 |
|
|
$result{error} = Encode::decode('utf-8', 'Ошибка индексации. Для разбора полетов обратитесь к разработчикам'); |
| 48 |
|
|
} |
| 49 |
|
|
} else { |
| 50 |
|
|
$result{error} = Encode::decode('utf-8', 'Ошибка перемещения. Для разбора полетов обратитесь к разработчикам'); |
| 51 |
|
|
} |
| 52 |
|
|
} else { |
| 53 |
|
|
$result{error} = Encode::decode('utf-8', 'В данной секции отключен режим ручной сортировки'); |
| 54 |
|
|
} |
| 55 |
|
|
} else { |
| 56 |
|
|
$result{error} = Encode::decode('utf-8', 'Секция не найдена'); |
| 57 |
|
|
} |
| 58 |
|
|
} else { |
| 59 |
|
|
$result{error} = Encode::decode('utf-8', 'Переданы неверные параметры'); |
| 60 |
|
|
} |
| 61 |
|
|
|
| 62 |
|
|
my $json = encode_json \%result; |
| 63 |
|
|
|
| 64 |
|
|
</%init> |