- Timestamp:
- 12/18/15 07:25:11 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrForms.pm
r1490 r1500 28 28 endcircuit 29 29 locked 30 snNative 31 givenNameNative 32 wWWHomePage 33 halReference 30 34 services 31 35 create … … 38 42 name => 'Statut RH', 39 43 attrs => [ qw( 40 sn givenName description41 comment44 sn givenName 45 description 42 46 company 43 47 department … … 47 51 expire 48 52 endcircuit 49 snNative 50 givenNameNative 51 wWWHomePage 52 halReference 53 create 54 createdby 55 date 56 modifiedby 57 ) ], 53 create 54 createdby 55 date 56 modifiedby 57 ) ], 58 }, 59 useremployment => { 60 name => 'Suivi RH', 61 attrs => [ qw( 62 sn givenName 63 endEmployment 64 manager 65 66 ) ] 58 67 }, 59 68 useraddress => { … … 105 114 description 106 115 facsimileTelephoneNumber 116 ) ], 117 }, 118 employment => { 119 name => 'Nouvelle période', 120 attrs => [ qw( 121 firstday 122 lastday 123 endcircuit 124 contratType 125 managerContact 126 company 127 department 107 128 ) ], 108 129 }, … … 246 267 if ($form) { 247 268 foreach (@{ $forms->{$form}->{attrs} }) { 248 $new->{_attr}{$_} = $c->model('AttrFormsA', $_, ( $object269 $new->{_attr}{$_} = $c->model('AttrFormsA', $_, (ref $object 249 270 ? ($object) 250 271 : ($base, $new->{otype}))) … … 344 365 345 366 sub set_attrs { 346 my ($self, $attrs ) = @_;347 $self->{c}->req->param($self-> label) || $attrs or return;367 my ($self, $attrs, $id) = @_; 368 $self->{c}->req->param($self->{form}) || $attrs or return; 348 369 my %fields; 349 370 foreach ($attrs ? @{ $attrs } : $self->write_attributes) { 350 371 my $attr = ref $_ ? $_ : $self->{_attr}{$_}; 372 $attr ||= $self->{c}->model('AttrFormsA', $_, ( 373 ref $self->object 374 ? ($self->object) 375 : ($self->base, $self->{otype}) 376 ) 377 ); 378 351 379 if ($attr->{multiple}) { 352 380 $fields{$attr->name} = [ grep { $_ } $self->{c}->req->param($attr->htmlname) ]; 353 381 } else { 354 $fields{$attr->name} = $self->{c}->req->param($attr->htmlname) ;382 $fields{$attr->name} = $self->{c}->req->param($attr->htmlname) || undef; 355 383 } 356 384 } 357 $self->{object}->set_c_fields(%fields) or do { 358 $self->{c}->stash->{page}{error} = 359 LATMOS::Accounts::Log::lastmessage(LA_ERR); 360 $self->{object}->base->rollback; 361 return; 362 }; 363 $self->{object}->base->commit; 385 if ($self->object) { 386 $self->object->set_c_fields(%fields) or do { 387 $self->{c}->stash->{page}{error} = 388 LATMOS::Accounts::Log::lastmessage(LA_ERR); 389 $self->object->base->rollback; 390 return; 391 }; 392 } else { 393 $id ||= join('', map {('a'..'z')[rand(26)]}(0..8)); 394 $self->base->create_object($self->otype, $id, %fields) or do { 395 $self->{c}->stash->{page}{error} = 396 LATMOS::Accounts::Log::lastmessage(LA_ERR); 397 $self->base->rollback; 398 return; 399 }; 400 } 401 $self->base->commit; 402 $self->reset_param; 403 return $id || $self->object->id; 404 405 } 406 407 sub reset_param { 408 my ($self) = @_; 409 foreach (values %{ $self->{_attr} }) { 410 delete($self->{c}->req->params->{$_->htmlname}); 411 } 364 412 } 365 413 366 414 sub submit { 367 my ($self ) = @_;415 my ($self, $hidden) = @_; 368 416 return sprintf( 369 '<input type="submit" name="%s" value="Enregistrer">', 370 $self->escape($self->label), 417 '<input type="%s" name="%s" value="Enregistrer">', 418 ($hidden ? 'hidden' : 'submit'), 419 $self->escape($self->{form}), 371 420 ); 372 421 }
Note: See TracChangeset
for help on using the changeset viewer.