ajax test

This commit is contained in:
2016-05-26 09:18:04 +10:00
parent 148a6be855
commit 65e29b0be2

View File

@@ -34,7 +34,19 @@ function booking_manual_email()
'#required' => TRUE, '#required' => TRUE,
'#default_value' => 'NULL', '#default_value' => 'NULL',
'#options' => $email_options_array, '#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( $header = array(
'booking_nid' => array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'), 'booking_nid' => array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'),
@@ -116,6 +128,8 @@ function booking_manual_email()
'#default_value' => $values, '#default_value' => $values,
'#empty' => t('No attendees found.'), '#empty' => t('No attendees found.'),
'#attributes' => array('id' => 'sort-table'), '#attributes' => array('id' => 'sort-table'),
'#prefix' => '<div id="manual-email-attendees-items">',
'#suffix' => '</div>',
); );
$form['submit'] = array ( $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) { function booking_manual_email_submit($form, &$form_state) {
$counter = 0; $counter = 0;
$update_messages = array(); $update_messages = array();
@@ -206,7 +265,7 @@ function booking_manual_email_submit($form, &$form_state) {
//increase the counter of people we've emailed //increase the counter of people we've emailed
$counter++; $counter++;
//store info about the email //store info about the email
$update_messages[] = $message; $update_messages[] = $message;
} }
} }
} }