Dancer-Plugin-SimpleCRUD

 view release on metacpan or  search on metacpan

lib/Dancer/Plugin/SimpleCRUD.pm  view on Meta::CPAN

    $sth->execute(@binds)
        or die "Failed to query for records in $table_name - "
        . $dbh->errstr;

    if ($args->{downloadable} && params->{format}) {

        ##Return results as a downloaded file, instead of generating the HTML table.
        return _return_downloadable_query($args, $sth, params->{format});
    }

    my @custom_callbacks = ();
    for my $custom_col_spec (@{ $args->{custom_columns} || [] } ) {
        push @custom_callbacks, {
            column=>$custom_col_spec->{name}, 
            transform=> ($custom_col_spec->{transform} or sub { return shift;}),
        };
    }


    my $table = HTML::Table::FromDatabase->new(
        -sth       => $sth,
        -border    => 1,
        -callbacks => [
            {
                column    => 'actions',
                transform => sub {
                    my $id = shift;
                    my $action_links;
                    if ($args->{editable} && _has_permission('edit', $args)) {
                        my $edit_url
                            = _external_url(
                                $args->{dancer_prefix}, $args->{prefix}, 
                                "/edit/$id"

lib/Dancer/Plugin/SimpleCRUD.pm  view on Meta::CPAN

                            );
                            $action_links
                                .= qq[ / <a href="$del_url" class="delete_link"]
                                . qq[ onclick="delrec('$id'); return false;">]
                                . qq[Delete</a>];
                        }
                    }
                    return $action_links;
                },
            },
            @custom_callbacks,
        ],
        -rename_headers      => \%columns_sort_options,
        -html                => 'escape',
        -class               => $table_class,
    );

    # apply custom columns' column_classes as specified. Can this be done via HTML::Table::FromDatabase->new() above?
    my @all_column_names = ( (map { $_->{COLUMN_NAME} } @$columns), (map { $_->{name} } @{$args->{custom_columns}}) );
    for my $custom_col_spec (@{ $args->{custom_columns} || [] } ) {
        if (my $column_class = $custom_col_spec->{column_class}) {



( run in 0.257 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )