work on dynamic form for manual emails
This commit is contained in:
@@ -269,6 +269,7 @@ function booking_manual_email_form($form, &$form_state, $input_option = "")
|
||||
//see http://www.jaypan.com/blog/themeing-drupal-7-forms-tables-checkboxes-or-radios
|
||||
$form = array();
|
||||
$options = array();
|
||||
$preselection_options = array();
|
||||
$values = array();
|
||||
$group_text = "";
|
||||
$prefix = t("<p>Send a manual email to people registered for this event.</p>");
|
||||
@@ -282,6 +283,8 @@ function booking_manual_email_form($form, &$form_state, $input_option = "")
|
||||
$email_options_array['initialtravelrequired'] = 'Initial Travel Form Required Email';
|
||||
$email_options_array['remindertravelrequired'] = 'Reminder Travel Form Required Email';
|
||||
$email_options_array['travelcomplete'] = 'Travel Form Complete Email';
|
||||
$preselection_options['---'] = "---";
|
||||
$preselection_options['bookedin'] = 'bookedin';
|
||||
|
||||
//add in the custom email types
|
||||
for ($i = 1; $i <= variable_get('booking_custom_email_count','5'); $i++)
|
||||
@@ -304,6 +307,17 @@ function booking_manual_email_form($form, &$form_state, $input_option = "")
|
||||
$form['#attached']['css'] = array(
|
||||
drupal_get_path('module', 'booking') . '/booking.css',
|
||||
);
|
||||
//attach js for dynamically setting checkboxes
|
||||
$form['#attached']['js'][] = drupal_get_path("module", "booking")."/booking.js"
|
||||
|
||||
//@todo add booking prefix
|
||||
$form['email-type'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Email Type'),
|
||||
'#required' => TRUE,
|
||||
'#default_value' => 'NULL',
|
||||
'#options' => $email_options_array,
|
||||
);
|
||||
|
||||
//@todo
|
||||
/*
|
||||
@@ -323,12 +337,23 @@ function booking_manual_email_form($form, &$form_state, $input_option = "")
|
||||
http://jsfiddle.net/nanoquantumtech/dnhwz/
|
||||
*/
|
||||
|
||||
$form['email-type'] = array(
|
||||
$form['booking-email-default-ids'] = array (
|
||||
'#type' => 'hidden',
|
||||
'#value' => "",
|
||||
'#prefix' => '<div id="booking_email_default_ids_wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
$form['booking-email-preselection'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Email Type'),
|
||||
'#required' => TRUE,
|
||||
'#default_value' => 'NULL',
|
||||
'#options' => $email_options_array,
|
||||
'#title' => t('Preselect Attendees'),
|
||||
'#options' => $preselection_options,
|
||||
'#default_value' => '---',
|
||||
'#ajax' => array(
|
||||
'event' => 'change',
|
||||
'callback' => '_booking_email_get_default_selection_callback',
|
||||
'wrapper' => 'booking_email_default_ids_wrapper',
|
||||
),
|
||||
);
|
||||
|
||||
$header = array(
|
||||
@@ -434,6 +459,54 @@ function booking_manual_email_form($form, &$form_state, $input_option = "")
|
||||
'form' => $form,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to update hidden form value with default checkbox details
|
||||
*
|
||||
* Callback element needs only select the portion of the form to be updated.
|
||||
* Since #ajax['callback'] return can be HTML or a renderable array (or an
|
||||
* array of commands), we can just return a piece of the form.
|
||||
* Source: http://www.maged.me/blog/drupal-7-execute-javascript-code-after-ajax-call
|
||||
*/
|
||||
function _booking_email_get_default_selection_callback($form, $form_state) {
|
||||
global $event;
|
||||
$defaults = array();
|
||||
$replacementform_data = array();
|
||||
|
||||
//get type of selection from $form_state['values']['booking-email-preselection']
|
||||
$selection = $form_state['values']['booking-email-preselection'];
|
||||
//load nodes
|
||||
$people = booking_load_query(NULL, TRUE);
|
||||
//populate $defaults based on type of selection
|
||||
foreach ($people as $person) {
|
||||
if ($selection == 'bookedin' && $person->booking_status == 1) {
|
||||
$defaults[] = $person->nid;
|
||||
}
|
||||
}
|
||||
//set return value via drupal_json_encode($var)
|
||||
$replacementform_data['booking-email-default-ids'] = array (
|
||||
'#type' => 'hidden',
|
||||
'#value' => drupal_json_encode($defaults),
|
||||
'#prefix' => '<div id="booking_email_default_ids_wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
return array(
|
||||
'#type' => 'ajax',
|
||||
'#commands' => array(
|
||||
ajax_command_replace("#booking_email_default_ids_wrapper", render($replacementform_data['booking-email-default-ids'])),
|
||||
array('command' => 'bookingEmailIDs'), // This will call the command nameOfCommand we just created in the JS file.
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to update hidden form value with default checkbox details
|
||||
*/
|
||||
function () {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to handle sending the manual emails
|
||||
*/
|
||||
|
6
booking.js
Normal file
6
booking.js
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Special Effects AJAX framework command.
|
||||
*/
|
||||
Drupal.ajax.prototype.commands.bookingEmailIDs = function(ajax, response, status) {
|
||||
alert("Hello I'm Maged Eladawy...") ; // this will be executed after the ajax call
|
||||
}
|
@@ -608,6 +608,7 @@ function booking_studygroups_edit_form_submit($form, &$form_state) {
|
||||
'booking_studygroup_role' => 0,
|
||||
))
|
||||
->execute();
|
||||
//@todo fix this - should be dynamic not hard coded
|
||||
if ($key == 7)
|
||||
{
|
||||
booking_studygroups_process_colours();
|
||||
|
Reference in New Issue
Block a user