From 65e29b0be2a1a52b1db381ecfaf97f1899bcae71 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Thu, 26 May 2016 09:18:04 +1000 Subject: [PATCH] ajax test --- booking.emails.inc | 63 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/booking.emails.inc b/booking.emails.inc index 9f35b59..e31142c 100644 --- a/booking.emails.inc +++ b/booking.emails.inc @@ -34,7 +34,19 @@ function booking_manual_email() '#required' => TRUE, '#default_value' => 'NULL', '#options' => $email_options_array, - ); + ); + + $form['select-type'] = array( + '#type' => 'select', + '#title' => t('Pre-Select People'), + '#options' => array("---" => "NULL", "Unpaid" => "Unpaid", "Waiting List" => "Waiting List"), + '#default_value' => "---", + '#ajax' => array( + 'callback' => '_booking_manual_email_form_selecttype_dropdown_callback', + 'event' => 'change', + ), + ); + $header = array( 'booking_nid' => array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'), @@ -116,6 +128,8 @@ function booking_manual_email() '#default_value' => $values, '#empty' => t('No attendees found.'), '#attributes' => array('id' => 'sort-table'), + '#prefix' => '
', + '#suffix' => '
', ); $form['submit'] = array ( @@ -132,6 +146,51 @@ function booking_manual_email() ); } +function _booking_manual_email_form_selecttype_dropdown_callback($form, &$form_state) { + + //$courseid = $form_state['values']['courseid']; + //$scheduleid = $form_state['values']['scheduleid']; + + $checkboxes = $form_state['values']['table']; + $select_type = $form_state['values']['select-type']; + $new_default_values = array() + + // generate new default values + // @todo use a function for this + if ($select_type == "Unpaid") { + $new_default_values = array("1814"); + } else { + $new_default_values = array("1815"); + } + //$options = laycoaches_schedule_course_form_schedule_options($courseid, $scheduleid); + + // update cached options for tableselect + $cached_form = form_get_cache($form['#build_id'], $form_state); + $cached_form['table']['#default_value'] = $new_default_values; + form_set_cache($form['#build_id'], $cached_form, $form_state); + + // remove radios from tableselect + /* + $form['new']['table']['#options'] = $options; + foreach (element_children($form['items']) as $key) { + if (is_numeric($key)) { + unset($form['table'][$key]); + } + } + + // add new radios to tableselect + form_builder($form['#form_id'], $form['table'], $form_state); + // remove current value + unset($form['table']['#default_value']); + unset($form['table']['#value']); + */ + + // update the tableselect + $commands = array(); + $commands[] = ajax_command_replace('#manual-email-attendees-items', drupal_render($form['table'])); + return array('#type' => 'ajax', '#commands' => $commands); +} + function booking_manual_email_submit($form, &$form_state) { $counter = 0; $update_messages = array(); @@ -206,7 +265,7 @@ function booking_manual_email_submit($form, &$form_state) { //increase the counter of people we've emailed $counter++; //store info about the email - $update_messages[] = $message; + $update_messages[] = $message; } } }