Revision 275 (by ahitrov, 2013/02/07 18:20:04) |
Lookup multi bug - multiple deletion didn't funtion
Links block now can be used in plugins. It returns BACK to the caller, not to /contenido/
|
<%ARGS>
$id => undef
$class => undef
$source_class => undef
$dest_class => undef
$update => undef
$parent_url => undef
</%ARGS>
<%init>
if ($id) {
my $document = $keeper->get_document_by_id($id, class=>$class);
if ( $update ) {
my %updated;
while ( my ($field, $value) = each %ARGS ) {
if ( $field =~ /^update_(\d+)_(\w+)$/ ) {
my $oid = $1;
my $attr = $2;
$updated{$oid}{$attr} = $value;
}
}
my %classes = map { $_->{class} => 1 } values %updated;
foreach my $update_class ( keys %classes ) {
my @ids;
while ( my ($oid, $attr) = each %updated) {
push @ids, $oid if $attr->{class} eq $update_class;
}
my @objects = $keeper->get_links (
id => \@ids,
class => $update_class
) if @ids;
foreach my $object ( @objects ) {
my $fields = $updated{$object->id};
my @props = grep { exists $_->{inline} && $_->{inline} } $object->structure;
if ( ref $fields eq 'HASH' ) {
foreach my $prop ( @props ) {
my $attr = $prop->{attr};
my $value = ref $fields && exists $fields->{$attr} ? $fields->{$attr} : undef;
if ( $prop->{db_type} eq 'float' ) {
for ( $value ) {
s/\,/\./;
s/^\s+//;
s/\s+$//;
}
}
if ( $prop->{type} eq 'checkbox' ) {
$value = $value ? 1 : undef;
}
$object->$attr($value);
}
$object->store;
}
}
}
} else {
my @link_args = ();
if ( exists $ARGS{links} && ref $ARGS{links} eq 'ARRAY' ) {
@link_args = @{ $ARGS{links} }
} elsif ( exists $ARGS{links} ) {
@link_args = ( $ARGS{links} );
}
my %nlinks = ();
foreach my $name (@link_args)
{
if ($name =~ /^link_(\d+)_(\d+)_(.*)$/)
{
my ($id, $dest_id, $lclass) = ($1, $2, $3);
if ( $id && $lclass ) {
my $link = $keeper->get_link_by_id ($id,
class => $lclass,
);
$link->delete if ref $link;
}
}
}
}
$parent_url = URI::Escape::uri_escape( $parent_url ) if $parent_url;
# Проброс на содержание документа...
if ( $source_class ) {
$m->redirect ("document_links.html?id=$id&class=$class&source_class=$source_class&parent_url=$parent_url");
} elsif ( $dest_class ) {
$m->redirect ("document_links.html?id=$id&class=$class&dest_class=$dest_class&parent_url=$parent_url");
} else {
$m->redirect ("document_links.html?id=$id&class=$class&parent_url=$parent_url");
}
}
</%init>