From 0dc753ab3e0b7fb26d03f8d04f3b557fcf92382d Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Wed, 8 Jun 2016 09:00:02 +1000 Subject: [PATCH] add email preview --- .DS_Store | Bin 6148 -> 0 bytes booking.emails_admin.inc | 111 ++++++++++++++++++++++++++++++++------- 2 files changed, 92 insertions(+), 19 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 556a339970fde6dbbc6c04acaf294a5a7c8ecf43..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJ5Iw;5Znb9k!VsWOwtcssRL&=iTgi>= z-u(fZ~t`mOphN>x0V+TRP72ufp}-C6#39f>9SA-G0PQ#44c9(P0E;Dnb>a|+3`~Ox465dcp+QH! zWL=#&1O{C+hY!s=YfdQYcgOj~%SG!zMk+uB#tK}K zG;6$4_SVVES+6bd2l$Vn*2@vR6$8B$V_~iM`mC#>1%5+; EZ$%m?WdHyG diff --git a/booking.emails_admin.inc b/booking.emails_admin.inc index 1769cf3..c880b25 100644 --- a/booking.emails_admin.inc +++ b/booking.emails_admin.inc @@ -267,6 +267,22 @@ function booking_manual_email_form($form, &$form_state) { global $event; //see http://www.jaypan.com/blog/themeing-drupal-7-forms-tables-checkboxes-or-radios + /* + create hidden form element that we will populate with JSON data via ajax + create select element defining the pre-selections available + create submit button that calls ajax to update hidden form element, then calls ajax to check the checkboxes based on the hidden form element + + info on turning JSON data back to array + http://stackoverflow.com/questions/29076219/javascript-storing-array-of-objects-in-hidden-field + + ajax references: + http://www.maged.me/blog/drupal-7-execute-javascript-code-after-ajax-call + https://www.drupal.org/node/1028410 + https://www.drupal.org/node/2046693 + + jquery to check the checkboxes: + http://jsfiddle.net/nanoquantumtech/dnhwz/ + */ $form = array(); $options = array(); $preselection_options = array(); @@ -335,26 +351,13 @@ function booking_manual_email_form($form, &$form_state) '#required' => TRUE, '#default_value' => 'NULL', '#options' => $email_options_array, + '#ajax' => array( + 'event' => 'change', + 'callback' => '_booking_email_get_preview_callback', + 'wrapper' => 'booking_email_preview_wrapper', + ), ); - //@todo - /* - create hidden form element that we will populate with JSON data via ajax - create select element defining the pre-selections available - create submit button that calls ajax to update hidden form element, then calls ajax to check the checkboxes based on the hidden form element - - info on turning JSON data back to array - http://stackoverflow.com/questions/29076219/javascript-storing-array-of-objects-in-hidden-field - - ajax references: - http://www.maged.me/blog/drupal-7-execute-javascript-code-after-ajax-call - https://www.drupal.org/node/1028410 - https://www.drupal.org/node/2046693 - - jquery to check the checkboxes: - http://jsfiddle.net/nanoquantumtech/dnhwz/ - */ - $form['booking-email-default-ids'] = array ( '#type' => 'hidden', '#value' => "[]", @@ -375,7 +378,14 @@ function booking_manual_email_form($form, &$form_state) 'callback' => '_booking_email_get_default_selection_callback', 'wrapper' => 'booking_email_default_ids_wrapper', ), - ); + ); + + $form['booking-email-preview'] = array( + '#type' => 'container', + '#children' => "

Preview Email

Blah
", + '#prefix' => '
', + '#suffix' => '
', + ); $form['submit'] = array ( '#type' => 'submit', @@ -469,6 +479,69 @@ function booking_manual_email_form($form, &$form_state) ); } +/** + * Callback to update preview of email that will be sent + * + */ +function _booking_email_get_preview_callback($form, $form_state) { + global $event; + $markup_pre = "
";
+  $markup_post = "
"; + $text = ""; + $emailtype = $form_state['values']['email-type']; + + switch ($emailtype) { + case "registration": + $text = variable_get('booking_email_bookedin_text'); + break; + } +/* + if ($form_state['values']['email-type'] == 'registration') { + $message = t('Processing a manual registration email to id @info', array ('@info' => $key)); + _booking_registration_email($key, false, true); + } + elseif ($form_state['values']['email-type'] == 'initialtravelrequired') { + $message = t('Processing a manual initial travel form request email to id @info', array ('@info' => $key)); + _booking_travelform_initial_request_email($key); + } + elseif ($form_state['values']['email-type'] == 'remindertravelrequired') { + $message = t('Processing a manual reminder travel form request email to id @info', array ('@info' => $key)); + _booking_travelform_reminder_request_email($key); + } + elseif ($form_state['values']['email-type'] == 'balance') { + $message = t('Processing a manual outstanding balance email to id @info', array ('@info' => $key)); + _booking_balance_payment_email($key); + } + elseif ($form_state['values']['email-type'] == 'complete') { + $message = t('Processing a manual registration complete email to id @info', array ('@info' => $key)); + _booking_registration_email($key, true, true); + } + elseif ($form_state['values']['email-type'] == 'travelcomplete') { + $message = t('Processing a manual travelform complete email to id @info', array ('@info' => $key)); + _booking_travelform_confirmation_email($key); + } + elseif ($form_state['values']['email-type'] == 'withdrawal') { + $message = t('Processing a manual withdrawal email to id @info', array ('@info' => $key)); + _booking_demoted_to_notcoming_email($key); + } + elseif ($form_state['values']['email-type'] == 'missedpayment') { + $message = t('Processing a manual missedpayment email to id @info', array ('@info' => $key)); + _booking_missedpayment_email($key); + } + elseif (strpos($form_state['values']['email-type'], 'customlogistics') !== false) { + $message = t('Processing a @custom type email from logistics to id @info', array ('@custom' => $form_state['values']['email-type'], '@info' => $key)); + _booking_custom_email($key, $form_state['values']['email-type'], 'logistics'); + } + elseif (strpos($form_state['values']['email-type'], 'custom') !== false) { + $message = t('Processing a @custom type email to id @info', array ('@custom' => $form_state['values']['email-type'], '@info' => $key)); + _booking_custom_email($key, $form_state['values']['email-type'], 'contact'); + } +*/ + + //generate html that will be used to update div booking_email_preview_wrapper + return $markup_pre . $text . $markup_post; +} + /** * Callback to update hidden form value with default checkbox details *