source: LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Ajax.pm @ 407

Last change on this file since 407 was 407, checked in by nanardon, 15 years ago
  • attributes needing to have uniq value are now check online, showing img on field change
File size: 1.7 KB
Line 
1package LATMOS::Accounts::Web::Controller::Ajax;
2
3use strict;
4use warnings;
5use base 'LATMOS::Accounts::Web::Controller';
6
7=head1 NAME
8
9LATMOS::Accounts::Web::Controller::Ajax - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19
20=head2 index
21
22=cut
23
24sub index : Private {
25    my ( $self, $c ) = @_;
26
27    $c->response->body('Matched LATMOS::Accounts::Web::Controller::Ajax in Ajax.');
28}
29
30sub rawattr : Local {
31    my ($self, $c, $otype) = @_;
32
33    my $base = $c->model('Accounts')->db;
34
35    if (!$c->req->param('id')) {
36        $c->stash->{value} = '';
37        return;
38    }
39
40    my $obj = $base->get_object($otype, $c->req->param('id')) or do {
41        $c->stash->{value} = 'N/A';
42        return;
43    };
44    $c->stash->{value} = $obj->get_c_field($c->req->param('attr')) || 'N/A';
45}
46
47sub attrvalues : Local {
48    my ($self, $c, $otype, $attr) = @_;
49
50    my $base = $c->model('Accounts')->db;
51    my $val = $c->req->param('val');
52    $c->stash->{'complete'} = $c->prototype->auto_complete_result([
53        grep { /^\Q$val\E/ } $base->attributes_summary($otype, $attr)
54    ]);
55
56}
57
58sub objattrexist : Local {
59    my ($self, $c, $otype, $attr) = @_;
60    my $base = $c->model('Accounts')->db;
61    my $val = $c->req->param('val');
62    my @obj = $base->search_objects($otype, "$attr=$val");
63
64    if (my $filter = $c->req->param('exclude')) {
65        @obj = grep { $_ ne $filter } @obj;
66    }
67    $c->stash->{'exists'} = join(', ', @obj);
68}
69
70sub end : Private {
71    my ( $self, $c ) = @_;
72    $c->forward($c->view('TTpart'));
73}
74
75=head1 AUTHOR
76
77Thauvin Olivier
78
79=head1 LICENSE
80
81This library is free software, you can redistribute it and/or modify
82it under the same terms as Perl itself.
83
84=cut
85
861;
Note: See TracBrowser for help on using the repository browser.