source: LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Attributes.pm @ 852

Last change on this file since 852 was 852, checked in by nanardon, 14 years ago
  • add basic code to handle attributes schema and factorize code through all possible GUI (web/curses/...)
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1package LATMOS::Accounts::Bases::Attributes;
2
3# $Id$
4
5use strict;
6use warnings;
7use LATMOS::Accounts::Log;
8
9=head1 NAME
10
11    LATMOS::Accounts::Bases::Attributes - Object to handle attribute schema
12
13=head1 FUNCTIONS
14
15=head2 new($attributes, $base_or_object, $maybe_otype)
16
17=cut
18
19sub new {
20    my ($class, $attributes, $base_or_object, $maybe_otype) = @_;
21   
22    my ($object, $base, $otype) =
23    $base_or_object->isa('LATMOS::Accounts::Bases::Objects')
24        ? ($base_or_object, $base_or_object->base, $base_or_object->type)
25        : (undef, $base_or_object, $maybe_otype);
26
27    my $attr_info = $base->get_attr_schema($otype, $attributes);
28
29    $attr_info->{_base} = $base;
30    $attr_info->{_object} = $object;
31    $attr_info->{_name} = $attributes;
32    $attr_info->{_otype} = $otype;
33
34    bless($attr_info, $class);
35}
36
37sub base  { $_[0]->{_base}  }
38sub name  { $_[0]->{_name}  }
39sub otype { $_[0]->{_otype} }
40
41sub label { $_[0]->{label} || $_[0]->{_name} }
42
43sub can_values {
44    my ($self) = @_;
45    if (my @values = $self->base->obj_attr_allowed_values(
46            $self->otype,
47            $self->name)) {
48        return @values;
49    } elsif ($self->{can_values}) {
50        if (ref $self->{can_values} eq 'ARRAY') {
51            return @{$self->{can_values}};
52        } elsif (ref $self->{can_values} eq 'CODE') {
53            $self->{can_values}->($self);
54        } else {
55            return;
56        }
57    } else { return }
58}
59
60sub ro { 
61    my ($self) = @_;
62    return 1 if ($self->{ro});
63   
64    return ! $self->base->check_acl($self->object
65        ? ($self->object, $self->name, 'w')
66        : ($self->otype, '@CREATE', 'w'));
67}
68
69=head2 form_type
70
71Return the way the fields must be show in GUI:
72
73=over 4
74
75=item LABEL
76
77=item TEXT
78
79=item DATE
80
81=item LIST
82
83=item CHECKBOX
84
85=back
86
87=cut
88
89sub form_type { $_[0]->ro ? 'LABEL' : ($_[0]->{formtype} || 'TEXT') }
90
91sub uniq { $_[0]->{uniq} || 0 }
92
93sub multiple { $_[0]->{multiple} || 0 }
94
951;
Note: See TracBrowser for help on using the repository browser.