work on better custom email definition form

This commit is contained in:
Nathan Coad
2018-05-22 10:19:29 +10:00
parent d75667d32e
commit 65463ecb76
4 changed files with 145 additions and 3 deletions

View File

@@ -248,6 +248,108 @@ function booking_emails_workflow_admin() {
return system_settings_form($form, FALSE);
}
// TODO : Use ajax to select email definition instead of drawing so many WYSIWYG text editors which take ages to load
/**
* Hook form() to use ajax to allow admin user to define custom emails that can be sent by Bookings module
*
* @param
* @return form render array
*/
function booking_emails_custom_ajax_form($node, &$form_state) {
global $event;
$form = array();
$data = $node;
//$email_options_array = _booking_custom_email_types();
//add in the custom email types
for ($i = 1; $i <= variable_get('booking_custom_email_count','5'); $i++) {
$email_options_array['custom' . $i] = variable_get('booking_email_subject_custom' . $i, $event->booking_eventname . ' custom ' . $i);
}
//add in the custom email types from logistics
for ($i = 1; $i <= 5; $i++) {
$email_options_array['customlogistics' . $i] = variable_get('booking_email_subject_customlogistics' . $i,
$event->booking_eventname . ' logistics custom ' . $i) . " **Logistics**";
}
if(variable_get('booking_enable_html_mail', 0) == 1) {
$form_type = 'text_format';
$form_format = 'full_html';
}
else {
$form_type = 'textarea';
$form_format = NULL;
}
$form['email-type'] = array(
'#type' => 'select',
'#title' => t('Email Type'),
'#required' => TRUE,
'#default_value' => 'NULL',
'#options' => $email_options_array,
'#ajax' => array(
'event' => 'change',
'callback' => 'booking_emails_custom_ajax_form_callback',
'wrapper' => 'booking_emails_custom_fieldset_wrapper',
),
);
$form['email-definition'] = array(
'#type' => 'fieldset',
'#title' => 'Email Definition',
'#prefix' => '<div id="booking_emails_custom_fieldset_wrapper">',
'#suffix' => '</div>'
);
$form['email-definition']['booking_email_subjectline_custom'] = array (
'#type' => 'textfield',
'#title' => t('Subject line for Custom Email'),
'#size' => 150,
'#maxlength' => 300,
'#default_value' => isset($form_state['values']['booking_email_subjectline_custom']) ? $form_state['values']['booking_email_subjectline_custom'] : '',
);
$form['email-definition']['booking_email_body_custom'] = array(
'#title' => t('Email text for custom email'),
'#description' => t(''),
'#default_value' => isset($form_state['values']['booking_email_body_custom']) ? $form_state['values']['booking_email_body_custom'] : '',
'#type' => $form_type,
'#format' => $form_format,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return array (
'form' => $form,
);
}
/**
* Callback function to display the custom email definition for form booking_emails_custom_ajax_form
*/
function booking_emails_custom_ajax_form_callback($form, &$form_state) {
global $event;
$text = "";
$data = $form_state['input'];
//check the selected email type
//configure the input text field and textarea based on select field
$emailtype = $form_state['input']['email-type'];
if (strpos($emailtype, 'custom') !== false) {
$subject = variable_get('booking_email_subject_' . $emailtype, '');
$form['form']['email-definition']['booking_email_subjectline_custom']['#default_value'] = $subject;
$text = variable_get('booking_email_' . $emailtype, '');
$text = isset($text['format']) ? $text['value'] : $text;
$form['form']['email-definition']['booking_email_body_custom']['#default_value'] = $text;
}
// Rebuild the form
$form_state['rebuild'] = TRUE;
return $form['form'];
}
/**
* Function to allow admin user to define custom emails that can be sent by Bookings module
*