remove unworkable ajax tableselect code
This commit is contained in:
@@ -36,22 +36,7 @@ function booking_manual_email_form($form, &$form_state, $input_option = "")
|
||||
'#default_value' => 'NULL',
|
||||
'#options' => $email_options_array,
|
||||
);
|
||||
|
||||
//can't get ajax callback to return a working tableselect
|
||||
/*
|
||||
$form['select-type'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Pre-Select People'),
|
||||
'#options' => array("---" => "---", "Unpaid" => "Unpaid", "Waiting List" => "Waiting List"),
|
||||
'#default_value' => "---",
|
||||
'#ajax' => array(
|
||||
'callback' => '_booking_manual_email_selecttype_ajax_callback',
|
||||
'wrapper' => 'manual-email-attendees-items',
|
||||
'method' => 'replace',
|
||||
'event' => 'change',
|
||||
),
|
||||
);
|
||||
*/
|
||||
|
||||
$header = array(
|
||||
'booking_nid' => array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'),
|
||||
'booking_name' => array('data' => t('Name'), 'field' => 'booking_lastname'),
|
||||
@@ -153,250 +138,6 @@ function booking_manual_email_form($form, &$form_state, $input_option = "")
|
||||
);
|
||||
}
|
||||
|
||||
function _booking_manual_email_generate_options() {
|
||||
global $event;
|
||||
$form = array ();
|
||||
$options = array ();
|
||||
|
||||
if (variable_get('booking_enable_studygroups', 0) == 1)
|
||||
{
|
||||
//select entries from the study groups mapping table
|
||||
$query = db_select('booking_studygroup_mapping', 'm');
|
||||
$query->join('booking_studygroup_list', 's', 's.sid = m.booking_studygroup_id');
|
||||
$query->condition('m.booking_eventid', $event->eid, '=');
|
||||
$query->fields('m')->fields('s', array('booking_studygroup_descrip'));
|
||||
$group_mapping = $query->execute()->fetchAllAssoc('sid');
|
||||
//add a column to the table header
|
||||
$header['group_roles'] = array('data' => t('Group Role'));
|
||||
}
|
||||
|
||||
$query = db_select('booking_person', 'p');
|
||||
$query->join('booking_price', 'pr', 'pr.pid = p.booking_payment_id');
|
||||
$query->leftJoin('booking_travel', 't', 'p.nid = t.booking_person_nid');
|
||||
|
||||
$query->fields('p')
|
||||
->fields('pr', array('booking_price', 'booking_late_price'))
|
||||
->fields('t')
|
||||
->condition('p.booking_eventid', $event->eid, '=');
|
||||
|
||||
$table_sort = $query->extend('TableSort')->orderbyHeader($header);
|
||||
$result = $table_sort->execute();
|
||||
|
||||
foreach($result as $data)
|
||||
{
|
||||
$group_text = "";
|
||||
$class = $data->booking_welfare_required == 'Y' ? "welfare-row" : "normal-row";
|
||||
$options[$data->nid] = array (
|
||||
'booking_nid' => l(t('!id', array('!id' => $data->nid)), t('node/!id', array('!id' => $data->nid))),
|
||||
'booking_name' => $data->booking_firstname . " " . $data->booking_lastname,
|
||||
'booking_gender' => $data->booking_gender == 'M' ? 'Male' : 'Female',
|
||||
'booking_email' => $data->booking_email,
|
||||
'booking_state' => $data->booking_state,
|
||||
'booking_status' => _booking_status_generate($data->booking_status),
|
||||
'amount_paid' => $data->booking_amount_paid,
|
||||
'amount_reqd' => $data->booking_total_pay_reqd,
|
||||
'booking_fully_paid' => $data->booking_payment_complete == 'Y' ? 'Yes' : 'No',
|
||||
'welfare_required' => $data->booking_welfare_required == 'Y' ? 'Yes' : 'No',
|
||||
'travel_form' => $data->tid > 0 ? 'Yes' : 'No',
|
||||
'#attributes' => array('class' => array($class)),
|
||||
);
|
||||
|
||||
if (variable_get('booking_enable_studygroups', 0) == 1) {
|
||||
foreach ($group_mapping as $group) {
|
||||
$role = $group->booking_studygroup_role;
|
||||
if ($group->booking_node_id == $data->nid && $role > 0) {
|
||||
$text = _booking_studygroup_role_lookup($role);
|
||||
$group_text .= "<b>" . $text . "</b> for " . $group->booking_studygroup_descrip . " #" . $group->booking_session_id . "; ";
|
||||
}
|
||||
}
|
||||
$options[$data->nid]['group_roles'] = $group_text;
|
||||
}
|
||||
|
||||
//$values[$data->nid] = ($data->booking_payment_complete == 'Y' || $data->booking_status != 1) ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
return $options;
|
||||
/*
|
||||
return array (
|
||||
'#type' => 'tableselect',
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
'#default_value' => $values,
|
||||
'#empty' => t('No attendees found.'),
|
||||
'#attributes' => array('id' => 'sort-table'),
|
||||
'#prefix' => '<div id="manual-email-attendees-items">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
function _booking_manual_email_selecttype_ajax_callback($form, &$form_state) {
|
||||
|
||||
|
||||
$select_type = $form_state['values']['select-type'];
|
||||
$new_default_values = array();
|
||||
$options = _booking_manual_email_generate_options();
|
||||
$header = array(
|
||||
'booking_nid' => array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'),
|
||||
'booking_name' => array('data' => t('Name'), 'field' => 'booking_lastname'),
|
||||
'booking_gender' => array('data' => t('Gender'), 'field' => 'booking_gender'),
|
||||
'booking_email' => array('data' => t('Email'), 'field' => 'booking_email'),
|
||||
'booking_state' => array('data' => t('State'), 'field' => 'booking_state'),
|
||||
'booking_status' => array('data' => t('Status'), 'field' => 'booking_status'),
|
||||
'amount_paid' => array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid'),
|
||||
'amount_reqd' => array('data' => t('Total Payment Required'), 'field' => 'booking_total_pay_reqd'),
|
||||
'booking_fully_paid' => array('data' => t('Fully paid?'), 'field' => 'booking_payment_complete'),
|
||||
'welfare_required' => array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required'),
|
||||
'travel_form' => array('data' => t('Travel Submitted?'), 'field' => 'tid'),
|
||||
);
|
||||
|
||||
// generate new default values
|
||||
// @todo use a function for this
|
||||
if ($select_type == "Unpaid") {
|
||||
$new_default_values = array("1814" => TRUE);
|
||||
} else {
|
||||
$new_default_values = array("1815" => TRUE);
|
||||
}
|
||||
|
||||
//unset($form['table']);
|
||||
|
||||
$form['new']['table'] = array (
|
||||
'#type' => 'tableselect',
|
||||
'#multiple' => TRUE,
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
'#default_value' => $new_default_values,
|
||||
'#empty' => t('No attendees found.'),
|
||||
'#attributes' => array('id' => 'sort-table'),
|
||||
'#prefix' => '<div id="manual-email-attendees-items">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' =>$new_default_values,
|
||||
);
|
||||
|
||||
// update cached options for tableselect
|
||||
$cached_form = form_get_cache($form['#build_id'], $form_state);
|
||||
$cached_form['table'] = $form['new']['table'];
|
||||
form_set_cache($form['#build_id'], $cached_form, $form_state);
|
||||
/*
|
||||
$form['table']['#options'] = $options;
|
||||
$form['table']['#header'] = $header;
|
||||
$form['table']['#default_value'] = $new_default_values;
|
||||
$form['table']['#value'] = $new_default_values;
|
||||
*/
|
||||
watchdog('booking_debug', "<pre>Manual email new form table\n@info</pre>", array('@info' => print_r( $form['new']['table'], true)));
|
||||
return form_process_tableselect($form['new']['table']);
|
||||
|
||||
$form['table'] = array (
|
||||
'#type' => 'tableselect',
|
||||
'#multiple' => TRUE,
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
'#value' => $new_default_values,
|
||||
'#default_value' => $new_default_values,
|
||||
'#empty' => t('No attendees found.'),
|
||||
'#attributes' => array('id' => 'sort-table'),
|
||||
'#prefix' => '<div id="manual-email-attendees-items">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
watchdog('booking_debug', "<pre>Manual email new form table before\n@info</pre>", array('@info' => print_r( $form['table'], true)));
|
||||
//$form['table']['#default_value'] = $new_default_values;
|
||||
$form['table'] = form_process_tableselect($form['table']);
|
||||
//$form['table']['#default_value'] = $new_default_values;
|
||||
watchdog('booking_debug', "<pre>Manual email new form table after\n@info</pre>", array('@info' => print_r( $form['table'], true)));
|
||||
return $form['table'];
|
||||
|
||||
|
||||
//$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();
|
||||
|
||||
$options = _booking_manual_email_generate_options();
|
||||
$header = array(
|
||||
'booking_nid' => array('data' => t('Id'), 'field' => 'nid', 'sort' => 'asc'),
|
||||
'booking_name' => array('data' => t('Name'), 'field' => 'booking_lastname'),
|
||||
'booking_gender' => array('data' => t('Gender'), 'field' => 'booking_gender'),
|
||||
'booking_email' => array('data' => t('Email'), 'field' => 'booking_email'),
|
||||
'booking_state' => array('data' => t('State'), 'field' => 'booking_state'),
|
||||
'booking_status' => array('data' => t('Status'), 'field' => 'booking_status'),
|
||||
'amount_paid' => array('data' => t('Payment To Date'), 'field' => 'booking_amount_paid'),
|
||||
'amount_reqd' => array('data' => t('Total Payment Required'), 'field' => 'booking_total_pay_reqd'),
|
||||
'booking_fully_paid' => array('data' => t('Fully paid?'), 'field' => 'booking_payment_complete'),
|
||||
'welfare_required' => array('data' => t('Welfare Required?'), 'field' => 'booking_welfare_required'),
|
||||
'travel_form' => array('data' => t('Travel Submitted?'), 'field' => 'tid'),
|
||||
);
|
||||
|
||||
// generate new default values
|
||||
// @todo use a function for this
|
||||
if ($select_type == "Unpaid") {
|
||||
$new_default_values = array("1814" => TRUE);
|
||||
} else {
|
||||
$new_default_values = array("1815" => TRUE);
|
||||
}
|
||||
/*
|
||||
// update cached options for tableselect
|
||||
$cached_form = form_get_cache($form['#build_id'], $form_state);
|
||||
$cached_form['table']['#options'] = $options;
|
||||
form_set_cache($form['#build_id'], $cached_form, $form_state);
|
||||
|
||||
// remove radios from tableselect
|
||||
$form['new']['table']['#options'] = $options;
|
||||
foreach (element_children($form['table']) 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']);
|
||||
watchdog('booking_debug', "<pre>Manual email new form table\n@info</pre>", array('@info' => print_r( $form['table'], true)));
|
||||
// update the tableselect
|
||||
$commands = array();
|
||||
$commands[] = ajax_command_replace('#manual-email-attendees-items', drupal_render($form['table']));
|
||||
return array('#type' => 'ajax', '#commands' => $commands);
|
||||
*/
|
||||
// update cached options for tableselect
|
||||
//$cached_form = form_get_cache($form['#build_id'], $form_state);
|
||||
//watchdog('booking_debug', "<pre>Manual email cached form for tableselect\n@info</pre>", array('@info' => print_r( $cached_form['table'], true)));
|
||||
|
||||
//unset old tableselect
|
||||
unset($form['table']);
|
||||
|
||||
// configure new tableselect based on old table select
|
||||
$form['table'] = array (
|
||||
'#type' => 'tableselect',
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
//'#default_value' => $new_default_values,
|
||||
'#empty' => t('No attendees found.'),
|
||||
'#attributes' => array('id' => 'sort-table'),
|
||||
'#prefix' => '<div id="manual-email-attendees-items">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
//unset($form_state['input']['table']);
|
||||
//$form['table']['#options'] = $options;
|
||||
|
||||
//set new default values
|
||||
//$form['table']['#default_value'] = $new_default_values;
|
||||
//form_builder($form['#form_id'], $form['table'], $form_state);
|
||||
watchdog('booking_debug', "<pre>Manual email new form table\n@info</pre>", array('@info' => print_r( $form['table'], true)));
|
||||
watchdog('booking_debug', "<pre>Manual email new default values\n@info</pre>", array('@info' => print_r( $form['table']['#default_value'], true)));
|
||||
watchdog('booking_debug', "<pre>Manual email new form array\n@info</pre>", array('@info' => print_r( $form, true)));
|
||||
|
||||
//$new_html = drupal_render($form['table']);
|
||||
watchdog('booking_debug', "<pre>Manual email rendered table\n@info</pre>", array('@info' => print_r( drupal_render($form['table'])), true));
|
||||
|
||||
// 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_form_submit($form, &$form_state) {
|
||||
$counter = 0;
|
||||
$update_messages = array();
|
||||
|
Reference in New Issue
Block a user