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

Last change on this file since 131 was 131, checked in by nanardon, 15 years ago
  • fix address form
File size: 2.9 KB
Line 
1package LATMOS::Accounts::Web::Model::AttrForms;
2
3use strict;
4use warnings;
5use base 'Catalyst::Model';
6
7=head1 NAME
8
9LATMOS::Accounts::Web::Model::AttrForms - Catalyst Model
10
11=head1 DESCRIPTION
12
13Catalyst Model.
14
15=cut
16
17my $attrs = {
18    uid => 'Login',
19    uidNumber => 'UID',
20    gidNumber => 'GID',
21    sn => 'Nom',
22    givenName => 'Prénom',
23    homeDirectory => 'Home',
24    loginShell => 'Shell',
25    physicalDeliveryOfficeName => 'Bureau',
26    telephoneNumber => 'Téléphone',
27    otherTelephone => 'Téléphone (autre)',
28    company => 'Société',
29    l => 'Ville',
30    postalCode => 'Code postal',
31    postOfficeBox => 'BP',
32    st => 'Département',
33    streetAddress => 'Rue',
34};
35
36my $forms = {
37    user => {
38        name => 'SystÚme',
39        acl => 'admin',
40        attrs => [ qw(
41            sn givenName description
42            uid uidNumber gidNumber gecos homeDirectory loginShell
43            mail
44        ) ],
45    },
46    useraddress => {
47        name => 'Adresse',
48        attrs => [ qw(
49            initials
50            telephoneNumber
51            otherTelephone
52            mail
53            streetAddress
54            postOfficeBox
55            postalCode
56            l
57            physicalDeliveryOfficeName
58        ) ],
59    },
60    userstatus => {
61        name => 'Status',
62        attrs => [ qw(
63            company
64            st
65        ) ],
66    },
67    group => {
68        name => 'SystÚme',
69        acl => 'admin',
70        attrs => [ qw(
71            gidNumber description
72        ) ],
73    },
74};
75
76sub escape {
77    my ($self, $text) = @_;
78    $text ||= '';
79    for ($text) {
80        s/&/&/g;
81        s/</&lt;/g;
82        s/>/&gt;/g;
83        s/"/&quot;/g;
84    }
85    $text;
86}
87
88sub new {
89    my ($class) = @_;
90    bless({}, $class);
91}
92
93sub ACCEPT_CONTEXT {
94    my ($self, $c, $form, $object) = @_;
95    $form or return $self;
96    $forms->{$form} or return;
97    $self->{c} = $c;
98    $self->{form} = $form;
99    $self->{object} = $object or return;
100    $self
101}
102
103sub label {
104    my ($self) = @_;
105    $forms->{$self->{form}}->{name} || ''
106}
107
108sub attributes {
109    my ($self) = @_;
110    grep { $self->{object}->get_field_name($_, 'w') } @{ $forms->{$self->{form}}->{attrs} };
111}
112
113sub attr_label {
114    my ($self, $attr) = @_;
115    return $self->escape($attrs->{$attr} || $attr);
116}
117
118sub attr_field {
119    my ($self, $attr) = @_;
120    return sprintf(
121        '<input type="text" name="%s" value="%s">',
122        $attr,
123        $self->escape(
124            $self->{c}->req->param($attr) ||
125            $self->{object}->get_c_field($attr)
126        )
127    );
128}
129
130sub set_attrs {
131    my ($self) = @_;
132    $self->{object}->set_c_fields(
133        map {
134            $_ => $self->{c}->req->param($_)
135        } grep { 
136            exists $self->{c}->req->params->{$_}
137        } $self->attributes
138    );
139    $self->{object}->base->commit;
140}
141
142=head1 AUTHOR
143
144Thauvin Olivier
145
146=head1 LICENSE
147
148This library is free software, you can redistribute it and/or modify
149it under the same terms as Perl itself.
150
151=cut
152
1531;
Note: See TracBrowser for help on using the repository browser.