Catalyst-Plugin-AutoCRUD

 view release on metacpan or  search on metacpan

lib/Catalyst/Plugin/AutoCRUD/Controller/DisplayEngine/ExtJS2.pm  view on Meta::CPAN

            $searchrow{$col} = '';
        }
        else {
            if (exists $c->req->params->{ 'cpac_filter.'. $col }) {
                $searchrow{$col} = $c->req->params->{ 'cpac_filter.'. $col };
            }
            else {
                $searchrow{$col} = '(click to add filter)';
            }
        }
    }
    unshift @{$c->stash->{json_data}->{rows}}, \%searchrow;
}

sub filter_from_ext : Private {
    my ($self, $c) = @_;
    my $conf = $c->stash->{cpac}->{tc};
    my $meta = $c->stash->{cpac}->{tm};
    my @columns = @{$conf->{cols}};

    my $do_filter = sub {
        my ($ci, $col) = @_;
        return unless exists $c->req->params->{$col}
            and defined $c->req->params->{$col};

        if ($ci->extra('extjs_xtype')
            and exists $filter_for{ $ci->extra('extjs_xtype') }) {

            $c->req->params->{$col} =
                $filter_for{ $ci->extra('extjs_xtype') }->{from_ext}->(
                    $c->req->params->{$col}
                );
        }
    };

    # filter data types coming from the Ext form
    foreach my $col (@columns) {
        my $ci = $meta->f->{$col};
        if ($ci->is_foreign_key) {
            next unless $ci->extra('ref_table');
            my $link = $c->stash->{cpac}->{m}->t->{ $ci->extra('ref_table') };
            next unless $link->extra('fields');

            foreach my $fcol (@{$link->extra('fields')}) {
                my $fci = $link->f->{$fcol};
                $do_filter->($fci, "$col.$fcol");
            }
        }
        else {
            $do_filter->($ci, $col);
        }
    }
}

sub create : Chained('base') Args(0) {
    my ($self, $c) = @_; 
    $c->forward('filter_from_ext');
    $c->forward('/autocrud/ajax/create');
}

sub update : Chained('base') Args(0) {
    my ($self, $c) = @_;
    $c->forward('filter_from_ext');
    $c->forward('/autocrud/ajax/update');
}

sub delete : Chained('base') Args(0) {
    my ($self, $c) = @_;
    $c->forward('/autocrud/ajax/delete');
}

sub list_stringified : Chained('base') Args(0) {
    my ($self, $c) = @_;
    $c->forward('/autocrud/ajax/list_stringified');
}

1;



( run in 0.483 second using v1.01-cache-2.11-cpan-39bf76dae61 )