1 package SL::Controller::Chart;
4 use parent qw(SL::Controller::Base);
8 use SL::Controller::Helper::GetModels;
9 use SL::DB::Helper::Paginated;
10 use SL::Locale::String qw(t8);
13 use Rose::Object::MakeMethods::Generic (
14 'scalar --get_set_init' => [ qw(charts models chart) ],
17 sub action_ajax_autocomplete {
18 my ($self, %params) = @_;
20 my $value = $::form->{column} || 'description';
22 # if someone types something, and hits enter, assume he entered the full name.
23 # if something matches, treat that as sole match
24 # unfortunately get_models can't do more than one per package atm, so we do it
25 # the oldfashioned way.
26 if ($::form->{prefer_exact}) {
28 # we still need the type filter so that we can't choose an illegal chart
29 # via exact_match if we have preset a link type, e.g. AR_paid
30 if (1 == scalar @{ $exact_matches = SL::DB::Manager::Chart->get_all(
32 SL::DB::Manager::Chart->type_filter($::form->{filter}{type}),
34 description => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
35 accno => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
40 $self->charts($exact_matches);
46 value => $_->displayable_name,
47 label => $_->displayable_name,
50 description => $_->description,
52 } @{ $self->charts }; # neato: if exact match triggers we don't even need the init_parts
54 $self->render(\ SL::JSON::to_json(\@hashes), { layout => 0, type => 'json', process => 0 });
57 sub action_test_page {
58 $_[0]->render('chart/test_page');
61 sub action_chart_picker_search {
62 $_[0]->render('chart/chart_picker_search', { layout => 0 }, charts => $_[0]->charts);
65 sub action_chart_picker_result {
66 $_[0]->render('chart/_chart_picker_result', { layout => 0 });
72 if ($::request->type eq 'json') {
77 require Rose::DB::Object::Helpers;
78 $chart_hash = $self->chart->as_tree;
79 $chart_hash->{displayable_name} = $self->chart->displayable_name;
82 $self->render(\ SL::JSON::to_json($chart_hash), { layout => 0, type => 'json', process => 0 });
88 # disable pagination when hiding chart details = paginate when showing chart details
89 if ($::form->{hide_chart_details}) {
90 $_[0]->models->disable_plugin('paginated');
97 SL::DB::Chart->new(id => $::form->{id} || $::form->{chart}{id})->load;
103 SL::Controller::Helper::GetModels->new(
110 accno => t8('Account number'),
111 description => t8('Description'),