From 22bcb6b18c5832dad188a72ed75cd98c38d299e3 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 9 Jan 2017 16:38:20 +0100 Subject: [PATCH] =?utf8?q?ActionBar:=20Angebote/Auftr=C3=A4ge:=20E-Mail-Ve?= =?utf8?q?rsand=20=C3=BCber=20Dialog=20implementiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- bin/mozilla/io.pl | 55 +++++++++++++ bin/mozilla/oe.pl | 10 ++- js/kivi.SalesPurchase.js | 79 +++++++++++++++++++ js/locale/de.js | 1 + locale/de/all | 1 + .../webpages/common/_send_email_dialog.html | 44 +++++++++++ templates/webpages/generic/print_options.html | 22 +++--- templates/webpages/oe/form_footer.html | 12 +-- templates/webpages/oe/form_header.html | 8 +- 9 files changed, 208 insertions(+), 24 deletions(-) create mode 100644 templates/webpages/common/_send_email_dialog.html diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index a716f16d0..0cd7385bd 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -53,6 +53,7 @@ use SL::IO; use SL::File; use SL::PriceSource; +use SL::DB::Contact; use SL::DB::Customer; use SL::DB::Default; use SL::DB::Language; @@ -60,6 +61,7 @@ use SL::DB::Printer; use SL::DB::Vendor; use SL::Helper::CreatePDF; use SL::Helper::Flash; +use SL::Helper::PrintOptions; require "bin/mozilla/common.pl"; @@ -2026,3 +2028,56 @@ sub _make_record { return $obj; } + +sub setup_sales_purchase_print_options { + my $print_form = Form->new(''); + $print_form->{printers} = SL::DB::Manager::Printer->get_all_sorted; + $print_form->{languages} = SL::DB::Manager::Language->get_all_sorted; + + $print_form->{$_} = $::form->{$_} for qw(type media language_id printer_id); + + return SL::Helper::PrintOptions->get_print_options( + form => $print_form, + options => { + show_headers => 1, + }, + ); +} + +sub show_sales_purchase_email_dialog { + my $contact = $::form->{cp_id} ? SL::DB::Contact->load_cached($::form->{cp_id}) : undef; + my $email_form = { + to => $contact ? $contact->cp_email : '', + subject => $::form->generate_email_subject, + attachment_filename => $::form->generate_attachment_filename, + }; + + my $html = $::form->parse_html_template("common/_send_email_dialog", { + email_form => $email_form, + show_bcc => $::auth->assert('email_bcc', 'may fail'), + }); + + print $::form->ajax_response_header, $html; +} + +sub send_sales_purchase_email { + my $type = $::form->{type}; + my $id = $::form->{id}; + my $script = $type =~ m{sales_order|purchase_order|quotation} ? 'oe.pl' + : $type =~ m{delivery_} ? 'do.pl' + : 'is.pl'; + + my $email_form = delete $::form->{email_form}; + my %field_names = (to => 'email'); + + $::form->{ $field_names{$_} // $_ } = $email_form->{$_} for keys %{ $email_form }; + + $::form->{media} = 'email'; + + print_form("return"); + Common->save_email_status(\%::myconfig, $::form); + + flash_later('info', $::locale->text('The email has been sent.')); + + print $::form->redirect_header($script . '?action=edit&id=' . $::form->escape($id) . '&type=' . $::form->escape($type)); +} diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index bc01dbbc4..4c33c974a 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -399,7 +399,7 @@ sub setup_oe_action_bar { ], action => [ t8('E Mail'), - submit => [ '#form', { action_print => 1 } ], + call => [ 'kivi.SalesPurchase.show_email_dialog' ], checks => [ @req_trans_desc ], ], ], #end of combobox "Export" @@ -593,11 +593,11 @@ sub form_header { push @custom_hiddens, map { "shiptocvar_" . $_->name } @{ SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'ShipTo' ]) }; $TMPL_VAR{HIDDENS} = [ map { name => $_, value => $form->{$_} }, - qw(id action type vc formname media format proforma queued printed emailed + qw(id type vc proforma queued printed emailed title creditlimit creditremaining tradediscount business max_dunning_level dunning_amount CFDD_shipto CFDD_shipto_id - message email subject cc bcc taxpart taxservice taxaccounts cursor_fokus + taxpart taxservice taxaccounts cursor_fokus show_details useasnew), @custom_hiddens, map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} ]; # deleted: discount @@ -684,9 +684,11 @@ sub form_footer { $TMPL_VAR{ALL_DELIVERY_TERMS} = SL::DB::Manager::DeliveryTerm->get_all_sorted(); + my $print_options_html = setup_sales_purchase_print_options(); + print $form->parse_html_template("oe/form_footer", { %TMPL_VAR, - print_options => print_options(inline => 1), + print_options => $print_options_html, is_sales => scalar ($form->{type} =~ /^sales_/), # these vars are exported, so that the template is_order => scalar ($form->{type} =~ /_order$/), # may determine what to show is_sales_quo => scalar ($form->{type} =~ /sales_quotation$/), diff --git a/js/kivi.SalesPurchase.js b/js/kivi.SalesPurchase.js index 69fec6d8b..2659c858e 100644 --- a/js/kivi.SalesPurchase.js +++ b/js/kivi.SalesPurchase.js @@ -208,4 +208,83 @@ namespace('kivi.SalesPurchase', function(ns) { } }); }; + + this.show_print_options_elements = function(elements, show) { + $(elements).each(function(idx, elt) { + var $elements = $('#print_options_header_' + elt + ',#print_options_input_' + elt); + if (show) + $elements.show(); + else + $elements.hide(); + }); + }; + + this.show_all_print_options_elements = function() { + kivi.SalesPurchase.show_print_options_elements([ 'formname', 'language_id', 'format', 'sendmode', 'media', 'printer_id', 'copies', 'groupitems', 'remove_draft' ], true); + }; + + // Sending records via email. + this.send_email = function() { + var unset = $('#email_form_to,#email_form_subject,#email_form_message').filter(function(idx, elt) { + return $(elt).val() === ''; + }); + + if (unset.length > 0) { + alert(kivi.t8("The recipient, subject or body is missing.")); + $(unset[0]).focus(); + + return false; + } + + $('#send_email_dialog').children().remove().appendTo('#email_inputs'); + $('#send_email_dialog').dialog('close'); + + $('#action').val('send_sales_purchase_email'); + $('#form').submit(); + + return true; + }; + + this.setup_send_email_dialog = function() { + kivi.SalesPurchase.show_all_print_options_elements(); + kivi.SalesPurchase.show_print_options_elements([ 'sendmode', 'media', 'copies', 'remove_draft' ], false); + + $('#print_options').children().remove().appendTo('#email_form_print_options'); + + var to_focus = $('#email_form_to').val() === '' ? 'to' : 'subject'; + $('#email_form_' + to_focus).focus(); + }; + + this.finish_send_email_dialog = function() { + $('#email_form_print_options').children().remove().appendTo('#print_options'); + return true; + }; + + this.show_email_dialog = function() { + kivi.popup_dialog({ + id: 'send_email_dialog', + url: 'io.pl', + load: kivi.SalesPurchase.setup_send_email_dialog, + data: { + action: 'show_sales_purchase_email_dialog', + type: $('#type').val(), + formname: $('#formname').val(), + format: $('#format').val(), + media: 'email', + ordnumber: $('#ordnumber').val(), + donumber: $('#donumber').val(), + invnumber: $('#invnumber').val(), + quonumber: $('#quonumber').val(), + cp_id: $('#cp_id').val(), + language_id: $('#language_id').val(), + }, + dialog: { + height: 600, + title: kivi.t8('Send email'), + beforeClose: kivi.SalesPurchase.finish_send_email_dialog + } + }); + + return true; + }; }); diff --git a/js/locale/de.js b/js/locale/de.js index d7db4951f..fec17ed1e 100644 --- a/js/locale/de.js +++ b/js/locale/de.js @@ -90,6 +90,7 @@ namespace("kivi").setupLocale({ "Save and keep open":"Speichern und geöffnet lassen", "Section/Function block actions":"Abschnitts-/Funktionsblockaktionen", "Select template to paste":"Einzufügende Vorlage auswählen", +"Send email":"E-Mail verschicken", "Set all source and memo fields":"Alle Beleg-/Memo-Felder setzen", "Show all details":"Alle Details anzeigen", "Show details":"Details anzeigen", diff --git a/locale/de/all b/locale/de/all index 49c08b959..5876d9b8c 100755 --- a/locale/de/all +++ b/locale/de/all @@ -2586,6 +2586,7 @@ $self->{texts} = { 'Semicolon' => 'Semikolon', 'Send a BCC to logged in user?' => 'BCC an eingeloggten Benutzer?', 'Send a blind copy of all outgoing emails to current user\'s email address?' => 'Eine blinde Kopie aller ausgehenden E-Mails wird an den angemeldeten Nutzer geschickt', + 'Send email' => 'E-Mail verschicken', 'Send invoice via email' => 'Rechnung via E-Mail verschicken', 'Send letter via e-mail' => 'Brief via E-Mail verschicken', 'Sender' => 'AbsenderIn', diff --git a/templates/webpages/common/_send_email_dialog.html b/templates/webpages/common/_send_email_dialog.html new file mode 100644 index 000000000..20d8b2d77 --- /dev/null +++ b/templates/webpages/common/_send_email_dialog.html @@ -0,0 +1,44 @@ +[%- USE HTML %][%- USE LxERP -%][%- USE L -%] + + + + + + + + + + + + + + [%- IF show_bcc %] + + + + + [%- END %] + + + + + + + + + + + + + + + + +
[% LxERP.t8("To") %][% L.input_tag("email_form.to", email_form.to, size="80") %]
[% LxERP.t8("Cc") %][% L.input_tag("email_form.cc", email_form.cc, size="80") %]
[% LxERP.t8("Bcc") %][% L.input_tag("email_form.bcc", email_form.bcc, size="80") %]
[% LxERP.t8("Subject") %][% L.input_tag("email_form.subject", email_form.subject, size="80") %]
[% LxERP.t8("Attachment name") %][% L.input_tag("email_form.attachment_filename", email_form.attachment_filename, size="80") %]
[% LxERP.t8("Message") %][% L.textarea_tag("email_form.message", email_form.message, rows="15" cols="80" wrap="soft") %]
+ +
+ +

+ [% L.button_tag("kivi.SalesPurchase.send_email()", LxERP.t8("Send email")) %] + [% L.button_tag("\$('#send_email_dialog').dialog('close');", LxERP.t8("Abort")) %] +

diff --git a/templates/webpages/generic/print_options.html b/templates/webpages/generic/print_options.html index b5757e1cb..30b87df3c 100644 --- a/templates/webpages/generic/print_options.html +++ b/templates/webpages/generic/print_options.html @@ -9,25 +9,25 @@ [%- FOREACH row = SELECTS %] [%- IF row.show %] - [%- row.hname %] + [%- row.hname %] [%- END %] [%- END %] [%- IF display_copies %] - [% 'Copies' | $T8 %] + [% 'Copies' | $T8 %] [%- END %] [%- IF display_groupitems %] - [% 'Group Items' | $T8 %] + [% 'Group Items' | $T8 %] [%- END %] [%- IF display_remove_draft %] - [% 'Remove Draft' | $T8 %] + [% 'Remove Draft' | $T8 %] [%- END %] [%- END %] [%- FOREACH row = SELECTS %] [%- IF row.show %] - - [%- FOREACH data = row.DATA %] [%- END %] @@ -36,16 +36,16 @@ [%- END %] [%- END %] [%- IF display_copies %] - [%- IF !show_headers %][%- 'Copies' | $T8 %][%- END %] + [%- IF !show_headers %][%- 'Copies' | $T8 %][%- END %] [%- END %] [%- IF display_groupitems %] - [%- IF !show_headers %][% 'Group Items' | $T8 %][%- END %] - + [%- IF !show_headers %][% 'Group Items' | $T8 %][%- END %] + [%- END %] [%- IF display_remove_draft %] - [%- IF !show_headers %][% 'Remove Draft' | $T8 %][%- END %] - + [%- IF !show_headers %][% 'Remove Draft' | $T8 %][%- END %] + [%- END %] diff --git a/templates/webpages/oe/form_footer.html b/templates/webpages/oe/form_footer.html index aad73eb13..80892da5b 100644 --- a/templates/webpages/oe/form_footer.html +++ b/templates/webpages/oe/form_footer.html @@ -129,11 +129,7 @@ -
- -

[% print_options %]

- - + [% L.hidden_tag("rowcount", rowcount) %] @@ -146,6 +142,12 @@ + + + + diff --git a/templates/webpages/oe/form_header.html b/templates/webpages/oe/form_header.html index 6482185b2..7899ab324 100644 --- a/templates/webpages/oe/form_header.html +++ b/templates/webpages/oe/form_header.html @@ -16,7 +16,7 @@ [%- END %] [%- FOREACH row = HIDDENS %] - + [%- END %] @@ -190,17 +190,17 @@ [%- IF is_order %] [% 'Order Number' | $T8 %] - + [%- END %] [% IF is_req_quo %][% 'RFQ Number' | $T8 %][% ELSE %][% 'Quotation Number' | $T8 %][% END %] - + [%- IF is_order %] [% 'Customer Order Number' | $T8 %] - + [%- END %] -- 2.20.1