1 package SL::Controller::Chart;
4 use parent qw(SL::Controller::Base);
8 use SL::Controller::Helper::GetModels;
9 use SL::Locale::String qw(t8);
12 use Rose::Object::MakeMethods::Generic (
13 'scalar --get_set_init' => [ qw(charts models chart filter) ],
16 sub action_ajax_autocomplete {
17 my ($self, %params) = @_;
19 my $value = $::form->{column} || 'description';
21 # if someone types something, and hits enter, assume he entered the full name.
22 # if something matches, treat that as sole match
23 # unfortunately get_models can't do more than one per package atm, so we do it
24 # the oldfashioned way.
25 if ($::form->{prefer_exact}) {
27 # we still need the type filter so that we can't choose an illegal chart
28 # via exact_match if we have preset a link type, e.g. AR_paid
29 if (1 == scalar @{ $exact_matches = SL::DB::Manager::Chart->get_all(
31 SL::DB::Manager::Chart->type_filter($::form->{filter}{type}),
33 description => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
34 accno => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
39 $self->charts($exact_matches);
45 value => $_->displayable_name,
46 label => $_->displayable_name,
49 description => $_->description,
51 } @{ $self->charts }; # neato: if exact match triggers we don't even need the init_parts
53 $self->render(\ SL::JSON::to_json(\@hashes), { layout => 0, type => 'json', process => 0 });
56 sub action_test_page {
57 $_[0]->render('chart/test_page');
60 sub action_chart_picker_search {
61 $_[0]->render('chart/chart_picker_search', { layout => 0 }, charts => $_[0]->charts);
64 sub action_chart_picker_result {
65 $_[0]->render('chart/_chart_picker_result', { layout => 0 });
71 if ($::request->type eq 'json') {
76 $chart_hash = $self->chart->as_tree;
77 $chart_hash->{displayable_name} = $self->chart->displayable_name;
80 $self->render(\ SL::JSON::to_json($chart_hash), { layout => 0, type => 'json', process => 0 });
86 # disable pagination when hiding chart details = paginate when showing chart details
87 if ($::form->{hide_chart_details}) {
88 $_[0]->models->disable_plugin('paginated');
95 SL::DB::Chart->new(id => $::form->{id} || $::form->{chart}{id})->load;
101 SL::Controller::Helper::GetModels->new(
108 accno => t8('Account number'),
109 description => t8('Description'),
114 sub init_filter { $_[0]->models->filtered->laundered }