source: LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrForms.pm @ 112

Last change on this file since 112 was 112, checked in by nanardon, 15 years ago
  • first step with forms
File size: 1.8 KB
Line 
1package LATMOS::Accounts::Web::Model::AttrForms;
2
3use strict;
4use warnings;
5use base 'Catalyst::Model';
6use HTML::Entities qw(encode_entities);
7
8=head1 NAME
9
10LATMOS::Accounts::Web::Model::AttrForms - Catalyst Model
11
12=head1 DESCRIPTION
13
14Catalyst Model.
15
16=cut
17
18my $attrs = {
19    uid => 'Login',
20    uidNumber => 'UID',
21    gidNumber => 'GID',
22    sn => 'Nom',
23    givenName => 'Prenom',
24    homeDirectory => 'Home',
25    loginShell => 'Shell',
26};
27
28my $forms = {
29    user_main => {
30        acl => 'admin',
31        attrs => [ qw(
32            sn givenName uid uidNumber gidNumber gecos homeDirectory loginShell
33        ) ],
34    }
35};
36
37
38sub new {
39    my ($class) = @_;
40    bless({}, $class);
41}
42
43sub 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
52sub attributes {
53    my ($self) = @_;
54    grep { $self->{object}->get_field_name($_, 'w') } @{ $forms->{$self->{form}}->{attrs} };
55}
56
57sub attr_label {
58    my ($self, $attr) = @_;
59    return encode_entities($attrs->{$attr} || $attr);
60}
61
62sub 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
74sub 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
88Thauvin Olivier
89
90=head1 LICENSE
91
92This library is free software, you can redistribute it and/or modify
93it under the same terms as Perl itself.
94
95=cut
96
971;
Note: See TracBrowser for help on using the repository browser.