Ignore:
Timestamp:
12/02/11 11:42:17 (13 years ago)
Author:
nanardon
Message:
  • reimport missing files from previous svn
Location:
LATMOS-Accounts-Web/lib/LATMOS/Accounts
Files:
3 added
11 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web.pm

    r860 r861  
    2424    /; 
    2525 
    26 our $VERSION = '0.0.11'; 
     26our $VERSION = '2.0.0'; 
    2727 
    2828# Configure the application.  
    29 # 
    30 # Note that settings in LATMOS::Accounts::Web.yml (or other external 
    31 # configuration file that you set up manually) take precedence 
    32 # over this when using ConfigLoader. Thus configuration 
    33 # details given here can function as a default configuration, 
    34 # with a external configuration file acting as an override for 
    35 # local deployment. 
     29 
     30my $config_file = '/etc/latmos-accounts/latmos-accounts-web.yml'; 
     31if (-r $config_file ) { 
     32    __PACKAGE__->config( 'Plugin::ConfigLoader' => {  
     33            file => $config_file  
     34        }  
     35    ); 
     36} 
    3637 
    3738# http://stackoverflow.com/questions/1664816/is-there-a-way-to-force-c-urifor-in-catalyst-to-generate-a-uri-that-begins-wit 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller.pm

    r718 r861  
    2525 
    2626    if (!$c->user_exists) { 
    27         if ($c->req->path ne 'login') { 
    28             $c->forward('/login'); 
     27        # No need to login for About section 
     28        if ($c->namespace ne 'about') { 
     29            if ($c->req->path ne 'login') { 
     30                $c->forward('/login'); 
     31            } 
     32            return; 
    2933        } 
    3034    } else { 
    31         $c->model('Accounts')->db->connect($c->user->{username}, 
     35        $c->model('Accounts')->db->connect( 
     36            $c->user->{username}, 
    3237            $c->user->{password}); 
    3338    } 
    34      
    35     my $menu = ''; 
    36     my @menus = ( 
    37         [ 'users' => 'Utilisateurs' ], 
    38         ($c->model('Accounts')->db->check_acl('user', '@CREATE', 'w') 
    39             ? [ 'create/user' => 'Nouvel Util.' ] 
    40             : ()), 
    41         [ 'groups' => 'Groupes' ], 
    42         ($c->model('Accounts')->db->check_acl('group', '@CREATE', 'w') 
    43             ? [ 'create/group' => 'Nouveau Groupe' ] 
    44             : ()), 
    45         [ 'sites' => 'Sites' ], 
    46         [ 'aliases' => 'Alias Mail' ], 
    47     ); 
    48     foreach(@menus) { 
    49         $menu .= sprintf( 
    50             q{<a href="%s"><span%s>%s</span></a>}, 
    51             $c->uri_for('/' . $_->[0]), 
    52             ($c->req->path =~ m:^$_->[0]: ? ' id="actif"' : ''), 
    53             $_->[1], 
    54         ); 
    55  
    56     } 
    57     $c->stash->{mainmenu} = $menu; 
    5839} 
    5940 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Ajax.pm

    r755 r861  
    4545} 
    4646 
     47sub displayattr : Local { 
     48    my ($self, $c, $otype) = @_; 
     49    my $attribute = $c->model('Accounts')->db->attribute($otype, 
     50        $c->req->param('attr')) or return; 
     51    $c->stash->{value} = $attribute->display($c->req->param('id')); 
     52} 
     53 
    4754sub attrvalues : Local { 
    4855    my ($self, $c, $otype, $attr) = @_; 
     
    6370 
    6471    $c->stash->{'exists'} = join(', ', $obj->get_attributes($c->req->param('attr') || 
    65             'displayName')) if($obj); 
     72            'displayName') || $obj->id) if($obj); 
    6673} 
    6774 
     
    8895    my ($self, $c, $otype, $attr) = @_; 
    8996    my $base = $c->model('Accounts')->db; 
    90     my $val = $c->req->param('val'); 
     97    my $attribute = $base->attribute($otype, $attr) or return; 
     98    my $val = $attribute->input($c->req->param('val')); 
    9199    my @obj = $val ? $base->search_objects($otype, "$attr=$val") : (); 
    92100 
     
    125133} 
    126134 
     135sub select_freeip_select : Local { 
     136    my ($self, $c) = @_; 
     137 
     138} 
     139 
     140sub goto : Local { 
     141    my ($self, $c) = @_; 
     142 
     143    $c->res->redirect( 
     144        $c->uri_for('/' . $c->req->param('otype') . 's', $c->req->param('goto'), 
     145        $c->req->param('subform')) 
     146    ); 
     147    $c->stash->{template} = 'no_object.tt'; 
     148} 
     149 
     150 
    127151sub end : Private { 
    128152    my ( $self, $c ) = @_; 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Aliases.pm

    r641 r861  
    2929    my @name = $c->req->param('name'); 
    3030    my @forward = $c->req->param('forward'); 
     31    $c->stash->{page}{title} = "Gestion des alias"; 
    3132    foreach my $idx (0 .. scalar(@name) - 1) { 
    3233 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Create.pm

    r765 r861  
    55use base 'LATMOS::Accounts::Web::Controller'; 
    66use LATMOS::Accounts::Utils; 
     7use LATMOS::Accounts::Log; 
    78 
    89=head1 NAME 
     
    2930} 
    3031 
    31 sub user : Local { 
    32     my ( $self, $c ) = @_; 
    33  
     32sub default : LocalPath { 
     33    my ($self, $c, undef, $otype ) = @_; 
    3434    my $base = $c->model('Accounts')->db; 
    35     $c->stash->{form} = $c->model('AttrForms', undef, 'user', $base); 
    36     for ($c->req->param('step') || '') { 
    37         /^1$/ and do { 
    38             $c->stash->{step} = 2; 
    39             my $acc = $c->model('Accounts')->accounts; 
    40             foreach ($acc->Parameters('_defattr_')) { 
    41                 if (/^user\.(.*)/) { 
    42                     $c->req->params->{$1} ||= $acc->val('_defattr_', $_); 
    43                 } 
    44             } 
    45             $c->req->params->{exported} = 1; 
    46             if (! $c->req->params->{id}) { 
    47                 for (1) { 
    48                     my $login; 
    49                     if ($c->req->param('sn')) { 
    50                         $login = lc(to_ascii($c->req->param('sn'))); 
    51                         length($login) > 10 and $login = substr($login, 0, 8); 
    52                         $base->get_object('user', $login) or do { 
    53                             $c->req->params->{id} = $login; 
    54                             last; 
    55                         }; 
    56                         if ($c->req->param('givenName')) { 
    57                             length($login) > 8 and $login = substr($login, 0, 8); 
    58                             $login .= substr(lc(to_ascii($c->req->param('givenName'))), 0, 1); 
    59                             $base->get_object('user', $login) or do { 
    60                                 $c->req->params->{id} = $login; 
    61                                 last; 
    62                             }; 
    63                         } 
    64                     } 
    65                 } 
    66  
    67                 my $mailid = $c->req->params->{givenName} && $c->req->params->{sn} 
    68                 ? sprintf('%s.%s', 
    69                     to_ascii(lc($c->req->params->{givenName})), 
    70                     to_ascii(lc($c->req->params->{sn})),) 
    71                 : undef; 
    72  
    73                 if ($mailid && 
    74                     $base->is_supported_object('aliases') && 
    75                     ! $base->get_object('aliases', $mailid)) { 
    76                     if ($base->get_field_name('user', 'mail', 'write')) { 
    77                         if ($base->{defattr}{'user.maildomain'}) { 
    78                             $c->req->params->{mail} ||= sprintf('%s@%s', 
    79                                 $mailid, 
    80                                 $base->{defattr}{'user.maildomain'}); 
    81                         } 
    82                     } 
    83                     if ($base->get_field_name('user', 'aliases', 'write')) { 
    84                         $c->req->params->{aliases} ||= $mailid; 
    85                     } 
    86                     warn $base->get_field_name('user', 'revaliases', 'write'); 
    87                     if ($base->get_field_name('user', 'revaliases', 'write')) { 
    88                         $c->req->params->{revaliases} ||= $mailid; 
    89                     } 
    90                 } 
    91             } 
    92             last; 
    93         }; 
    94         /^2$/ and do { 
    95             $c->stash->{step} = 2; 
    96             $c->req->params->{id} or return; 
    97             $base->get_object('user', $c->req->params->{id}) and do { 
    98                 $c->stash->{idexists} = 1; 
    99                 return; 
    100             }; 
    101             $base->create_c_object('user', $c->req->params->{id}, 
    102                 %{ $c->req->params }, 
    103                 exported => $c->req->param('exported') ? 1 : 0, 
    104             ) or return; 
    105             $base->commit; 
    106             $c->res->redirect($c->uri_for('/users', $c->req->params->{id})); 
    107             last; 
    108         }; 
     35    my ($step) = $c->req->param('step'); 
     36    my $form = $c->model('AttrForms', undef, $otype, $base); 
     37    my ($status, $info); 
     38    $c->stash->{page}{title} = "Ajouter un objet / $otype"; 
     39    if ($step) { 
     40        $info = $c->session->{ochelper}; 
    10941    } 
     42    if ($info->{name}{ask}) { 
     43        $info->{name}{content} = $c->req->param('_name'); 
     44    } 
     45    foreach my $attr (@{$info->{ask} || []}) { 
     46        $info->{contents}{$attr} = $c->req->param($form->attr_field_name($attr)); 
     47    } 
     48    my $ochelper = $base->ochelper($otype); 
     49    ($status, $info) = $ochelper->step($info); 
     50     
     51    if ($status eq 'CREATED') { 
     52        $base->commit; 
     53        $c->res->redirect($c->uri_for('/' . $otype . 's', 
     54                $info->{name}{content})); 
     55    } elsif ($status eq 'ERROR') { 
     56        # On error, restart the process 
     57        $c->stash->{page}{error} = 
     58            'Erreur lors de la création de l\'objet: ' . 
     59            LATMOS::Accounts::Log::lastmessage(LA_ERR); 
     60        foreach my $attr (@{$info->{ask} || []}) { 
     61            $c->req->params->{$form->attr_field_name($attr)} = $info->{contents}{$attr}; 
     62        } 
     63        $info->{step} = 0; # reset 
     64        ($status, $info) = $ochelper->step($info); 
     65    } else { 
     66        foreach my $attr (@{$info->{ask} || []}) { 
     67            $c->req->params->{$form->attr_field_name($attr)} = $info->{contents}{$attr}; 
     68        } 
     69    } 
     70    $c->stash->{form} = $form; 
     71    $c->stash->{ochelper} = $info;  
     72    $c->session->{ochelper} = $info; 
    11073} 
    11174 
    112 sub group : Local { 
    113     my ( $self, $c ) = @_; 
    114  
    115     my $base = $c->model('Accounts')->db; 
    116     $c->stash->{form} = $c->model('AttrForms', undef, 'group', $base); 
    117     if (!exists($c->req->params->{id})) { 
    118         $c->req->params->{exported} = 1; 
    119     } 
    120  
    121     if ($c->req->params->{id}) { 
    122         $base->get_object('group', $c->req->params->{id}) and do { 
    123             $c->stash->{idexists} = 1; 
    124             return; 
    125         }; 
    126         $base->create_c_object('group', $c->req->params->{id}, 
    127             %{ $c->req->params }, 
    128             exported => $c->req->param('exported') ? 1 : 0, 
    129         ) or return; 
    130         $base->commit; 
    131         $c->res->redirect($c->uri_for('/groups', $c->req->params->{id})); 
    132     } 
    133 } 
    13475 
    13576=head1 AUTHOR 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Groups.pm

    r718 r861  
    2727    $c->stash->{ofilter} = $c->model('AttrFilter', 'group'); 
    2828    $c->stash->{groupslist} = [  map { $_->id } @{ $c->stash->{objectslist} } ]; 
     29    $c->stash->{page}{title} = "Liste des groupes"; 
    2930 
    3031} 
     
    3536    my $base = $c->model('Accounts')->db; 
    3637 
     38    $c->stash->{page}{title} = "Groupe :: $groupname"; 
    3739    $c->stash->{groupname} = $groupname; 
    3840    $c->stash->{group} = $base->get_object('group', $groupname) or do { 
     
    6567            last; 
    6668        }; 
     69        /^dpmt$/ and do { 
     70            $c->stash->{template} = 'groups/dpmt.tt'; 
     71            my @filter = (); 
     72            push(@filter, 'active=*') if (!$c->req->param('inactive')); 
     73            push(@filter, 'mail=*') if ($c->req->param('mail')); 
     74            push(@filter, 'company=' . $c->req->param('company')) if 
     75                ($c->req->param('company')); 
     76            $c->stash->{dpmt} = $groupname; 
     77            $c->stash->{odpmt} = $c->stash->{group}; 
     78            $c->stash->{user} = [ $base->search_objects('user', 
     79                    'department=' . $c->stash->{dpmt}, 
     80                    @filter, 
     81                ) ]; 
     82            foreach my $u ($base->search_objects('user', 
     83                    'memberOf=' . $c->stash->{dpmt}, 
     84                    @filter, 
     85                )) { 
     86                push(@{$c->{stash}->{guser}}, $u) 
     87                unless(grep { $u eq $_ } @{$c->stash->{user}}); 
     88            } 
     89            last; 
     90        }; 
    6791 
    6892        $c->stash->{form} = $c->model('AttrForms', 'group' . $c->stash->{subform}, $c->stash->{group}); 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Sites.pm

    r718 r861  
    2727    $c->stash->{ofilter} = $c->model('AttrFilter', 'site'); 
    2828    $c->stash->{siteslist} = [  map { $_->id } @{ $c->stash->{objectslist} } ]; 
     29    $c->stash->{page}{title} = "Liste des sites"; 
    2930} 
    3031 
     
    3435    my $base = $c->model('Accounts')->db; 
    3536 
     37    $c->stash->{page}{title} = "Site :: $sitename"; 
    3638    $c->stash->{sitename} = $sitename; 
    3739    $c->stash->{site} = $base->get_object('site', $sitename) or do { 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Users.pm

    r759 r861  
    4343        $c->stash->{initials} = [ sort keys %initials ]; 
    4444    } 
     45    $c->stash->{page}{title} = 'Listes des utilisateurs (' . scalar(@{ 
     46                $c->stash->{objectslist} }) . ')'; 
    4547    $c->stash->{userslist} = \@userlist; 
    4648} 
     
    5153    my $base = $c->model('Accounts')->db; 
    5254 
     55    $c->stash->{page}{title} = "Utilisateur :: $username"; 
    5356    $c->stash->{username} = $username; 
    5457    $c->stash->{user} = $base->get_object('user', $username) or do { 
     
    5760    }; 
    5861    $c->stash->{subform} = $subform || ''; 
     62    $c->stash->{page}{title} = "Utilisateur :: $username"; 
    5963 
    6064    for ($subform || '') { 
     
    155159            last; 
    156160        }; 
     161        /^my$/ and do { 
     162            $c->stash->{db} = $base; 
     163            $c->stash->{template} = 'users/my.tt'; 
     164        }; 
    157165        /^dump$/ and do { 
    158166            $c->stash->{db} = $base; 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/Accounts.pm

    r791 r861  
    5656} 
    5757 
     58sub object_navigate { 
     59    my ($self, $otype, $id, @filter) = @_; 
     60 
     61    my @list = $self->db->search_objects($otype, @filter); 
     62 
     63    my $i = 0; 
     64    for($i = 0; $i <= $#list; $i++) { 
     65        $list[$i] eq $id and last; 
     66    } 
     67 
     68    my %ptr = (); 
     69    $ptr{oprev} = $list[$i-1] if ($i > 0); 
     70    $ptr{'onext'} = $list[$i+1] if ($i < $#list); 
     71    $ptr{ofirst} = $list[0] if ($i > 1); 
     72    $ptr{'olast'} = $list[$#list] if ($i < $#list -1); 
     73    $ptr{list} = \@list; 
     74 
     75    return \%ptr; 
     76} 
     77 
    5878# Such function must not be here, but in LATMOS::Accounts 
    5979# But code does not allow this at time 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrFilter.pm

    r638 r861  
    1919    group => [ qw(cn description gidNumber sutype) ], 
    2020    site => [ qw(l) ], 
     21    nethost => [ qw(name cname otherName ip macaddr owner serialNumber) ], 
     22    netzone => [ qw(net group type site) ], 
    2123}; 
    2224 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrForms.pm

    r804 r861  
    44use warnings; 
    55use base 'Catalyst::Model'; 
     6use LATMOS::Accounts::Log; 
    67 
    78=head1 NAME 
     
    3940    sutype => [ 'Structure admin.', 'select-N:sutype' ], 
    4041    exported => [ 'Propagé', 'label' ], 
     42    unexported => [ 'Caché' ], 
    4143    locked => [ 'Vérouillé', 'checkbox:l' ], 
    4244    isMainAddress => [ 'Adresse principale', 'checkbox' ], 
     
    5456    contratType => [ 'Type de contrat', 'select-N:group/sutype=contrattype' ], 
    5557    managerContact => [ 'Contact' ], 
     58    owner => [ 'Propriétaire' ], 
     59    description => [ 'Description' ], 
     60    name => [ 'Nom' ], 
     61    net => [ "Réseau" ], 
     62    macaddr => [ "Adresse Ethernet" ], 
     63    noDynamic => [ "Pas d'adressage dyn." ], 
     64    cname => [ "Alias (CName)" ], 
     65    type => [ "Type" ], 
     66    netExclude => [ "Réseau exclus" ], 
     67    output => [ "Sortie" ], 
     68    template => [ "ModÚle" ], 
     69    outputD => [ "Sortie" ], 
     70    templateD => [ "ModÚle" ], 
     71    group => [ "Groupe" ], 
     72    allow_dyn => [ "DHCP dynamique" ], 
     73    ipCount => [ "Nb d'IP" ], 
     74    freeIPCount => [ "Nb d'IP libres" ], 
     75    dnsRevision => [ "Révision DNS" ], 
     76    lastUpdate => [ "DerniÚre mise à jour "], 
     77    otherName => [ "Autres noms (A)" ], 
     78    'reverse' => [ "Forcer le reverse à" ], 
     79    dynFrom => [ 'Sans Ip depuis' ], 
     80    siteNick => [ 'Acronyme' ], 
     81    serialNumber => [ 'N° de série' ], 
     82    snNative => [ 'Nom d\'origine' ], 
     83    givenNameNative => [ 'Prénom d\'origine' ], 
     84    wWWHomePage => [ 'Site Web' ], 
     85    halReference => [ 'Référence HAL' ], 
    5686}; 
    5787 
     
    6494            mail initials nickname 
    6595            locked 
    66             exported 
    6796            create 
    6897            date 
     
    76105        ) ], 
    77106    }, 
    78     userstatus => { 
    79         name => 'Status', 
     107    userstatut => { 
     108        name => 'Statut', 
    80109        attrs => [ qw( 
    81110            company 
     
    87116        ) ], 
    88117    }, 
     118    usermy => { 
     119        name => 'My', 
     120        attrs => [ qw( 
     121            snNative 
     122            givenNameNative 
     123            wWWHomePage 
     124            halReference 
     125        ) ], 
     126    }, 
    89127    site => { 
    90128        name => 'Site', 
    91129        attrs => [ qw( 
    92130            description 
     131            siteNick 
    93132            streetAddress 
    94133            postOfficeBox 
     
    115154            site 
    116155            co 
    117             exported 
     156            unexported 
    118157            description 
    119158        ) ], 
     
    124163            gidNumber description 
    125164            managedBy 
    126             sutype exported 
     165            sutype 
    127166            create 
    128167            date 
     168        ) ], 
     169    }, 
     170    nethost => { 
     171        name => 'Ordinateur', 
     172        attrs => [ qw( 
     173            name 
     174            description 
     175            serialNumber 
     176            owner 
     177            ip 
     178            macaddr 
     179            noDynamic 
     180            cname 
     181            otherName 
     182            reverse 
     183            create 
     184            date 
     185            unexported 
     186        ) ], 
     187    }, 
     188    netzone => { 
     189        name => 'Zone réseau', 
     190        attrs => [ qw( 
     191            name 
     192            description 
     193            type 
     194            net 
     195            netExclude 
     196            outputD 
     197            templateD 
     198            site 
     199            allow_dyn 
     200            dynFrom 
     201            domain 
     202            ipCount 
     203            freeIPCount 
     204            create 
     205            date 
     206            dnsRevision 
     207            lastUpdate 
     208            unexported 
    129209        ) ], 
    130210    }, 
     
    179259    my ($self, $for) = @_; 
    180260    grep { $_ } 
    181     grep { $self->base->check_acl($self->{object} || $self->otype, $_, 'r') } 
    182     grep { $self->base->get_field_name($self->otype, $_, $for || 'a') } 
     261    grep { $self->base->attribute($self->otype, $_) } 
    183262    @{ $forms->{$self->{form}}->{attrs} }; 
    184263} 
     
    196275    my ($self, $attr) = @_; 
    197276    return $self->{c}->req->param($attr) || 
    198         ($self->{object} ? $self->{object}->get_c_field($attr) : '') 
    199 } 
    200  
    201 sub attr_field { 
    202     my ($self, $attr, $type) = @_; 
    203     my $modallow = $self->base->check_acl($self->{object} 
    204         ? ($self->{object}, $attr, 'w') 
    205         : ($self->otype, '@CREATE', 'w')); 
    206     $type ||= $attrs->{$attr}[1] || ''; 
    207     if (!($self->base->get_field_name($self->otype, $attr, 'w') && $modallow)) { 
    208         $type = 'label'; 
    209     } 
    210     # exception: gidNumber is used also in group, but we don't want 
    211     # group list here, really the number ! 
    212     $type = $modallow ? 'text-U:6' : 'label' if ($self->{otype} eq 'group' && $attr eq 'gidNumber'); 
    213     $type ||= 'text'; 
    214      
    215     my $htmlname = $self->escape(($self->{object}  
     277        ($self->{object} ? $self->{object}->get_attributes($attr) : '') 
     278} 
     279 
     280sub attr_field_name { 
     281    my ($self, $attr) = @_; 
     282    return ($self->{object} 
    216283            ? $self->{object}->id . '_' 
    217284            : '' 
    218285        ) . $attr 
    219     ); 
    220     for ($type) { 
    221         /^textarea$/ and return sprintf( 
    222             '<textarea id="%s" name="%s" cols="40">%s</textarea>', 
    223             $self->escape($htmlname), 
    224             $self->escape($htmlname), 
    225             $self->escape($self->attr_raw_value($attr) || ''), 
    226         ); 
    227         /^label$/ and do { 
    228             my $field = $self->escape( 
    229                 $self->attr_raw_value($attr) 
    230             ); 
    231             $field =~ s/\n/<br>/g; 
    232             return $field . sprintf('<input type="hidden" name="%s" value="%s">', 
    233                 $self->escape($htmlname), ($self->attr_raw_value($attr) || '')); 
    234         }; 
    235         /^date$/ and do { 
    236             my ($date, $time) = split(/ /, $self->attr_raw_value($attr) || ''); 
    237             if ($date && $date =~ /^(\d+)-(\d+)-(\d+)$/) { 
    238                 $date = "$3/$2/$1"; 
    239             } 
    240             my $html = "\n" . q{<SCRIPT LANGUAGE="JavaScript" ID="js13"> 
    241             var cal13 = new CalendarPopup(); 
    242             </SCRIPT>} . "\n"; 
    243             $html .= sprintf( 
    244                 '<input type="text" id="%s" name="%s" value="%s" size="12">', 
    245                 $self->escape($htmlname), 
    246                 $self->escape($htmlname), 
    247                 $self->escape($date) 
    248             ); 
    249             $html .= q{<DIV ID="testdiv1" STYLE="position:absolute;visibility:hidden;background-color:white;layer-background-color:white;"></DIV>}; 
    250             $html .= qq| 
    251             <A HREF="#" 
    252                 onClick="cal13.select(document.forms[0].$htmlname,'${htmlname}_anc','dd/MM/yyyy');return false;" 
    253                 TITLE="cal13.select(document.forms[0].$htmlname,'${htmlname}_anc','dd/MM/yyyy');return false;" 
    254                 NAME="${htmlname}_anc" ID="${htmlname}_anc"> 
    255                 <img src="| . $self->{c}->uri_for(qw(/static icons view-calendar-day.png)) 
    256                 . qq{" style="ref"></A> 
    257                 } . "\n"; 
    258             return $html; 
    259         }; 
    260         /^checkbox(?::(\w+))?$/ and do { 
    261             my $options = $1 || ''; 
    262             my $text = sprintf('<input type="checkbox" name="%s"%s>', 
    263                 $self->escape($htmlname), 
    264                 $self->attr_raw_value($attr) ? '  checked="yes"' : '' 
    265             );  
    266             $text .= sprintf('<input type="hidden" name="%s">', 
    267                 $self->escape($htmlname)); 
    268             if ($options =~ /l/) { 
    269                 $text .= $self->attr_raw_value($attr) 
    270                     ? ' ' . $self->attr_raw_value($attr) 
    271                     : '';  
    272             } 
    273             return $text; 
    274         }; 
    275         /^select(-\w+)?:([^:\/]+)(?:\/([^:]+))?(?::(.*))?/ and do { 
    276             my $options = $1 || ''; 
    277             my $otype = $2; 
    278             my $filter = $3; 
    279             my $keyfield = $4; 
    280             my $observe_keyfield = $keyfield || 'displayName'; 
    281             my $select = sprintf('<select id="%s" name="%s">', 
    282                 $self->escape($htmlname), 
    283                 $self->escape($htmlname)) . "\n"; 
    284             $select .= '<option value="">--</option>' . "\n" if ($options =~ /N/); 
    285             my $value = $self->attr_raw_value($attr) || ''; 
    286             my $initial_observed = ''; 
    287             foreach my $id (sort $filter 
    288                 ? $self->base->search_objects($otype, $filter) 
    289                 : $self->base->list_objects($otype)) { 
    290                 my $val = $id; 
    291                 if ($keyfield) { 
    292                     my $obj = $self->base->get_object($otype, $id) or next; 
    293                     $val = $obj->get_c_field($keyfield); 
    294                 } 
    295                 $select .= sprintf( 
    296                     '    <option value="%s"%s>%s</option>', 
    297                     $self->escape($val || ''), 
    298                     $value eq $val ? ' selected="selected"' : '', 
    299                     $self->escape($id || ''), 
     286} 
     287 
     288sub attr_field { 
     289    my ($self, $attr, $type) = @_; 
     290 
     291    my $attribute = ($self->{object} 
     292        ? $self->{object}->attribute($attr) 
     293        : $self->base->attribute($self->otype, $attr)) or return; 
     294 
     295    my $htmlname = $self->escape($self->attr_field_name($attr)); 
     296 
     297    my @html_fields; 
     298    foreach my $attr_raw_value ( 
     299        $attribute->{multiple} 
     300            ? ((grep { $_ } $self->attr_raw_value($attr)), 
     301                $attribute->readonly 
     302                    ? () 
     303                    : ('') 
     304            ) 
     305            : ($self->attr_raw_value($attr))) { 
     306 
     307        my $html_id = $htmlname . 
     308            (scalar(@html_fields) ? scalar(@html_fields) : ''); 
     309 
     310        my $html_field = ''; 
     311        for ($attribute->form_type) { 
     312            /^textarea$/i and do { 
     313                $html_field = sprintf( 
     314                    '<textarea id="%s" name="%s" cols="40">%s</textarea>', 
     315                    $self->escape($html_id), 
     316                    $self->escape($htmlname), 
     317                    $self->escape($attr_raw_value || ''), 
    300318                ); 
    301                 $select .= "\n"; 
    302                 if($value eq $val) { 
    303                     if (my $obj = $self->base->get_object($otype, $id)) { 
    304                         $initial_observed = $obj->get_c_field($observe_keyfield) 
    305                         || ''; 
    306                     } 
    307                 } 
    308             } 
    309             $select .= "</select>\n"; 
    310             $select .= $self->{c}->prototype->observe_field( $htmlname, { 
    311                 update => "${htmlname}_span", 
    312                 url => $self->{c}->uri_for('/ajax', 'rawattr', $otype), 
    313                 frequency => 1, 
    314                 with   => "'attr=" . $observe_keyfield . 
    315                 "&id='+element.options[element.selectedIndex].text", 
    316             }) . 
    317             qq|<span id="${htmlname}_span">$initial_observed</span>|; 
    318             return $select; 
    319         }; 
    320         /^text(-\w+)?(?::(\d+))?/ and do { 
    321             my $flag = $1 || ''; 
    322             if (my @allowed = $self->base->obj_attr_allowed_values( 
    323                     $self->{otype}, $attr)) { 
    324                 my $cvalue = $self->attr_raw_value($attr); 
    325                 my $textf = sprintf('<select  id="%s" name="%s">', 
     319                last; 
     320            }; 
     321            /^label$/i and do { 
     322                $attr_raw_value or last; 
     323                $html_field = $self->escape($attr_raw_value); 
     324                $html_field =~ s/\n/<br>/g; 
     325                $html_field .= sprintf('<input type="hidden" name="%s" value="%s">', 
     326                    $self->escape($htmlname), ($attr_raw_value || '')); 
     327                last; 
     328            }; 
     329            /^date$/i and do { 
     330                my ($date, $time) = split(/ /, $self->attr_raw_value($attr) || ''); 
     331                if ($date && $date =~ /^(\d+)-(\d+)-(\d+)$/) { 
     332                    $date = "$3/$2/$1"; 
     333                } 
     334                my $html = "\n" . q{<SCRIPT LANGUAGE="JavaScript" ID="js13"> 
     335                var cal13 = new CalendarPopup(); 
     336                </SCRIPT>} . "\n"; 
     337                $html .= sprintf( 
     338                    '<input type="text" id="%s" name="%s" value="%s" size="12">', 
     339                    $self->escape($html_id), 
    326340                    $self->escape($htmlname), 
     341                    $self->escape($date) 
     342                ); 
     343                $html .= q{<DIV ID="testdiv1" STYLE="position:absolute;visibility:hidden;background-color:white;layer-background-color:white;"></DIV>}; 
     344                $html .= qq| 
     345                <A HREF="#" 
     346                    onClick="cal13.select(document.getElementById('$html_id'),'${html_id}_anc','dd/MM/yyyy');return false;" 
     347                    TITLE="Date" 
     348                    NAME="${html_id}_anc" ID="${html_id}_anc"> 
     349                    <img class="attr" src="| . $self->{c}->uri_for(qw(/static icons view-calendar-day.png)) 
     350                    . qq{" style="ref"></A> 
     351                    } . "\n"; 
     352                $html_field = $html; 
     353                last; 
     354            }; 
     355            /^checkbox(?::(\w+))?$/i and do { 
     356                my $options = $1 || ''; 
     357                $html_field = sprintf('<input type="checkbox" name="%s"%s>', 
     358                    $self->escape($htmlname), 
     359                    $attr_raw_value ? '  checked="yes"' : '' 
     360                );  
     361                $html_field .= sprintf('<input type="hidden" name="%s">', 
     362                    $self->escape($htmlname)); 
     363                if ($attribute->form_option('rawvalue')) { 
     364                    $html_field .= $attr_raw_value 
     365                        ? ' ' . $attr_raw_value 
     366                        : '';  
     367                } 
     368                last; 
     369            }; 
     370            /^LIST/ and do { 
     371                my $options = $1 || ''; 
     372                my $select = sprintf('<select id="%s" name="%s">', 
     373                    $self->escape($html_id), 
    327374                    $self->escape($htmlname)) . "\n"; 
    328                 $textf .= '<option value="">--</option>' . "\n"; 
    329                 foreach (sort @allowed) { 
    330                     $textf .= sprintf('<option value="%s"%s>%s</option>' . "\n", 
    331                         $self->escape($_), 
    332                         (($cvalue || '') eq $_ ? ' selected="selected"' : ''), 
    333                         $self->escape($_), 
     375                $select .= '<option value="">--</option>' . "\n" 
     376                    unless($attribute->mandatory); 
     377                my $value = $attr_raw_value || ''; 
     378                my $initial_observed = ''; 
     379                my @valslist; 
     380                foreach my $val (sort $attribute->can_values) { 
     381                    push(@valslist, { 
     382                        val => $val, 
     383                        disp => $attribute->display($val || ''), 
     384                    }); 
     385                } 
     386                foreach (sort { $a->{disp} cmp $b->{disp} } @valslist) { 
     387                    $select .= sprintf( 
     388                        '    <option value="%s"%s>%s</option>', 
     389                        $self->escape($_->{val} || ''), 
     390                        $value eq $_->{val} ? ' selected="selected"' : '', 
     391                        $self->escape($_->{disp} || ''), 
    334392                    ); 
    335                 } 
    336                 $textf .= "</select>\n"; 
    337                 return $textf; 
    338             } else { 
    339                 my $textf = sprintf( 
     393                    $select .= "\n"; 
     394                } 
     395                $select .= "</select>\n"; 
     396 
     397                $html_field = $select; 
     398                last; 
     399            }; 
     400            /^text(-\w+)?(?::(\d+))?/i and do { 
     401                my $flag = $1 || ''; 
     402                $html_field = sprintf( 
    340403                    '<input type="text" id="%s" name="%s" value="%s" size="%d">', 
     404                    $self->escape($html_id), 
    341405                    $self->escape($htmlname), 
    342                     $self->escape($htmlname), 
    343                     $self->escape($self->attr_raw_value($attr)), 
    344                     $2 || 30, 
     406                    $self->escape($attr_raw_value), 
     407                    $attribute->form_option('length') || 30, 
    345408                ); 
    346409                if ($flag =~ /A/) { 
    347                 $textf .= qq|<span id="${htmlname}_auto_complete"></span>|; 
    348                 $textf .= "\n"; 
    349                 $textf .= $self->{c}->prototype->auto_complete_field( 
    350                     $htmlname, 
    351                     { 
    352                     update => "${htmlname}_auto_complete", 
    353                     url => $self->{c}->uri_for('/ajax', 'attrvalues', $self->otype, $attr), 
    354                     indicator => "${htmlname}_stat", min_chars => 1, 
    355                     with => "'val='+document.getElementById('$htmlname').value", 
    356                     frequency => 2, 
    357                     } 
    358                 ); 
    359                 } 
    360                 if ($flag =~ /U/) { 
    361                 $textf .= qq|<span id="${htmlname}_observer_uniq"></span>|; 
    362                 $textf .= "\n"; 
    363                 $textf .= $self->{c}->prototype->observe_field( 
    364                     $htmlname, 
    365                     { 
    366                     update => "${htmlname}_observer_uniq", 
    367                     url => $self->{c}->uri_for('/ajax', 'objattrexist', 
    368                         $self->otype, $attr), 
    369                     frequency => 2, 
    370                     indicator => "${htmlname}_stat", min_chars => 1, 
    371                     with => "'val='+document.getElementById('$htmlname').value" . 
    372                         ($self->{object} ? "+'&exclude=" . $self->{object}->id . "'" : 
    373                             ''), 
    374                     } 
    375                 ); 
    376                 } 
    377                 $textf .= qq|<span style="display:none" id="${htmlname}_stat">Searching...</span>|; 
    378  
    379                 return $textf; 
     410                    $html_field .= qq|<span id="${html_id}_auto_complete"></span>|; 
     411                    $html_field .= "\n"; 
     412                    $html_field .= $self->{c}->prototype->auto_complete_field( 
     413                        $html_id, 
     414                        { 
     415                            update => "${html_id}_auto_complete", 
     416                            url => $self->{c}->uri_for('/ajax', 'attrvalues', $self->otype, $attr), 
     417                            indicator => "${html_id}_stat", min_chars => 1, 
     418                            with => "'val='+document.getElementById('$html_id').value", 
     419                            frequency => 2, 
     420                        } 
     421                    ); 
     422                } 
     423                if ($attribute->uniq) { 
     424                    $html_field .= qq|<span class="inputvalidate" id="${html_id}_observer_uniq"></span>|; 
     425                    $html_field .= "\n"; 
     426                    $html_field .= $self->{c}->prototype->observe_field( 
     427                        $html_id, 
     428                        { 
     429                            update => "${html_id}_observer_uniq", 
     430                            url => $self->{c}->uri_for('/ajax', 'objattrexist', 
     431                                $self->otype, $attr), 
     432                            frequency => 2, 
     433                            indicator => "${html_id}_stat", min_chars => 1, 
     434                            with => "'val='+document.getElementById('$html_id').value" . 
     435                            ($self->{object} ? "+'&exclude=" . $self->{object}->id . "'" : 
     436                                ''), 
     437                        } 
     438                    ); 
     439                    $html_field .= qq|<span style="display:none" id="${html_id}_stat">Searching...</span>|; 
     440                } 
     441                last; 
     442            }; 
     443        } 
     444        if (my $ref = $attribute->reference) { 
     445            my $uri_part= { 
     446                user => 'users', 
     447                group => 'groups', 
     448                nethost => 'nethosts', 
     449                netzone => 'netzones', 
     450                site => 'sites' 
     451            }->{$ref}; 
     452            my $text; 
     453            if ($self->base->attribute($ref, 'displayName')) { 
     454                if ($attr_raw_value && 
     455                    (my $obj = $self->base->get_object($ref, $attr_raw_value))) 
     456                { 
     457                    $text = $obj->get_attributes('displayName'); 
     458                } 
     459                 
     460                $html_field .= $self->{c}->prototype->observe_field( $html_id, { 
     461                        update => "${html_id}_span", 
     462                        url => $self->{c}->uri_for('/ajax', 'rawattr', $ref), 
     463                        frequency => 1, 
     464                        with   => "'attr=displayName" . 
     465                        "&id=' + element.options[element.selectedIndex].text", 
     466                    }) . "\n" if ($attribute->form_type =~ /list/i); 
     467            } elsif($attr_raw_value && $uri_part) { 
     468                $text = sprintf( 
     469                    '<img class="attr" src="%s" title="%s">', 
     470                    $self->{c}->uri_for('/static', 'icons', 'arrow-right.png'), 
     471                    $attr_raw_value, 
     472                ) 
    380473            } 
    381         }; 
     474            $html_field .= sprintf(qq{<span id="%s" style="margin-left: 1em">}, 
     475                "${html_id}_span"); 
     476 
     477            if (defined($text)) { 
     478                $html_field .= $uri_part 
     479                    ? sprintf('<a href="%s">%s</a>', 
     480                        $self->{c}->uri_for("/$uri_part", $attribute->display($attr_raw_value)), 
     481                        $text,) 
     482                    : $text; 
     483            } 
     484 
     485            $html_field .= "</span>\n"; 
     486        } 
     487        push(@html_fields, $html_field); 
    382488    } 
     489    return join("<br>\n", @html_fields); 
    383490} 
    384491 
     
    391498} 
    392499 
     500sub write_attributes { 
     501    my ($self) = @_; 
     502    my @attrs; 
     503    foreach ($self->attributes) { 
     504        my $attr = ($self->{object} 
     505            ? $self->{object}->attribute($_) 
     506            : $self->base->attribute($self->otype, $_)) or next; 
     507        $attr->readonly and next; 
     508        push(@attrs, $_); 
     509    } 
     510    @attrs; 
     511} 
     512 
    393513sub set_attrs { 
    394514    my ($self) = @_; 
     
    396516    my $prefix = $self->{object}->id . '_'; 
    397517    my %fields; 
    398     foreach ( 
    399         grep { $self->base->get_field_name($self->otype, $_, 'w') } 
    400         $self->attributes) { 
     518    foreach ($self->write_attributes) { 
     519        my $attr = ($self->{object} 
     520            ? $self->{object}->attribute($_) 
     521            : $self->base->attribute($self->otype, $_)) or next; 
    401522        if (($attrs->{$_}[1] || '') eq 'checkbox') { 
    402523            $fields{$_} = $self->{c}->req->param("$prefix$_") ? 1 : 0; 
     524        } elsif ($attr->{multiple}) { 
     525            $fields{$_} = [ grep { $_ } $self->{c}->req->param("$prefix$_") ]; 
    403526        } else { 
    404527            $fields{$_} = $self->{c}->req->param("$prefix$_"); 
    405528        } 
    406529    } 
    407     $self->{object}->set_c_fields(%fields) or return; 
     530    $self->{object}->set_c_fields(%fields) or do { 
     531        $self->{c}->stash->{page}{error} = 
     532            LATMOS::Accounts::Log::lastmessage(LA_ERR); 
     533        $self->{object}->base->rollback; 
     534        return; 
     535    }; 
    408536    $self->{object}->base->commit; 
    409537} 
Note: See TracChangeset for help on using the changeset viewer.