diff --git a/booking.emails_admin.inc b/booking.emails_admin.inc index 535625d..7d0a641 100644 --- a/booking.emails_admin.inc +++ b/booking.emails_admin.inc @@ -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("

Send a manual email to people registered for this event.

"); @@ -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,13 +337,24 @@ 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' => '
', + '#suffix' => '
', + ); + + $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( 'booking_nid' => array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'), @@ -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' => '
', + '#suffix' => '
', + ); + + 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 */ diff --git a/booking.js b/booking.js new file mode 100644 index 0000000..228ccc8 --- /dev/null +++ b/booking.js @@ -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 +} \ No newline at end of file diff --git a/booking.studygroups.inc b/booking.studygroups.inc index d11235b..763de88 100644 --- a/booking.studygroups.inc +++ b/booking.studygroups.inc @@ -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();