Changeset 1500 for trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web
- Timestamp:
- 12/18/15 07:25:11 (9 years ago)
- Location:
- trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Summary/Expire.pm
r1480 r1500 25 25 my ( $self, $c ) = @_; 26 26 27 my $base = $c->model('Accounts')->db; 28 29 my %exists = map { $_ => 1 } $base->search_objects('user', 'active=1'); 30 my %expire = $base->attributes_summary_by_object('user', 'expire'); 31 32 my %list = (); 33 foreach (keys %expire) { 34 $exists{$_} or next; 35 my $ex = $expire{$_}->[0] or next; 36 push(@{ $list{$ex} }, $_); 37 } 38 39 $c->stash->{expirelist} = \%list; 27 40 } 28 41 -
trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Users.pm
r1473 r1500 4 4 use warnings; 5 5 use base 'Catalyst::Controller'; 6 7 use Date::Parse; 8 use DateTime; 9 use DateTime::TimeZone; 10 use POSIX; 6 11 7 12 =head1 NAME … … 61 66 my ( $self, $c, undef, $username, $subform, $arg ) = @_; 62 67 68 if ($c->config->{features}->{user_employment}) { 69 # Replace standard RH form by employment 70 $subform ||= 'employment'; 71 } 72 63 73 my $base = $c->model('Accounts')->db; 64 74 … … 86 96 } 87 97 98 88 99 for ($subform || '') { 89 100 # Exceptions... 101 /^employment$/ and do { 102 $arg ||= $c->stash->{user}->get_attributes('currentEmployment'); 103 if ($arg) { 104 if ($arg =~ m/^\@/) { 105 $c->stash->{newemployment} = 1; 106 $c->stash->{forme} = $c->model('AttrForms', 'employment', 'employment', $base); 107 if ($arg =~ m/\@duplicate/i) { 108 my $oldempl = $c->model('Accounts')->db->get_object('employment', 109 $c->req->param('source') 110 ? $c->req->param('source') 111 : ($c->stash->{user}->listEmployment)[0]) 112 or return; 113 foreach (qw(company managerContact contratType department)) { 114 $c->req->params->{$_} = $oldempl->get_attributes($_); 115 } 116 if (my $lastday = $oldempl->get_attributes('lastday')) { 117 my $time = DateTime->from_epoch(epoch => str2time($lastday)); 118 $time->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 119 $time->add( days => 1 ); 120 $c->req->params->{firstday} = $time->ymd; 121 } 122 } elsif ($arg =~ m/\@create/i) { 123 124 my $time = str2time($c->req->param('firstday')); 125 my $lastd = DateTime->from_epoch( epoch => $time ) 126 ->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 127 128 my ($empl) = $c->stash->{user}->listEmployment; 129 if ($empl) { 130 my $obj = $c->model('Accounts')->db->get_object('employment', $empl); 131 if (!$obj->get_attributes('lastday')) { 132 $obj->set_c_fields(lastday => $lastd->subtract(days => 1)->ymd('-')); 133 } 134 } 135 136 my $id = $username . '-' . $lastd->ymd('-'); 137 $c->req->params->{user} = $username; 138 if ($id = $c->stash->{forme}->set_attrs([ 'user', 139 map { $_->name } $c->stash->{forme}->write_attributes], $id)) { 140 $c->res->redirect($c->uri_for('/users', $username, 'employment', $id)); 141 return 1; 142 } 143 } 144 } else { 145 $c->stash->{employment} = $base->get_object('employment', $arg); 146 $c->stash->{forme} = $c->model('AttrForms', 'employment', $c->stash->{employment}); 147 $c->stash->{forme}->set_attrs; 148 } 149 } 150 if (my $delemp = $c->req->param('delemployment')) { 151 $base->delete_object('employment', $delemp); 152 $base->commit; 153 } 154 155 $c->stash->{template} = 'users/employment.tt'; 156 }; 90 157 /^passwd$/ and do { 91 158 $c->stash->{template} = 'users/passwd.tt'; … … 145 212 if (my $ad = $base->get_object('address', 146 213 $c->req->param('main'))) { 147 warn $c->req->param('main');148 warn $ad->set_c_fields('isMainAddress' => 1);149 214 $ad->base->commit; 150 215 } -
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 } -
trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrFormsA.pm
r1408 r1500 6 6 use base 'Catalyst::Model'; 7 7 use LATMOS::Accounts::Log; 8 use Date::Parse; 9 use DateTime; 10 use DateTime::TimeZone; 8 11 9 12 =head1 NAME … … 271 274 sub attr_LABEL { 272 275 my ($self, $value) = @_; 276 277 if ($self->real_form_type =~ m/(DATE|DATETIME)/) { 278 if (my $time = str2time($value)) { 279 my $dt = DateTime->from_epoch(epoch => $time); 280 $dt->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 281 $value = $dt->dmy('/') . ($self->real_form_type eq 'DATE' 282 ? '' 283 : ' ' . $dt->hms(':')); 284 } 285 } 286 273 287 return sprintf('%s <input id="%s" type=hidden name="%s" value="%s">', 274 288 $self->escape($value), … … 289 303 } 290 304 305 306 sub attr_DATE { 307 my ($self, $value, $name, $id) = @_; 308 309 if (my $time = str2time($value)) { 310 my $dt = DateTime->from_epoch(epoch => $time); 311 $dt->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 312 $value = $dt->dmy('/') 313 } 314 315 return sprintf( 316 '<input type="text" id="%s" name="%s" value="%s" size="%d">', 317 $self->escape($id || $self->htmlid), 318 $self->escape($name || $self->htmlname), 319 $self->escape($value), 320 $self->form_option('length') || 20, 321 ); 322 } 323 291 324 sub attr_DATE_js { 325 my ($self, $value) = @_; 326 return sprintf(q| 327 $('[name="%s"]').datepicker( { 328 changeMonth: true, 329 changeYear: true, 330 dateFormat: 'dd/mm/yy' 331 } ); 332 |, $self->escape($self->htmlname)); 333 } 334 335 sub attr_DATETIME { 336 my ($self, $value, $name, $id) = @_; 337 338 if (my $time = str2time($value)) { 339 my $dt = DateTime->from_epoch(epoch => $time); 340 $dt->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); 341 $value = $dt->dmy('/') . ' ' . $dt->hms(':') 342 } 343 344 return sprintf( 345 '<input type="text" id="%s" name="%s" value="%s" size="%d">', 346 $self->escape($id || $self->htmlid), 347 $self->escape($name || $self->htmlname), 348 $self->escape($value), 349 $self->form_option('length') || 20, 350 ); 351 } 352 353 sub attr_DATETIME_js { 292 354 my ($self, $value) = @_; 293 355 return sprintf(q|
Note: See TracChangeset
for help on using the changeset viewer.