Line | |
---|
1 | package LATMOS::Accounts::Web::Model::AttrForms; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use base 'Catalyst::Model'; |
---|
6 | use HTML::Entities qw(encode_entities); |
---|
7 | |
---|
8 | =head1 NAME |
---|
9 | |
---|
10 | LATMOS::Accounts::Web::Model::AttrForms - Catalyst Model |
---|
11 | |
---|
12 | =head1 DESCRIPTION |
---|
13 | |
---|
14 | Catalyst Model. |
---|
15 | |
---|
16 | =cut |
---|
17 | |
---|
18 | my $attrs = { |
---|
19 | uid => 'Login', |
---|
20 | uidNumber => 'UID', |
---|
21 | gidNumber => 'GID', |
---|
22 | sn => 'Nom', |
---|
23 | givenName => 'Prenom', |
---|
24 | homeDirectory => 'Home', |
---|
25 | loginShell => 'Shell', |
---|
26 | }; |
---|
27 | |
---|
28 | my $forms = { |
---|
29 | user_main => { |
---|
30 | acl => 'admin', |
---|
31 | attrs => [ qw( |
---|
32 | sn givenName uid uidNumber gidNumber gecos homeDirectory loginShell |
---|
33 | ) ], |
---|
34 | } |
---|
35 | }; |
---|
36 | |
---|
37 | |
---|
38 | sub new { |
---|
39 | my ($class) = @_; |
---|
40 | bless({}, $class); |
---|
41 | } |
---|
42 | |
---|
43 | sub ACCEPT_CONTEXT { |
---|
44 | my ($self, $c, $form, $object) = @_; |
---|
45 | $forms->{$form} or return; |
---|
46 | $self->{c} = $c; |
---|
47 | $self->{form} = $form; |
---|
48 | $self->{object} = $object or return; |
---|
49 | $self |
---|
50 | } |
---|
51 | |
---|
52 | sub attributes { |
---|
53 | my ($self) = @_; |
---|
54 | grep { $self->{object}->get_field_name($_, 'w') } @{ $forms->{$self->{form}}->{attrs} }; |
---|
55 | } |
---|
56 | |
---|
57 | sub attr_label { |
---|
58 | my ($self, $attr) = @_; |
---|
59 | return encode_entities($attrs->{$attr} || $attr); |
---|
60 | } |
---|
61 | |
---|
62 | sub attr_field { |
---|
63 | my ($self, $attr) = @_; |
---|
64 | return sprintf( |
---|
65 | '<input type="text" name="%s" value="%s">', |
---|
66 | $attr, |
---|
67 | encode_entities( |
---|
68 | $self->{c}->req->param($attr) || |
---|
69 | $self->{object}->get_c_field($attr) |
---|
70 | ) |
---|
71 | ); |
---|
72 | } |
---|
73 | |
---|
74 | sub set_attrs { |
---|
75 | my ($self) = @_; |
---|
76 | $self->{object}->set_c_fields( |
---|
77 | map { |
---|
78 | $_ => $self->{c}->req->param($_) |
---|
79 | } grep { |
---|
80 | exists $self->{c}->req->params->{$_} |
---|
81 | } $self->attributes |
---|
82 | ); |
---|
83 | $self->{object}->base->commit; |
---|
84 | } |
---|
85 | |
---|
86 | =head1 AUTHOR |
---|
87 | |
---|
88 | Thauvin Olivier |
---|
89 | |
---|
90 | =head1 LICENSE |
---|
91 | |
---|
92 | This library is free software, you can redistribute it and/or modify |
---|
93 | it under the same terms as Perl itself. |
---|
94 | |
---|
95 | =cut |
---|
96 | |
---|
97 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.