Revision 1c62fca1
Von Tamino Steinert vor 12 Monaten hinzugefügt
SL/Controller/EmailJournal.pm | ||
---|---|---|
9 | 9 |
use SL::DB::EmailJournal; |
10 | 10 |
use SL::DB::EmailJournalAttachment; |
11 | 11 |
use SL::Presenter::EmailJournal; |
12 |
use SL::Presenter::Tag qw(html_tag div_tag radio_button_tag);
|
|
12 |
use SL::Presenter::Tag qw(html_tag div_tag button_tag); |
|
13 | 13 |
use SL::Helper::Flash; |
14 | 14 |
use SL::Locale::String qw(t8); |
15 | 15 |
|
... | ... | |
103 | 103 |
my $class = $RECORD_TYPES_INFO{$_}->{class}; |
104 | 104 |
map { $_ => "SL::DB::Manager::$class" } @{ $RECORD_TYPES_INFO{$_}->{types} } |
105 | 105 |
} keys %RECORD_TYPES_INFO; |
106 |
my @ALL_RECORD_TYPES = map { @{ $RECORD_TYPES_INFO{$_}->{types} } } keys %RECORD_TYPES_INFO; |
|
106 |
my @ALL_RECORD_TYPES = |
|
107 |
map { @{ $RECORD_TYPES_INFO{$_}->{types} } } keys %RECORD_TYPES_INFO; |
|
107 | 108 |
my %RECORD_TYPE_TO_NR_KEY = |
108 | 109 |
map { |
109 | 110 |
my $model = $RECORD_TYPE_TO_MODEL{$_}; |
... | ... | |
329 | 330 |
my $customer_vendor = $::form->{customer_vendor_selection}; |
330 | 331 |
my $customer_vendor_id = $::form->{"${customer_vendor}_id"}; |
331 | 332 |
my $action = $::form->{action_selection}; |
332 |
my $record_type_id = $::form->{"record_type_id"}; |
|
333 |
die t8("No record is selected.") unless $record_type_id || $action eq 'create_new'; |
|
333 |
my $record_id = $::form->{"record_id"}; |
|
334 |
my $record_type = $::form->{"record_type"}; |
|
335 |
$record_type ||= $::form->{"${customer_vendor}_record_type_selection"}; |
|
334 | 336 |
|
337 |
die t8("No record is selected.") unless $record_id || $action eq 'create_new'; |
|
338 |
die t8("No record type is selected.") unless $record_type; |
|
335 | 339 |
die "no 'email_journal_id' was given" unless $email_journal_id; |
336 | 340 |
die "no 'customer_vendor_selection' was given" unless $customer_vendor; |
337 | 341 |
die "no 'action_selection' was given" unless $action; |
338 | 342 |
|
339 |
my ($record_type, $record_id) = split(/-/, $record_type_id); |
|
340 |
|
|
341 | 343 |
if ($action eq 'linking') { |
342 | 344 |
return $self->link_and_add_attachment_to_record({ |
343 |
email_journal_id => $email_journal_id,
|
|
344 |
attachment_id => $attachment_id,
|
|
345 |
record_type => $record_type,
|
|
346 |
record_id => $record_id,
|
|
345 |
email_journal_id => $email_journal_id, |
|
346 |
attachment_id => $attachment_id, |
|
347 |
record_type => $record_type, |
|
348 |
record_id => $record_id, |
|
347 | 349 |
}); |
348 | 350 |
} |
349 | 351 |
|
... | ... | |
404 | 406 |
with_closed => $with_closed, |
405 | 407 |
); |
406 | 408 |
|
407 |
unless (@records) { |
|
408 |
$self->js->replaceWith('#record_list', div_tag( |
|
409 |
html_tag('h3', t8('No records found.')), |
|
410 |
id => 'record_list', |
|
411 |
))->render(); |
|
412 |
return; |
|
409 |
my $new_list; |
|
410 |
if (@records) { |
|
411 |
$new_list = join('', map { |
|
412 |
button_tag( |
|
413 |
"kivi.EmailJournal.apply_action_with_attachment('${\$_->id}', '${\$_->record_type}');", |
|
414 |
$_->displayable_name, |
|
415 |
class => "record_button", |
|
416 |
); |
|
417 |
} @records); |
|
418 |
} else { |
|
419 |
$new_list = html_tag('h3', t8('No records found.')); |
|
413 | 420 |
} |
414 |
|
|
415 | 421 |
my $new_div = div_tag( |
416 |
join('', map { |
|
417 |
div_tag( |
|
418 |
radio_button_tag('record_type_id', |
|
419 |
value => $_->record_type . "-" . $_->id, label => $_->displayable_name, |
|
420 |
class => "record_radio", label_class => "record_radio", |
|
421 |
), |
|
422 |
id => "record_$_->{id}", |
|
423 |
) |
|
424 |
} @records), |
|
422 |
$new_list, |
|
425 | 423 |
id => 'record_list', |
426 | 424 |
); |
427 | 425 |
|
428 |
$self->js->replaceWith('#record_list', $new_div)->render(); |
|
426 |
|
|
427 |
$self->js->replaceWith('#record_list', $new_div); |
|
428 |
$self->js->hide('#record_toggle_closed') if scalar @records < 20; |
|
429 |
$self->js->show('#record_toggle_open') if scalar @records < 20; |
|
430 |
$self->js->render(); |
|
429 | 431 |
} |
430 | 432 |
|
431 | 433 |
# |
... | ... | |
443 | 445 |
sub link_and_add_attachment_to_record { |
444 | 446 |
my ($self, $params) = @_; |
445 | 447 |
|
446 |
my $email_journal_id = $params->{email_journal_id};
|
|
447 |
my $attachment_id = $params->{attachment_id};
|
|
448 |
my $record_type = $params->{record_type};
|
|
449 |
my $record_id = $params->{record_id};
|
|
448 |
my $email_journal_id = $params->{email_journal_id}; |
|
449 |
my $attachment_id = $params->{attachment_id}; |
|
450 |
my $record_type = $params->{record_type}; |
|
451 |
my $record_id = $params->{record_id}; |
|
450 | 452 |
|
451 | 453 |
my $record_type_model = $RECORD_TYPE_TO_MODEL{$record_type}; |
452 | 454 |
my $record = $record_type_model->new(id => $record_id)->load; |
... | ... | |
459 | 461 |
|
460 | 462 |
$email_journal->link_to_record($record); |
461 | 463 |
|
462 |
return $self->js->flash('info', $::locale->text('Linked e-mail and attachment to ') . $record->displayable_name)->render(); |
|
464 |
$self->js->flash('info', |
|
465 |
$::locale->text('Linked e-mail and attachment to ') . $record->displayable_name |
|
466 |
)->render(); |
|
463 | 467 |
} |
464 | 468 |
|
465 | 469 |
sub find_customer_vendor_from_email { |
... | ... | |
501 | 505 |
return $customer_vendor; |
502 | 506 |
} |
503 | 507 |
|
504 |
sub find_customer_from_email { |
|
505 |
my ($self, $email_journal) = @_; |
|
506 |
my $email_address = $email_journal->from; |
|
507 |
|
|
508 |
my $customer = SL::DB::Manager::Customer->get_first( |
|
509 |
where => [ |
|
510 |
or => [ |
|
511 |
email => $email_address, |
|
512 |
cc => $email_address, |
|
513 |
bcc => $email_address, |
|
514 |
'contacts.cp_email' => $email_address, |
|
515 |
'contacts.cp_privatemail' => $email_address, |
|
516 |
'shipto.shiptoemail' => $email_address, |
|
517 |
], |
|
518 |
], |
|
519 |
with_objects => [ 'contacts', 'shipto' ], |
|
520 |
); |
|
521 |
|
|
522 |
return $customer; |
|
523 |
} |
|
524 |
|
|
525 | 508 |
sub add_js { |
526 | 509 |
$::request->{layout}->use_javascript("${_}.js") for qw( |
527 | 510 |
kivi.EmailJournal |
Auch abrufbar als: Unified diff
EmailJournal: Workflow: Auswahl von Beleg optimiert