From e59fa2d3f8263d1b2b349ba14d6ea0c593a2791c Mon Sep 17 00:00:00 2001 From: wiredloose Date: Tue, 11 Dec 2012 09:18:39 -0600 Subject: [PATCH 1/3] renaming function names to clarify difference between reservation updates and reservations deletes and their related form functions --- ding_reservation.module | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 93a6939..9c8e0e2 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -406,11 +406,11 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#suffix' => '', '#type' => 'submit', /* '#submit' => array('ding_reservation_update_reservation_form'), */ - '#submit' => array('ding_reservation_reservations_form_submit'), + '#submit' => array('ding_reservation_updates_form_submit'), '#value' => t('Update reservations'), '#ajax' => array( - 'callback' => 'ding_reservation_reservations_form_callback', - 'wrapper' => 'ding-reservation-reservations-form', + 'callback' => 'ding_reservation_updates_form_callback', + 'wrapper' => 'ding-reservation-updates-form', ), ); } @@ -434,7 +434,7 @@ function ding_reservation_reservations_delete_submit($form, &$form_state) { /** * Submit handler for the form. */ -function ding_reservation_reservations_form_submit($form, &$form_state) { +function ding_reservation_updates_form_submit($form, &$form_state) { global $user; $ids = join(',', array_map('rawurlencode', array_filter($form_state['values']['reservations'],'is_string'))); $form_state['encoded_reservations'] = $ids; @@ -444,7 +444,7 @@ function ding_reservation_reservations_form_submit($form, &$form_state) { /** * Ajax callback. */ -function ding_reservation_reservations_form_callback($form, &$form_state) { +function ding_reservation_updates_form_callback($form, &$form_state) { global $user; $response = array( '#type' => 'ajax', From 1c5bf9cbc6fed510d50987a51a6b897c588fb7d7 Mon Sep 17 00:00:00 2001 From: wiredloose Date: Mon, 7 Jan 2013 11:41:43 +0100 Subject: [PATCH 2/3] re-implementing reservation delete functions to include a confirm pop-up in the flow --- ding_reservation.module | 125 +++++++++++++++++++++++++++++++++------- 1 file changed, 105 insertions(+), 20 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 9c8e0e2..9814095 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -34,7 +34,15 @@ function ding_reservation_menu() { 'access callback' => 'ding_reservation_access', 'access arguments' => array(1), ); - + + $items['user/%user/status/reservations/delete/%'] = array( + 'title' => 'Delete reservations', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('ding_reservation_delete_reservations_form', 1, 5), + 'access callback' => 'ding_reservation_access', + 'access arguments' => array(1), + ); + return $items; } @@ -392,12 +400,16 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( } } - $form['submit'] = array( + $form['delete'] = array( '#prefix' => '
', '#suffix' => '
', - '#submit' => array('ding_reservation_reservations_delete_submit'), + '#submit' => array('ding_reservation_deletes_form_submit'), '#type' => 'submit', '#value' => t('Delete reservations'), + '#ajax' => array( + 'callback' => 'ding_reservation_deletes_form_callback', + 'wrapper' => 'ding-reservation-reservations-form', + ), ); if ($type == 'not_ready_for_pickup') { @@ -418,22 +430,16 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( return $form; } -function ding_reservation_reservations_delete_submit($form, &$form_state) { +/** + * Submit handlers for the reservations form. + */ +function ding_reservation_deletes_form_submit($form, &$form_state) { global $user; - if (!empty($form_state['triggering_element']['#reservation_id'])) { - $reservations = array($form_state['triggering_element']['#reservation_id']); - } - else { - $reservations = array_filter($form_state['values']['reservations']); - } - foreach ($reservations as $entity_id) { - ding_provider_invoke('reservation', 'delete', $user, $entity_id); - } + $ids = join(',', array_map('rawurlencode', array_filter($form_state['values']['reservations'],'is_string'))); + $form_state['encoded_reservations'] = $ids; + $form_state['redirect'] = array('user/' . $user->uid . '/status/reservations/delete/' . $ids, array('query' => drupal_get_destination())); } -/** - * Submit handler for the form. - */ function ding_reservation_updates_form_submit($form, &$form_state) { global $user; $ids = join(',', array_map('rawurlencode', array_filter($form_state['values']['reservations'],'is_string'))); @@ -442,8 +448,24 @@ function ding_reservation_updates_form_submit($form, &$form_state) { } /** - * Ajax callback. + * Ajax callbacks. */ +function ding_reservation_deletes_form_callback($form, &$form_state) { + global $user; + $response = array( + '#type' => 'ajax', + '#commands' => array(), + ); + + $html = theme('status_messages'); + $html .= drupal_render(drupal_get_form('ding_reservation_delete_reservations_form', $user, $form_state['encoded_reservations'])); + + if ($html) { + $response['#commands'][] = ajax_command_ding_popup('ding_reservation', t('Delete reservations'), $html, array('refresh' => TRUE)); + } + return $response; +} + function ding_reservation_updates_form_callback($form, &$form_state) { global $user; $response = array( @@ -460,6 +482,45 @@ function ding_reservation_updates_form_callback($form, &$form_state) { return $response; } +/** + * Delete reservations form. + */ +function ding_reservation_delete_reservations_form($form, $form_state, $account, $reservation_ids) { + global $user; + $ids = array_map('rawurldecode', explode(',', $reservation_ids)); + + $form_state['cache'] = TRUE; + + $form['reservations'] = array( + '#type' => 'value', + '#value' => $ids, + ); + + $form['confirm_text'] = array( + '#markup' => '
' . t('Are you sure you want to delete these reservations?') . '
', + ); + + $form['submit'] = array( + '#type' => 'submit', + '#submit' => array('ding_reservation_delete_reservations_form_submit'), + '#ajax' => array( + 'callback' => 'ding_reservation_delete_reservations_form_callback', + 'wrapper' => 'ding-reservation-delete-reservation-form', + ), + '#value' => t('Yes'), + '#name' => 'delete_reservations', + ); + + $form['cancel'] = array( + '#type' => 'link', + '#title' => t('Cancel'), + '#href' => 'user/' . $user->uid . '/status/reservations', + '#value' => t('Cancel'), + ); + + return $form; +} + /** * Update reservations form. */ @@ -528,18 +589,42 @@ function ding_reservation_update_reservations_form_validate($form, &$form_state) } /** - * Submit handler. + * Submit handlers. * - * Updates selected reservations. */ +function ding_reservation_delete_reservations_form_submit($form, &$form_state) { + global $user; + if (!empty($form_state['triggering_element']['#reservation_id'])) { + $reservations = array($form_state['triggering_element']['#reservation_id']); + } + else { + $reservations = array_filter($form_state['values']['reservations']); + } + foreach ($reservations as $entity_id) { + ding_provider_invoke('reservation', 'delete', $user, $entity_id); + } +} + function ding_reservation_update_reservations_form_submit($form, &$form_state) { global $user; ding_provider_invoke('reservation', 'update', $user, $form_state['values']['reservations'], $form_state['values']['provider_options']); } /** - * Ajax callback function. + * Ajax callback functions. */ +function ding_reservation_delete_reservations_form_callback($form, &$form_state) { + $response = array( + '#type' => 'ajax', + '#commands' => array(), + ); + + $html = theme('status_messages') . t('Your reservations have been deleted.'); + $response['#commands'][] = ajax_command_ding_popup('ding_reservation', t('Delete reservations'), $html, array('refresh' => TRUE)); + + return $response; +} + function ding_reservation_update_reservations_form_callback($form, &$form_state) { $response = array( '#type' => 'ajax', From d350730bc8a4115de446f6720ae1498389056e1d Mon Sep 17 00:00:00 2001 From: Ewan Andreasen Date: Wed, 6 Feb 2013 12:34:00 +0100 Subject: [PATCH 3/3] re-implementing row delete button's submit handler --- ding_reservation.module | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 9814095..2d8469e 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -312,7 +312,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#prefix' => '
', '#suffix' => '
', '#type' => 'submit', - '#submit' => array('ding_reservation_reservations_delete_submit'), + '#submit' => array('ding_reservation_reservation_delete_submit'), '#reservation_id' => $item->id, '#name' => 'delete-' . preg_replace('/\W/', '-', $item->id), // Need this for formAPI can tell buttons apart '#value' => t('Delete'), @@ -371,7 +371,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#prefix' => '
', '#suffix' => '
', '#type' => 'submit', - '#submit' => array('ding_reservation_reservations_delete_submit'), + '#submit' => array('ding_reservation_reservation_delete_submit'), '#reservation_id' => $item->id, '#name' => 'delete-' . preg_replace('/\W/', '-', $item->id), // Need this for formAPI can tell buttons apart '#value' => t('Delete'), @@ -431,7 +431,23 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( } /** - * Submit handlers for the reservations form. + * Submit handler for the reservations form. + */ +function ding_reservation_reservation_delete_submit($form, &$form_state) { + global $user; + if (!empty($form_state['triggering_element']['#reservation_id'])) { + $reservations = array($form_state['triggering_element']['#reservation_id']); + } + else { + $reservations = array_filter($form_state['values']['reservations']); + } + foreach ($reservations as $entity_id) { + ding_provider_invoke('reservation', 'delete', $user, $entity_id); + } +} + +/** + * Submit handler for the delete form. */ function ding_reservation_deletes_form_submit($form, &$form_state) { global $user; @@ -440,6 +456,9 @@ function ding_reservation_deletes_form_submit($form, &$form_state) { $form_state['redirect'] = array('user/' . $user->uid . '/status/reservations/delete/' . $ids, array('query' => drupal_get_destination())); } +/** + * Submit handler for the update form. + */ function ding_reservation_updates_form_submit($form, &$form_state) { global $user; $ids = join(',', array_map('rawurlencode', array_filter($form_state['values']['reservations'],'is_string'))); @@ -448,7 +467,7 @@ function ding_reservation_updates_form_submit($form, &$form_state) { } /** - * Ajax callbacks. + * Ajax callback for the delete form. */ function ding_reservation_deletes_form_callback($form, &$form_state) { global $user; @@ -466,6 +485,9 @@ function ding_reservation_deletes_form_callback($form, &$form_state) { return $response; } +/** + * Ajax callback for the update form. + */ function ding_reservation_updates_form_callback($form, &$form_state) { global $user; $response = array(