From 1ab722adc7544e10d477161fea5f1c7d33d075eb Mon Sep 17 00:00:00 2001 From: Ulrich Christensen Date: Wed, 15 Aug 2012 14:34:47 +0200 Subject: [PATCH 001/125] ding2 -> ding2tal --- ding_reservation.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index d6c6336..78c325e 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -10,20 +10,20 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" -projects[ding_base][download][url] = "git@github.com:ding2/ding_base.git" +projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" projects[ding_base][download][tag] = "7.x-0.4" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" -projects[ding_popup][download][url] = "git@github.com:ding2/ding_popup.git" +projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" projects[ding_popup][download][tag] = "7.x-0.4" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" -projects[ding_user][download][url] = "git@github.com:ding2/ding_user.git" +projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" projects[ding_user][download][tag] = "7.x-0.19" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" -projects[ding_provider][download][url] = "git@github.com:ding2/ding_provider.git" +projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" projects[ding_provider][download][tag] = "7.x-0.13" From 46d3b099b443e53fc378501aec952aea32218e21 Mon Sep 17 00:00:00 2001 From: Ulrich Christensen Date: Mon, 27 Aug 2012 10:09:56 -0500 Subject: [PATCH 002/125] tag -> branch --- ding_reservation.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index 78c325e..d8398f6 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -11,19 +11,19 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" -projects[ding_base][download][tag] = "7.x-0.4" +projects[ding_base][download][branch] = "development" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" -projects[ding_popup][download][tag] = "7.x-0.4" +projects[ding_popup][download][branch] = "development" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" -projects[ding_user][download][tag] = "7.x-0.19" +projects[ding_user][download][branch] = "development" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-0.13" +projects[ding_provider][download][branch] = "development" From 4f040ad902ba9b11827dd378e83cfeb0a3d649de Mon Sep 17 00:00:00 2001 From: yusuf amer Date: Tue, 4 Dec 2012 14:45:37 +0100 Subject: [PATCH 003/125] fixed reserved message (it is set to getProviderId() instead of getTitle()) --- ding_reservation.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index 93a6939..44e0772 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -207,7 +207,7 @@ function ding_reservation_reserve_form_submit($form, &$form_state) { drupal_set_message(t('"@title" reserved and will be available for pickup at @branch.', array('@title' => $reservable->getTitle(), '@branch' => $branch_name))); } else { - drupal_set_message(t('"@title" reserved.', array('@title' => $reservable->getProviderId()))); + drupal_set_message(t('"@title" reserved.', array('@title' => $reservable->getTitle()))); } if (is_array($reservation_result) and !empty($reservation_result['queue_number'])) { From b2eea1c6d6d462f58ecb42bba0925ce1d39689f8 Mon Sep 17 00:00:00 2001 From: wiredloose Date: Thu, 31 Jan 2013 12:13:18 +0100 Subject: [PATCH 004/125] 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 44e0772..c1b93c8 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 d64bc89ca3712754be03988e18f3ef3f4cf0b309 Mon Sep 17 00:00:00 2001 From: wiredloose Date: Thu, 31 Jan 2013 12:13:49 +0100 Subject: [PATCH 005/125] 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 c1b93c8..8d4ba06 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 6979ed708f1c103806121769d5f2c422543a27fd Mon Sep 17 00:00:00 2001 From: wiredloose Date: Wed, 6 Feb 2013 12:41:41 +0100 Subject: [PATCH 006/125] 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 8d4ba06..ec8e0be 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( From d41bd9be1e9eccbe39d9a443698f68141c818c0c Mon Sep 17 00:00:00 2001 From: Rasmus Frey Date: Fri, 15 Mar 2013 15:34:11 +0100 Subject: [PATCH 007/125] Added a submit button to the top of the form, made in a hurry just before leaving work on a friday. --- ding_reservation.module | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index ec8e0be..bdd0953 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -400,7 +400,42 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( } } - $form['delete'] = array( + $form['actions_top'] = array( + '#weight' => -10, + ); + + $form['actions_top']['delete_first'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#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') { + $form['actions_top']['update_first'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'submit', + /* '#submit' => array('ding_reservation_update_reservation_form'), */ + '#submit' => array('ding_reservation_updates_form_submit'), + '#value' => t('Update reservations'), + '#ajax' => array( + 'callback' => 'ding_reservation_updates_form_callback', + 'wrapper' => 'ding-reservation-updates-form', + ), + ); + } + + $form['actions_bottom'] = array( + '#weight' => 10, + ); + + $form['actions_bottom']['delete_second'] = array( '#prefix' => '
', '#suffix' => '
', '#submit' => array('ding_reservation_deletes_form_submit'), @@ -413,7 +448,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( ); if ($type == 'not_ready_for_pickup') { - $form['update'] = array( + $form['actions_bottom']['update_second'] = array( '#prefix' => '
', '#suffix' => '
', '#type' => 'submit', From 9b3173e2823d22d993e481d38f0d705b3e901326 Mon Sep 17 00:00:00 2001 From: "Jorgen G. Nielsen" Date: Thu, 1 Mar 2012 16:14:21 +0100 Subject: [PATCH 008/125] Added handling of order_arrived == false in reservation list --- ding_reservation.module | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index bdd0953..cb62209 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -321,21 +321,30 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'class' => 'operations', ), ); - if (isset($item->pickup_order_id)) { + if (isset($item->order_arrived) && !$item->order_arrived) { $options[$item->id]['title']['data'][] = array( '#type' => 'markup', - '#prefix' => '

', - '#markup' => t('(Pickup id: @pickup_id)', array('@pickup_id' => check_plain($item->pickup_order_id))), - '#suffix' => '

', - ); - } - if (!isset($item->pickup_order_id) && isset($item->order_id)) { - $options[$item->id]['title']['data'][] = array( - '#type' => 'markup', - '#prefix' => '

', - '#markup' => t('(Order no. @order_id)', array('@order_id' => check_plain($item->order_id))), + '#prefix' => '

', + '#markup' => t('The material is in transit and is still not available for loan on the library'), '#suffix' => '

', ); + } else { + if (isset($item->pickup_order_id)) { + $options[$item->id]['title']['data'][] = array( + '#type' => 'markup', + '#prefix' => '

', + '#markup' => t('(Pickup id: @pickup_id)', array('@pickup_id' => check_plain($item->pickup_order_id))), + '#suffix' => '

', + ); + } + if (!isset($item->pickup_order_id) && isset($item->order_id)) { + $options[$item->id]['title']['data'][] = array( + '#type' => 'markup', + '#prefix' => '

', + '#markup' => t('(Order no. @order_id)', array('@order_id' => check_plain($item->order_id))), + '#suffix' => '

', + ); + } } $form['reservations'] = array( '#type' => 'tableselect_form', From 2774add98c1260629698af7e5033ce26ddebc6d2 Mon Sep 17 00:00:00 2001 From: AnatolyMuntean Date: Fri, 7 Sep 2012 17:51:58 +0300 Subject: [PATCH 009/125] Fixed merge conflict from PH libraries --- ding_reservation.module | 45 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index cb62209..b557c23 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -287,6 +287,9 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( } foreach ($items as $id => $item) { $entity = $item->entity; + if (!is_object($entity)) { + $entity = ding_reservation_replace_entity($item->ding_entity_id); + } $pickup_branch = ding_provider_invoke('reservation', 'branch_name', $item->pickup_branch_id); switch ($type) { case 'ready_for_pickup': @@ -474,10 +477,50 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( return $form; } +/** + * Create a dummy ting entity object, when item is not found in the ting well. + * Fill in data using info fetched from certain provider. + * + * @param $entity_id + * Ting object id. + * @return + * A TingEntity object or FALSE if provider failed to fetch the data. + */ +function ding_reservation_replace_entity($entity_id) { + // @todo + // Implement openruth fallback. + $faust_number = explode(':', $entity_id); + $faust_number = $faust_number[1]; + + $alma_object = alma_client_invoke('catalogue_record_detail', $faust_number); + if ($alma_object['request_status'] == 'ok' && isset($alma_object['records'][$faust_number])) { + $source = $alma_object['records'][$faust_number]; + $pseudo_ting_object = new TingEntity(); + $pseudo_ting_object->ding_entity_id = $entity_id; + $pseudo_ting_object->reply = new TingClientObject(); + $pseudo_ting_object->reply->record['dc:title']['dkdcplus:full'] = array($source['titles'][0]); + $pseudo_ting_object->reply->record['dc:type']['dkdcplus:BibDK-Type'] = array($source['media_class']); + // @todo + // Author from provider. + $pseudo_ting_object->reply->record['dc:creator']['dkdcplus:aut'] = array(''); + $pseudo_ting_object->reply->record['dc:date'][''] = array($source['publication_year']); + $pseudo_ting_object->ting_title = array(LANGUAGE_NONE => array(array('id' => $entity_id))); + $pseudo_ting_object->ting_type = array(LANGUAGE_NONE => array(array('id' => $entity_id))); + $pseudo_ting_object->ting_author = array(LANGUAGE_NONE => array(array('id' => $entity_id))); + $pseudo_ting_object->ting_cover = array(LANGUAGE_NONE => array(array('id' => $entity_id))); + $pseudo_ting_object->ding_entity_type = 'ding_entity'; + $pseudo_ting_object->provider_id = $faust_number; + + return $pseudo_ting_object; + } + + return FALSE; +} + /** * Submit handler for the reservations form. */ -function ding_reservation_reservation_delete_submit($form, &$form_state) { +function ding_reservation_reservations_delete_submit($form, &$form_state) { global $user; if (!empty($form_state['triggering_element']['#reservation_id'])) { $reservations = array($form_state['triggering_element']['#reservation_id']); From de64ee682536a9dc74823a26b0f1ccebe225a53b Mon Sep 17 00:00:00 2001 From: Dragan Date: Wed, 26 Sep 2012 15:05:41 +0300 Subject: [PATCH 010/125] case-559 - Refactoring of calling alma-openruth instances. --- ding_reservation.module | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index b557c23..68fe698 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -98,6 +98,9 @@ function ding_reservation_ding_provider_user() { * function, use this to let have their own form id. */ function ding_reservation_forms($form_id, $args) { +//var_dump($args); +//debug_print_backtrace(); +//die(); $forms['ding_reservation_reservations_ready_form'] = array( 'callback' => 'ding_reservation_reservations_form', ); @@ -288,8 +291,9 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( foreach ($items as $id => $item) { $entity = $item->entity; if (!is_object($entity)) { - $entity = ding_reservation_replace_entity($item->ding_entity_id); + $entity = ding_reservation_replace_entity($item); } + $pickup_branch = ding_provider_invoke('reservation', 'branch_name', $item->pickup_branch_id); switch ($type) { case 'ready_for_pickup': @@ -486,35 +490,9 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( * @return * A TingEntity object or FALSE if provider failed to fetch the data. */ -function ding_reservation_replace_entity($entity_id) { - // @todo - // Implement openruth fallback. - $faust_number = explode(':', $entity_id); - $faust_number = $faust_number[1]; - - $alma_object = alma_client_invoke('catalogue_record_detail', $faust_number); - if ($alma_object['request_status'] == 'ok' && isset($alma_object['records'][$faust_number])) { - $source = $alma_object['records'][$faust_number]; - $pseudo_ting_object = new TingEntity(); - $pseudo_ting_object->ding_entity_id = $entity_id; - $pseudo_ting_object->reply = new TingClientObject(); - $pseudo_ting_object->reply->record['dc:title']['dkdcplus:full'] = array($source['titles'][0]); - $pseudo_ting_object->reply->record['dc:type']['dkdcplus:BibDK-Type'] = array($source['media_class']); - // @todo - // Author from provider. - $pseudo_ting_object->reply->record['dc:creator']['dkdcplus:aut'] = array(''); - $pseudo_ting_object->reply->record['dc:date'][''] = array($source['publication_year']); - $pseudo_ting_object->ting_title = array(LANGUAGE_NONE => array(array('id' => $entity_id))); - $pseudo_ting_object->ting_type = array(LANGUAGE_NONE => array(array('id' => $entity_id))); - $pseudo_ting_object->ting_author = array(LANGUAGE_NONE => array(array('id' => $entity_id))); - $pseudo_ting_object->ting_cover = array(LANGUAGE_NONE => array(array('id' => $entity_id))); - $pseudo_ting_object->ding_entity_type = 'ding_entity'; - $pseudo_ting_object->provider_id = $faust_number; - - return $pseudo_ting_object; - } - - return FALSE; +function ding_reservation_replace_entity($item) { + $provider = _ding_provider_get_provider(); + return call_user_func($provider['reservation']['module'] . '_replace_entity', $item); } /** From cbb48803fa117e913aad54e20b8b780fa79834f0 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 20 Mar 2013 12:03:07 +0100 Subject: [PATCH 011/125] Removed debug statements --- ding_reservation.module | 3 --- 1 file changed, 3 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 68fe698..6ba7f6f 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -98,9 +98,6 @@ function ding_reservation_ding_provider_user() { * function, use this to let have their own form id. */ function ding_reservation_forms($form_id, $args) { -//var_dump($args); -//debug_print_backtrace(); -//die(); $forms['ding_reservation_reservations_ready_form'] = array( 'callback' => 'ding_reservation_reservations_form', ); From 2fd1f28f2350c23590e9897da43c9804e3f59c2f Mon Sep 17 00:00:00 2001 From: AnatolyMuntean Date: Fri, 5 Oct 2012 14:36:36 +0300 Subject: [PATCH 012/125] Resolved merge conflict in inter library loans --- ding_reservation.module | 63 ++++++++++++++++++- .../reservations/reservations.inc | 25 +++++--- 2 files changed, 76 insertions(+), 12 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 6ba7f6f..9f6fe51 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -97,13 +97,18 @@ function ding_reservation_ding_provider_user() { * to be able to tell which was submitted. As we're using one builder * function, use this to let have their own form id. */ -function ding_reservation_forms($form_id, $args) { +function ding_reservation_forms($form_id, $args) { $forms['ding_reservation_reservations_ready_form'] = array( 'callback' => 'ding_reservation_reservations_form', ); + $forms['ding_reservation_reservations_notready_form'] = array( 'callback' => 'ding_reservation_reservations_form', ); + + $forms['ding_reservation_reservations_ill'] = array( + 'callback' => 'ding_reservation_reservations_form', + ); return $forms; } @@ -272,7 +277,8 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'operations' => '', ); uasort($items, 'ding_reservation_sort_queue_by_pickup_date'); - break; + break; + case 'not_ready_for_pickup': $header = array( 'title' => t('Title'), @@ -283,7 +289,17 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'operations' => '', ); uasort($items, 'ding_reservation_sort_queue_by_queue_number'); - break; + break; + + case 'interlibrary_loans': + $header = array( + 'title' => t('Title'), + 'created' => t('Created date'), + 'expiry' => t('Expiry date'), + 'library' => t('Library'), + 'ill_status' => t('Status'), + ); + break; } foreach ($items as $id => $item) { $entity = $item->entity; @@ -357,6 +373,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#empty' => t('No reservations ready for pickup'), ); break; + case 'not_ready_for_pickup': $options[$item->id] = array( 'title' => array( @@ -410,6 +427,46 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#empty' => t('No Reservations'), ); break; + case 'interlibrary_loans': + $options[$item->id] = array( + 'title' => array( + 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), + 'class' => 'title', + ), + 'created' => array( + 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'date_only') : '', + 'class' => 'created-date', + ), + 'expiry' => array( + 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'date_only') : '', + 'class' => 'expire-date', + ), + 'library' => array( + 'data' => $pickup_branch ? check_plain($pickup_branch) : '', + 'class' => 'pickup-branch', + ), + 'ill_status' => array( + 'data' => $item->ill_status ? check_plain($item->ill_status) : '', + 'class' => 'ill-status', + ), + ); + + if (isset($item->order_id)) { + $options[$item->id]['title']['data'][] = array( + '#type' => 'markup', + '#prefix' => '

', + '#markup' => t('(Order no. @order_id)', array('@order_id' => check_plain($item->order_id))), + '#suffix' => '

', + ); + } + + $form['reservations'] = array( + '#type' => 'tableselect_form', + '#header' => $header, + '#options' => $options, + '#empty' => t('No inter-library loans'), + ); + break; } } diff --git a/plugins/content_types/reservations/reservations.inc b/plugins/content_types/reservations/reservations.inc index 34eecdf..c6c40d1 100644 --- a/plugins/content_types/reservations/reservations.inc +++ b/plugins/content_types/reservations/reservations.inc @@ -18,12 +18,12 @@ $plugin = array( */ function ding_reservation_reservations_content_type_render($subtype, $conf, $panel_args, $context) { static $preload_reservations = TRUE; - $account = isset($context->data) ? $context->data : NULL; - $preload_ids = array(); - $items = array(); - $reservation_list = array(); + $account = isset($context->data) ? $context->data : NULL; + $preload_ids = array(); + $items = array(); + $reservation_list = array(); - $block = new stdClass(); + $block = new stdClass(); $block->module = 'ding_reservation'; $block->delta = 'reservations'; @@ -32,13 +32,19 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan $block->title = t('Reservations ready for pickup'); $no_reservation_text = t('There are no reservations ready for pickup.'); $form_id = 'ding_reservation_reservations_ready_form'; - break; + break; + default: case 'not_ready_for_pickup': $block->title = t('Reservations'); $no_reservation_text = t('There are no reservations.'); $form_id = 'ding_reservation_reservations_notready_form'; - break; + break; + + case 'interlibrary_loans': + $block->title = t('Interlibrary loans'); + $no_reservation_text = t('There are no interlibrary loans.'); + $form_id = 'ding_reservation_reservations_ill'; } $list = ding_provider_invoke_page('reservation', 'list', $account); @@ -48,7 +54,7 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan $preload_ids[] = $item->ding_entity_id; } if (isset($conf['reservation_type_list'])) { - if ($conf['reservation_type_list'] == 'ready_for_pickup' && $item->ready_for_pickup == TRUE || $conf['reservation_type_list'] == 'not_ready_for_pickup' && $item->ready_for_pickup == FALSE) { + if (($conf['reservation_type_list'] == 'ready_for_pickup' && $item->ready_for_pickup === 1) || ($conf['reservation_type_list'] == 'not_ready_for_pickup' && $item->ready_for_pickup === 0) || ($conf['reservation_type_list'] == 'interlibrary_loans' && isset($item->ill_status))) { $reservation_list[] = $item; } } @@ -72,7 +78,8 @@ function ding_reservation_reservations_content_type_edit_form($form, &$form_stat '#title' => t('Reservation list type'), '#options' => array( 'not_ready_for_pickup' => t('Not ready for pickup'), - 'ready_for_pickup' => t('Ready for pickup'), + 'ready_for_pickup' => t('Ready for pickup'), + 'interlibrary_loans' => t('Interlibrary loans'), ), '#default_value' => !empty($conf['reservation_type_list']) ? $conf['reservation_type_list'] : NULL, ); From 7afd9f54117603ec8d4a67834e5e8037b138a4cb Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 20 Mar 2013 12:53:43 +0100 Subject: [PATCH 013/125] Show pickup id in a separate column --- ding_reservation.module | 81 +++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 9f6fe51..90bb781 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -271,6 +271,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( case 'ready_for_pickup': $header = array( 'title' => t('Title'), + 'pickup_id' => t('Pickup id'), 'created' => t('Created date'), 'pickup_date' => t('Pickup date'), 'pickup_branch' => t('Pickup branch'), @@ -282,6 +283,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( case 'not_ready_for_pickup': $header = array( 'title' => t('Title'), + 'pickup_id' => t('Pickup id'), 'created' => t('Created date'), 'expiry' => t('Expiry date'), 'pickup_branch' => t('Pickup branch'), @@ -294,6 +296,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( case 'interlibrary_loans': $header = array( 'title' => t('Title'), + 'pickup_id' => t('Pickup id'), 'created' => t('Created date'), 'expiry' => t('Expiry date'), 'library' => t('Library'), @@ -301,6 +304,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( ); break; } + foreach ($items as $id => $item) { $entity = $item->entity; if (!is_object($entity)) { @@ -315,6 +319,10 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), 'class' => 'title', ), + 'pickup_id' =>array( + 'data' => ding_reservation_get_pickup_id($item), + 'class' => 'pickup-id', + ), 'created' => array( 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'date_only') : '', 'class' => 'created-date', @@ -341,31 +349,16 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'class' => 'operations', ), ); - if (isset($item->order_arrived) && !$item->order_arrived) { + + if (!empty($item->notes)) { $options[$item->id]['title']['data'][] = array( '#type' => 'markup', - '#prefix' => '

', - '#markup' => t('The material is in transit and is still not available for loan on the library'), + '#prefix' => '

', + '#markup' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($item->notes))), '#suffix' => '

', ); - } else { - if (isset($item->pickup_order_id)) { - $options[$item->id]['title']['data'][] = array( - '#type' => 'markup', - '#prefix' => '

', - '#markup' => t('(Pickup id: @pickup_id)', array('@pickup_id' => check_plain($item->pickup_order_id))), - '#suffix' => '

', - ); - } - if (!isset($item->pickup_order_id) && isset($item->order_id)) { - $options[$item->id]['title']['data'][] = array( - '#type' => 'markup', - '#prefix' => '

', - '#markup' => t('(Order no. @order_id)', array('@order_id' => check_plain($item->order_id))), - '#suffix' => '

', - ); - } } + $form['reservations'] = array( '#type' => 'tableselect_form', '#header' => $header, @@ -380,6 +373,10 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), 'class' => 'title', ), + 'pickup_id' =>array( + 'data' => ding_reservation_get_pickup_id($item), + 'class' => 'pickup-id', + ), 'created' => array( 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'date_only') : '', 'class' => 'created-date', @@ -410,12 +407,12 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'class' => 'operations', ), ); - - if (isset($item->order_id)) { + + if (!empty($item->notes)) { $options[$item->id]['title']['data'][] = array( '#type' => 'markup', - '#prefix' => '

', - '#markup' => t('(Order no. @order_id)', array('@order_id' => check_plain($item->order_id))), + '#prefix' => '

', + '#markup' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($item->notes))), '#suffix' => '

', ); } @@ -427,12 +424,17 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#empty' => t('No Reservations'), ); break; + case 'interlibrary_loans': $options[$item->id] = array( 'title' => array( 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), 'class' => 'title', ), + 'pickup_id' =>array( + 'data' => ding_reservation_get_pickup_id($item), + 'class' => 'pickup-id', + ), 'created' => array( 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'date_only') : '', 'class' => 'created-date', @@ -451,11 +453,11 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( ), ); - if (isset($item->order_id)) { + if (!empty($item->notes)) { $options[$item->id]['title']['data'][] = array( '#type' => 'markup', - '#prefix' => '

', - '#markup' => t('(Order no. @order_id)', array('@order_id' => check_plain($item->order_id))), + '#prefix' => '

', + '#markup' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($item->notes))), '#suffix' => '

', ); } @@ -535,6 +537,31 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( return $form; } +/** + * Get pickup id number. + * + * @param $item + * Reserved item object. + * @return type + * Pickup id, if any. + */ +function ding_reservation_get_pickup_id($item) { + if (isset($item->order_arrived) && !$item->order_arrived) { + return t('The material is in transit and is still not available for loan on the library'); + } + else { + if (!isset($item->pickup_order_id) && isset($item->order_id)) { + return $item->order_id; + } + elseif (isset($item->pickup_order_id)) { + return $item->pickup_order_id; + } + else { + return t('On route') . ' ' . l('(?)', current_path(), array('attributes' => array('title' => t('The material is on route to the library. You will be notified when it is ready for pickup.')))); + } + } +} + /** * Create a dummy ting entity object, when item is not found in the ting well. * Fill in data using info fetched from certain provider. From 1b936d479270f6bdb05ffe30335baed87ae14841 Mon Sep 17 00:00:00 2001 From: AnatolyMuntean Date: Tue, 13 Nov 2012 11:33:04 +0200 Subject: [PATCH 014/125] case 1510 - Interest period field validation and display logic. --- ding_reservation.module | 44 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 90bb781..7253c7a 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -180,6 +180,7 @@ function ding_reservation_reserve_form_validate($form, &$form_state) { * result. */ $provider_options = array(); + $provider = ding_provider_get_provider_module_name('reservation'); foreach ($res as $key => $value) { if (is_array($value) && !empty($value['#error'])) { if (!$form_state['options_hidden']) { @@ -188,6 +189,15 @@ function ding_reservation_reserve_form_validate($form, &$form_state) { } else { // Else simply rebuild the form. + $removal = ''; + if ($key == $provider . '_preferred_branch') { + $removal = $provider . '_interest_period'; + } + elseif ($key == $provider . '_interest_period') { + $removal = $provider . '_preferred_branch'; + } + + $form_state['removable'] = $removal; $form_state['rebuild'] = TRUE; } } @@ -252,6 +262,12 @@ function ding_reservation_reserve_form_callback($form, &$form_state) { $html = theme('status_messages'); if ($form_state['rebuild'] || form_get_errors()) { + // Hide certain fields, if any. + if (!empty($form_state['removable'])) { + $removal = $form_state['removable']; + unset($form['provider_options'][$removal]); + unset($form['provider_options'][$removal . 'description']); + } // Redisplay form. $html .= drupal_render($form); } @@ -867,9 +883,33 @@ function ding_reservation_interest_period_selector($type, $name, $default, $opti */ function ding_reservation_default_options_branch_validate($type, $name, $default, $values) { if (empty($values[$name])) { + $provider = ding_provider_get_provider_module_name('reservation'); + if ($type == 'create' && empty($default)) { + $result[$provider . '_preferred_branch'] = array( + '#error' => t('You must select a branch'), + ); + } + else { + $result[$name] = $default; + } + return $result; + } + else { + return $values; + } +} + +/** + * Validate interest period selector. + * + * Returns what ding_reservation expects. + */ +function ding_reservation_default_options_interest_period_validate($type, $name, $default, $values) { + if (empty($values[$name])) { + $provider = ding_provider_get_provider_module_name('reservation'); if ($type == 'create' && empty($default)) { - $result['openruth_preferred_branch'] = array( - '#error' => 'You must select a branch', + $result[$provider . '_interest_period'] = array( + '#error' => t('You must select an interest period'), ); } else { From 718d71692adb1f20e4d77ab291067105c3d0c195 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 20 Mar 2013 13:07:22 +0100 Subject: [PATCH 015/125] Corrected order and pickup id --- ding_reservation.module | 49 ++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 7253c7a..d940368 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -299,7 +299,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( case 'not_ready_for_pickup': $header = array( 'title' => t('Title'), - 'pickup_id' => t('Pickup id'), + 'order_nr' => t('Order nr.'), 'created' => t('Created date'), 'expiry' => t('Expiry date'), 'pickup_branch' => t('Pickup branch'), @@ -335,8 +335,8 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), 'class' => 'title', ), - 'pickup_id' =>array( - 'data' => ding_reservation_get_pickup_id($item), + 'order_nr' =>array( + 'data' => ding_reservation_get_order_nr($item), 'class' => 'pickup-id', ), 'created' => array( @@ -554,29 +554,38 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( } /** - * Get pickup id number. - * - * @param $item - * Reserved item object. - * @return type - * Pickup id, if any. - */ +* Get pickup id number. +* +* @param $item +* Reserved item object. +* @return +* Pickup id, if any. +*/ function ding_reservation_get_pickup_id($item) { if (isset($item->order_arrived) && !$item->order_arrived) { return t('The material is in transit and is still not available for loan on the library'); } + elseif (isset($item->pickup_order_id)) { + return $item->pickup_order_id; + } +} + +/** +* Get order id number. +* +* @param $item +* Reserved item object. +* @return +* Order number, if any. +*/ +function ding_reservation_get_order_nr($item) { + if (!isset($item->pickup_order_id) && isset($item->order_id)) { + return $item->order_id; + } else { - if (!isset($item->pickup_order_id) && isset($item->order_id)) { - return $item->order_id; - } - elseif (isset($item->pickup_order_id)) { - return $item->pickup_order_id; - } - else { - return t('On route') . ' ' . l('(?)', current_path(), array('attributes' => array('title' => t('The material is on route to the library. You will be notified when it is ready for pickup.')))); - } + return t('On route') . ' ' . l('(?)', current_path(), array('attributes' => array('title' => t('The material is on route to the library. You will be notified when it is ready for pickup.')))); } -} +} /** * Create a dummy ting entity object, when item is not found in the ting well. From 513b689e6298d23833b080769f99b22562283b51 Mon Sep 17 00:00:00 2001 From: AnatolyMuntean Date: Tue, 20 Nov 2012 12:06:23 +0200 Subject: [PATCH 016/125] case 1510 - Improved check for empty profile fields when reserving. --- ding_reservation.module | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index d940368..6f65616 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -181,6 +181,7 @@ function ding_reservation_reserve_form_validate($form, &$form_state) { */ $provider_options = array(); $provider = ding_provider_get_provider_module_name('reservation'); + $removal = array(); foreach ($res as $key => $value) { if (is_array($value) && !empty($value['#error'])) { if (!$form_state['options_hidden']) { @@ -189,14 +190,18 @@ function ding_reservation_reserve_form_validate($form, &$form_state) { } else { // Else simply rebuild the form. - $removal = ''; if ($key == $provider . '_preferred_branch') { - $removal = $provider . '_interest_period'; + $removal[] = $provider . '_interest_period'; } elseif ($key == $provider . '_interest_period') { - $removal = $provider . '_preferred_branch'; + $removal[] = $provider . '_preferred_branch'; } - + + // In case both fields are not set, remove nothing. + if (count($removal) == 2) { + $removal = array(); + } + $form_state['removable'] = $removal; $form_state['rebuild'] = TRUE; } @@ -263,10 +268,13 @@ function ding_reservation_reserve_form_callback($form, &$form_state) { $html = theme('status_messages'); if ($form_state['rebuild'] || form_get_errors()) { // Hide certain fields, if any. - if (!empty($form_state['removable'])) { + if (is_array($form_state['removable'])) { $removal = $form_state['removable']; - unset($form['provider_options'][$removal]); - unset($form['provider_options'][$removal . 'description']); + foreach ($removal as $v) { + unset($form['provider_options'][$v]); + unset($form['provider_options'][$v . 'description']); + } + } // Redisplay form. $html .= drupal_render($form); From 9e7eb833040e3bbff6ef43928c3dd58e74f19fd8 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 20 Mar 2013 13:10:15 +0100 Subject: [PATCH 017/125] Mising return, caused fatal errors with operand types on form build --- ding_reservation.module | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ding_reservation.module b/ding_reservation.module index 6f65616..459a0b8 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -576,6 +576,8 @@ function ding_reservation_get_pickup_id($item) { elseif (isset($item->pickup_order_id)) { return $item->pickup_order_id; } + + return ''; } /** From 28d7a0bcf7887b54d6c7b5d2a9a739d4c9d6502a Mon Sep 17 00:00:00 2001 From: lexor Date: Fri, 30 Nov 2012 16:51:52 +0200 Subject: [PATCH 018/125] case 1495 - Better hadnling of return values and properties. --- ding_reservation.module | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index 459a0b8..cb883c9 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -173,6 +173,11 @@ function ding_reservation_reserve_form_validate($form, &$form_state) { global $user; if (ding_provider_implements('reservation', 'options_validate')) { $res = ding_provider_invoke('reservation', 'options_validate', 'create', $user, $form_state['values']['reservable'], $form_state['values']['provider_options']); + // No valudation options returned by provider. + if (is_null($res)) { + return; + } + /** * We cannot set the value of the individual provider form elements, as * they might not have been show, and thus not exist. However, setting the @@ -993,12 +998,13 @@ class DingReservationReservableEntity implements DingReservationReservable { } public function getProviderId() { - return $this->entity->provider_id; + return isset($this->entity->provider_id) ? $this->entity->provider_id : NULL; } public function getEntity() { return $this->entity; } + public function getTitle() { return $this->entity->title; } From 8687b8457c14db867f9012cab79f86f051d64421 Mon Sep 17 00:00:00 2001 From: lexor Date: Fri, 30 Nov 2012 16:55:58 +0200 Subject: [PATCH 019/125] case 1495 - Handle missing title. --- ding_reservation.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index cb883c9..299c3da 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -1006,7 +1006,7 @@ class DingReservationReservableEntity implements DingReservationReservable { } public function getTitle() { - return $this->entity->title; + return isset($this->entity->title) ? $this->entity->title : NULL; } } From e95959e6587978534c5d5bf1d032b55b3a2573a5 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 20 Mar 2013 13:18:47 +0100 Subject: [PATCH 020/125] Minor correction to make reservations work properly --- ding_reservation.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 299c3da..2104ee1 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -998,7 +998,7 @@ class DingReservationReservableEntity implements DingReservationReservable { } public function getProviderId() { - return isset($this->entity->provider_id) ? $this->entity->provider_id : NULL; + return isset($this->entity->localId) ? $this->entity->localId : NULL; } public function getEntity() { @@ -1006,7 +1006,7 @@ class DingReservationReservableEntity implements DingReservationReservable { } public function getTitle() { - return isset($this->entity->title) ? $this->entity->title : NULL; + return isset($this->entity->record['dc:title'][''][0]) ? $this->entity->record['dc:title'][''][0] : ''; } } From 398114959a759cb7a95bc2d20098fcf7bba019f0 Mon Sep 17 00:00:00 2001 From: AnatolyMuntean Date: Tue, 11 Dec 2012 12:39:22 +0200 Subject: [PATCH 021/125] case 1770 - Translate interest period values. --- ding_reservation.module | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ding_reservation.module b/ding_reservation.module index 2104ee1..dfacb64 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -883,6 +883,14 @@ function ding_reservation_default_options_branch($type, $name, $default, $option */ function ding_reservation_interest_period_selector($type, $name, $default, $options) { $create = ($type == 'create'); + + // Used for options translation. + if (is_array($options)) { + foreach ($options as $k => $v) { + $options[$k] = t(check_plain($v)); + } + } + $allowed_periods = ($create ? array() : array('' => t('No change'))) + $options; // $default_value = $create ? $default : ''; $form[$name] = array( From 772f5806c3842e9d21fc8ff403153e1f5a98b776 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 20 Mar 2013 13:21:16 +0100 Subject: [PATCH 022/125] Translatable ILL loans status --- ding_reservation.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index dfacb64..9eab662 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -477,7 +477,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'class' => 'pickup-branch', ), 'ill_status' => array( - 'data' => $item->ill_status ? check_plain($item->ill_status) : '', + 'data' => $item->ill_status ? t(check_plain($item->ill_status)) : '', 'class' => 'ill-status', ), ); From 74685f79f63726afa6db847850592a9b1e35cb41 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 20 Mar 2013 13:24:09 +0100 Subject: [PATCH 023/125] Pickup ID column should be removed from Inter library loans --- ding_reservation.module | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 9eab662..87451a8 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -325,7 +325,6 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( case 'interlibrary_loans': $header = array( 'title' => t('Title'), - 'pickup_id' => t('Pickup id'), 'created' => t('Created date'), 'expiry' => t('Expiry date'), 'library' => t('Library'), @@ -460,10 +459,6 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), 'class' => 'title', ), - 'pickup_id' =>array( - 'data' => ding_reservation_get_pickup_id($item), - 'class' => 'pickup-id', - ), 'created' => array( 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'date_only') : '', 'class' => 'created-date', From c29aeb42ae3854ead1f795ed33f2953f8e243db6 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 20 Mar 2013 13:59:09 +0100 Subject: [PATCH 024/125] Ability to control reservation deletion from PH libraries --- ding_reservation.module | 116 +++++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 44 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 87451a8..955d3c7 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -296,6 +296,12 @@ function ding_reservation_reserve_form_callback($form, &$form_state) { function ding_reservation_reservations_form($form, &$form_state, $items = array(), $type = 'not_ready_for_pickup') { $options = array(); $destination = drupal_get_destination(); + $provider = ding_provider_get_provider_module_name('reservation'); + $able_to_delete = variable_get($provider . '_enable_reservation_deletion', FALSE); + $alma_rule = (($type == 'ready_for_pickup' || $type == 'interlibray_loans' || $type == 'not_ready_for_pickup') && $provider == 'alma'); + $openruth_rule = ($type == 'not_ready_for_pickup' && $provider == 'openruth'); + $empty_message = ''; + switch ($type) { case 'ready_for_pickup': $header = array( @@ -342,6 +348,16 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( $pickup_branch = ding_provider_invoke('reservation', 'branch_name', $item->pickup_branch_id); switch ($type) { case 'ready_for_pickup': + $delete_button = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => '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'), + '#options' => array('query' => $destination), + ); $options[$item->id] = array( 'title' => array( 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), @@ -364,16 +380,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'class' => 'pickup-branch', ), 'operations' => array( - 'data' => array( - '#prefix' => '
', - '#suffix' => '
', - '#type' => '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'), - '#options' => array('query' => $destination), - ), + 'data' => ($able_to_delete && $provider != 'openruth') ? $delete_button : '', 'class' => 'operations', ), ); @@ -396,6 +403,16 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( break; case 'not_ready_for_pickup': + $delete_button = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => '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'), + '#options' => array('query' => $destination), + ); $options[$item->id] = array( 'title' => array( 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), @@ -422,16 +439,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'class' => 'queue-number', ), 'operations' => array( - 'data' => array( - '#prefix' => '
', - '#suffix' => '
', - '#type' => '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'), - '#options' => array('query' => $destination), - ), + 'data' => ($able_to_delete) ? $delete_button : '', 'class' => 'operations', ), ); @@ -496,24 +504,42 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( } } + if ($alma_rule || $openruth_rule) { + $form['reservations'] = array( + '#type' => 'tableselect_form', + '#header' => $header, + '#options' => $options, + '#empty' => $empty_message, + ); + } + else { + $form['reservations'] = array( + '#type' => 'item', + '#markup' => theme('table', array('header' => $header, 'rows' => $options, 'empty' => $empty_message)), + ); + } + $form['actions_top'] = array( '#weight' => -10, + ); - $form['actions_top']['delete_first'] = array( - '#prefix' => '
', - '#suffix' => '
', - '#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 ($alma_rule || $openruth_rule) { + $form['actions_top']['delete'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#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') { - $form['actions_top']['update_first'] = array( + $form['actions_top']['update'] = array( '#prefix' => '
', '#suffix' => '
', '#type' => 'submit', @@ -531,20 +557,22 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#weight' => 10, ); - $form['actions_bottom']['delete_second'] = array( - '#prefix' => '
', - '#suffix' => '
', - '#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 ($alma_rule || $openruth_rule) { + $form['actions_bottom']['delete'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#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') { - $form['actions_bottom']['update_second'] = array( + $form['actions_bottom']['update'] = array( '#prefix' => '
', '#suffix' => '
', '#type' => 'submit', From 77152112548e50316d9341e86319c3b22c2f1cf3 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 20 Mar 2013 14:04:15 +0100 Subject: [PATCH 025/125] Fixed logic for reservation update --- ding_reservation.module | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 955d3c7..bf7580a 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -790,7 +790,7 @@ function ding_reservation_update_reservations_form($form, $form_state, $account, function ding_reservation_update_reservations_form_validate($form, &$form_state) { global $user; if (ding_provider_implements('reservation', 'options_validate')) { - $res = ding_provider_invoke('reservation', 'options_validate', 'create', $user, $form_state['values']['reservations'], $form_state['values']['provider_options']); + $res = ding_provider_invoke('reservation', 'options_validate', 'update', $user, $form_state['values']['reservations'], $form_state['values']['provider_options']); /** * We cannot set the value of the individual provider form elements, as * they might not have been show, and thus not exist. However, setting the @@ -882,8 +882,8 @@ function ding_reservation_update_reservations_form_callback($form, &$form_state) */ function ding_reservation_default_options_branch($type, $name, $default, $options) { $create = ($type == 'create'); - $allowed_branches = ($create ? array() : array('' => t('No change'))) + $options; - $default_value = $create ? $default : ''; + $allowed_branches = ($create ? array('' => 'Select') : array($default => t('No change'))) + $options; + $default_value = $default; $form[$name] = array( '#type' => 'select', '#title' => t('Select branch'), From c132229f294b3192a916307730bb7cdded8762be Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 20 Mar 2013 14:08:23 +0100 Subject: [PATCH 026/125] Use defalt interest period values when no user value has been entered --- ding_reservation.module | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ding_reservation.module b/ding_reservation.module index bf7580a..47d0418 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -272,6 +272,16 @@ function ding_reservation_reserve_form_callback($form, &$form_state) { $html = theme('status_messages'); if ($form_state['rebuild'] || form_get_errors()) { + $provider = ding_provider_get_provider_module_name('reservation'); + + // Populate the inputs with default values from settings. + $field_name = $provider . '_interest_period'; + $field_info = field_info_instance('profile2', 'field_' . $field_name, 'provider_' . $provider); + + // Use #value instead of #default_value when rendering forms + // using drupal_render(). + $form['provider_options'][$field_name]['#value'] = $field_info['default_value'][0]['value']; + // Hide certain fields, if any. if (is_array($form_state['removable'])) { $removal = $form_state['removable']; From 1b648dcb4174f71d911615b721d974fd3a25592e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 20 Mar 2013 14:09:30 +0100 Subject: [PATCH 027/125] Fix unsupported operand types PHP error --- ding_reservation.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 47d0418..53d3cd0 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -892,7 +892,7 @@ function ding_reservation_update_reservations_form_callback($form, &$form_state) */ function ding_reservation_default_options_branch($type, $name, $default, $options) { $create = ($type == 'create'); - $allowed_branches = ($create ? array('' => 'Select') : array($default => t('No change'))) + $options; + $allowed_branches = ($create ? array('' => 'Select') : array($default => t('No change'))) + (array)$options; $default_value = $default; $form[$name] = array( '#type' => 'select', @@ -924,7 +924,7 @@ function ding_reservation_interest_period_selector($type, $name, $default, $opti } } - $allowed_periods = ($create ? array() : array('' => t('No change'))) + $options; + $allowed_periods = ($create ? array() : array('' => t('No change'))) + (array)$options; // $default_value = $create ? $default : ''; $form[$name] = array( '#type' => 'select', From 0700c83020a44d25f639c788dc2094334b6fa84d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 20 Mar 2013 16:31:38 +0100 Subject: [PATCH 028/125] Fixed order_nr vs. pickup_id in reservation form --- ding_reservation.module | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 53d3cd0..6b64bff 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -373,10 +373,10 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), 'class' => 'title', ), - 'order_nr' =>array( - 'data' => ding_reservation_get_order_nr($item), + 'pickup_id' =>array( + 'data' => ding_reservation_get_pickup_id($item), 'class' => 'pickup-id', - ), + ), 'created' => array( 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'date_only') : '', 'class' => 'created-date', @@ -428,10 +428,11 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), 'class' => 'title', ), - 'pickup_id' =>array( - 'data' => ding_reservation_get_pickup_id($item), + 'order_nr' =>array( + 'data' => ding_reservation_get_order_nr($item), 'class' => 'pickup-id', ), + 'created' => array( 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'date_only') : '', 'class' => 'created-date', From 72d404fd95d1d6a0664d6481ec069b616aa1016c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 20 Mar 2013 16:50:25 +0100 Subject: [PATCH 029/125] Fixed logic in deletion of reservation buttons --- ding_reservation.module | 87 +++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 6b64bff..73d1f03 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -34,7 +34,7 @@ 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', @@ -42,7 +42,7 @@ function ding_reservation_menu() { 'access callback' => 'ding_reservation_access', 'access arguments' => array(1), ); - + return $items; } @@ -97,15 +97,15 @@ function ding_reservation_ding_provider_user() { * to be able to tell which was submitted. As we're using one builder * function, use this to let have their own form id. */ -function ding_reservation_forms($form_id, $args) { +function ding_reservation_forms($form_id, $args) { $forms['ding_reservation_reservations_ready_form'] = array( 'callback' => 'ding_reservation_reservations_form', ); - + $forms['ding_reservation_reservations_notready_form'] = array( 'callback' => 'ding_reservation_reservations_form', ); - + $forms['ding_reservation_reservations_ill'] = array( 'callback' => 'ding_reservation_reservations_form', ); @@ -277,11 +277,11 @@ function ding_reservation_reserve_form_callback($form, &$form_state) { // Populate the inputs with default values from settings. $field_name = $provider . '_interest_period'; $field_info = field_info_instance('profile2', 'field_' . $field_name, 'provider_' . $provider); - + // Use #value instead of #default_value when rendering forms // using drupal_render(). $form['provider_options'][$field_name]['#value'] = $field_info['default_value'][0]['value']; - + // Hide certain fields, if any. if (is_array($form_state['removable'])) { $removal = $form_state['removable']; @@ -308,15 +308,13 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( $destination = drupal_get_destination(); $provider = ding_provider_get_provider_module_name('reservation'); $able_to_delete = variable_get($provider . '_enable_reservation_deletion', FALSE); - $alma_rule = (($type == 'ready_for_pickup' || $type == 'interlibray_loans' || $type == 'not_ready_for_pickup') && $provider == 'alma'); - $openruth_rule = ($type == 'not_ready_for_pickup' && $provider == 'openruth'); $empty_message = ''; - + switch ($type) { case 'ready_for_pickup': $header = array( 'title' => t('Title'), - 'pickup_id' => t('Pickup id'), + 'pickup_id' => t('Pickup id'), 'created' => t('Created date'), 'pickup_date' => t('Pickup date'), 'pickup_branch' => t('Pickup branch'), @@ -324,11 +322,11 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( ); uasort($items, 'ding_reservation_sort_queue_by_pickup_date'); break; - + case 'not_ready_for_pickup': $header = array( 'title' => t('Title'), - 'order_nr' => t('Order nr.'), + 'order_nr' => t('Order nr.'), 'created' => t('Created date'), 'expiry' => t('Expiry date'), 'pickup_branch' => t('Pickup branch'), @@ -337,7 +335,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( ); uasort($items, 'ding_reservation_sort_queue_by_queue_number'); break; - + case 'interlibrary_loans': $header = array( 'title' => t('Title'), @@ -348,7 +346,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( ); break; } - + foreach ($items as $id => $item) { $entity = $item->entity; if (!is_object($entity)) { @@ -394,7 +392,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'class' => 'operations', ), ); - + if (!empty($item->notes)) { $options[$item->id]['title']['data'][] = array( '#type' => 'markup', @@ -403,7 +401,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#suffix' => '

', ); } - + $form['reservations'] = array( '#type' => 'tableselect_form', '#header' => $header, @@ -411,18 +409,8 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#empty' => t('No reservations ready for pickup'), ); break; - + case 'not_ready_for_pickup': - $delete_button = array( - '#prefix' => '
', - '#suffix' => '
', - '#type' => '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'), - '#options' => array('query' => $destination), - ); $options[$item->id] = array( 'title' => array( 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), @@ -431,7 +419,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'order_nr' =>array( 'data' => ding_reservation_get_order_nr($item), 'class' => 'pickup-id', - ), + ), 'created' => array( 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'date_only') : '', @@ -450,11 +438,20 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'class' => 'queue-number', ), 'operations' => array( - 'data' => ($able_to_delete) ? $delete_button : '', + 'data' => array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => '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'), + '#options' => array('query' => $destination), + ), 'class' => 'operations', ), ); - + if (!empty($item->notes)) { $options[$item->id]['title']['data'][] = array( '#type' => 'markup', @@ -471,7 +468,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#empty' => t('No Reservations'), ); break; - + case 'interlibrary_loans': $options[$item->id] = array( 'title' => array( @@ -515,7 +512,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( } } - if ($alma_rule || $openruth_rule) { + if ($able_to_delete) { $form['reservations'] = array( '#type' => 'tableselect_form', '#header' => $header, @@ -529,13 +526,13 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#markup' => theme('table', array('header' => $header, 'rows' => $options, 'empty' => $empty_message)), ); } - + $form['actions_top'] = array( '#weight' => -10, - + ); - if ($alma_rule || $openruth_rule) { + if ($able_to_delete) { $form['actions_top']['delete'] = array( '#prefix' => '
', '#suffix' => '
', @@ -554,7 +551,6 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#prefix' => '
', '#suffix' => '
', '#type' => 'submit', - /* '#submit' => array('ding_reservation_update_reservation_form'), */ '#submit' => array('ding_reservation_updates_form_submit'), '#value' => t('Update reservations'), '#ajax' => array( @@ -568,7 +564,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#weight' => 10, ); - if ($alma_rule || $openruth_rule) { + if ($able_to_delete) { $form['actions_bottom']['delete'] = array( '#prefix' => '
', '#suffix' => '
', @@ -587,7 +583,6 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#prefix' => '
', '#suffix' => '
', '#type' => 'submit', - /* '#submit' => array('ding_reservation_update_reservation_form'), */ '#submit' => array('ding_reservation_updates_form_submit'), '#value' => t('Update reservations'), '#ajax' => array( @@ -615,7 +610,7 @@ function ding_reservation_get_pickup_id($item) { elseif (isset($item->pickup_order_id)) { return $item->pickup_order_id; } - + return ''; } @@ -644,7 +639,7 @@ function ding_reservation_get_order_nr($item) { * Ting object id. * @return * A TingEntity object or FALSE if provider failed to fetch the data. - */ + */ function ding_reservation_replace_entity($item) { $provider = _ding_provider_get_provider(); return call_user_func($provider['reservation']['module'] . '_replace_entity', $item); @@ -737,11 +732,11 @@ function ding_reservation_delete_reservations_form($form, $form_state, $account, '#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'), @@ -752,14 +747,14 @@ function ding_reservation_delete_reservations_form($form, $form_state, $account, '#value' => t('Yes'), '#name' => 'delete_reservations', ); - + $form['cancel'] = array( '#type' => 'link', - '#title' => t('Cancel'), + '#title' => t('Cancel'), '#href' => 'user/' . $user->uid . '/status/reservations', '#value' => t('Cancel'), ); - + return $form; } From c8783449812730210980b86f2dd5bedd9af286fd Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 21 Mar 2013 10:17:26 +0100 Subject: [PATCH 030/125] Updated coding style in the panels plugin to reservations --- .../reservations/reservations.inc | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/plugins/content_types/reservations/reservations.inc b/plugins/content_types/reservations/reservations.inc index c6c40d1..41092b4 100644 --- a/plugins/content_types/reservations/reservations.inc +++ b/plugins/content_types/reservations/reservations.inc @@ -1,9 +1,10 @@ t('User reservation list'), 'description' => t('The current reservations for a user'), @@ -20,41 +21,43 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan static $preload_reservations = TRUE; $account = isset($context->data) ? $context->data : NULL; $preload_ids = array(); - $items = array(); $reservation_list = array(); + // Defined the return block. $block = new stdClass(); $block->module = 'ding_reservation'; $block->delta = 'reservations'; + // Set title and get the form id base on the list type. switch ($conf['reservation_type_list']) { case 'ready_for_pickup': $block->title = t('Reservations ready for pickup'); - $no_reservation_text = t('There are no reservations ready for pickup.'); + $block->content = t('There are no reservations ready for pickup.'); $form_id = 'ding_reservation_reservations_ready_form'; break; - + + case 'interlibrary_loans': + $block->title = t('Interlibrary loans'); + $block->content = t('There are no interlibrary loans.'); + $form_id = 'ding_reservation_reservations_ill'; + default: - case 'not_ready_for_pickup': $block->title = t('Reservations'); - $no_reservation_text = t('There are no reservations.'); + $block->content = t('There are no reservations.'); $form_id = 'ding_reservation_reservations_notready_form'; break; - - case 'interlibrary_loans': - $block->title = t('Interlibrary loans'); - $no_reservation_text = t('There are no interlibrary loans.'); - $form_id = 'ding_reservation_reservations_ill'; } - $list = ding_provider_invoke_page('reservation', 'list', $account); - - foreach ($list as $item) { + // Get the lists + $items = ding_provider_invoke_page('reservation', 'list', $account); + foreach ($items as $item) { if (isset($item->ding_entity_id)) { $preload_ids[] = $item->ding_entity_id; } if (isset($conf['reservation_type_list'])) { - if (($conf['reservation_type_list'] == 'ready_for_pickup' && $item->ready_for_pickup === 1) || ($conf['reservation_type_list'] == 'not_ready_for_pickup' && $item->ready_for_pickup === 0) || ($conf['reservation_type_list'] == 'interlibrary_loans' && isset($item->ill_status))) { + if (($conf['reservation_type_list'] == 'ready_for_pickup' && $item->ready_for_pickup === 1) || + ($conf['reservation_type_list'] == 'not_ready_for_pickup' && $item->ready_for_pickup === 0) || + ($conf['reservation_type_list'] == 'interlibrary_loans' && isset($item->ill_status))) { $reservation_list[] = $item; } } @@ -64,7 +67,12 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan ding_entity_load_multiple($preload_ids); $preload_reservations = FALSE; } - $block->content = count($reservation_list) == TRUE ? ding_provider_get_form($form_id, $reservation_list, $conf['reservation_type_list']) : $no_reservation_text; + + // Change the default block content, if the list is not empty + if (!empty($reservation_list)) { + $block->content = ding_provider_get_form($form_id, $reservation_list, $conf['reservation_type_list']); + } + return $block; } From 3e2f90e11317a89729d46e0268ab3e530a112c59 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 21 Mar 2013 12:18:27 +0100 Subject: [PATCH 031/125] Fixed reservation (provider_id) and delete submit callback function name --- ding_reservation.module | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 73d1f03..6710b30 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -25,6 +25,8 @@ function ding_reservation_ctools_plugin_directory($module, $plugin) { * Implements hook_menu(). */ function ding_reservation_menu() { + $items = array(); + // @todo ding_reservation really doesn't know that this path is correct. How // to handle it? $items['user/%user/status/reservations/update/%'] = array( @@ -98,18 +100,17 @@ function ding_reservation_ding_provider_user() { * function, use this to let have their own form id. */ function ding_reservation_forms($form_id, $args) { - $forms['ding_reservation_reservations_ready_form'] = array( - 'callback' => 'ding_reservation_reservations_form', - ); - - $forms['ding_reservation_reservations_notready_form'] = array( - 'callback' => 'ding_reservation_reservations_form', - ); - - $forms['ding_reservation_reservations_ill'] = array( - 'callback' => 'ding_reservation_reservations_form', + return array( + 'ding_reservation_reservations_ready_form' => array( + 'callback' => 'ding_reservation_reservations_form', + ), + 'ding_reservation_reservations_notready_form' => array( + 'callback' => 'ding_reservation_reservations_form', + ), + 'ding_reservation_reservations_ill' => array( + 'callback' => 'ding_reservation_reservations_form', + ), ); - return $forms; } /** @@ -360,7 +361,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#prefix' => '
', '#suffix' => '
', '#type' => 'submit', - '#submit' => array('ding_reservation_reservation_delete_submit'), + '#submit' => array('ding_reservation_reservations_delete_submit'), '#reservation_id' => $item->id, '#name' => 'delete-' . preg_replace('/\W/', '-', $item->id), // Need this for formAPI can tell buttons apart '#value' => t('Delete'), @@ -442,7 +443,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#prefix' => '
', '#suffix' => '
', '#type' => 'submit', - '#submit' => array('ding_reservation_reservation_delete_submit'), + '#submit' => array('ding_reservation_reservations_delete_submit'), '#reservation_id' => $item->id, '#name' => 'delete-' . preg_replace('/\W/', '-', $item->id), // Need this for formAPI can tell buttons apart '#value' => t('Delete'), @@ -1035,7 +1036,7 @@ class DingReservationReservableEntity implements DingReservationReservable { } public function getProviderId() { - return isset($this->entity->localId) ? $this->entity->localId : NULL; + return isset($this->entity->provider_id) ? $this->entity->provider_id : NULL; } public function getEntity() { From 0c5c263ba55b50074b7c8ddb81ca6d79294624d4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 19 Apr 2013 10:03:45 +0200 Subject: [PATCH 032/125] Wrapped reservation validation in a check for that users login status --- ding_reservation.module | 85 ++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 6710b30..7cfb23f 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -172,53 +172,58 @@ function ding_reservation_reserve_form($form, &$form_state, $reservable, $hide_o */ function ding_reservation_reserve_form_validate($form, &$form_state) { global $user; - if (ding_provider_implements('reservation', 'options_validate')) { - $res = ding_provider_invoke('reservation', 'options_validate', 'create', $user, $form_state['values']['reservable'], $form_state['values']['provider_options']); - // No valudation options returned by provider. - if (is_null($res)) { - return; - } + if (user_is_logged_in && ding_user_is_provider_user($user)) { + if (ding_provider_implements('reservation', 'options_validate')) { + $res = ding_provider_invoke('reservation', 'options_validate', 'create', $user, $form_state['values']['reservable'], $form_state['values']['provider_options']); + // No valudation options returned by provider. + if (is_null($res)) { + return; + } - /** - * We cannot set the value of the individual provider form elements, as - * they might not have been show, and thus not exist. However, setting the - * value of the parent element to an associative array gives the same end - * result. - */ - $provider_options = array(); - $provider = ding_provider_get_provider_module_name('reservation'); - $removal = array(); - foreach ($res as $key => $value) { - if (is_array($value) && !empty($value['#error'])) { - if (!$form_state['options_hidden']) { - // Only show an error if the user had a choice. - form_error($form['provider_options'], $res['#error']); - } - else { - // Else simply rebuild the form. - if ($key == $provider . '_preferred_branch') { - $removal[] = $provider . '_interest_period'; - } - elseif ($key == $provider . '_interest_period') { - $removal[] = $provider . '_preferred_branch'; + /** + * We cannot set the value of the individual provider form elements, as + * they might not have been show, and thus not exist. However, setting the + * value of the parent element to an associative array gives the same end + * result. + */ + $provider_options = array(); + $provider = ding_provider_get_provider_module_name('reservation'); + $removal = array(); + foreach ($res as $key => $value) { + if (is_array($value) && !empty($value['#error'])) { + if (!$form_state['options_hidden']) { + // Only show an error if the user had a choice. + form_error($form['provider_options'], $res['#error']); } - - // In case both fields are not set, remove nothing. - if (count($removal) == 2) { - $removal = array(); + else { + // Else simply rebuild the form. + if ($key == $provider . '_preferred_branch') { + $removal[] = $provider . '_interest_period'; + } + elseif ($key == $provider . '_interest_period') { + $removal[] = $provider . '_preferred_branch'; + } + + // In case both fields are not set, remove nothing. + if (count($removal) == 2) { + $removal = array(); + } + + $form_state['removable'] = $removal; + $form_state['rebuild'] = TRUE; } - - $form_state['removable'] = $removal; - $form_state['rebuild'] = TRUE; + } + else { + $provider_options[$key] = $value; } } - else { - $provider_options[$key] = $value; + if (!empty($provider_options)) { + form_set_value($form['provider_options'], $provider_options, $form_state); } } - if (!empty($provider_options)) { - form_set_value($form['provider_options'], $provider_options, $form_state); - } + } + else { + throw new DingProviderAuthException(); } } From 8dd4a4a3f0f67d0fb5492a0ef45e812211fb9982 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 19 Apr 2013 15:52:17 +0200 Subject: [PATCH 033/125] Change reservation to use new ding_provider_get_pseudo_entity function --- ding_reservation.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index 7cfb23f..988d029 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -356,7 +356,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( foreach ($items as $id => $item) { $entity = $item->entity; if (!is_object($entity)) { - $entity = ding_reservation_replace_entity($item); + $entity = ding_provider_get_pseudo_entity($item->ding_entity_id); } $pickup_branch = ding_provider_invoke('reservation', 'branch_name', $item->pickup_branch_id); From 96a0e9880b3cfdc728d4278399a3e70b37801354 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 19 Apr 2013 16:18:15 +0200 Subject: [PATCH 034/125] Removed the ding_reservation_replace_entity function that have been replaced by ding_provider_get_pseudo_entity --- ding_reservation.module | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 988d029..cbb2834 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -637,20 +637,6 @@ function ding_reservation_get_order_nr($item) { } } -/** - * Create a dummy ting entity object, when item is not found in the ting well. - * Fill in data using info fetched from certain provider. - * - * @param $entity_id - * Ting object id. - * @return - * A TingEntity object or FALSE if provider failed to fetch the data. - */ -function ding_reservation_replace_entity($item) { - $provider = _ding_provider_get_provider(); - return call_user_func($provider['reservation']['module'] . '_replace_entity', $item); -} - /** * Submit handler for the reservations form. */ From 542cd6c15c81fbd30b963301027651b9ef2200df Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 22 Apr 2013 13:19:44 +0200 Subject: [PATCH 035/125] Fixed missing function call in user_is_logged_in --- ding_reservation.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index cbb2834..2629a6e 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -172,7 +172,7 @@ function ding_reservation_reserve_form($form, &$form_state, $reservable, $hide_o */ function ding_reservation_reserve_form_validate($form, &$form_state) { global $user; - if (user_is_logged_in && ding_user_is_provider_user($user)) { + if (user_is_logged_in() && ding_user_is_provider_user($user)) { if (ding_provider_implements('reservation', 'options_validate')) { $res = ding_provider_invoke('reservation', 'options_validate', 'create', $user, $form_state['values']['reservable'], $form_state['values']['provider_options']); // No valudation options returned by provider. From 7dae9157120d5089f35750462c016124dba8d847 Mon Sep 17 00:00:00 2001 From: Rasmus Frey Date: Mon, 22 Apr 2013 14:14:21 +0200 Subject: [PATCH 036/125] Updated reserve button with class attributes --- ding_reservation.module | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ding_reservation.module b/ding_reservation.module index cbb2834..8ae503c 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -158,6 +158,12 @@ function ding_reservation_reserve_form($form, &$form_state, $reservable, $hide_o $form['submit'] = array( '#type' => 'submit', '#value' => t('Reserve'), + '#attributes' => array( + 'class' => array( + 'action-button', + 'reserve-button' + ), + ), '#ajax' => array( 'callback' => 'ding_reservation_reserve_form_callback', 'wrapper' => 'ding-reservation-reserve-form', From 3e3803204ab653d840bea2a6d0bab8797b50701c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 22 Apr 2013 20:36:44 +0200 Subject: [PATCH 037/125] Stream line of make file --- ding_reservation.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.make b/ding_reservation.make index d8398f6..cae1f1b 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -3,7 +3,7 @@ core = 7.x ; Contrib -projects[date][subdir] = contrib +projects[date][subdir] = "contrib" projects[date][version] = "2.6" ; Ding 2 modules From 4ec5d9067cced47ae985efa90c6a910d972749d1 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 30 Apr 2013 17:07:17 +0200 Subject: [PATCH 038/125] Minor coding style fixes --- ding_reservation.module | 40 +++++++++++++++++++++------------------- ding_reservation.test | 4 ++++ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index bde9812..c245f8c 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -383,7 +383,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), 'class' => 'title', ), - 'pickup_id' =>array( + 'pickup_id' => array( 'data' => ding_reservation_get_pickup_id($item), 'class' => 'pickup-id', ), @@ -428,7 +428,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), 'class' => 'title', ), - 'order_nr' =>array( + 'order_nr' => array( 'data' => ding_reservation_get_order_nr($item), 'class' => 'pickup-id', ), @@ -608,13 +608,13 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( } /** -* Get pickup id number. -* -* @param $item -* Reserved item object. -* @return -* Pickup id, if any. -*/ + * Get pickup id number. + * + * @param object $item + * Reserved item object. + * @return int + * Pickup id, if any. + */ function ding_reservation_get_pickup_id($item) { if (isset($item->order_arrived) && !$item->order_arrived) { return t('The material is in transit and is still not available for loan on the library'); @@ -627,13 +627,13 @@ function ding_reservation_get_pickup_id($item) { } /** -* Get order id number. -* -* @param $item -* Reserved item object. -* @return -* Order number, if any. -*/ + * Get order id number. + * + * @param object $item + * Reserved item object. + * @return int + * Order number, if any. + */ function ding_reservation_get_order_nr($item) { if (!isset($item->pickup_order_id) && isset($item->order_id)) { return $item->order_id; @@ -664,7 +664,7 @@ function ding_reservation_reservations_delete_submit($form, &$form_state) { */ function ding_reservation_deletes_form_submit($form, &$form_state) { global $user; - $ids = join(',', array_map('rawurlencode', array_filter($form_state['values']['reservations'],'is_string'))); + $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())); } @@ -674,7 +674,7 @@ function ding_reservation_deletes_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'))); + $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/update/' . $ids, array('query' => drupal_get_destination())); } @@ -965,6 +965,7 @@ function ding_reservation_default_options_branch_validate($type, $name, $default */ function ding_reservation_default_options_interest_period_validate($type, $name, $default, $values) { if (empty($values[$name])) { + $result = array(); $provider = ding_provider_get_provider_module_name('reservation'); if ($type == 'create' && empty($default)) { $result[$provider . '_interest_period'] = array( @@ -975,7 +976,8 @@ function ding_reservation_default_options_interest_period_validate($type, $name, $result[$name] = $default; } return $result; - } else { + } + else { return $values; } } diff --git a/ding_reservation.test b/ding_reservation.test index d17df23..a5787cb 100644 --- a/ding_reservation.test +++ b/ding_reservation.test @@ -1,4 +1,8 @@ Date: Mon, 6 May 2013 11:28:01 +0200 Subject: [PATCH 039/125] Changed makefile to point to ding2 on github --- ding_reservation.make | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index cae1f1b..7066255 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -10,20 +10,20 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" -projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" -projects[ding_base][download][branch] = "development" +projects[ding_base][download][url] = "git@github.com:ding2/ding_base.git" +projects[ding_base][download][branch] = "master" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" -projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" -projects[ding_popup][download][branch] = "development" +projects[ding_popup][download][url] = "git@github.com:ding2/ding_popup.git" +projects[ding_popup][download][branch] = "master" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" -projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" -projects[ding_user][download][branch] = "development" +projects[ding_user][download][url] = "git@github.com:ding2/ding_user.git" +projects[ding_user][download][branch] = "master" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" -projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][branch] = "development" +projects[ding_provider][download][url] = "git@github.com:ding2/ding_provider.git" +projects[ding_provider][download][branch] = "master" From 3034427f05b30a913ac101fcf5faa4823935385c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 16 May 2013 16:43:53 +0200 Subject: [PATCH 040/125] Removed hardcode default interest period and some clean up --- ding_reservation.module | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index c245f8c..9ca2f95 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -1,13 +1,9 @@ $v) { $options[$k] = t(check_plain($v)); } } - $allowed_periods = ($create ? array() : array('' => t('No change'))) + (array)$options; - // $default_value = $create ? $default : ''; + $allowed_periods = ($type == 'create' ? array() : array('' => t('No change'))) + (array)$options; $form[$name] = array( '#type' => 'select', '#title' => t('Select interest period'), '#options' => $allowed_periods, '#default_value' => $default, ); - if ($create) { + + if ($type == 'create') { $form[$name . 'description'] = array( '#markup' => '

' . t('Select an interest period.') . '

', ); } + return $form; } From 3a4892c117493e696784e2ab285c501c9e24ce49 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 16 May 2013 16:43:53 +0200 Subject: [PATCH 041/125] Removed hardcode default interest period and some clean up --- ding_reservation.module | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index c245f8c..9ca2f95 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -1,13 +1,9 @@ $v) { $options[$k] = t(check_plain($v)); } } - $allowed_periods = ($create ? array() : array('' => t('No change'))) + (array)$options; - // $default_value = $create ? $default : ''; + $allowed_periods = ($type == 'create' ? array() : array('' => t('No change'))) + (array)$options; $form[$name] = array( '#type' => 'select', '#title' => t('Select interest period'), '#options' => $allowed_periods, '#default_value' => $default, ); - if ($create) { + + if ($type == 'create') { $form[$name . 'description'] = array( '#markup' => '

' . t('Select an interest period.') . '

', ); } + return $form; } From 5c64efc0f0ca7a2adf01575c7384f27acac33498 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 4 Jun 2013 10:10:33 +0200 Subject: [PATCH 042/125] Added the new hook_default_interest_period() to reservation form --- ding_reservation.module | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 9ca2f95..5294796 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -200,9 +200,9 @@ function ding_reservation_reserve_form_validate($form, &$form_state) { else { // Else simply rebuild the form. if ($key == $provider . '_preferred_branch') { - $removal[] = $provider . '_interest_period'; + $removal[] = 'interest_period'; } - elseif ($key == $provider . '_interest_period') { + elseif ($key == 'interest_period') { $removal[] = $provider . '_preferred_branch'; } @@ -280,15 +280,12 @@ function ding_reservation_reserve_form_callback($form, &$form_state) { $html = theme('status_messages'); if ($form_state['rebuild'] || form_get_errors()) { - $provider = ding_provider_get_provider_module_name('reservation'); - - // Populate the inputs with default values from settings. - $field_name = $provider . '_interest_period'; - $field_info = field_info_instance('profile2', 'field_' . $field_name, 'provider_' . $provider); + // Get the default interest period for the current user. + $default_interest_period = ding_provider_invoke('reservation', 'default_interest_period'); // Use #value instead of #default_value when rendering forms // using drupal_render(). - $form['provider_options'][$field_name]['#value'] = $field_info['default_value'][0]['value']; + $form['provider_options']['interest_period']['#value'] = $default_interest_period; // Hide certain fields, if any. if (is_array($form_state['removable'])) { @@ -974,9 +971,8 @@ function ding_reservation_default_options_branch_validate($type, $name, $default function ding_reservation_default_options_interest_period_validate($type, $name, $default, $values) { if (empty($values[$name])) { $result = array(); - $provider = ding_provider_get_provider_module_name('reservation'); if ($type == 'create' && empty($default)) { - $result[$provider . '_interest_period'] = array( + $result['interest_period'] = array( '#error' => t('You must select an interest period'), ); } From bc896a4a8949a9624bf433d28ba9fbd3026ff7a1 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 4 Jun 2013 11:30:15 +0200 Subject: [PATCH 043/125] Fixed reservation form by using new hook_reservation_deletion_enabled() --- ding_reservation.module | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 5294796..e18325b 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -311,10 +311,14 @@ function ding_reservation_reserve_form_callback($form, &$form_state) { function ding_reservation_reservations_form($form, &$form_state, $items = array(), $type = 'not_ready_for_pickup') { $options = array(); $destination = drupal_get_destination(); - $provider = ding_provider_get_provider_module_name('reservation'); - $able_to_delete = variable_get($provider . '_enable_reservation_deletion', FALSE); $empty_message = ''; + // Check if reservations should be able to be deleted by the user. + $able_to_delete = FALSE; + if (ding_provider_implements('reservation', 'reservation_deletion_enabled')) { + $able_to_delete = ding_provider_invoke('reservation', 'reservation_deletion_enabled'); + } + switch ($type) { case 'ready_for_pickup': $header = array( @@ -371,6 +375,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#value' => t('Delete'), '#options' => array('query' => $destination), ); + $options[$item->id] = array( 'title' => array( 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), @@ -392,12 +397,16 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'data' => $pickup_branch ? check_plain($pickup_branch) : '', 'class' => 'pickup-branch', ), - 'operations' => array( - 'data' => ($able_to_delete && $provider != 'openruth') ? $delete_button : '', - 'class' => 'operations', - ), ); + // Check if able to delete reservation should be added. + if ($able_to_delete) { + $options[$item->id]['operations'] = array( + 'data' => $delete_button, + 'class' => 'operations', + ); + } + if (!empty($item->notes)) { $options[$item->id]['title']['data'][] = array( '#type' => 'markup', From 232e59e73bf88bba51737593ad0d50b1b66e89bf Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 6 Jun 2013 13:08:11 +0200 Subject: [PATCH 044/125] Moved sorting of reservation types back into the providers --- .../reservations/reservations.inc | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/plugins/content_types/reservations/reservations.inc b/plugins/content_types/reservations/reservations.inc index 41092b4..ad12a37 100644 --- a/plugins/content_types/reservations/reservations.inc +++ b/plugins/content_types/reservations/reservations.inc @@ -18,10 +18,7 @@ $plugin = array( * Render the block */ function ding_reservation_reservations_content_type_render($subtype, $conf, $panel_args, $context) { - static $preload_reservations = TRUE; $account = isset($context->data) ? $context->data : NULL; - $preload_ids = array(); - $reservation_list = array(); // Defined the return block. $block = new stdClass(); @@ -48,29 +45,31 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan break; } - // Get the lists - $items = ding_provider_invoke_page('reservation', 'list', $account); - foreach ($items as $item) { - if (isset($item->ding_entity_id)) { - $preload_ids[] = $item->ding_entity_id; - } - if (isset($conf['reservation_type_list'])) { - if (($conf['reservation_type_list'] == 'ready_for_pickup' && $item->ready_for_pickup === 1) || - ($conf['reservation_type_list'] == 'not_ready_for_pickup' && $item->ready_for_pickup === 0) || - ($conf['reservation_type_list'] == 'interlibrary_loans' && isset($item->ill_status))) { - $reservation_list[] = $item; + // Get the reservations lists. + $reservations = ding_provider_invoke_page('reservation', 'list', $account); + + // Try to preload ting entities, if not already loaded. + $preloaded_reservations = &drupal_static(__FUNCTION__, array()); + if (!isset($preloaded_reservations[$conf['reservation_type_list']])) { + $preload_ids = array(); + foreach ($reservations[$conf['reservation_type_list']] as $item) { + if (isset($item->ding_entity_id)) { + $preload_ids[] = $item->ding_entity_id; } } - } - // Preload all ting objects. - if ($preload_reservations) { - ding_entity_load_multiple($preload_ids); - $preload_reservations = FALSE; + + // Preload all ting entities. + if (!empty($preload_ids)) { + ding_entity_load_multiple($preload_ids); + } + + // Set this list type as preloaded. + $preloaded_reservations[$conf['reservation_type_list']] = TRUE; } - // Change the default block content, if the list is not empty - if (!empty($reservation_list)) { - $block->content = ding_provider_get_form($form_id, $reservation_list, $conf['reservation_type_list']); + // Set block content if any reservation of the type is listed. + if (!empty($reservations[$conf['reservation_type_list']])) { + $block->content = ding_provider_get_form($form_id, $reservations[$conf['reservation_type_list']], $conf['reservation_type_list']); } return $block; From 40590ae2b38ecd31f3608edc460e6d343c3255bb Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 6 Jun 2013 15:02:27 +0200 Subject: [PATCH 045/125] Added more configuration options to reservation lists panel panes --- .../reservations/reservations.inc | 103 ++++++++++++------ 1 file changed, 67 insertions(+), 36 deletions(-) diff --git a/plugins/content_types/reservations/reservations.inc b/plugins/content_types/reservations/reservations.inc index ad12a37..971c910 100644 --- a/plugins/content_types/reservations/reservations.inc +++ b/plugins/content_types/reservations/reservations.inc @@ -25,51 +25,51 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan $block->module = 'ding_reservation'; $block->delta = 'reservations'; - // Set title and get the form id base on the list type. - switch ($conf['reservation_type_list']) { - case 'ready_for_pickup': - $block->title = t('Reservations ready for pickup'); - $block->content = t('There are no reservations ready for pickup.'); - $form_id = 'ding_reservation_reservations_ready_form'; - break; - - case 'interlibrary_loans': - $block->title = t('Interlibrary loans'); - $block->content = t('There are no interlibrary loans.'); - $form_id = 'ding_reservation_reservations_ill'; - - default: - $block->title = t('Reservations'); - $block->content = t('There are no reservations.'); - $form_id = 'ding_reservation_reservations_notready_form'; - break; - } + // Get configuration for this pane. + $types = array_filter($conf['reservation_type_list']); + $block->title = t($conf['reservation_titel']); + $block->content = t($conf['reservation_empty_text']); + $form_id = $conf['reservation_form_id']; // Get the reservations lists. $reservations = ding_provider_invoke_page('reservation', 'list', $account); - // Try to preload ting entities, if not already loaded. + // Filter items base on configuration and preload ting entites. $preloaded_reservations = &drupal_static(__FUNCTION__, array()); - if (!isset($preloaded_reservations[$conf['reservation_type_list']])) { - $preload_ids = array(); - foreach ($reservations[$conf['reservation_type_list']] as $item) { - if (isset($item->ding_entity_id)) { - $preload_ids[] = $item->ding_entity_id; + $items = array(); + foreach ($types as $type) { + // Try to preload ting entities, if not already loaded. + if (!isset($preloaded_reservations[$type])) { + $preload_ids = array(); + foreach ($reservations[$type] as $item) { + if (isset($item->ding_entity_id)) { + $preload_ids[] = $item->ding_entity_id; + } } - } - // Preload all ting entities. - if (!empty($preload_ids)) { - ding_entity_load_multiple($preload_ids); + // Preload all ting entities. + if (!empty($preload_ids)) { + ding_entity_load_multiple($preload_ids); + } + + // Set this list type as preloaded. + $preloaded_reservations[$type] = TRUE; } - // Set this list type as preloaded. - $preloaded_reservations[$conf['reservation_type_list']] = TRUE; + // Add the current type to the items we want. + $items += $reservations[$type]; } - // Set block content if any reservation of the type is listed. - if (!empty($reservations[$conf['reservation_type_list']])) { - $block->content = ding_provider_get_form($form_id, $reservations[$conf['reservation_type_list']], $conf['reservation_type_list']); + // Build block content. + if (!empty($items)) { + if (count($types) > 1) { + // If more than one type is selected we will fallback to the most generic + // form type. + $block->content = ding_provider_get_form($form_id, $items, 'ready_for_pickup'); + } + else { + $block->content = ding_provider_get_form($form_id, $items, array_shift($types)); + } } return $block; @@ -81,8 +81,8 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan function ding_reservation_reservations_content_type_edit_form($form, &$form_state) { $conf = $form_state['conf']; $form['reservation_type_list'] = array( - '#type' => 'radios', - '#title' => t('Reservation list type'), + '#type' => 'checkboxes', + '#title' => t('Reservation list type(s)'), '#options' => array( 'not_ready_for_pickup' => t('Not ready for pickup'), 'ready_for_pickup' => t('Ready for pickup'), @@ -90,6 +90,29 @@ function ding_reservation_reservations_content_type_edit_form($form, &$form_stat ), '#default_value' => !empty($conf['reservation_type_list']) ? $conf['reservation_type_list'] : NULL, ); + + $form['reservation_titel'] = array( + '#type' => 'textfield', + '#title' => t('List titel'), + '#default_value' => !empty($conf['reservation_titel']) ? $conf['reservation_titel'] : 'Reservations', + ); + + $form['reservation_empty_text'] = array( + '#type' => 'textfield', + '#title' => t('Empty text'), + '#default_value' => !empty($conf['reservation_empty_text']) ? $conf['reservation_empty_text'] : 'There are no reservations.', + ); + + $form['reservation_form_id'] = array( + '#type' => 'select', + '#title' => t('Form to user for reservations'), + '#options' => array( + 'ding_reservation_reservations_notready_form' => t('Reservation form'), + 'ding_reservation_reservations_ready_form' => t('Reservations ready form'), + 'ding_reservation_reservations_ill' => t('Interlibrary reservation form'), + ), + '#default_value' => !empty($conf['reservation_form_id']) ? $conf['reservation_form_id'] : 'ding_reservation_reservations_notready_form', + ); return $form; } @@ -103,3 +126,11 @@ function ding_reservation_reservations_content_type_edit_form_submit(&$form, &$f } } } + +/** + * Returns the administrative title. + */ +function ding_reservation_reservations_content_type_admin_title($subtype, $conf) { + $types = implode(', ', array_filter($conf['reservation_type_list'])); + return 'Reservations (' . $types . ')'; +} \ No newline at end of file From 8c44bca4de033c88ef7feb712c09f0bcdda4b79d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 6 Jun 2013 21:50:25 +0200 Subject: [PATCH 046/125] Added support for user session cache --- ding_reservation.module | 32 +++++++++ .../reservations/reservations.inc | 66 ++++++++++++------- 2 files changed, 74 insertions(+), 24 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index e18325b..4f921e4 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -254,6 +254,9 @@ function ding_reservation_reserve_form_submit($form, &$form_state) { if (is_array($reservation_result) and !empty($reservation_result['queue_number'])) { drupal_set_message(t('You are number @number in queue.', array('@number' => $reservation_result['queue_number']))); } + + // Clear reservation sesion cache. + ding_reservation_cache_clear(); } catch (DingProviderUserException $e) { drupal_set_message($e->getMessageT(array('@title' => $reservable->getTitle())), 'error'); @@ -658,6 +661,9 @@ function ding_reservation_reservations_delete_submit($form, &$form_state) { } foreach ($reservations as $entity_id) { ding_provider_invoke('reservation', 'delete', $user, $entity_id); + + // Clear reservation sesion cache. + ding_reservation_cache_clear(); } } @@ -839,12 +845,18 @@ function ding_reservation_delete_reservations_form_submit($form, &$form_state) { } foreach ($reservations as $entity_id) { ding_provider_invoke('reservation', 'delete', $user, $entity_id); + + // Clear reservation sesion cache. + ding_reservation_cache_clear(); } } 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']); + + // Clear reservation sesion cache. + ding_reservation_cache_clear(); } /** @@ -1009,6 +1021,26 @@ function ding_reservation_default_options_branch_submit($type, $name, $default, } +function ding_reservation_cache_clear() { + if (module_exists('ding_session_cache')) { + ding_session_cache_clear('ding_reservation', 'reservations'); + } +} + +/** + * Implements hook_ding_session_cache_defaults(). + * + * Set default ding_session_cache settings and tell ding_session_cache that this + * module supports it. + */ +function ding_reservation_ding_session_cache_defaults() { + return array( + 'titel' => 'Ding reservation', + 'enabled' => TRUE, + 'expire' => 3600, + ); +} + /** * Callback function to sort array by pickup date */ diff --git a/plugins/content_types/reservations/reservations.inc b/plugins/content_types/reservations/reservations.inc index 971c910..bf3cade 100644 --- a/plugins/content_types/reservations/reservations.inc +++ b/plugins/content_types/reservations/reservations.inc @@ -31,44 +31,62 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan $block->content = t($conf['reservation_empty_text']); $form_id = $conf['reservation_form_id']; - // Get the reservations lists. - $reservations = ding_provider_invoke_page('reservation', 'list', $account); - - // Filter items base on configuration and preload ting entites. - $preloaded_reservations = &drupal_static(__FUNCTION__, array()); - $items = array(); - foreach ($types as $type) { - // Try to preload ting entities, if not already loaded. - if (!isset($preloaded_reservations[$type])) { - $preload_ids = array(); - foreach ($reservations[$type] as $item) { - if (isset($item->ding_entity_id)) { - $preload_ids[] = $item->ding_entity_id; + $content = array(); + if (module_exists('ding_session_cache')) { + $content = ding_session_cache_get('ding_reservation', 'reservations'); + } + + if (empty($content) || !isset($content[$form_id])) { + // Get the reservations lists. + $reservations = ding_provider_invoke_page('reservation', 'list', $account); + + // Filter items base on configuration and preload ting entites. + $preloaded_reservations = &drupal_static(__FUNCTION__, array()); + $items = array(); + foreach ($types as $type) { + // Try to preload ting entities, if not already loaded. + if (!isset($preloaded_reservations[$type])) { + $preload_ids = array(); + foreach ($reservations[$type] as $item) { + if (isset($item->ding_entity_id)) { + $preload_ids[] = $item->ding_entity_id; + } + } + + // Preload all ting entities. + if (!empty($preload_ids)) { + ding_entity_load_multiple($preload_ids); } - } - // Preload all ting entities. - if (!empty($preload_ids)) { - ding_entity_load_multiple($preload_ids); + // Set this list type as preloaded. + $preloaded_reservations[$type] = TRUE; } - // Set this list type as preloaded. - $preloaded_reservations[$type] = TRUE; + // Add the current type to the items we want. + $items += $reservations[$type]; } - // Add the current type to the items we want. - $items += $reservations[$type]; + // Add the preload entity to each loan (side effect of getting the entity). + foreach ($items as $id => &$item) { + $item->entity; + } + + $content[$form_id] = $items; + + if (module_exists('ding_session_cache')) { + ding_session_cache_set('ding_reservation', 'reservations', $content); + } } // Build block content. - if (!empty($items)) { + if (!empty($content[$form_id])) { if (count($types) > 1) { // If more than one type is selected we will fallback to the most generic // form type. - $block->content = ding_provider_get_form($form_id, $items, 'ready_for_pickup'); + $block->content = ding_provider_get_form($form_id, $content[$form_id], 'ready_for_pickup'); } else { - $block->content = ding_provider_get_form($form_id, $items, array_shift($types)); + $block->content = ding_provider_get_form($form_id, $content[$form_id], array_shift($types)); } } From 529a2f7b7db279dfa1607084772897ab308f2be4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 10 Jun 2013 12:57:39 +0200 Subject: [PATCH 047/125] Changed reservation lists date format to include year as reservation interest period may be up-to one year --- ding_reservation.module | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 4f921e4..5b0a74b 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -389,11 +389,11 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'class' => 'pickup-id', ), 'created' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'date_only') : '', + 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'long_date_only') : '', 'class' => 'created-date', ), 'pickup_date' => array( - 'data' => $item->pickup_date ? format_date(strtotime(check_plain($item->pickup_date)), 'date_only' ) : '', + 'data' => $item->pickup_date ? format_date(strtotime(check_plain($item->pickup_date)), 'long_date_only' ) : '', 'class' => 'pickup-date', ), 'pickup_branch' => array( @@ -439,11 +439,11 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( ), 'created' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'date_only') : '', + 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'long_date_only') : '', 'class' => 'created-date', ), 'expiry' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'date_only') : '', + 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'long_date_only') : '', 'class' => 'expire-date', ), 'pickup_branch' => array( @@ -493,11 +493,11 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'class' => 'title', ), 'created' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'date_only') : '', + 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'long_date_only') : '', 'class' => 'created-date', ), 'expiry' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'date_only') : '', + 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'long_date_only') : '', 'class' => 'expire-date', ), 'library' => array( From 473369bdd70cf3db9e5f12d6b4ebc32d17a4dc21 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 10 Jun 2013 13:43:01 +0200 Subject: [PATCH 048/125] Updated reservation lists with new date format --- ding_reservation.info | 2 +- ding_reservation.module | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ding_reservation.info b/ding_reservation.info index bc113f9..fa343fb 100644 --- a/ding_reservation.info +++ b/ding_reservation.info @@ -8,4 +8,4 @@ files[] = ding_reservation.test dependencies[] = ding_base dependencies[] = ding_provider dependencies[] = ding_user -dependencies[] = ding_popup +dependencies[] = ding_popup \ No newline at end of file diff --git a/ding_reservation.module b/ding_reservation.module index 5b0a74b..9df8ab6 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -389,11 +389,11 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'class' => 'pickup-id', ), 'created' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'long_date_only') : '', + 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'ding_reservation_lists_date') : '', 'class' => 'created-date', ), 'pickup_date' => array( - 'data' => $item->pickup_date ? format_date(strtotime(check_plain($item->pickup_date)), 'long_date_only' ) : '', + 'data' => $item->pickup_date ? format_date(strtotime(check_plain($item->pickup_date)), 'ding_reservation_lists_date' ) : '', 'class' => 'pickup-date', ), 'pickup_branch' => array( @@ -439,11 +439,11 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( ), 'created' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'long_date_only') : '', + 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'ding_reservation_lists_date') : '', 'class' => 'created-date', ), 'expiry' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'long_date_only') : '', + 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'ding_reservation_lists_date') : '', 'class' => 'expire-date', ), 'pickup_branch' => array( @@ -493,11 +493,11 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'class' => 'title', ), 'created' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'long_date_only') : '', + 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'ding_reservation_lists_date') : '', 'class' => 'created-date', ), 'expiry' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'long_date_only') : '', + 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'ding_reservation_lists_date') : '', 'class' => 'expire-date', ), 'library' => array( From 4fec69539007b82505378f7726035331d5bb0123 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 10 Jun 2013 13:51:11 +0200 Subject: [PATCH 049/125] Changed default reservation form list to "not ready for pickup" --- plugins/content_types/reservations/reservations.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/content_types/reservations/reservations.inc b/plugins/content_types/reservations/reservations.inc index bf3cade..5020cde 100644 --- a/plugins/content_types/reservations/reservations.inc +++ b/plugins/content_types/reservations/reservations.inc @@ -83,7 +83,7 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan if (count($types) > 1) { // If more than one type is selected we will fallback to the most generic // form type. - $block->content = ding_provider_get_form($form_id, $content[$form_id], 'ready_for_pickup'); + $block->content = ding_provider_get_form($form_id, $content[$form_id], 'not_ready_for_pickup'); } else { $block->content = ding_provider_get_form($form_id, $content[$form_id], array_shift($types)); From d1debfd6fd25884aaaefe15a7d2bfe9c1c20cece Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 24 Jun 2013 14:24:33 +0200 Subject: [PATCH 050/125] Updated make file to point to ding2tal --- ding_reservation.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index 7066255..4284909 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -10,20 +10,20 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" -projects[ding_base][download][url] = "git@github.com:ding2/ding_base.git" +projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" projects[ding_base][download][branch] = "master" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" -projects[ding_popup][download][url] = "git@github.com:ding2/ding_popup.git" +projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" projects[ding_popup][download][branch] = "master" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" -projects[ding_user][download][url] = "git@github.com:ding2/ding_user.git" +projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" projects[ding_user][download][branch] = "master" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" -projects[ding_provider][download][url] = "git@github.com:ding2/ding_provider.git" +projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" projects[ding_provider][download][branch] = "master" From 372309d73173bf995b5cbe70a178c1d1c73921c0 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 24 Jun 2013 14:56:38 +0200 Subject: [PATCH 051/125] Changed makefile to use development branch --- ding_reservation.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index 4284909..cae1f1b 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -11,19 +11,19 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" -projects[ding_base][download][branch] = "master" +projects[ding_base][download][branch] = "development" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" -projects[ding_popup][download][branch] = "master" +projects[ding_popup][download][branch] = "development" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" -projects[ding_user][download][branch] = "master" +projects[ding_user][download][branch] = "development" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][branch] = "master" +projects[ding_provider][download][branch] = "development" From 8088953b15508706afb9d1d505f888ed054b3115 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 3 Jul 2013 13:35:41 +0200 Subject: [PATCH 052/125] Updated makefile to point to development branch and ding2tal --- ding_reservation.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index 7066255..59409a2 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -11,19 +11,19 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" projects[ding_base][download][url] = "git@github.com:ding2/ding_base.git" -projects[ding_base][download][branch] = "master" +projects[ding_base][download][branch] = "development" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" projects[ding_popup][download][url] = "git@github.com:ding2/ding_popup.git" -projects[ding_popup][download][branch] = "master" +projects[ding_popup][download][branch] = "development" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" projects[ding_user][download][url] = "git@github.com:ding2/ding_user.git" -projects[ding_user][download][branch] = "master" +projects[ding_user][download][branch] = "development" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2/ding_provider.git" -projects[ding_provider][download][branch] = "master" +projects[ding_provider][download][branch] = "development" From 22fbb4c8debb9e05d5edb3ce88d686d9f7af9212 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 29 Aug 2013 07:45:27 +0200 Subject: [PATCH 053/125] Fixed indention of switch statment --- ding_reservation.module | 292 ++++++++++++++++++++-------------------- 1 file changed, 146 insertions(+), 146 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 9df8ab6..cdf3760 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -367,165 +367,165 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( $pickup_branch = ding_provider_invoke('reservation', 'branch_name', $item->pickup_branch_id); switch ($type) { - case 'ready_for_pickup': - $delete_button = array( - '#prefix' => '
', - '#suffix' => '
', - '#type' => 'submit', - '#submit' => array('ding_reservation_reservations_delete_submit'), - '#reservation_id' => $item->id, - '#name' => 'delete-' . preg_replace('/\W/', '-', $item->id), // Need this for formAPI can tell buttons apart - '#value' => t('Delete'), - '#options' => array('query' => $destination), - ); - - $options[$item->id] = array( - 'title' => array( - 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), - 'class' => 'title', - ), - 'pickup_id' => array( - 'data' => ding_reservation_get_pickup_id($item), - 'class' => 'pickup-id', - ), - 'created' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'ding_reservation_lists_date') : '', - 'class' => 'created-date', - ), - 'pickup_date' => array( - 'data' => $item->pickup_date ? format_date(strtotime(check_plain($item->pickup_date)), 'ding_reservation_lists_date' ) : '', - 'class' => 'pickup-date', - ), - 'pickup_branch' => array( - 'data' => $pickup_branch ? check_plain($pickup_branch) : '', - 'class' => 'pickup-branch', - ), - ); - - // Check if able to delete reservation should be added. - if ($able_to_delete) { - $options[$item->id]['operations'] = array( - 'data' => $delete_button, - 'class' => 'operations', + case 'ready_for_pickup': + $delete_button = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'submit', + '#submit' => array('ding_reservation_reservations_delete_submit'), + '#reservation_id' => $item->id, + '#name' => 'delete-' . preg_replace('/\W/', '-', $item->id), // Need this for formAPI can tell buttons apart + '#value' => t('Delete'), + '#options' => array('query' => $destination), ); - } - if (!empty($item->notes)) { - $options[$item->id]['title']['data'][] = array( - '#type' => 'markup', - '#prefix' => '

', - '#markup' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($item->notes))), - '#suffix' => '

', + $options[$item->id] = array( + 'title' => array( + 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), + 'class' => 'title', + ), + 'pickup_id' => array( + 'data' => ding_reservation_get_pickup_id($item), + 'class' => 'pickup-id', + ), + 'created' => array( + 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'ding_reservation_lists_date') : '', + 'class' => 'created-date', + ), + 'pickup_date' => array( + 'data' => $item->pickup_date ? format_date(strtotime(check_plain($item->pickup_date)), 'ding_reservation_lists_date' ) : '', + 'class' => 'pickup-date', + ), + 'pickup_branch' => array( + 'data' => $pickup_branch ? check_plain($pickup_branch) : '', + 'class' => 'pickup-branch', + ), ); - } - $form['reservations'] = array( - '#type' => 'tableselect_form', - '#header' => $header, - '#options' => $options, - '#empty' => t('No reservations ready for pickup'), - ); - break; + // Check if able to delete reservation should be added. + if ($able_to_delete) { + $options[$item->id]['operations'] = array( + 'data' => $delete_button, + 'class' => 'operations', + ); + } - case 'not_ready_for_pickup': - $options[$item->id] = array( - 'title' => array( - 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), - 'class' => 'title', - ), - 'order_nr' => array( - 'data' => ding_reservation_get_order_nr($item), - 'class' => 'pickup-id', - ), - - 'created' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'ding_reservation_lists_date') : '', - 'class' => 'created-date', - ), - 'expiry' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'ding_reservation_lists_date') : '', - 'class' => 'expire-date', - ), - 'pickup_branch' => array( - 'data' => $pickup_branch ? check_plain($pickup_branch) : '', - 'class' => 'pickup-branch', - ), - 'queue_number' => array( - 'data' => $item->queue_number ? check_plain($item->queue_number) : '', - 'class' => 'queue-number', - ), - 'operations' => array( - 'data' => array( - '#prefix' => '
', - '#suffix' => '
', - '#type' => 'submit', - '#submit' => array('ding_reservation_reservations_delete_submit'), - '#reservation_id' => $item->id, - '#name' => 'delete-' . preg_replace('/\W/', '-', $item->id), // Need this for formAPI can tell buttons apart - '#value' => t('Delete'), - '#options' => array('query' => $destination), + if (!empty($item->notes)) { + $options[$item->id]['title']['data'][] = array( + '#type' => 'markup', + '#prefix' => '

', + '#markup' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($item->notes))), + '#suffix' => '

', + ); + } + + $form['reservations'] = array( + '#type' => 'tableselect_form', + '#header' => $header, + '#options' => $options, + '#empty' => t('No reservations ready for pickup'), + ); + break; + + case 'not_ready_for_pickup': + $options[$item->id] = array( + 'title' => array( + 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), + 'class' => 'title', + ), + 'order_nr' => array( + 'data' => ding_reservation_get_order_nr($item), + 'class' => 'pickup-id', ), - 'class' => 'operations', - ), - ); - if (!empty($item->notes)) { - $options[$item->id]['title']['data'][] = array( - '#type' => 'markup', - '#prefix' => '

', - '#markup' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($item->notes))), - '#suffix' => '

', + 'created' => array( + 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'ding_reservation_lists_date') : '', + 'class' => 'created-date', + ), + 'expiry' => array( + 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'ding_reservation_lists_date') : '', + 'class' => 'expire-date', + ), + 'pickup_branch' => array( + 'data' => $pickup_branch ? check_plain($pickup_branch) : '', + 'class' => 'pickup-branch', + ), + 'queue_number' => array( + 'data' => $item->queue_number ? check_plain($item->queue_number) : '', + 'class' => 'queue-number', + ), + 'operations' => array( + 'data' => array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'submit', + '#submit' => array('ding_reservation_reservations_delete_submit'), + '#reservation_id' => $item->id, + '#name' => 'delete-' . preg_replace('/\W/', '-', $item->id), // Need this for formAPI can tell buttons apart + '#value' => t('Delete'), + '#options' => array('query' => $destination), + ), + 'class' => 'operations', + ), ); - } - $form['reservations'] = array( - '#type' => 'tableselect_form', - '#header' => $header, - '#options' => $options, - '#empty' => t('No Reservations'), - ); - break; + if (!empty($item->notes)) { + $options[$item->id]['title']['data'][] = array( + '#type' => 'markup', + '#prefix' => '

', + '#markup' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($item->notes))), + '#suffix' => '

', + ); + } - case 'interlibrary_loans': - $options[$item->id] = array( - 'title' => array( - 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), - 'class' => 'title', - ), - 'created' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'ding_reservation_lists_date') : '', - 'class' => 'created-date', - ), - 'expiry' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'ding_reservation_lists_date') : '', - 'class' => 'expire-date', - ), - 'library' => array( - 'data' => $pickup_branch ? check_plain($pickup_branch) : '', - 'class' => 'pickup-branch', - ), - 'ill_status' => array( - 'data' => $item->ill_status ? t(check_plain($item->ill_status)) : '', - 'class' => 'ill-status', - ), - ); + $form['reservations'] = array( + '#type' => 'tableselect_form', + '#header' => $header, + '#options' => $options, + '#empty' => t('No Reservations'), + ); + break; - if (!empty($item->notes)) { - $options[$item->id]['title']['data'][] = array( - '#type' => 'markup', - '#prefix' => '

', - '#markup' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($item->notes))), - '#suffix' => '

', + case 'interlibrary_loans': + $options[$item->id] = array( + 'title' => array( + 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), + 'class' => 'title', + ), + 'created' => array( + 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'ding_reservation_lists_date') : '', + 'class' => 'created-date', + ), + 'expiry' => array( + 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'ding_reservation_lists_date') : '', + 'class' => 'expire-date', + ), + 'library' => array( + 'data' => $pickup_branch ? check_plain($pickup_branch) : '', + 'class' => 'pickup-branch', + ), + 'ill_status' => array( + 'data' => $item->ill_status ? t(check_plain($item->ill_status)) : '', + 'class' => 'ill-status', + ), ); - } - $form['reservations'] = array( - '#type' => 'tableselect_form', - '#header' => $header, - '#options' => $options, - '#empty' => t('No inter-library loans'), - ); - break; + if (!empty($item->notes)) { + $options[$item->id]['title']['data'][] = array( + '#type' => 'markup', + '#prefix' => '

', + '#markup' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($item->notes))), + '#suffix' => '

', + ); + } + + $form['reservations'] = array( + '#type' => 'tableselect_form', + '#header' => $header, + '#options' => $options, + '#empty' => t('No inter-library loans'), + ); + break; } } From a55adc0b2b65b6f76fe1cd7bc5a3beb7a9799f4c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 29 Aug 2013 07:52:01 +0200 Subject: [PATCH 054/125] Moved the reservation "entity" class into own file --- ding_reservation.info | 2 +- ding_reservation.module | 32 ---------------------- includes/ding_reservation_entity.inc | 40 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 33 deletions(-) create mode 100644 includes/ding_reservation_entity.inc diff --git a/ding_reservation.info b/ding_reservation.info index fa343fb..5f0fae6 100644 --- a/ding_reservation.info +++ b/ding_reservation.info @@ -3,7 +3,7 @@ description = Allows users to reserve materials. package = Ding! version = "7.x-0.18" core = 7.x -files[] = ding_reservation.module +files[] = includes/ding_reservation_entity.inc files[] = ding_reservation.test dependencies[] = ding_base dependencies[] = ding_provider diff --git a/ding_reservation.module b/ding_reservation.module index cdf3760..81f6585 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -1060,35 +1060,3 @@ function ding_reservation_sort_queue_by_queue_number($a, $b) { } return ($a->queue_number < $b->queue_number) ? -1 : 1; } - -/** - * Interface for reservable items. - */ -interface DingReservationReservable { - public function getProviderId(); - // @todo, this should be optional. - public function getEntity(); - public function getTitle(); -} - -/** - * A reservable entity. - */ -class DingReservationReservableEntity implements DingReservationReservable { - public function __construct($entity) { - $this->entity = $entity; - } - - public function getProviderId() { - return isset($this->entity->provider_id) ? $this->entity->provider_id : NULL; - } - - public function getEntity() { - return $this->entity; - } - - public function getTitle() { - return isset($this->entity->record['dc:title'][''][0]) ? $this->entity->record['dc:title'][''][0] : ''; - } -} - diff --git a/includes/ding_reservation_entity.inc b/includes/ding_reservation_entity.inc new file mode 100644 index 0000000..6087586 --- /dev/null +++ b/includes/ding_reservation_entity.inc @@ -0,0 +1,40 @@ +entity = $entity; + } + + public function getProviderId() { + return isset($this->entity->provider_id) ? $this->entity->provider_id : NULL; + } + + public function getEntity() { + return $this->entity; + } + + public function getTitle() { + return isset($this->entity->record['dc:title'][''][0]) ? $this->entity->record['dc:title'][''][0] : ''; + } +} \ No newline at end of file From 4c26033ea19dde5bb10b0b09b1c5cb01d0d298c6 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 29 Aug 2013 08:11:02 +0200 Subject: [PATCH 055/125] Tried to fix coding style --- ding_reservation.module | 85 ++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 81f6585..95f661d 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -764,6 +764,42 @@ function ding_reservation_delete_reservations_form($form, $form_state, $account, return $form; } +/** + * Delete reservation submit normal handler. + * + * @see ding_reservation_delete_reservations_form_callback(). + */ +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); + + // Clear reservation sesion cache. + ding_reservation_cache_clear(); + } +} + +/** + * Delete reservation ajax callback. + */ +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; +} + /** * Update reservations form. */ @@ -797,7 +833,7 @@ function ding_reservation_update_reservations_form($form, $form_state, $account, } /** - * Validation handler. + * Update reservation validation handler. */ function ding_reservation_update_reservations_form_validate($form, &$form_state) { global $user; @@ -832,25 +868,10 @@ function ding_reservation_update_reservations_form_validate($form, &$form_state) } /** - * Submit handlers. + * Update reservation normal submit handler. * + * @see ding_reservation_update_reservations_form_callback(). */ -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); - - // Clear reservation sesion cache. - ding_reservation_cache_clear(); - } -} - 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']); @@ -860,20 +881,8 @@ function ding_reservation_update_reservations_form_submit($form, &$form_state) { } /** - * Ajax callback functions. + * Update reservations ajax callback. */ -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', @@ -899,24 +908,26 @@ function ding_reservation_update_reservations_form_callback($form, &$form_state) * Returns form element(s) for selecting a pickup branch. */ function ding_reservation_default_options_branch($type, $name, $default, $options) { + $form = array(); + $create = ($type == 'create'); $allowed_branches = ($create ? array('' => 'Select') : array($default => t('No change'))) + (array)$options; - $default_value = $default; $form[$name] = array( '#type' => 'select', '#title' => t('Select branch'), '#options' => $allowed_branches, - '#default_value' => $default_value, + '#default_value' => $default, ); + if ($create) { $form[$name . 'description'] = array( '#markup' => '

' . t('In order to make quick reservations, you must select a default pickup branch.') . '

', ); } + return $form; } - /** * Create an interest period form select element. * @@ -960,7 +971,6 @@ function ding_reservation_interest_period_selector($type, $name, $default, $opti return $form; } - /** * Validate pickup branch selector. * @@ -968,6 +978,7 @@ function ding_reservation_interest_period_selector($type, $name, $default, $opti */ function ding_reservation_default_options_branch_validate($type, $name, $default, $values) { if (empty($values[$name])) { + $result = array(); $provider = ding_provider_get_provider_module_name('reservation'); if ($type == 'create' && empty($default)) { $result[$provider . '_preferred_branch'] = array( @@ -1020,7 +1031,9 @@ function ding_reservation_default_options_branch_submit($type, $name, $default, return $result; } - +/** + * Clears the reservations cache if ding_session_cache is active. + */ function ding_reservation_cache_clear() { if (module_exists('ding_session_cache')) { ding_session_cache_clear('ding_reservation', 'reservations'); From 95e358680f3682190853c9c6c228d4266c1887c1 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 29 Aug 2013 10:17:29 +0200 Subject: [PATCH 056/125] Cleaned up reservation lists empty texts --- ding_reservation.module | 42 +++++++++---------- .../reservations/reservations.inc | 2 +- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 95f661d..a51c41b 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -19,12 +19,16 @@ function ding_reservation_ctools_plugin_directory($module, $plugin) { /** * Implements hook_menu(). + * + * These menu callbacks are used to handle non-ajax callbacks on the reservation + * update/delete buttons and simple redirects the users to the forms normal + * displayed in the ding_popup's. + * + * The id's is url_encoded in the last wildcard parameter. */ function ding_reservation_menu() { $items = array(); - // @todo ding_reservation really doesn't know that this path is correct. How - // to handle it? $items['user/%user/status/reservations/update/%'] = array( 'title' => 'Update reservations', 'page callback' => 'drupal_get_form', @@ -297,8 +301,8 @@ function ding_reservation_reserve_form_callback($form, &$form_state) { unset($form['provider_options'][$v]); unset($form['provider_options'][$v . 'description']); } - } + // Redisplay form. $html .= drupal_render($form); } @@ -419,12 +423,6 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( ); } - $form['reservations'] = array( - '#type' => 'tableselect_form', - '#header' => $header, - '#options' => $options, - '#empty' => t('No reservations ready for pickup'), - ); break; case 'not_ready_for_pickup': @@ -478,12 +476,6 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( ); } - $form['reservations'] = array( - '#type' => 'tableselect_form', - '#header' => $header, - '#options' => $options, - '#empty' => t('No Reservations'), - ); break; case 'interlibrary_loans': @@ -519,12 +511,6 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( ); } - $form['reservations'] = array( - '#type' => 'tableselect_form', - '#header' => $header, - '#options' => $options, - '#empty' => t('No inter-library loans'), - ); break; } } @@ -534,13 +520,12 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( '#type' => 'tableselect_form', '#header' => $header, '#options' => $options, - '#empty' => $empty_message, ); } else { $form['reservations'] = array( '#type' => 'item', - '#markup' => theme('table', array('header' => $header, 'rows' => $options, 'empty' => $empty_message)), + '#markup' => theme('table', array('header' => $header, 'rows' => $options)), ); } @@ -669,6 +654,8 @@ function ding_reservation_reservations_delete_submit($form, &$form_state) { /** * Submit handler for the delete form. + * + * @see ding_reservation_reservations_form(). */ function ding_reservation_deletes_form_submit($form, &$form_state) { global $user; @@ -679,6 +666,8 @@ function ding_reservation_deletes_form_submit($form, &$form_state) { /** * Submit handler for the update form. + * + * @see ding_reservation_reservations_form(). */ function ding_reservation_updates_form_submit($form, &$form_state) { global $user; @@ -689,6 +678,8 @@ function ding_reservation_updates_form_submit($form, &$form_state) { /** * Ajax callback for the delete form. + * + * @see ding_reservation_reservations_form(). */ function ding_reservation_deletes_form_callback($form, &$form_state) { global $user; @@ -708,6 +699,8 @@ function ding_reservation_deletes_form_callback($form, &$form_state) { /** * Ajax callback for the update form. + * + * @see ding_reservation_reservations_form(). */ function ding_reservation_updates_form_callback($form, &$form_state) { global $user; @@ -727,6 +720,8 @@ function ding_reservation_updates_form_callback($form, &$form_state) { /** * Delete reservations form. + * + * @see ding_reservation_reservations_form(). */ function ding_reservation_delete_reservations_form($form, $form_state, $account, $reservation_ids) { global $user; @@ -829,6 +824,7 @@ function ding_reservation_update_reservations_form($form, $form_state, $account, ), '#value' => t('Update reservations'), ); + return $form; } diff --git a/plugins/content_types/reservations/reservations.inc b/plugins/content_types/reservations/reservations.inc index 5020cde..dbc11c4 100644 --- a/plugins/content_types/reservations/reservations.inc +++ b/plugins/content_types/reservations/reservations.inc @@ -25,7 +25,7 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan $block->module = 'ding_reservation'; $block->delta = 'reservations'; - // Get configuration for this pane. + // Get configuration for this pane. Set title and empty text. $types = array_filter($conf['reservation_type_list']); $block->title = t($conf['reservation_titel']); $block->content = t($conf['reservation_empty_text']); From 75bea4374f915911992aaa95c7d7a86382054fe9 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 29 Aug 2013 10:42:04 +0200 Subject: [PATCH 057/125] Added even more comments to the code --- ding_reservation.module | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ding_reservation.module b/ding_reservation.module index a51c41b..1b1a5cd 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -515,6 +515,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( } } + // Set the form of table we want to be build. if ($able_to_delete) { $form['reservations'] = array( '#type' => 'tableselect_form', @@ -529,6 +530,8 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( ); } + + // Add action buttons to the top of the form. $form['actions_top'] = array( '#weight' => -10, @@ -562,6 +565,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( ); } + // Add action buttons to the bottom of the form. $form['actions_bottom'] = array( '#weight' => 10, ); From d5dd158170c1c9481fa7ecece2969b719dcfa9b8 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 2 Sep 2013 12:23:38 +0200 Subject: [PATCH 058/125] Changed reservation list to use new material item theme function --- ding_reservation.module | 340 ++++++++++++++-------------------------- 1 file changed, 122 insertions(+), 218 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 1b1a5cd..4d7b155 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -315,10 +315,10 @@ function ding_reservation_reserve_form_callback($form, &$form_state) { /** * Show a reservation list form. */ -function ding_reservation_reservations_form($form, &$form_state, $items = array(), $type = 'not_ready_for_pickup') { - $options = array(); - $destination = drupal_get_destination(); - $empty_message = ''; +function ding_reservation_reservations_form($form, &$form_state, $reservations = array(), $type = 'not_ready_for_pickup') { + $form = array( + '#tree' => TRUE, + ); // Check if reservations should be able to be deleted by the user. $able_to_delete = FALSE; @@ -326,252 +326,138 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( $able_to_delete = ding_provider_invoke('reservation', 'reservation_deletion_enabled'); } - switch ($type) { - case 'ready_for_pickup': - $header = array( - 'title' => t('Title'), - 'pickup_id' => t('Pickup id'), - 'created' => t('Created date'), - 'pickup_date' => t('Pickup date'), - 'pickup_branch' => t('Pickup branch'), - 'operations' => '', - ); - uasort($items, 'ding_reservation_sort_queue_by_pickup_date'); - break; - - case 'not_ready_for_pickup': - $header = array( - 'title' => t('Title'), - 'order_nr' => t('Order nr.'), - 'created' => t('Created date'), - 'expiry' => t('Expiry date'), - 'pickup_branch' => t('Pickup branch'), - 'queue_number' => t('Queue number'), - 'operations' => '', - ); - uasort($items, 'ding_reservation_sort_queue_by_queue_number'); - break; - - case 'interlibrary_loans': - $header = array( - 'title' => t('Title'), - 'created' => t('Created date'), - 'expiry' => t('Expiry date'), - 'library' => t('Library'), - 'ill_status' => t('Status'), - ); - break; - } - - foreach ($items as $id => $item) { - $entity = $item->entity; + foreach ($reservations as $reservation) { + $entity = $reservation->entity; if (!is_object($entity)) { - $entity = ding_provider_get_pseudo_entity($item->ding_entity_id); + $entity = ding_provider_get_pseudo_entity($reservation->ding_entity_id); } - $pickup_branch = ding_provider_invoke('reservation', 'branch_name', $item->pickup_branch_id); + $pickup_branch = ding_provider_invoke('reservation', 'branch_name', $reservation->pickup_branch_id); switch ($type) { case 'ready_for_pickup': - $delete_button = array( - '#prefix' => '
', - '#suffix' => '
', - '#type' => 'submit', - '#submit' => array('ding_reservation_reservations_delete_submit'), - '#reservation_id' => $item->id, - '#name' => 'delete-' . preg_replace('/\W/', '-', $item->id), // Need this for formAPI can tell buttons apart - '#value' => t('Delete'), - '#options' => array('query' => $destination), - ); - - $options[$item->id] = array( - 'title' => array( - 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), - 'class' => 'title', - ), - 'pickup_id' => array( - 'data' => ding_reservation_get_pickup_id($item), - 'class' => 'pickup-id', - ), - 'created' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'ding_reservation_lists_date') : '', - 'class' => 'created-date', - ), - 'pickup_date' => array( - 'data' => $item->pickup_date ? format_date(strtotime(check_plain($item->pickup_date)), 'ding_reservation_lists_date' ) : '', - 'class' => 'pickup-date', - ), - 'pickup_branch' => array( - 'data' => $pickup_branch ? check_plain($pickup_branch) : '', - 'class' => 'pickup-branch', + $item = array( + '#type' => 'material_item', + '#id' => $reservation->id, + '#title' => $entity ? $entity->getTitle() : $reservation->display_name, + '#cover' => field_view_field('ting_entity', $entity, 'ting_cover', 'user_list'), + '#information' => array( + 'pickup_id' => array( + 'label' => t('Pickup id'), + 'data' => ding_reservation_get_pickup_id($reservation), + 'class' => 'pickup-id', + ), + 'created' => array( + 'label' => t('Created date'), + 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', + 'class' => 'created-date', + ), + 'pickup_date' => array( + 'label' => t('Pickup date'), + 'data' => $reservation->pickup_date ? format_date(strtotime(check_plain($reservation->pickup_date)), 'ding_reservation_lists_date' ) : '', + 'class' => 'pickup-date', + ), + 'pickup_branch' => array( + 'label' => t('Pickup branch'), + 'data' => $pickup_branch ? check_plain($pickup_branch) : t('Unknown branch'), + 'class' => 'pickup-branch', + ), ), ); - - // Check if able to delete reservation should be added. - if ($able_to_delete) { - $options[$item->id]['operations'] = array( - 'data' => $delete_button, - 'class' => 'operations', - ); - } - - if (!empty($item->notes)) { - $options[$item->id]['title']['data'][] = array( - '#type' => 'markup', - '#prefix' => '

', - '#markup' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($item->notes))), - '#suffix' => '

', - ); - } - break; case 'not_ready_for_pickup': - $options[$item->id] = array( - 'title' => array( - 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), - 'class' => 'title', - ), - 'order_nr' => array( - 'data' => ding_reservation_get_order_nr($item), - 'class' => 'pickup-id', - ), - - 'created' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'ding_reservation_lists_date') : '', - 'class' => 'created-date', - ), - 'expiry' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'ding_reservation_lists_date') : '', - 'class' => 'expire-date', - ), - 'pickup_branch' => array( - 'data' => $pickup_branch ? check_plain($pickup_branch) : '', - 'class' => 'pickup-branch', - ), - 'queue_number' => array( - 'data' => $item->queue_number ? check_plain($item->queue_number) : '', - 'class' => 'queue-number', - ), - 'operations' => array( - 'data' => array( - '#prefix' => '
', - '#suffix' => '
', - '#type' => 'submit', - '#submit' => array('ding_reservation_reservations_delete_submit'), - '#reservation_id' => $item->id, - '#name' => 'delete-' . preg_replace('/\W/', '-', $item->id), // Need this for formAPI can tell buttons apart - '#value' => t('Delete'), - '#options' => array('query' => $destination), + $item = array( + '#type' => 'material_item', + '#id' => $reservation->id, + '#title' => $entity ? $entity->getTitle() : $reservation->display_name, + '#cover' => field_view_field('ting_object', $entity, 'ting_cover', 'user_list'), + '#information' => array( + 'order_nr' => array( + 'label' => t('Order nr.'), + 'data' => ding_reservation_get_order_nr($reservation), + 'class' => 'pickup-id', + ), + 'created' => array( + 'label' => t('Created date'), + 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', + 'class' => 'created-date', + ), + 'expiry' => array( + 'label' => t('Expiry date'), + 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->expiry)), 'ding_reservation_lists_date') : '', + 'class' => 'expire-date', + ), + 'pickup_branch' => array( + 'label' => t('Pickup branch'), + 'data' => $pickup_branch ? check_plain($pickup_branch) : '', + 'class' => 'pickup-branch', + ), + 'queue_number' => array( + 'label' => t('Queue number'), + 'data' => $reservation->queue_number ? check_plain($reservation->queue_number) : '', + 'class' => 'queue-number', ), - 'class' => 'operations', ), ); - - if (!empty($item->notes)) { - $options[$item->id]['title']['data'][] = array( - '#type' => 'markup', - '#prefix' => '

', - '#markup' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($item->notes))), - '#suffix' => '

', - ); - } - break; case 'interlibrary_loans': - $options[$item->id] = array( - 'title' => array( - 'data' => array($entity ? ting_object_view($entity, 'user_list') : array('#markup' => $item->display_name)), - 'class' => 'title', - ), - 'created' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->created)), 'ding_reservation_lists_date') : '', - 'class' => 'created-date', - ), - 'expiry' => array( - 'data' => $item->created ? format_date(strtotime(check_plain($item->expiry)), 'ding_reservation_lists_date') : '', - 'class' => 'expire-date', - ), - 'library' => array( - 'data' => $pickup_branch ? check_plain($pickup_branch) : '', - 'class' => 'pickup-branch', - ), - 'ill_status' => array( - 'data' => $item->ill_status ? t(check_plain($item->ill_status)) : '', - 'class' => 'ill-status', + $item = array( + '#type' => 'material_item', + '#id' => $reservation->id, + '#title' => $entity ? $entity->getTitle() : $reservation->display_name, + '#cover' => field_view_field('ting_entity', $entity, 'ting_cover', 'user_list'), + '#information' => array( + 'created' => array( + 'label' => t('Expiry date'), + 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', + 'class' => 'created-date', + ), + 'expiry' => array( + 'label' => t('Library'), + 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->expiry)), 'ding_reservation_lists_date') : '', + 'class' => 'expire-date', + ), + 'library' => array( + 'label' => t('Library'), + 'data' => $pickup_branch ? check_plain($pickup_branch) : '', + 'class' => 'pickup-branch', + ), + 'ill_status' => array( + 'label' => t('Status'), + 'data' => $reservation->ill_status ? t(check_plain($reservation->ill_status)) : '', + 'class' => 'ill-status', + ), ), ); - - if (!empty($item->notes)) { - $options[$item->id]['title']['data'][] = array( - '#type' => 'markup', - '#prefix' => '

', - '#markup' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($item->notes))), - '#suffix' => '

', - ); - } - break; } - } - // Set the form of table we want to be build. - if ($able_to_delete) { - $form['reservations'] = array( - '#type' => 'tableselect_form', - '#header' => $header, - '#options' => $options, - ); - } - else { - $form['reservations'] = array( - '#type' => 'item', - '#markup' => theme('table', array('header' => $header, 'rows' => $options)), - ); - } + // Add extra information if it's a periodical. + if (!empty($reservation->notes)) { + $item['#information']['extra'][] = array( + 'data' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($reservation->notes))), + 'class' => 'periodical-number', + ); + } + + // Render the items. + $form['reservations'][$reservation->id] = $item; + } // Add action buttons to the top of the form. $form['actions_top'] = array( '#weight' => -10, - ); - if ($able_to_delete) { - $form['actions_top']['delete'] = array( - '#prefix' => '
', - '#suffix' => '
', - '#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') { - $form['actions_top']['update'] = array( - '#prefix' => '
', - '#suffix' => '
', - '#type' => 'submit', - '#submit' => array('ding_reservation_updates_form_submit'), - '#value' => t('Update reservations'), - '#ajax' => array( - 'callback' => 'ding_reservation_updates_form_callback', - 'wrapper' => 'ding-reservation-updates-form', - ), - ); - } - // Add action buttons to the bottom of the form. $form['actions_bottom'] = array( '#weight' => 10, ); if ($able_to_delete) { - $form['actions_bottom']['delete'] = array( + $form['actions_top']['delete'] = array( '#prefix' => '
', '#suffix' => '
', '#submit' => array('ding_reservation_deletes_form_submit'), @@ -582,10 +468,11 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'wrapper' => 'ding-reservation-reservations-form', ), ); + $form['actions_bottom']['delete'] = $form['actions_top']['delete']; } if ($type == 'not_ready_for_pickup') { - $form['actions_bottom']['update'] = array( + $form['actions_top']['update'] = array( '#prefix' => '
', '#suffix' => '
', '#type' => 'submit', @@ -596,6 +483,7 @@ function ding_reservation_reservations_form($form, &$form_state, $items = array( 'wrapper' => 'ding-reservation-updates-form', ), ); + $form['actions_bottom']['update'] = $form['actions_top']['update']; } return $form; @@ -663,7 +551,15 @@ function ding_reservation_reservations_delete_submit($form, &$form_state) { */ function ding_reservation_deletes_form_submit($form, &$form_state) { global $user; - $ids = join(',', array_map('rawurlencode', array_filter($form_state['values']['reservations'], 'is_string'))); + + // Extra checkbox values form the form. + $ids = array(); + foreach($form_state['values']['reservations'] as $reservations) { + $ids = array_merge($reservations, $ids); + } + $ids = join(',', array_map('rawurlencode', array_filter($ids, 'is_string'))); + + // Save the encoded id's and redirect the form. $form_state['encoded_reservations'] = $ids; $form_state['redirect'] = array('user/' . $user->uid . '/status/reservations/delete/' . $ids, array('query' => drupal_get_destination())); } @@ -675,7 +571,15 @@ function ding_reservation_deletes_form_submit($form, &$form_state) { */ function ding_reservation_updates_form_submit($form, &$form_state) { global $user; + + // Extra checkbox values form the form. + $ids = array(); + foreach($form_state['values']['reservations'] as $reservations) { + $ids = array_merge($reservations, $ids); + } $ids = join(',', array_map('rawurlencode', array_filter($form_state['values']['reservations'], 'is_string'))); + + // Save the encoded id's and redirect the form. $form_state['encoded_reservations'] = $ids; $form_state['redirect'] = array('user/' . $user->uid . '/status/reservations/update/' . $ids, array('query' => drupal_get_destination())); } From a9d5136e50b9cdd51aae987a7c814711844ef2f2 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 2 Sep 2013 12:43:40 +0200 Subject: [PATCH 059/125] Change information order in reservation lists --- ding_reservation.module | 52 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 4d7b155..f6fb3b8 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -346,11 +346,6 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = 'data' => ding_reservation_get_pickup_id($reservation), 'class' => 'pickup-id', ), - 'created' => array( - 'label' => t('Created date'), - 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', - 'class' => 'created-date', - ), 'pickup_date' => array( 'label' => t('Pickup date'), 'data' => $reservation->pickup_date ? format_date(strtotime(check_plain($reservation->pickup_date)), 'ding_reservation_lists_date' ) : '', @@ -361,6 +356,11 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = 'data' => $pickup_branch ? check_plain($pickup_branch) : t('Unknown branch'), 'class' => 'pickup-branch', ), + 'created' => array( + 'label' => t('Created date'), + 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', + 'class' => 'created-date', + ), ), ); break; @@ -372,15 +372,10 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = '#title' => $entity ? $entity->getTitle() : $reservation->display_name, '#cover' => field_view_field('ting_object', $entity, 'ting_cover', 'user_list'), '#information' => array( - 'order_nr' => array( - 'label' => t('Order nr.'), - 'data' => ding_reservation_get_order_nr($reservation), - 'class' => 'pickup-id', - ), - 'created' => array( - 'label' => t('Created date'), - 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', - 'class' => 'created-date', + 'queue_number' => array( + 'label' => t('Queue number'), + 'data' => $reservation->queue_number ? check_plain($reservation->queue_number) : '', + 'class' => 'queue-number', ), 'expiry' => array( 'label' => t('Expiry date'), @@ -392,10 +387,15 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = 'data' => $pickup_branch ? check_plain($pickup_branch) : '', 'class' => 'pickup-branch', ), - 'queue_number' => array( - 'label' => t('Queue number'), - 'data' => $reservation->queue_number ? check_plain($reservation->queue_number) : '', - 'class' => 'queue-number', + 'created' => array( + 'label' => t('Created date'), + 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', + 'class' => 'created-date', + ), + 'order_nr' => array( + 'label' => t('Order nr.'), + 'data' => ding_reservation_get_order_nr($reservation), + 'class' => 'pickup-id', ), ), ); @@ -408,10 +408,10 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = '#title' => $entity ? $entity->getTitle() : $reservation->display_name, '#cover' => field_view_field('ting_entity', $entity, 'ting_cover', 'user_list'), '#information' => array( - 'created' => array( - 'label' => t('Expiry date'), - 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', - 'class' => 'created-date', + 'ill_status' => array( + 'label' => t('Status'), + 'data' => $reservation->ill_status ? t(check_plain($reservation->ill_status)) : t('Unknown status'), + 'class' => 'ill-status', ), 'expiry' => array( 'label' => t('Library'), @@ -423,10 +423,10 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = 'data' => $pickup_branch ? check_plain($pickup_branch) : '', 'class' => 'pickup-branch', ), - 'ill_status' => array( - 'label' => t('Status'), - 'data' => $reservation->ill_status ? t(check_plain($reservation->ill_status)) : '', - 'class' => 'ill-status', + 'created' => array( + 'label' => t('Expiry date'), + 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', + 'class' => 'created-date', ), ), ); From 439642ee61edef63b2994791743a2eae46126970 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 2 Sep 2013 12:46:59 +0200 Subject: [PATCH 060/125] Fixed entity type in view of ting cover field --- ding_reservation.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index f6fb3b8..c6d75c9 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -339,7 +339,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = '#type' => 'material_item', '#id' => $reservation->id, '#title' => $entity ? $entity->getTitle() : $reservation->display_name, - '#cover' => field_view_field('ting_entity', $entity, 'ting_cover', 'user_list'), + '#cover' => field_view_field('ting_object', $entity, 'ting_cover', 'user_list'), '#information' => array( 'pickup_id' => array( 'label' => t('Pickup id'), @@ -406,7 +406,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = '#type' => 'material_item', '#id' => $reservation->id, '#title' => $entity ? $entity->getTitle() : $reservation->display_name, - '#cover' => field_view_field('ting_entity', $entity, 'ting_cover', 'user_list'), + '#cover' => field_view_field('ting_object', $entity, 'ting_cover', 'user_list'), '#information' => array( 'ill_status' => array( 'label' => t('Status'), From 9dd80a1c3d701b46b360ef8a11de525cf1c8d1a9 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 2 Sep 2013 15:21:12 +0200 Subject: [PATCH 061/125] Added support for a select all checkboxes in the reservation list --- ding_reservation.module | 19 ++++++++++++- js/ding_reservation.js | 17 ++++++++++++ .../reservations/reservations.inc | 27 +++++++++---------- 3 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 js/ding_reservation.js diff --git a/ding_reservation.module b/ding_reservation.module index c6d75c9..7058d9c 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -315,11 +315,28 @@ function ding_reservation_reserve_form_callback($form, &$form_state) { /** * Show a reservation list form. */ -function ding_reservation_reservations_form($form, &$form_state, $reservations = array(), $type = 'not_ready_for_pickup') { +function ding_reservation_reservations_form($form, &$form_state, $reservations = array(), $type = 'not_ready_for_pickup', $conf = array()) { $form = array( '#tree' => TRUE, ); + // Add title item. + $form['title'] = array( + '#type' => 'checkbox', + '#title' => $conf['reservation_title'], + '#attributes' => array( + 'class' => array( + 'select-all-checkbox', + drupal_html_id($type), + ) + ), + '#attached' => array( + 'js' => array( + drupal_get_path('module', 'ding_reservation') . '/js/ding_reservation.js', + ), + ), + ); + // Check if reservations should be able to be deleted by the user. $able_to_delete = FALSE; if (ding_provider_implements('reservation', 'reservation_deletion_enabled')) { diff --git a/js/ding_reservation.js b/js/ding_reservation.js new file mode 100644 index 0000000..8c2c8bc --- /dev/null +++ b/js/ding_reservation.js @@ -0,0 +1,17 @@ +/** + * Javascript that adds the extra select all checkbox option to the titles on + * the user reservation page. + */ +(function ($) { + $(document).ready(function($) { + $('.select-all-checkbox').click(function() { + var checkboxes = $('input[type=checkbox]', $(this).closest('form')); + if ($(this).prop('checked')) { + checkboxes.prop('checked', true); + } + else { + checkboxes.prop('checked', false); + } + }); + }); +})(jQuery); \ No newline at end of file diff --git a/plugins/content_types/reservations/reservations.inc b/plugins/content_types/reservations/reservations.inc index dbc11c4..e1a28e1 100644 --- a/plugins/content_types/reservations/reservations.inc +++ b/plugins/content_types/reservations/reservations.inc @@ -25,9 +25,8 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan $block->module = 'ding_reservation'; $block->delta = 'reservations'; - // Get configuration for this pane. Set title and empty text. + // Get configuration for this pane and set empty text. $types = array_filter($conf['reservation_type_list']); - $block->title = t($conf['reservation_titel']); $block->content = t($conf['reservation_empty_text']); $form_id = $conf['reservation_form_id']; @@ -83,10 +82,10 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan if (count($types) > 1) { // If more than one type is selected we will fallback to the most generic // form type. - $block->content = ding_provider_get_form($form_id, $content[$form_id], 'not_ready_for_pickup'); + $block->content = ding_provider_get_form($form_id, $content[$form_id], 'not_ready_for_pickup', $conf); } else { - $block->content = ding_provider_get_form($form_id, $content[$form_id], array_shift($types)); + $block->content = ding_provider_get_form($form_id, $content[$form_id], array_shift($types), $conf); } } @@ -99,8 +98,8 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan function ding_reservation_reservations_content_type_edit_form($form, &$form_state) { $conf = $form_state['conf']; $form['reservation_type_list'] = array( - '#type' => 'checkboxes', - '#title' => t('Reservation list type(s)'), + '#type' => 'checkboxes', + '#title' => t('Reservation list type(s)'), '#options' => array( 'not_ready_for_pickup' => t('Not ready for pickup'), 'ready_for_pickup' => t('Ready for pickup'), @@ -109,21 +108,21 @@ function ding_reservation_reservations_content_type_edit_form($form, &$form_stat '#default_value' => !empty($conf['reservation_type_list']) ? $conf['reservation_type_list'] : NULL, ); - $form['reservation_titel'] = array( - '#type' => 'textfield', - '#title' => t('List titel'), - '#default_value' => !empty($conf['reservation_titel']) ? $conf['reservation_titel'] : 'Reservations', + $form['reservation_title'] = array( + '#type' => 'textfield', + '#title' => t('List title'), + '#default_value' => !empty($conf['reservation_title']) ? $conf['reservation_title'] : 'Reservations', ); $form['reservation_empty_text'] = array( - '#type' => 'textfield', - '#title' => t('Empty text'), + '#type' => 'textfield', + '#title' => t('Empty text'), '#default_value' => !empty($conf['reservation_empty_text']) ? $conf['reservation_empty_text'] : 'There are no reservations.', ); $form['reservation_form_id'] = array( - '#type' => 'select', - '#title' => t('Form to user for reservations'), + '#type' => 'select', + '#title' => t('Form to user for reservations'), '#options' => array( 'ding_reservation_reservations_notready_form' => t('Reservation form'), 'ding_reservation_reservations_ready_form' => t('Reservations ready form'), From 08bac0589351090ac04afe0c784401b830386e09 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 2 Sep 2013 15:34:55 +0200 Subject: [PATCH 062/125] Moved reservation sort functions and re-add the sort to the list --- ding_reservation.module | 20 ----------- .../reservations/reservations.inc | 33 ++++++++++++++++++- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 7058d9c..c84b17b 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -974,23 +974,3 @@ function ding_reservation_ding_session_cache_defaults() { 'expire' => 3600, ); } - -/** - * Callback function to sort array by pickup date - */ -function ding_reservation_sort_queue_by_pickup_date($a, $b) { - if ($a->pickup_date == $b->pickup_date) { - return 0; - } - return ($a->pickup_date < $b->pickup_date) ? -1 : 1; -} - -/** - * Callback function for sorting loans by queue_number - */ -function ding_reservation_sort_queue_by_queue_number($a, $b) { - if ($a->queue_number == $b->queue_number) { - return 0; - } - return ($a->queue_number < $b->queue_number) ? -1 : 1; -} diff --git a/plugins/content_types/reservations/reservations.inc b/plugins/content_types/reservations/reservations.inc index e1a28e1..3fea2d3 100644 --- a/plugins/content_types/reservations/reservations.inc +++ b/plugins/content_types/reservations/reservations.inc @@ -32,7 +32,7 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan $content = array(); if (module_exists('ding_session_cache')) { - $content = ding_session_cache_get('ding_reservation', 'reservations'); + //$content = ding_session_cache_get('ding_reservation', 'reservations'); } if (empty($content) || !isset($content[$form_id])) { @@ -63,6 +63,17 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan // Add the current type to the items we want. $items += $reservations[$type]; + + // Sort the reservations based on type. + switch ($type) { + case 'ready_for_pickup': + uasort($items, 'ding_reservation_sort_queue_by_pickup_date'); + break; + + case 'not_ready_for_pickup': + uasort($items, 'ding_reservation_sort_queue_by_queue_number'); + break; + } } // Add the preload entity to each loan (side effect of getting the entity). @@ -150,4 +161,24 @@ function ding_reservation_reservations_content_type_edit_form_submit(&$form, &$f function ding_reservation_reservations_content_type_admin_title($subtype, $conf) { $types = implode(', ', array_filter($conf['reservation_type_list'])); return 'Reservations (' . $types . ')'; +} + +/** + * Callback function to sort array by pickup date + */ +function ding_reservation_sort_queue_by_pickup_date($a, $b) { + if ($a->pickup_date == $b->pickup_date) { + return 0; + } + return ($a->pickup_date < $b->pickup_date) ? -1 : 1; +} + +/** + * Callback function for sorting loans by queue_number + */ +function ding_reservation_sort_queue_by_queue_number($a, $b) { + if ($a->queue_number == $b->queue_number) { + return 0; + } + return ($a->queue_number < $b->queue_number) ? -1 : 1; } \ No newline at end of file From ad8974068006f727a010acd789184ea54b1ad5bd Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 2 Sep 2013 15:56:06 +0200 Subject: [PATCH 063/125] Added checkbox count to buttons on the reservation list --- ding_reservation.module | 4 ++-- js/ding_reservation.js | 27 +++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index c84b17b..f617ba1 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -479,7 +479,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = '#suffix' => '', '#submit' => array('ding_reservation_deletes_form_submit'), '#type' => 'submit', - '#value' => t('Delete reservations'), + '#value' => t('Delete reservations (0)'), '#ajax' => array( 'callback' => 'ding_reservation_deletes_form_callback', 'wrapper' => 'ding-reservation-reservations-form', @@ -494,7 +494,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = '#suffix' => '', '#type' => 'submit', '#submit' => array('ding_reservation_updates_form_submit'), - '#value' => t('Update reservations'), + '#value' => t('Update reservations (0)'), '#ajax' => array( 'callback' => 'ding_reservation_updates_form_callback', 'wrapper' => 'ding-reservation-updates-form', diff --git a/js/ding_reservation.js b/js/ding_reservation.js index 8c2c8bc..9102174 100644 --- a/js/ding_reservation.js +++ b/js/ding_reservation.js @@ -1,9 +1,9 @@ /** - * Javascript that adds the extra select all checkbox option to the titles on - * the user reservation page. + * Handle reservation checkboxes select all and select count on buttons. */ (function ($) { $(document).ready(function($) { + // Handle select all checkboxes. $('.select-all-checkbox').click(function() { var checkboxes = $('input[type=checkbox]', $(this).closest('form')); if ($(this).prop('checked')) { @@ -12,6 +12,29 @@ else { checkboxes.prop('checked', false); } + checkboxes.change(); }); + + // Handle checkbox button count. + $('.material_item input[type=checkbox]').change(function() { + var form = $(this).closest('form'); + var buttons = $('input[type=submit]', form); + var count = $('.material_item input[type=checkbox]:checked', form).length; + update_buttons(buttons, count); + + // Handle all checkbox checked state, so if no all selected the checkbox + // is not checked. + if ($('.material_item input[type=checkbox]', form).length != count) { + $('.select-all-checkbox', form).prop('checked', false); + } + }) + + // Update count string on the buttons. + function update_buttons(buttons, count) { + buttons.each(function(index) { + var btn = $(buttons[index]); + btn.val(btn.val().replace(/\(\d+\)/, '(' + count + ')')); + }); + } }); })(jQuery); \ No newline at end of file From 1e2bb8ed70817514b15b592ffd76c1c39967ce9d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 2 Sep 2013 16:27:06 +0200 Subject: [PATCH 064/125] Re-activated session cache for reservations --- plugins/content_types/reservations/reservations.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/content_types/reservations/reservations.inc b/plugins/content_types/reservations/reservations.inc index 3fea2d3..30b5a43 100644 --- a/plugins/content_types/reservations/reservations.inc +++ b/plugins/content_types/reservations/reservations.inc @@ -32,7 +32,7 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan $content = array(); if (module_exists('ding_session_cache')) { - //$content = ding_session_cache_get('ding_reservation', 'reservations'); + $content = ding_session_cache_get('ding_reservation', 'reservations'); } if (empty($content) || !isset($content[$form_id])) { From 04eae927e556a895f5365425b114c0bc41ff6528 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 2 Sep 2013 17:23:28 +0200 Subject: [PATCH 065/125] Change the way periodical number gets add to a material item --- ding_reservation.module | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index f617ba1..b45dd8a 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -452,14 +452,14 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = // Add extra information if it's a periodical. if (!empty($reservation->notes)) { - $item['#information']['extra'][] = array( - 'data' => t('(Periodical no. @periodical)', array('@periodical' => check_plain($reservation->notes))), + $item['#information']['periodical_number'] = array( + 'label' => t('Periodical no.'), + 'data' => check_plain($reservation->notes), 'class' => 'periodical-number', ); } - - // Render the items. + // Add the reservation to the form. $form['reservations'][$reservation->id] = $item; } From c20eb1c13185297aa0376982b4bbc4c060b3ac99 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 4 Sep 2013 08:31:18 +0200 Subject: [PATCH 066/125] Updated javascript to match correct class names --- js/ding_reservation.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/ding_reservation.js b/js/ding_reservation.js index 9102174..f2c2fff 100644 --- a/js/ding_reservation.js +++ b/js/ding_reservation.js @@ -16,15 +16,15 @@ }); // Handle checkbox button count. - $('.material_item input[type=checkbox]').change(function() { + $('.material-item input[type=checkbox]').change(function() { var form = $(this).closest('form'); var buttons = $('input[type=submit]', form); - var count = $('.material_item input[type=checkbox]:checked', form).length; + var count = $('.material-item input[type=checkbox]:checked', form).length; update_buttons(buttons, count); // Handle all checkbox checked state, so if no all selected the checkbox // is not checked. - if ($('.material_item input[type=checkbox]', form).length != count) { + if ($('.material-item input[type=checkbox]', form).length != count) { $('.select-all-checkbox', form).prop('checked', false); } }) From 01146f0156a86cd681dbd367bceec2083f0359a4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 4 Sep 2013 09:24:20 +0200 Subject: [PATCH 067/125] Added wrapper to check-all checkboxes to better style them --- ding_reservation.module | 8 ++------ js/ding_reservation.js | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index b45dd8a..613057c 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -324,12 +324,8 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = $form['title'] = array( '#type' => 'checkbox', '#title' => $conf['reservation_title'], - '#attributes' => array( - 'class' => array( - 'select-all-checkbox', - drupal_html_id($type), - ) - ), + '#prefix' => '
', + '#suffix' => '
', '#attached' => array( 'js' => array( drupal_get_path('module', 'ding_reservation') . '/js/ding_reservation.js', diff --git a/js/ding_reservation.js b/js/ding_reservation.js index f2c2fff..0e6ecff 100644 --- a/js/ding_reservation.js +++ b/js/ding_reservation.js @@ -4,7 +4,7 @@ (function ($) { $(document).ready(function($) { // Handle select all checkboxes. - $('.select-all-checkbox').click(function() { + $('.select-all input[type=checkbox]').click(function() { var checkboxes = $('input[type=checkbox]', $(this).closest('form')); if ($(this).prop('checked')) { checkboxes.prop('checked', true); @@ -25,7 +25,7 @@ // Handle all checkbox checked state, so if no all selected the checkbox // is not checked. if ($('.material-item input[type=checkbox]', form).length != count) { - $('.select-all-checkbox', form).prop('checked', false); + $('.select-all input[type=checkbox]', form).prop('checked', false); } }) From 14c3838183114912d0200a02019a0cf1624c5467 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 4 Sep 2013 10:53:14 +0200 Subject: [PATCH 068/125] Ensured that check all checkbox is checked when all reservation are selected --- js/ding_reservation.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/js/ding_reservation.js b/js/ding_reservation.js index 0e6ecff..0b5f21c 100644 --- a/js/ding_reservation.js +++ b/js/ding_reservation.js @@ -22,11 +22,14 @@ var count = $('.material-item input[type=checkbox]:checked', form).length; update_buttons(buttons, count); - // Handle all checkbox checked state, so if no all selected the checkbox - // is not checked. + // Handle all checkbox checked state, so if not are all selected the + // checkbox is not checked. if ($('.material-item input[type=checkbox]', form).length != count) { $('.select-all input[type=checkbox]', form).prop('checked', false); } + else { + $('.select-all input[type=checkbox]', form).prop('checked', true); + } }) // Update count string on the buttons. From 92fc7af557280626849582068be18c02f7c5f6a7 Mon Sep 17 00:00:00 2001 From: Rasmus Frey Date: Wed, 4 Sep 2013 13:28:08 +0200 Subject: [PATCH 069/125] Add wrapper for action buttons --- ding_reservation.module | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ding_reservation.module b/ding_reservation.module index 613057c..8041f2a 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -461,11 +461,15 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = // Add action buttons to the top of the form. $form['actions_top'] = array( + '#prefix' => '
', + '#suffix' => '
', '#weight' => -10, ); // Add action buttons to the bottom of the form. $form['actions_bottom'] = array( + '#prefix' => '
', + '#suffix' => '
', '#weight' => 10, ); From 45a3713da4121cbfc80fd2cf7e62441c2884ff13 Mon Sep 17 00:00:00 2001 From: Rasmus Frey Date: Wed, 4 Sep 2013 14:35:03 +0200 Subject: [PATCH 070/125] Modify class name --- ding_reservation.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 8041f2a..1c21aa7 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -475,7 +475,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = if ($able_to_delete) { $form['actions_top']['delete'] = array( - '#prefix' => '
', + '#prefix' => '
', '#suffix' => '
', '#submit' => array('ding_reservation_deletes_form_submit'), '#type' => 'submit', @@ -490,7 +490,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = if ($type == 'not_ready_for_pickup') { $form['actions_top']['update'] = array( - '#prefix' => '
', + '#prefix' => '
', '#suffix' => '
', '#type' => 'submit', '#submit' => array('ding_reservation_updates_form_submit'), From 3607babf37034b819cf8ea6476b13dfe902a3533 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 5 Sep 2013 16:32:12 +0200 Subject: [PATCH 071/125] Ensured that the form title element for reservations can be translated --- ding_reservation.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index 1c21aa7..0cc3862 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -323,7 +323,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = // Add title item. $form['title'] = array( '#type' => 'checkbox', - '#title' => $conf['reservation_title'], + '#title' => check_plain(t($conf['reservation_title'])), '#prefix' => '
', '#suffix' => '
', '#attached' => array( From fcb3012904a321d401d29eef61570b3878cd7664 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 9 Sep 2013 14:15:20 +0200 Subject: [PATCH 072/125] Fixed coding style issues --- ding_reservation.module | 85 ++++++++++--------- js/ding_reservation.js | 5 +- .../reservations/reservations.inc | 20 ++--- 3 files changed, 56 insertions(+), 54 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 0cc3862..d32e94c 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -161,7 +161,7 @@ function ding_reservation_reserve_form($form, &$form_state, $reservable, $hide_o '#attributes' => array( 'class' => array( 'action-button', - 'reserve-button' + 'reserve-button', ), ), '#ajax' => array( @@ -181,17 +181,16 @@ function ding_reservation_reserve_form_validate($form, &$form_state) { if (user_is_logged_in() && ding_user_is_provider_user($user)) { if (ding_provider_implements('reservation', 'options_validate')) { $res = ding_provider_invoke('reservation', 'options_validate', 'create', $user, $form_state['values']['reservable'], $form_state['values']['provider_options']); - // No valudation options returned by provider. + // No validation options returned by provider. if (is_null($res)) { return; } - /** - * We cannot set the value of the individual provider form elements, as - * they might not have been show, and thus not exist. However, setting the - * value of the parent element to an associative array gives the same end - * result. - */ + + // We cannot set the value of the individual provider form elements, as + // they might not have been show, and thus not exist. However, setting the + // value of the parent element to an associative array gives the same end + // result. $provider_options = array(); $provider = ding_provider_get_provider_module_name('reservation'); $removal = array(); @@ -259,7 +258,7 @@ function ding_reservation_reserve_form_submit($form, &$form_state) { drupal_set_message(t('You are number @number in queue.', array('@number' => $reservation_result['queue_number']))); } - // Clear reservation sesion cache. + // Clear reservation session cache. ding_reservation_cache_clear(); } catch (DingProviderUserException $e) { @@ -361,7 +360,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = ), 'pickup_date' => array( 'label' => t('Pickup date'), - 'data' => $reservation->pickup_date ? format_date(strtotime(check_plain($reservation->pickup_date)), 'ding_reservation_lists_date' ) : '', + 'data' => $reservation->pickup_date ? format_date(strtotime(check_plain($reservation->pickup_date)), 'ding_reservation_lists_date') : '', 'class' => 'pickup-date', ), 'pickup_branch' => array( @@ -510,9 +509,10 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = * Get pickup id number. * * @param object $item - * Reserved item object. + * Reserved item object. + * * @return int - * Pickup id, if any. + * Pickup id, if any. */ function ding_reservation_get_pickup_id($item) { if (isset($item->order_arrived) && !$item->order_arrived) { @@ -529,16 +529,17 @@ function ding_reservation_get_pickup_id($item) { * Get order id number. * * @param object $item - * Reserved item object. + * Reserved item object. + * * @return int - * Order number, if any. + * Order number, if any. */ function ding_reservation_get_order_nr($item) { if (!isset($item->pickup_order_id) && isset($item->order_id)) { return $item->order_id; } else { - return t('On route') . ' ' . l('(?)', current_path(), array('attributes' => array('title' => t('The material is on route to the library. You will be notified when it is ready for pickup.')))); + return t('On route') . ' ' . l(t('(?)'), current_path(), array('attributes' => array('title' => t('The material is on route to the library. You will be notified when it is ready for pickup.')))); } } @@ -564,17 +565,17 @@ function ding_reservation_reservations_delete_submit($form, &$form_state) { /** * Submit handler for the delete form. * - * @see ding_reservation_reservations_form(). + * @see ding_reservation_reservations_form() */ function ding_reservation_deletes_form_submit($form, &$form_state) { global $user; // Extra checkbox values form the form. $ids = array(); - foreach($form_state['values']['reservations'] as $reservations) { + foreach ($form_state['values']['reservations'] as $reservations) { $ids = array_merge($reservations, $ids); } - $ids = join(',', array_map('rawurlencode', array_filter($ids, 'is_string'))); + $ids = implode(',', array_map('rawurlencode', array_filter($ids, 'is_string'))); // Save the encoded id's and redirect the form. $form_state['encoded_reservations'] = $ids; @@ -584,17 +585,17 @@ function ding_reservation_deletes_form_submit($form, &$form_state) { /** * Submit handler for the update form. * - * @see ding_reservation_reservations_form(). + * @see ding_reservation_reservations_form() */ function ding_reservation_updates_form_submit($form, &$form_state) { global $user; // Extra checkbox values form the form. $ids = array(); - foreach($form_state['values']['reservations'] as $reservations) { + foreach ($form_state['values']['reservations'] as $reservations) { $ids = array_merge($reservations, $ids); } - $ids = join(',', array_map('rawurlencode', array_filter($form_state['values']['reservations'], 'is_string'))); + $ids = implode(',', array_map('rawurlencode', array_filter($form_state['values']['reservations'], 'is_string'))); // Save the encoded id's and redirect the form. $form_state['encoded_reservations'] = $ids; @@ -604,7 +605,7 @@ function ding_reservation_updates_form_submit($form, &$form_state) { /** * Ajax callback for the delete form. * - * @see ding_reservation_reservations_form(). + * @see ding_reservation_reservations_form() */ function ding_reservation_deletes_form_callback($form, &$form_state) { global $user; @@ -625,7 +626,7 @@ function ding_reservation_deletes_form_callback($form, &$form_state) { /** * Ajax callback for the update form. * - * @see ding_reservation_reservations_form(). + * @see ding_reservation_reservations_form() */ function ding_reservation_updates_form_callback($form, &$form_state) { global $user; @@ -646,7 +647,7 @@ function ding_reservation_updates_form_callback($form, &$form_state) { /** * Delete reservations form. * - * @see ding_reservation_reservations_form(). + * @see ding_reservation_reservations_form() */ function ding_reservation_delete_reservations_form($form, $form_state, $account, $reservation_ids) { global $user; @@ -687,7 +688,7 @@ function ding_reservation_delete_reservations_form($form, $form_state, $account, /** * Delete reservation submit normal handler. * - * @see ding_reservation_delete_reservations_form_callback(). + * @see ding_reservation_delete_reservations_form_callback() */ function ding_reservation_delete_reservations_form_submit($form, &$form_state) { global $user; @@ -700,7 +701,7 @@ function ding_reservation_delete_reservations_form_submit($form, &$form_state) { foreach ($reservations as $entity_id) { ding_provider_invoke('reservation', 'delete', $user, $entity_id); - // Clear reservation sesion cache. + // Clear reservation session cache. ding_reservation_cache_clear(); } } @@ -760,12 +761,11 @@ function ding_reservation_update_reservations_form_validate($form, &$form_state) global $user; if (ding_provider_implements('reservation', 'options_validate')) { $res = ding_provider_invoke('reservation', 'options_validate', 'update', $user, $form_state['values']['reservations'], $form_state['values']['provider_options']); - /** - * We cannot set the value of the individual provider form elements, as - * they might not have been show, and thus not exist. However, setting the - * value of the parent element to an associative array gives the same end - * result. - */ + + // We cannot set the value of the individual provider form elements, as + // they might not have been show, and thus not exist. However, setting the + // value of the parent element to an associative array gives the same end + // result. $provider_options = array(); foreach ($res as $key => $value) { if (is_array($value) && !empty($value['#error'])) { @@ -791,13 +791,13 @@ function ding_reservation_update_reservations_form_validate($form, &$form_state) /** * Update reservation normal submit handler. * - * @see ding_reservation_update_reservations_form_callback(). + * @see ding_reservation_update_reservations_form_callback() */ 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']); - // Clear reservation sesion cache. + // Clear reservation session cache. ding_reservation_cache_clear(); } @@ -832,7 +832,7 @@ function ding_reservation_default_options_branch($type, $name, $default, $option $form = array(); $create = ($type == 'create'); - $allowed_branches = ($create ? array('' => 'Select') : array($default => t('No change'))) + (array)$options; + $allowed_branches = ($create ? array('' => 'Select') : array($default => t('No change'))) + (array) $options; $form[$name] = array( '#type' => 'select', '#title' => t('Select branch'), @@ -855,15 +855,16 @@ function ding_reservation_default_options_branch($type, $name, $default, $option * @TODO: Find a better solution on this type variable. * * @param string $type - * The type of form element to create. + * The type of form element to create. * @param string $name - * Form element name + * Form element name * @param int $default - * The pre-selected value. + * The pre-selected value. * @param array $options - * The options that should be available in the dropdown. - * @return array $form - * Form select element. + * The options that should be available in the dropdown. + * + * @return array + * Form select element. */ function ding_reservation_interest_period_selector($type, $name, $default, $options) { $form = array(); @@ -875,7 +876,7 @@ function ding_reservation_interest_period_selector($type, $name, $default, $opti } } - $allowed_periods = ($type == 'create' ? array() : array('' => t('No change'))) + (array)$options; + $allowed_periods = ($type == 'create' ? array() : array('' => t('No change'))) + (array) $options; $form[$name] = array( '#type' => 'select', '#title' => t('Select interest period'), diff --git a/js/ding_reservation.js b/js/ding_reservation.js index 0b5f21c..b101bba 100644 --- a/js/ding_reservation.js +++ b/js/ding_reservation.js @@ -2,6 +2,7 @@ * Handle reservation checkboxes select all and select count on buttons. */ (function ($) { + "use strict"; $(document).ready(function($) { // Handle select all checkboxes. $('.select-all input[type=checkbox]').click(function() { @@ -30,7 +31,7 @@ else { $('.select-all input[type=checkbox]', form).prop('checked', true); } - }) + }); // Update count string on the buttons. function update_buttons(buttons, count) { @@ -40,4 +41,4 @@ }); } }); -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/plugins/content_types/reservations/reservations.inc b/plugins/content_types/reservations/reservations.inc index 30b5a43..eafaca2 100644 --- a/plugins/content_types/reservations/reservations.inc +++ b/plugins/content_types/reservations/reservations.inc @@ -15,7 +15,7 @@ $plugin = array( ); /** - * Render the block + * Render the block. */ function ding_reservation_reservations_content_type_render($subtype, $conf, $panel_args, $context) { $account = isset($context->data) ? $context->data : NULL; @@ -39,11 +39,11 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan // Get the reservations lists. $reservations = ding_provider_invoke_page('reservation', 'list', $account); - // Filter items base on configuration and preload ting entites. + // Filter items base on configuration and pre-load ting entities. $preloaded_reservations = &drupal_static(__FUNCTION__, array()); $items = array(); foreach ($types as $type) { - // Try to preload ting entities, if not already loaded. + // Try to pre-load ting entities, if not already loaded. if (!isset($preloaded_reservations[$type])) { $preload_ids = array(); foreach ($reservations[$type] as $item) { @@ -52,7 +52,7 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan } } - // Preload all ting entities. + // Pre-load all ting entities. if (!empty($preload_ids)) { ding_entity_load_multiple($preload_ids); } @@ -76,7 +76,7 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan } } - // Add the preload entity to each loan (side effect of getting the entity). + // Add the pre-load entity to each loan (side effect of getting the entity). foreach ($items as $id => &$item) { $item->entity; } @@ -104,7 +104,7 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan } /** - * Adding the admin form, to be able to control the required context + * Adding the admin form, to be able to control the required context. */ function ding_reservation_reservations_content_type_edit_form($form, &$form_state) { $conf = $form_state['conf']; @@ -145,7 +145,7 @@ function ding_reservation_reservations_content_type_edit_form($form, &$form_stat } /** - * Submit handler for the admin form + * Submit handler for the admin form. */ function ding_reservation_reservations_content_type_edit_form_submit(&$form, &$form_state) { foreach (element_children($form) as $key) { @@ -164,7 +164,7 @@ function ding_reservation_reservations_content_type_admin_title($subtype, $conf) } /** - * Callback function to sort array by pickup date + * Callback function to sort array by pickup date. */ function ding_reservation_sort_queue_by_pickup_date($a, $b) { if ($a->pickup_date == $b->pickup_date) { @@ -174,11 +174,11 @@ function ding_reservation_sort_queue_by_pickup_date($a, $b) { } /** - * Callback function for sorting loans by queue_number + * Callback function for sorting loans by queue_number. */ function ding_reservation_sort_queue_by_queue_number($a, $b) { if ($a->queue_number == $b->queue_number) { return 0; } return ($a->queue_number < $b->queue_number) ? -1 : 1; -} \ No newline at end of file +} From 3a3094bb108c0011f4cc09fb78c1ad54e9e87c83 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 9 Sep 2013 15:48:09 +0200 Subject: [PATCH 073/125] Fixed updated and deletion of reservations --- ding_reservation.module | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index d32e94c..143ea14 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -572,8 +572,8 @@ function ding_reservation_deletes_form_submit($form, &$form_state) { // Extra checkbox values form the form. $ids = array(); - foreach ($form_state['values']['reservations'] as $reservations) { - $ids = array_merge($reservations, $ids); + foreach ($form_state['values']['reservations'] as $id => $reservations) { + $ids[] = $reservations[$id]; } $ids = implode(',', array_map('rawurlencode', array_filter($ids, 'is_string'))); @@ -592,10 +592,10 @@ function ding_reservation_updates_form_submit($form, &$form_state) { // Extra checkbox values form the form. $ids = array(); - foreach ($form_state['values']['reservations'] as $reservations) { - $ids = array_merge($reservations, $ids); + foreach ($form_state['values']['reservations'] as $id => $reservations) { + $ids[] = $reservations[$id]; } - $ids = implode(',', array_map('rawurlencode', array_filter($form_state['values']['reservations'], 'is_string'))); + $ids = implode(',', array_map('rawurlencode', array_filter($ids, 'is_string'))); // Save the encoded id's and redirect the form. $form_state['encoded_reservations'] = $ids; From 11262cf2b662c178f96689ac792d4c9aca8cc470 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 10 Sep 2013 13:05:02 +0200 Subject: [PATCH 074/125] Addded count to string translation for buttons text --- ding_reservation.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 143ea14..a7a17f1 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -478,7 +478,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = '#suffix' => '
', '#submit' => array('ding_reservation_deletes_form_submit'), '#type' => 'submit', - '#value' => t('Delete reservations (0)'), + '#value' => t('Delete reservations (@count)', array('@count' => 0)), '#ajax' => array( 'callback' => 'ding_reservation_deletes_form_callback', 'wrapper' => 'ding-reservation-reservations-form', @@ -493,7 +493,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = '#suffix' => '
', '#type' => 'submit', '#submit' => array('ding_reservation_updates_form_submit'), - '#value' => t('Update reservations (0)'), + '#value' => t('Update reservations (@count)', array('@count' => 0)), '#ajax' => array( 'callback' => 'ding_reservation_updates_form_callback', 'wrapper' => 'ding-reservation-updates-form', From b1666e883f8c041f1ff5b2a41366e95534ada821 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 10 Sep 2013 13:27:42 +0200 Subject: [PATCH 075/125] Added #weight to reservation list form --- ding_reservation.module | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ding_reservation.module b/ding_reservation.module index a7a17f1..21658aa 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -357,21 +357,25 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = 'label' => t('Pickup id'), 'data' => ding_reservation_get_pickup_id($reservation), 'class' => 'pickup-id', + '#weight' => 0, ), 'pickup_date' => array( 'label' => t('Pickup date'), 'data' => $reservation->pickup_date ? format_date(strtotime(check_plain($reservation->pickup_date)), 'ding_reservation_lists_date') : '', 'class' => 'pickup-date', + '#weight' => 4, ), 'pickup_branch' => array( 'label' => t('Pickup branch'), 'data' => $pickup_branch ? check_plain($pickup_branch) : t('Unknown branch'), 'class' => 'pickup-branch', + '#weight' => 8, ), 'created' => array( 'label' => t('Created date'), 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', 'class' => 'created-date', + '#weight' => 16, ), ), ); @@ -388,26 +392,31 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = 'label' => t('Queue number'), 'data' => $reservation->queue_number ? check_plain($reservation->queue_number) : '', 'class' => 'queue-number', + '#weight' => 0, ), 'expiry' => array( 'label' => t('Expiry date'), 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->expiry)), 'ding_reservation_lists_date') : '', 'class' => 'expire-date', + '#weight' => 4, ), 'pickup_branch' => array( 'label' => t('Pickup branch'), 'data' => $pickup_branch ? check_plain($pickup_branch) : '', 'class' => 'pickup-branch', + '#weight' => 8, ), 'created' => array( 'label' => t('Created date'), 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', 'class' => 'created-date', + '#weight' => 16, ), 'order_nr' => array( 'label' => t('Order nr.'), 'data' => ding_reservation_get_order_nr($reservation), 'class' => 'pickup-id', + '#weight' => 32, ), ), ); @@ -424,21 +433,25 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = 'label' => t('Status'), 'data' => $reservation->ill_status ? t(check_plain($reservation->ill_status)) : t('Unknown status'), 'class' => 'ill-status', + '#weight' => 0, ), 'expiry' => array( 'label' => t('Library'), 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->expiry)), 'ding_reservation_lists_date') : '', 'class' => 'expire-date', + '#weight' => 4, ), 'library' => array( 'label' => t('Library'), 'data' => $pickup_branch ? check_plain($pickup_branch) : '', 'class' => 'pickup-branch', + '#weight' => 8, ), 'created' => array( 'label' => t('Expiry date'), 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', 'class' => 'created-date', + '#weight' => 16, ), ), ); @@ -451,6 +464,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations = 'label' => t('Periodical no.'), 'data' => check_plain($reservation->notes), 'class' => 'periodical-number', + '#weight' => -4, ); } From 17f448f9eae09f25beeb1b6ddd2046ff6a2283e1 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 11 Sep 2013 07:56:41 +0200 Subject: [PATCH 076/125] Added better function documentation --- ding_reservation.module | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 21658aa..ffcc9bb 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -841,6 +841,20 @@ function ding_reservation_update_reservations_form_callback($form, &$form_state) * Create a pickup branch selector. * * Returns form element(s) for selecting a pickup branch. + * + * @TODO: Find a better solution on this type variable. + * + * @param string $type + * String used to indicate the type of operation ('create'). + * @param string $name + * The name of the form element to build. + * @param string $default + * The default branch option name eg. hb => Hovedbiblioteket. + * @param array $options + * The branches that should be available for selection in the form element. + * + * @return array + * Form element with a selection input type to select pickup branch. */ function ding_reservation_default_options_branch($type, $name, $default, $options) { $form = array(); @@ -869,16 +883,16 @@ function ding_reservation_default_options_branch($type, $name, $default, $option * @TODO: Find a better solution on this type variable. * * @param string $type - * The type of form element to create. + * String used to indicate the type of operation ('create'). * @param string $name - * Form element name + * The name of the form element to build. * @param int $default * The pre-selected value. * @param array $options - * The options that should be available in the dropdown. + * The periods that should be available for selection in the form element. * * @return array - * Form select element. + * Form element with a selection input type to select interest period. */ function ding_reservation_interest_period_selector($type, $name, $default, $options) { $form = array(); @@ -911,6 +925,8 @@ function ding_reservation_interest_period_selector($type, $name, $default, $opti * Validate pickup branch selector. * * Returns what ding_reservation expects. + * + * @TODO: Find a better solution on this type variable. */ function ding_reservation_default_options_branch_validate($type, $name, $default, $values) { if (empty($values[$name])) { @@ -935,6 +951,8 @@ function ding_reservation_default_options_branch_validate($type, $name, $default * Validate interest period selector. * * Returns what ding_reservation expects. + * + * @TODO: Find a better solution on this type variable. */ function ding_reservation_default_options_interest_period_validate($type, $name, $default, $values) { if (empty($values[$name])) { @@ -958,6 +976,8 @@ function ding_reservation_default_options_interest_period_validate($type, $name, * Submit pickup branch selector. * * Returns new properties to save, if any. + * + * @TODO: Find a better solution on this type variable. */ function ding_reservation_default_options_branch_submit($type, $name, $default, $values) { $result = array(); From 8e109a5a860691b8e3f704a40df92c5bd5faa670 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 11 Sep 2013 07:57:43 +0200 Subject: [PATCH 077/125] Removed floating comment, not allowed due to coding style --- ding_reservation.module | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index ffcc9bb..e716889 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -830,13 +830,6 @@ function ding_reservation_update_reservations_form_callback($form, &$form_state) return $response; } -/** - * Default options handling. - * - * Reservation providers may use these to use standard implementations of - * widgets like pickup branch and get much logic for free. - */ - /** * Create a pickup branch selector. * From 6c3624848b681cb9490ccd39d64841a627f19922 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 11 Sep 2013 16:30:54 +0200 Subject: [PATCH 078/125] Reworked the reserve process to handle better branch seletion and better user interface --- ding_reservation.module | 211 ++++++++++------------------------------ 1 file changed, 49 insertions(+), 162 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index e716889..5c1305d 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -75,6 +75,8 @@ function ding_reservation_ding_entity_menu(&$items, $type, $path, $index) { */ function ding_reservation_ding_entity_buttons($type, $entity) { if ($type == 'ding_entity' && $entity->is('reservable')) { + // The last parameter to the form below (TRUE) hides the provider options in + // the form (interest period and branch). return array(ding_provider_get_form('ding_reservation_reserve_form', new DingReservationReservableEntity($entity), TRUE)); } } @@ -144,14 +146,25 @@ function ding_reservation_reserve_form($form, &$form_state, $reservable, $hide_o '#value' => array(), ); + // Helps decide if the provider options should be displayed in the reserve + // form. If the user have default value these are used to make a quicker + // reservation process. $hide_options = !isset($form_state['options_hidden']) ? $hide_options : FALSE; $form_state['options_hidden'] = $hide_options; if (!$hide_options) { - if (ding_provider_implements('reservation', 'options') && $provider_form = ding_provider_invoke('reservation', 'options', 'create', $user, $reservable)) { + if (ding_provider_implements('reservation', 'options') && $provider_form = ding_provider_invoke('reservation', 'options', $user)) { $form['provider_options'] = $provider_form + array( '#tree' => TRUE, ); + + // The normal reserve button and the reserve for with provider options are + // the same form. But DDBasic hides the reserve buttons until availability + // have been confirmed. So we need to add a class to the form to make it + // visible. + $form['#attributes'] = array( + 'class' => array('reservable'), + ); } } @@ -174,55 +187,35 @@ function ding_reservation_reserve_form($form, &$form_state, $reservable, $hide_o } /** - * Form validation. + * Reserve form validation. */ function ding_reservation_reserve_form_validate($form, &$form_state) { global $user; if (user_is_logged_in() && ding_user_is_provider_user($user)) { - if (ding_provider_implements('reservation', 'options_validate')) { - $res = ding_provider_invoke('reservation', 'options_validate', 'create', $user, $form_state['values']['reservable'], $form_state['values']['provider_options']); - // No validation options returned by provider. - if (is_null($res)) { - return; - } - + if (ding_provider_implements('reservation', 'default_options')) { + $defaults = ding_provider_invoke('reservation', 'default_options', $user); - // We cannot set the value of the individual provider form elements, as - // they might not have been show, and thus not exist. However, setting the - // value of the parent element to an associative array gives the same end - // result. $provider_options = array(); - $provider = ding_provider_get_provider_module_name('reservation'); - $removal = array(); - foreach ($res as $key => $value) { - if (is_array($value) && !empty($value['#error'])) { - if (!$form_state['options_hidden']) { - // Only show an error if the user had a choice. - form_error($form['provider_options'], $res['#error']); + foreach ($defaults as $key => $default) { + // Check if the current provider options has a default value. + if (empty($default) && empty($form_state['values']['provider_options'][$key])) { + // Set form error to trigger display of the form in ding pop-up. The + // message will not be shown and the user will have to select values. + form_error($key, t('Please select a valied value.')); + $form_state['rebuild'] = TRUE; + } + else { + if (empty($default)) { + $provider_options[$key] = $form_state['values']['provider_options'][$key]; } else { - // Else simply rebuild the form. - if ($key == $provider . '_preferred_branch') { - $removal[] = 'interest_period'; - } - elseif ($key == 'interest_period') { - $removal[] = $provider . '_preferred_branch'; - } - - // In case both fields are not set, remove nothing. - if (count($removal) == 2) { - $removal = array(); - } - - $form_state['removable'] = $removal; - $form_state['rebuild'] = TRUE; + $provider_options[$key] = $default; } - } - else { - $provider_options[$key] = $value; + } } - if (!empty($provider_options)) { + + if (!$form_state['rebuild']) { form_set_value($form['provider_options'], $provider_options, $form_state); } } @@ -238,7 +231,7 @@ function ding_reservation_reserve_form_validate($form, &$form_state) { function ding_reservation_reserve_form_submit($form, &$form_state) { global $user; if (ding_provider_implements('reservation', 'options_submit')) { - ding_provider_invoke('reservation', 'options_submit', 'create', $user, $form_state['values']['reservable'], $form_state['values']['provider_options']); + ding_provider_invoke('reservation', 'options_submit', $user, $form_state['values']['provider_options']); } if ($form_state['values']['reservable']) { $reservable = $form_state['values']['reservable']; @@ -571,7 +564,7 @@ function ding_reservation_reservations_delete_submit($form, &$form_state) { foreach ($reservations as $entity_id) { ding_provider_invoke('reservation', 'delete', $user, $entity_id); - // Clear reservation sesion cache. + // Clear reservation session cache. ding_reservation_cache_clear(); } } @@ -649,8 +642,11 @@ function ding_reservation_updates_form_callback($form, &$form_state) { '#commands' => array(), ); + // Get reservation form. + $form_raw = drupal_get_form('ding_reservation_update_reservations_form', $user, $form_state['encoded_reservations']); + $html = theme('status_messages'); - $html .= drupal_render(drupal_get_form('ding_reservation_update_reservations_form', $user, $form_state['encoded_reservations'])); + $html .= drupal_render($form_raw); if ($html) { $response['#commands'][] = ajax_command_ding_popup('ding_reservation', t('Update reservations'), $html, array('refresh' => TRUE)); @@ -749,7 +745,7 @@ function ding_reservation_update_reservations_form($form, $form_state, $account, '#value' => $ids, ); - if (ding_provider_implements('reservation', 'options') && $provider_form = ding_provider_invoke('reservation', 'options', 'update', $user, NULL)) { + if (ding_provider_implements('reservation', 'options') && $provider_form = ding_provider_invoke('reservation', 'options', $user)) { $form['provider_options'] = $provider_form + array( '#tree' => TRUE, ); @@ -768,40 +764,6 @@ function ding_reservation_update_reservations_form($form, $form_state, $account, return $form; } -/** - * Update reservation validation handler. - */ -function ding_reservation_update_reservations_form_validate($form, &$form_state) { - global $user; - if (ding_provider_implements('reservation', 'options_validate')) { - $res = ding_provider_invoke('reservation', 'options_validate', 'update', $user, $form_state['values']['reservations'], $form_state['values']['provider_options']); - - // We cannot set the value of the individual provider form elements, as - // they might not have been show, and thus not exist. However, setting the - // value of the parent element to an associative array gives the same end - // result. - $provider_options = array(); - foreach ($res as $key => $value) { - if (is_array($value) && !empty($value['#error'])) { - if (!$form_state['options_hidden']) { - // Only show an error if the user had a choice. - form_error($form['provider_options'], $res['#error']); - } - else { - // Else simply rebuild the form. - $form_state['rebuild'] = TRUE; - } - } - else { - $provider_options[$key] = $value; - } - } - if (!empty($provider_options)) { - form_set_value($form['provider_options'], $provider_options, $form_state); - } - } -} - /** * Update reservation normal submit handler. * @@ -835,10 +797,6 @@ function ding_reservation_update_reservations_form_callback($form, &$form_state) * * Returns form element(s) for selecting a pickup branch. * - * @TODO: Find a better solution on this type variable. - * - * @param string $type - * String used to indicate the type of operation ('create'). * @param string $name * The name of the form element to build. * @param string $default @@ -849,19 +807,18 @@ function ding_reservation_update_reservations_form_callback($form, &$form_state) * @return array * Form element with a selection input type to select pickup branch. */ -function ding_reservation_default_options_branch($type, $name, $default, $options) { +function ding_reservation_default_options_branch($name, $default, $options) { $form = array(); - $create = ($type == 'create'); - $allowed_branches = ($create ? array('' => 'Select') : array($default => t('No change'))) + (array) $options; $form[$name] = array( '#type' => 'select', '#title' => t('Select branch'), - '#options' => $allowed_branches, - '#default_value' => $default, + '#options' => $options, + '#required' => TRUE, + '#default_value' => !empty($default) ? $default : '', ); - if ($create) { + if (empty($default)) { $form[$name . 'description'] = array( '#markup' => '

' . t('In order to make quick reservations, you must select a default pickup branch.') . '

', ); @@ -873,10 +830,6 @@ function ding_reservation_default_options_branch($type, $name, $default, $option /** * Create an interest period form select element. * - * @TODO: Find a better solution on this type variable. - * - * @param string $type - * String used to indicate the type of operation ('create'). * @param string $name * The name of the form element to build. * @param int $default @@ -887,7 +840,7 @@ function ding_reservation_default_options_branch($type, $name, $default, $option * @return array * Form element with a selection input type to select interest period. */ -function ding_reservation_interest_period_selector($type, $name, $default, $options) { +function ding_reservation_interest_period_selector($name, $default, $options) { $form = array(); // Used to enable translation of options. @@ -897,15 +850,15 @@ function ding_reservation_interest_period_selector($type, $name, $default, $opti } } - $allowed_periods = ($type == 'create' ? array() : array('' => t('No change'))) + (array) $options; $form[$name] = array( '#type' => 'select', '#title' => t('Select interest period'), - '#options' => $allowed_periods, - '#default_value' => $default, + '#options' => $options, + '#required' => TRUE, + '#default_value' => !empty($default) ? $default : '', ); - if ($type == 'create') { + if (empty($default)) { $form[$name . 'description'] = array( '#markup' => '

' . t('Select an interest period.') . '

', ); @@ -914,72 +867,6 @@ function ding_reservation_interest_period_selector($type, $name, $default, $opti return $form; } -/** - * Validate pickup branch selector. - * - * Returns what ding_reservation expects. - * - * @TODO: Find a better solution on this type variable. - */ -function ding_reservation_default_options_branch_validate($type, $name, $default, $values) { - if (empty($values[$name])) { - $result = array(); - $provider = ding_provider_get_provider_module_name('reservation'); - if ($type == 'create' && empty($default)) { - $result[$provider . '_preferred_branch'] = array( - '#error' => t('You must select a branch'), - ); - } - else { - $result[$name] = $default; - } - return $result; - } - else { - return $values; - } -} - -/** - * Validate interest period selector. - * - * Returns what ding_reservation expects. - * - * @TODO: Find a better solution on this type variable. - */ -function ding_reservation_default_options_interest_period_validate($type, $name, $default, $values) { - if (empty($values[$name])) { - $result = array(); - if ($type == 'create' && empty($default)) { - $result['interest_period'] = array( - '#error' => t('You must select an interest period'), - ); - } - else { - $result[$name] = $default; - } - return $result; - } - else { - return $values; - } -} - -/** - * Submit pickup branch selector. - * - * Returns new properties to save, if any. - * - * @TODO: Find a better solution on this type variable. - */ -function ding_reservation_default_options_branch_submit($type, $name, $default, $values) { - $result = array(); - if ($type == 'create' && !empty($values[$name]) && $values[$name] != $default) { - $result[$name] = $values['name']; - } - return $result; -} - /** * Clears the reservations cache if ding_session_cache is active. */ From a9d5b49433cc95ca7458748910c1eac84921625c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 11 Sep 2013 16:42:31 +0200 Subject: [PATCH 079/125] Added more documentation to the reserve form validation handler --- ding_reservation.module | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index 5c1305d..7c52e39 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -206,15 +206,19 @@ function ding_reservation_reserve_form_validate($form, &$form_state) { } else { if (empty($default)) { + // If default value id not defined, try using the forms value. $provider_options[$key] = $form_state['values']['provider_options'][$key]; } else { + // Default value was set, so we use it (as the forms selection + // options should not have been shown to the user). $provider_options[$key] = $default; } - } } + // Do not set provider options, if the form was marked for rebuild. The + // user should have a change to select the values first. if (!$form_state['rebuild']) { form_set_value($form['provider_options'], $provider_options, $form_state); } From 4971257acf283ce4854cc0b1be47441197318d61 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 11 Sep 2013 17:36:51 +0200 Subject: [PATCH 080/125] Added better selection of default branch based on the reservations that are being updated --- ding_reservation.module | 45 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 7c52e39..a03aa0e 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -29,10 +29,10 @@ function ding_reservation_ctools_plugin_directory($module, $plugin) { function ding_reservation_menu() { $items = array(); - $items['user/%user/status/reservations/update/%'] = array( + $items['user/%user/status/reservations/update/%/%'] = array( 'title' => 'Update reservations', 'page callback' => 'drupal_get_form', - 'page arguments' => array('ding_reservation_update_reservations_form', 1, 5), + 'page arguments' => array('ding_reservation_update_reservations_form', 1, 5, 6), 'access callback' => 'ding_reservation_access', 'access arguments' => array(1), ); @@ -311,11 +311,17 @@ function ding_reservation_reserve_form_callback($form, &$form_state) { /** * Show a reservation list form. */ -function ding_reservation_reservations_form($form, &$form_state, $reservations = array(), $type = 'not_ready_for_pickup', $conf = array()) { +function ding_reservation_reservations_form($form, &$form_state, $reservations, $type = 'not_ready_for_pickup', $conf = array()) { $form = array( '#tree' => TRUE, ); + // Store the reservations list in the form (on server site). + $form['reservations'] = array( + '#type' => 'value', + '#value' => $reservations, + ); + // Add title item. $form['title'] = array( '#type' => 'checkbox', @@ -604,13 +610,28 @@ function ding_reservation_updates_form_submit($form, &$form_state) { // Extra checkbox values form the form. $ids = array(); foreach ($form_state['values']['reservations'] as $id => $reservations) { - $ids[] = $reservations[$id]; + if ($reservations[$id]) { + $ids[] = $reservations[$id]; + } + } + + // Try to make a bette default branch selection based on the selected + // reservations. + $current_branch = $form['reservations']['#value'][$ids[0]]->pickup_branch_id; + foreach ($ids as $id) { + if ($form['reservations']['#value'][$id]->pickup_branch_id != $current_branch) { + $current_branch = FALSE; + break; + } } + + // Encode the ids. $ids = implode(',', array_map('rawurlencode', array_filter($ids, 'is_string'))); // Save the encoded id's and redirect the form. + $form_state['current_branch'] = $current_branch; $form_state['encoded_reservations'] = $ids; - $form_state['redirect'] = array('user/' . $user->uid . '/status/reservations/update/' . $ids, array('query' => drupal_get_destination())); + $form_state['redirect'] = array('user/' . $user->uid . '/status/reservations/update/' . $ids . '/' . $current_branch, array('query' => drupal_get_destination())); } /** @@ -625,8 +646,11 @@ function ding_reservation_deletes_form_callback($form, &$form_state) { '#commands' => array(), ); + // Get delete form. + $form_raw = drupal_get_form('ding_reservation_delete_reservations_form', $user, $form_state['encoded_reservations']); + $html = theme('status_messages'); - $html .= drupal_render(drupal_get_form('ding_reservation_delete_reservations_form', $user, $form_state['encoded_reservations'])); + $html .= drupal_render($form_raw); if ($html) { $response['#commands'][] = ajax_command_ding_popup('ding_reservation', t('Delete reservations'), $html, array('refresh' => TRUE)); @@ -647,7 +671,7 @@ function ding_reservation_updates_form_callback($form, &$form_state) { ); // Get reservation form. - $form_raw = drupal_get_form('ding_reservation_update_reservations_form', $user, $form_state['encoded_reservations']); + $form_raw = drupal_get_form('ding_reservation_update_reservations_form', $user, $form_state['encoded_reservations'], $form_state['current_branch']); $html = theme('status_messages'); $html .= drupal_render($form_raw); @@ -738,18 +762,17 @@ function ding_reservation_delete_reservations_form_callback($form, &$form_state) /** * Update reservations form. */ -function ding_reservation_update_reservations_form($form, $form_state, $account, $reservation_ids) { - global $user; +function ding_reservation_update_reservations_form($form, $form_state, $account, $reservation_ids, $current_branch) { + // Decode the reservation ids. $ids = array_map('rawurldecode', explode(',', $reservation_ids)); $form_state['cache'] = TRUE; - $form['reservations'] = array( '#type' => 'value', '#value' => $ids, ); - if (ding_provider_implements('reservation', 'options') && $provider_form = ding_provider_invoke('reservation', 'options', $user)) { + if (ding_provider_implements('reservation', 'options') && $provider_form = ding_provider_invoke('reservation', 'options', $account, $current_branch)) { $form['provider_options'] = $provider_form + array( '#tree' => TRUE, ); From 75a3dff183251b694c06bce03fe0646939c4a421 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 12 Sep 2013 11:03:01 +0200 Subject: [PATCH 081/125] Disabled action buttons when no reservations are selected --- js/ding_reservation.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/js/ding_reservation.js b/js/ding_reservation.js index b101bba..2bf1285 100644 --- a/js/ding_reservation.js +++ b/js/ding_reservation.js @@ -4,6 +4,10 @@ (function ($) { "use strict"; $(document).ready(function($) { + // Ensure that all checkboxes are on click (if user reloads the page etc.). + $('form input[type=checkbox]').prop('checked', false); + $('.action-buttons input[type=submit]').prop('disabled', 'disabled'); + // Handle select all checkboxes. $('.select-all input[type=checkbox]').click(function() { var checkboxes = $('input[type=checkbox]', $(this).closest('form')); @@ -38,6 +42,14 @@ buttons.each(function(index) { var btn = $(buttons[index]); btn.val(btn.val().replace(/\(\d+\)/, '(' + count + ')')); + + // Toggle buttons based on count. + if (count > 0) { + btn.removeAttr("disabled"); + } + else { + btn.prop('disabled', 'disabled'); + } }); } }); From 4ec1592c19146389a0d7cf819cbaadc703b049dd Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 12 Sep 2013 14:41:12 +0200 Subject: [PATCH 082/125] Fixed weight of the different form elements in the reservation list form --- ding_reservation.module | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index a03aa0e..bdbcfb5 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -333,6 +333,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, drupal_get_path('module', 'ding_reservation') . '/js/ding_reservation.js', ), ), + '#weight' => -10, ); // Check if reservations should be able to be deleted by the user. @@ -479,7 +480,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, $form['actions_top'] = array( '#prefix' => '
', '#suffix' => '
', - '#weight' => -10, + '#weight' => -20, ); // Add action buttons to the bottom of the form. From 8cc53699fc4e4be9d709e015f5f656d70dd862b7 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 12 Sep 2013 20:13:08 +0200 Subject: [PATCH 083/125] Changed title in reservation list to link to the entity --- ding_reservation.module | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index bdbcfb5..1809758 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -348,13 +348,17 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, $entity = ding_provider_get_pseudo_entity($reservation->ding_entity_id); } + // Create title that links to the object. + $uri = entity_uri('ting_object', $entity); + $title = l($entity->getTitle() ? $entity->getTitle() : $reservation->display_name, $uri['path']); + $pickup_branch = ding_provider_invoke('reservation', 'branch_name', $reservation->pickup_branch_id); switch ($type) { case 'ready_for_pickup': $item = array( '#type' => 'material_item', '#id' => $reservation->id, - '#title' => $entity ? $entity->getTitle() : $reservation->display_name, + '#title' => $title, '#cover' => field_view_field('ting_object', $entity, 'ting_cover', 'user_list'), '#information' => array( 'pickup_id' => array( From 1fb5b53c10c4f388015ea59ed7f7d7d6d40fd768 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 13 Sep 2013 08:45:45 +0200 Subject: [PATCH 084/125] Updated JS comment --- js/ding_reservation.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/ding_reservation.js b/js/ding_reservation.js index 2bf1285..92560cb 100644 --- a/js/ding_reservation.js +++ b/js/ding_reservation.js @@ -4,7 +4,8 @@ (function ($) { "use strict"; $(document).ready(function($) { - // Ensure that all checkboxes are on click (if user reloads the page etc.). + // Ensure that all checkboxes are not checked (if user reloads the page + // etc.). $('form input[type=checkbox]').prop('checked', false); $('.action-buttons input[type=submit]').prop('disabled', 'disabled'); From 1cefc298e765fe8e40a338875ac0f1d255e9ce84 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 16 Sep 2013 10:48:06 +0200 Subject: [PATCH 085/125] Added expire message to the reservation list when reservation is about to expire --- ding_reservation.module | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ding_reservation.module b/ding_reservation.module index 1809758..f70a490 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -428,6 +428,16 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, ), ), ); + + // Set reservation expire message. + $expire = strtotime(check_plain($reservation->expiry)); + if ($expire - (7 * 24 * 60 * 60) <= time()) { + $item['#material_message'] = array( + 'message' => t('This reservation is about to expire.'), + 'class' => 'messages warning', + ); + $item['#weight'] = -30; + } break; case 'interlibrary_loans': @@ -463,6 +473,16 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, ), ), ); + + // Set reservation expire message. + $expire = strtotime(check_plain($reservation->expiry)); + if ($expire - (7 * 24 * 60 * 60) <= time()) { + $item['#material_message'] = array( + 'message' => t('This reservation is about to expire.'), + 'class' => 'messages warning', + ); + } + $item['#weight'] = -30; break; } From 47a9f1336772009e76d8822b2cbc504dfe7af04d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 16 Sep 2013 11:34:24 +0200 Subject: [PATCH 086/125] Updated reservation expire message with configurable expire time --- ding_reservation.module | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index f70a490..b6ff815 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -428,16 +428,6 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, ), ), ); - - // Set reservation expire message. - $expire = strtotime(check_plain($reservation->expiry)); - if ($expire - (7 * 24 * 60 * 60) <= time()) { - $item['#material_message'] = array( - 'message' => t('This reservation is about to expire.'), - 'class' => 'messages warning', - ); - $item['#weight'] = -30; - } break; case 'interlibrary_loans': @@ -473,17 +463,19 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, ), ), ); + break; + } - // Set reservation expire message. - $expire = strtotime(check_plain($reservation->expiry)); - if ($expire - (7 * 24 * 60 * 60) <= time()) { - $item['#material_message'] = array( - 'message' => t('This reservation is about to expire.'), - 'class' => 'messages warning', - ); - } + if (in_array($type, array('not_ready_for_pickup', 'interlibrary_loans'))) { + // Set reservation expire message. + $expire = strtotime(check_plain($reservation->expiry)); + if ($expire - variable_get('reservation_expire', 604800) <= time()) { + $item['#material_message'] = array( + 'message' => t('This reservation is about to expire.'), + 'class' => 'messages warning', + ); $item['#weight'] = -30; - break; + } } // Add extra information if it's a periodical. From 4200a50a3675fe88cdbf1655a0f40887ad6e4e52 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 16 Sep 2013 13:56:17 +0200 Subject: [PATCH 087/125] Fixed problem with deletion of reservertion with only one reservation --- ding_reservation.module | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index b6ff815..6d01acf 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -316,12 +316,6 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, '#tree' => TRUE, ); - // Store the reservations list in the form (on server site). - $form['reservations'] = array( - '#type' => 'value', - '#value' => $reservations, - ); - // Add title item. $form['title'] = array( '#type' => 'checkbox', @@ -753,8 +747,8 @@ function ding_reservation_delete_reservations_form_submit($form, &$form_state) { else { $reservations = array_filter($form_state['values']['reservations']); } - foreach ($reservations as $entity_id) { - ding_provider_invoke('reservation', 'delete', $user, $entity_id); + foreach ($reservations as $reservation_id) { + ding_provider_invoke('reservation', 'delete', $user, $reservation_id); // Clear reservation session cache. ding_reservation_cache_clear(); From ddb39281d266a4f75c51239bce01545b31b7c64b Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 16 Sep 2013 14:13:42 +0200 Subject: [PATCH 088/125] Added title to reservation list --- plugins/content_types/reservations/reservations.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/content_types/reservations/reservations.inc b/plugins/content_types/reservations/reservations.inc index eafaca2..a4e7e4e 100644 --- a/plugins/content_types/reservations/reservations.inc +++ b/plugins/content_types/reservations/reservations.inc @@ -22,6 +22,7 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan // Defined the return block. $block = new stdClass(); + $block->title = t('My reservations'); $block->module = 'ding_reservation'; $block->delta = 'reservations'; From cc4e9ed08ff8337d1360d91679291a8b22f3c433 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 20 Sep 2013 11:41:24 +0200 Subject: [PATCH 089/125] Added exception to when to add periodicl information in the reservation list --- ding_reservation.module | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 6d01acf..bc7e833 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -472,8 +472,10 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, } } - // Add extra information if it's a periodical. - if (!empty($reservation->notes)) { + // Add extra information if it's a periodical. There is an exception because + // the notes field is also used to set library information for ill's but + // only when they are ready for pick-up. + if (!empty($reservation->notes) && !($reservation->ill_status && $type == 'ready_for_pickup')) { $item['#information']['periodical_number'] = array( 'label' => t('Periodical no.'), 'data' => check_plain($reservation->notes), From 85c62dd0c679614a7a366f424242319117fc6e35 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 30 Sep 2013 13:00:23 +0200 Subject: [PATCH 090/125] Ensured that select-all checkboxes is not selected when disabled --- js/ding_reservation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/ding_reservation.js b/js/ding_reservation.js index 92560cb..6c8a813 100644 --- a/js/ding_reservation.js +++ b/js/ding_reservation.js @@ -31,10 +31,10 @@ // Handle all checkbox checked state, so if not are all selected the // checkbox is not checked. if ($('.material-item input[type=checkbox]', form).length != count) { - $('.select-all input[type=checkbox]', form).prop('checked', false); + $('.select-all input[type=checkbox]:not(:disabled)', form).prop('checked', false); } else { - $('.select-all input[type=checkbox]', form).prop('checked', true); + $('.select-all input[type=checkbox]:not(:disabled)', form).prop('checked', true); } }); From 08fb4ffb0050d89e57bf466f2373c863bfd98e3e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 30 Sep 2013 15:10:20 +0200 Subject: [PATCH 091/125] Added support for scrolling action buttons --- ding_reservation.module | 9 ------- js/ding_reservation.js | 57 +++++++++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index bc7e833..86f7912 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -495,13 +495,6 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, '#weight' => -20, ); - // Add action buttons to the bottom of the form. - $form['actions_bottom'] = array( - '#prefix' => '
', - '#suffix' => '
', - '#weight' => 10, - ); - if ($able_to_delete) { $form['actions_top']['delete'] = array( '#prefix' => '
', @@ -514,7 +507,6 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, 'wrapper' => 'ding-reservation-reservations-form', ), ); - $form['actions_bottom']['delete'] = $form['actions_top']['delete']; } if ($type == 'not_ready_for_pickup') { @@ -529,7 +521,6 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, 'wrapper' => 'ding-reservation-updates-form', ), ); - $form['actions_bottom']['update'] = $form['actions_top']['update']; } return $form; diff --git a/js/ding_reservation.js b/js/ding_reservation.js index 6c8a813..eba998a 100644 --- a/js/ding_reservation.js +++ b/js/ding_reservation.js @@ -4,6 +4,11 @@ (function ($) { "use strict"; $(document).ready(function($) { + // Variables used to make the buttons follow scroll. + var actions = $(".action-buttons:first"); + var actions_offset = 0; + var win = $(window); + // Ensure that all checkboxes are not checked (if user reloads the page // etc.). $('form input[type=checkbox]').prop('checked', false); @@ -38,20 +43,46 @@ } }); - // Update count string on the buttons. + /** + * Update count string on the buttons. + */ function update_buttons(buttons, count) { - buttons.each(function(index) { - var btn = $(buttons[index]); - btn.val(btn.val().replace(/\(\d+\)/, '(' + count + ')')); - - // Toggle buttons based on count. - if (count > 0) { - btn.removeAttr("disabled"); - } - else { - btn.prop('disabled', 'disabled'); - } - }); + buttons.each(function(index) { + var btn = $(buttons[index]); + btn.val(btn.val().replace(/\(\d+\)/, '(' + count + ')')); + + // Toggle buttons based on count. + if (count > 0) { + btn.closest('.action-buttons').addClass('action-buttons-is-visible'); + actions_offset = actions.offset().top; + btn.removeAttr("disabled"); + } + else { + btn.closest('.action-buttons').removeClass('action-buttons-is-visible'); + btn.prop('disabled', 'disabled'); + } + }); + + toggle_scroll_buttons(); + } + + // Enable scroll and toggle of buttons. It uses class to this effect can be + // cancelled by removing classes from the theme. + $(window).scroll(function(){ + toggle_scroll_buttons(); + }); + + /** + * Helper function to toggle the "action-buttons-is-scrolling" class, which + * moves the out of flow to follow the top of the screen on scroll. + */ + function toggle_scroll_buttons() { + if (actions_offset < win.scrollTop() && actions.hasClass('action-buttons-is-visible')) { + actions.addClass('action-buttons-is-scrolling'); + } + else { + actions.removeClass('action-buttons-is-scrolling'); + } } }); })(jQuery); From 6323d1556c583af70853fe003f95ab7956df6a7b Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 30 Sep 2013 15:21:09 +0200 Subject: [PATCH 092/125] Added comment and if statement to JS --- js/ding_reservation.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/js/ding_reservation.js b/js/ding_reservation.js index eba998a..cde88c0 100644 --- a/js/ding_reservation.js +++ b/js/ding_reservation.js @@ -5,7 +5,7 @@ "use strict"; $(document).ready(function($) { // Variables used to make the buttons follow scroll. - var actions = $(".action-buttons:first"); + var actions = $(".action-buttons"); var actions_offset = 0; var win = $(window); @@ -54,7 +54,10 @@ // Toggle buttons based on count. if (count > 0) { btn.closest('.action-buttons').addClass('action-buttons-is-visible'); - actions_offset = actions.offset().top; + if (!actions_offset) { + // First time buttons are shown, get their offset value. + actions_offset = actions.offset().top; + } btn.removeAttr("disabled"); } else { From 04fb28d6a3841f2ee9c253b863bc995d7e7a8b28 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 17 Oct 2013 14:31:38 +0200 Subject: [PATCH 093/125] Changed date format to ding material list --- ding_reservation.module | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 86f7912..8276776 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -363,7 +363,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, ), 'pickup_date' => array( 'label' => t('Pickup date'), - 'data' => $reservation->pickup_date ? format_date(strtotime(check_plain($reservation->pickup_date)), 'ding_reservation_lists_date') : '', + 'data' => $reservation->pickup_date ? format_date(strtotime(check_plain($reservation->pickup_date)), 'ding_material_lists_date') : '', 'class' => 'pickup-date', '#weight' => 4, ), @@ -375,7 +375,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, ), 'created' => array( 'label' => t('Created date'), - 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', + 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_material_lists_date') : '', 'class' => 'created-date', '#weight' => 16, ), @@ -398,7 +398,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, ), 'expiry' => array( 'label' => t('Expiry date'), - 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->expiry)), 'ding_reservation_lists_date') : '', + 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->expiry)), 'ding_material_lists_date') : '', 'class' => 'expire-date', '#weight' => 4, ), @@ -410,7 +410,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, ), 'created' => array( 'label' => t('Created date'), - 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', + 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_material_lists_date') : '', 'class' => 'created-date', '#weight' => 16, ), @@ -439,7 +439,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, ), 'expiry' => array( 'label' => t('Library'), - 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->expiry)), 'ding_reservation_lists_date') : '', + 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->expiry)), 'ding_material_lists_date') : '', 'class' => 'expire-date', '#weight' => 4, ), @@ -451,7 +451,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, ), 'created' => array( 'label' => t('Expiry date'), - 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_reservation_lists_date') : '', + 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_material_lists_date') : '', 'class' => 'created-date', '#weight' => 16, ), From 3361870dcc7ae3d5b77cbd3705b6f31545112f32 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 4 Nov 2013 21:21:36 +0100 Subject: [PATCH 094/125] Updated makefile to point to tag 7.x-1.0-beta2 --- ding_reservation.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index cae1f1b..a196059 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -11,19 +11,19 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" -projects[ding_base][download][branch] = "development" +projects[ding_base][download][tag] = "7.x-1.0-beta2" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" -projects[ding_popup][download][branch] = "development" +projects[ding_popup][download][tag] = "7.x-1.0-beta2" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" -projects[ding_user][download][branch] = "development" +projects[ding_user][download][tag] = "7.x-1.0-beta2" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][branch] = "development" +projects[ding_provider][download][tag] = "7.x-1.0-beta2" From 510a952e65684e7373e42427913deca696722780 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 26 Nov 2013 12:45:45 +0100 Subject: [PATCH 095/125] Updated makefile to point to tag 7.x-1.0-beta3 --- ding_reservation.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index a196059..85aed8d 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -11,19 +11,19 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" -projects[ding_base][download][tag] = "7.x-1.0-beta2" +projects[ding_base][download][tag] = "7.x-1.0-beta3" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" -projects[ding_popup][download][tag] = "7.x-1.0-beta2" +projects[ding_popup][download][tag] = "7.x-1.0-beta3" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" -projects[ding_user][download][tag] = "7.x-1.0-beta2" +projects[ding_user][download][tag] = "7.x-1.0-beta3" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-beta2" +projects[ding_provider][download][tag] = "7.x-1.0-beta3" From 59bc3793fa0f1dc63fc4cba0a6cc657ff3e68a96 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 3 Dec 2013 22:00:10 +0100 Subject: [PATCH 096/125] Added more information to reservation list based on new reservation types --- ding_reservation.module | 34 +++++++++++++------ .../reservations/reservations.inc | 29 ++++++++++------ 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 8276776..c2b8b36 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -4,6 +4,13 @@ * Handles display and creation/deletion of reservations for users. */ +/** + * Define reservation types. + */ +define('DING_RESERVATION_READY', 'ready_for_pickup'); +define('DING_RESERVATION_NOT_READY', 'not_ready_for_pickup'); +define('DING_RESERVATION_INTERLIBRARY_LOANS', 'interlibrary_loans'); + /** * Implements hook_ctools_plugin_directory(). * @@ -311,7 +318,7 @@ function ding_reservation_reserve_form_callback($form, &$form_state) { /** * Show a reservation list form. */ -function ding_reservation_reservations_form($form, &$form_state, $reservations, $type = 'not_ready_for_pickup', $conf = array()) { +function ding_reservation_reservations_form($form, &$form_state, $reservations, $type = DING_RESERVATION_NOT_READY, $conf = array()) { $form = array( '#tree' => TRUE, ); @@ -347,8 +354,8 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, $title = l($entity->getTitle() ? $entity->getTitle() : $reservation->display_name, $uri['path']); $pickup_branch = ding_provider_invoke('reservation', 'branch_name', $reservation->pickup_branch_id); - switch ($type) { - case 'ready_for_pickup': + switch ($reservation->reservation_type) { + case DING_RESERVATION_READY: $item = array( '#type' => 'material_item', '#id' => $reservation->id, @@ -383,7 +390,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, ); break; - case 'not_ready_for_pickup': + case DING_RESERVATION_NOT_READY: $item = array( '#type' => 'material_item', '#id' => $reservation->id, @@ -424,11 +431,12 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, ); break; - case 'interlibrary_loans': + case DING_RESERVATION_INTERLIBRARY_LOANS: + $title = $entity ? $entity->getTitle() : $reservation->display_name; $item = array( '#type' => 'material_item', '#id' => $reservation->id, - '#title' => $entity ? $entity->getTitle() : $reservation->display_name, + '#title' => $title ? $title : $reservation->display_name, '#cover' => field_view_field('ting_object', $entity, 'ting_cover', 'user_list'), '#information' => array( 'ill_status' => array( @@ -444,7 +452,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, '#weight' => 4, ), 'library' => array( - 'label' => t('Library'), + 'label' => t('Pickup branch'), 'data' => $pickup_branch ? check_plain($pickup_branch) : '', 'class' => 'pickup-branch', '#weight' => 8, @@ -455,12 +463,18 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, 'class' => 'created-date', '#weight' => 16, ), + 'order_nr' => array( + 'label' => t('Order nr.'), + 'data' => ding_reservation_get_order_nr($reservation), + 'class' => 'pickup-id', + '#weight' => 32, + ), ), ); break; } - if (in_array($type, array('not_ready_for_pickup', 'interlibrary_loans'))) { + if (in_array($type, array(DING_RESERVATION_NOT_READY, DING_RESERVATION_INTERLIBRARY_LOANS))) { // Set reservation expire message. $expire = strtotime(check_plain($reservation->expiry)); if ($expire - variable_get('reservation_expire', 604800) <= time()) { @@ -475,7 +489,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, // Add extra information if it's a periodical. There is an exception because // the notes field is also used to set library information for ill's but // only when they are ready for pick-up. - if (!empty($reservation->notes) && !($reservation->ill_status && $type == 'ready_for_pickup')) { + if (!empty($reservation->notes) && !($reservation->ill_status && $type == DING_RESERVATION_READY)) { $item['#information']['periodical_number'] = array( 'label' => t('Periodical no.'), 'data' => check_plain($reservation->notes), @@ -509,7 +523,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, ); } - if ($type == 'not_ready_for_pickup') { + if ($type == DING_RESERVATION_NOT_READY) { $form['actions_top']['update'] = array( '#prefix' => '
', '#suffix' => '
', diff --git a/plugins/content_types/reservations/reservations.inc b/plugins/content_types/reservations/reservations.inc index a4e7e4e..f8f67ae 100644 --- a/plugins/content_types/reservations/reservations.inc +++ b/plugins/content_types/reservations/reservations.inc @@ -62,19 +62,26 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan $preloaded_reservations[$type] = TRUE; } - // Add the current type to the items we want. - $items += $reservations[$type]; - // Sort the reservations based on type. + $sorted = array(); switch ($type) { - case 'ready_for_pickup': - uasort($items, 'ding_reservation_sort_queue_by_pickup_date'); + case DING_RESERVATION_READY: + $sorted = $reservations[$type]; + uasort($sorted, 'ding_reservation_sort_queue_by_pickup_date'); + break; + + case DING_RESERVATION_NOT_READY: + $sorted = $reservations[$type]; + uasort($sorted, 'ding_reservation_sort_queue_by_queue_number'); break; - case 'not_ready_for_pickup': - uasort($items, 'ding_reservation_sort_queue_by_queue_number'); + case DING_RESERVATION_INTERLIBRARY_LOANS: + $sorted = $reservations[$type]; break; } + + // Add the current type to the items we want. + $items += $sorted; } // Add the pre-load entity to each loan (side effect of getting the entity). @@ -94,7 +101,7 @@ function ding_reservation_reservations_content_type_render($subtype, $conf, $pan if (count($types) > 1) { // If more than one type is selected we will fallback to the most generic // form type. - $block->content = ding_provider_get_form($form_id, $content[$form_id], 'not_ready_for_pickup', $conf); + $block->content = ding_provider_get_form($form_id, $content[$form_id], DING_RESERVATION_NOT_READY, $conf); } else { $block->content = ding_provider_get_form($form_id, $content[$form_id], array_shift($types), $conf); @@ -113,9 +120,9 @@ function ding_reservation_reservations_content_type_edit_form($form, &$form_stat '#type' => 'checkboxes', '#title' => t('Reservation list type(s)'), '#options' => array( - 'not_ready_for_pickup' => t('Not ready for pickup'), - 'ready_for_pickup' => t('Ready for pickup'), - 'interlibrary_loans' => t('Interlibrary loans'), + DING_RESERVATION_NOT_READY => t('Not ready for pickup'), + DING_RESERVATION_READY => t('Ready for pickup'), + DING_RESERVATION_INTERLIBRARY_LOANS => t('Interlibrary loans'), ), '#default_value' => !empty($conf['reservation_type_list']) ? $conf['reservation_type_list'] : NULL, ); From 5102153983beac106239050868c27e2ca27de49d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 4 Dec 2013 14:41:45 +0100 Subject: [PATCH 097/125] Fixed IIL label in reservation lists --- ding_reservation.module | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index c2b8b36..6eaaf73 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -446,19 +446,19 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, '#weight' => 0, ), 'expiry' => array( - 'label' => t('Library'), + 'label' => t('Expiry date'), 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->expiry)), 'ding_material_lists_date') : '', 'class' => 'expire-date', '#weight' => 4, ), - 'library' => array( + 'pickup_branch' => array( 'label' => t('Pickup branch'), 'data' => $pickup_branch ? check_plain($pickup_branch) : '', 'class' => 'pickup-branch', '#weight' => 8, ), 'created' => array( - 'label' => t('Expiry date'), + 'label' => t('Created date'), 'data' => $reservation->created ? format_date(strtotime(check_plain($reservation->created)), 'ding_material_lists_date') : '', 'class' => 'created-date', '#weight' => 16, From 87393cbf289d2545ce88c9724608284d85878200 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 10 Dec 2013 17:59:20 +0100 Subject: [PATCH 098/125] Fixed title links in reservation lists --- ding_reservation.module | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 6eaaf73..296bd4a 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -394,7 +394,7 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, $item = array( '#type' => 'material_item', '#id' => $reservation->id, - '#title' => $entity ? $entity->getTitle() : $reservation->display_name, + '#title' => $title, '#cover' => field_view_field('ting_object', $entity, 'ting_cover', 'user_list'), '#information' => array( 'queue_number' => array( @@ -432,11 +432,10 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, break; case DING_RESERVATION_INTERLIBRARY_LOANS: - $title = $entity ? $entity->getTitle() : $reservation->display_name; $item = array( '#type' => 'material_item', '#id' => $reservation->id, - '#title' => $title ? $title : $reservation->display_name, + '#title' => $title, '#cover' => field_view_field('ting_object', $entity, 'ting_cover', 'user_list'), '#information' => array( 'ill_status' => array( From 715fe13a385715dcbaf189d89e4759365e13e6e3 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 12 Dec 2013 13:13:06 +0100 Subject: [PATCH 099/125] Updated makefile to point to tag 7.x-1.0-beta4 --- ding_reservation.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index 85aed8d..ea619b7 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -11,19 +11,19 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" -projects[ding_base][download][tag] = "7.x-1.0-beta3" +projects[ding_base][download][tag] = "7.x-1.0-beta4" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" -projects[ding_popup][download][tag] = "7.x-1.0-beta3" +projects[ding_popup][download][tag] = "7.x-1.0-beta4" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" -projects[ding_user][download][tag] = "7.x-1.0-beta3" +projects[ding_user][download][tag] = "7.x-1.0-beta4" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-beta3" +projects[ding_provider][download][tag] = "7.x-1.0-beta4" From 61f9d17c6788d52f21fcfe6dd74c08590fea85b5 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 18 Dec 2013 05:03:07 +0100 Subject: [PATCH 100/125] Updated makefile to point to tag 7.x-1.0-beta5 --- ding_reservation.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index ea619b7..7120876 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -11,19 +11,19 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" -projects[ding_base][download][tag] = "7.x-1.0-beta4" +projects[ding_base][download][tag] = "7.x-1.0-beta5" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" -projects[ding_popup][download][tag] = "7.x-1.0-beta4" +projects[ding_popup][download][tag] = "7.x-1.0-beta5" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" -projects[ding_user][download][tag] = "7.x-1.0-beta4" +projects[ding_user][download][tag] = "7.x-1.0-beta5" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-beta4" +projects[ding_provider][download][tag] = "7.x-1.0-beta5" From c9e7c9bb350deda4237b3e29db08b0e40762f155 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 20 Dec 2013 15:39:21 +0100 Subject: [PATCH 101/125] Updated makefile to point to tag 7.x-1.0-rc1 --- ding_reservation.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index 7120876..aa2bfc3 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -11,19 +11,19 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" -projects[ding_base][download][tag] = "7.x-1.0-beta5" +projects[ding_base][download][tag] = "7.x-1.0-rc1" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" -projects[ding_popup][download][tag] = "7.x-1.0-beta5" +projects[ding_popup][download][tag] = "7.x-1.0-rc1" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" -projects[ding_user][download][tag] = "7.x-1.0-beta5" +projects[ding_user][download][tag] = "7.x-1.0-rc1" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-beta5" +projects[ding_provider][download][tag] = "7.x-1.0-rc1" From 4af87e8869b1ebd7da2d829ff9bd6b5ff4414460 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 8 Jan 2014 21:57:44 +0100 Subject: [PATCH 102/125] Updated makefile to point to tag 7.x-1.0-rc2 --- ding_reservation.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index aa2bfc3..51cf775 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -11,19 +11,19 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" -projects[ding_base][download][tag] = "7.x-1.0-rc1" +projects[ding_base][download][tag] = "7.x-1.0-rc2" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" -projects[ding_popup][download][tag] = "7.x-1.0-rc1" +projects[ding_popup][download][tag] = "7.x-1.0-rc2" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" -projects[ding_user][download][tag] = "7.x-1.0-rc1" +projects[ding_user][download][tag] = "7.x-1.0-rc2" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-rc1" +projects[ding_provider][download][tag] = "7.x-1.0-rc2" From 7c879ffb704f85f18786656f485d5b9401b0c24e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 20 Jan 2014 12:25:19 +0100 Subject: [PATCH 103/125] Updated makefile to point to tag 7.x-1.0-rc3 --- ding_reservation.make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index 51cf775..55b95ad 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -11,19 +11,19 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" -projects[ding_base][download][tag] = "7.x-1.0-rc2" +projects[ding_base][download][tag] = "7.x-1.0-rc3" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" -projects[ding_popup][download][tag] = "7.x-1.0-rc2" +projects[ding_popup][download][tag] = "7.x-1.0-rc3" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" -projects[ding_user][download][tag] = "7.x-1.0-rc2" +projects[ding_user][download][tag] = "7.x-1.0-rc3" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-rc2" +projects[ding_provider][download][tag] = "7.x-1.0-rc3" From 3a71d5523fe6c3e136efe7a8422199444f815877 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Feb 2014 13:41:37 +0100 Subject: [PATCH 104/125] Updated makefile to point to ding2 master branches --- ding_reservation.make | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index 55b95ad..7066255 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -10,20 +10,20 @@ projects[date][version] = "2.6" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" -projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" -projects[ding_base][download][tag] = "7.x-1.0-rc3" +projects[ding_base][download][url] = "git@github.com:ding2/ding_base.git" +projects[ding_base][download][branch] = "master" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" -projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" -projects[ding_popup][download][tag] = "7.x-1.0-rc3" +projects[ding_popup][download][url] = "git@github.com:ding2/ding_popup.git" +projects[ding_popup][download][branch] = "master" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" -projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" -projects[ding_user][download][tag] = "7.x-1.0-rc3" +projects[ding_user][download][url] = "git@github.com:ding2/ding_user.git" +projects[ding_user][download][branch] = "master" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" -projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][tag] = "7.x-1.0-rc3" +projects[ding_provider][download][url] = "git@github.com:ding2/ding_provider.git" +projects[ding_provider][download][branch] = "master" From 0782dbd1902c4fdc1f03e1575b09ba11ccad3e0a Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 24 Feb 2014 15:56:33 +0100 Subject: [PATCH 105/125] Added ajax reservation callback without generating a form for each reservation button --- ding_reservation.module | 92 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 4 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 296bd4a..72493d0 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -52,6 +52,13 @@ function ding_reservation_menu() { 'access arguments' => array(1), ); + $items['ting/object/%ting_object/reserve'] = array( + 'page callback' => 'ding_reservation_reserve_ajax', + 'page arguments' => array(2), + 'delivery callback' => 'ajax_deliver', + 'access arguments' => array('access content'), + ); + return $items; } @@ -80,12 +87,89 @@ function ding_reservation_ding_entity_menu(&$items, $type, $path, $index) { /** * Implements hook_ding_entity_buttons(). */ -function ding_reservation_ding_entity_buttons($type, $entity) { +function ding_reservation_ding_entity_buttons($type, $entity, $widget = 'default') { + $button = ''; + if ($type == 'ding_entity' && $entity->is('reservable')) { - // The last parameter to the form below (TRUE) hides the provider options in - // the form (interest period and branch). - return array(ding_provider_get_form('ding_reservation_reserve_form', new DingReservationReservableEntity($entity), TRUE)); + switch ($widget) { + case 'ajax': + drupal_add_library('system', 'drupal.ajax'); + + $button = array( + array( + '#theme' => 'link', + '#text' => t('Reserve'), + '#path' => 'ting/object/' . $entity->id . '/reserve', + '#options' => array( + 'attributes' => array( + 'class' => array( + 'action-button', + 'reserve-button', + 'use-ajax', + ), + 'id' => 'reservation-' . $entity->id, + ), + 'html' => FALSE, + ), + ), + ); + break; + + default: + // The last parameter to the form below (TRUE) hides the provider + // options in the form (interest period and branch). + $button = array(ding_provider_get_form('ding_reservation_reserve_form', new DingReservationReservableEntity($entity), TRUE)); + break; + } + } + + return $button; +} + +/** + * Ajax entry callback. + * + * Try to reserve the material, if the user is not logged in trigger a ajax + * login. + * + * @param TingEntity + * Ting entity object. + * + * @return array + * Render array with Ajax commands. + */ +function ding_reservation_reserve_ajax($entity) { + $commands = array(); + + // Check if the logged in user is a library user. + global $user; + if (user_is_logged_in()) { + if (ding_user_is_provider_user($user)) { + if (is_object($entity) && $entity instanceof TingEntity) { + // Try to make reservation. + $form_state = array('values' => array()); + drupal_form_submit('ding_reservation_reserve_form', $form_state, new DingReservationReservableEntity($entity)); + + // Return any status messages set by the form. + $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), theme('status_messages')); + } + else { + // Error not ting entity. + $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Unable to load information about the material.') . '

'); + } + } + else { + // Error not library user. + $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Only library user can make reservations.') . '

'); + } } + else { + // Trigger log-in (the reservation link will be triggered on success). + $commands[] = ajax_command_ding_user_authenticate(''); + } + + // Return the ajax commands as an render array. + return array('#type' => 'ajax', '#commands' => $commands); } /** From c5f1dae607903b6d6284d0897f620e058255c802 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 26 Feb 2014 16:03:41 +0100 Subject: [PATCH 106/125] Added support for periodical reservation in ajax callback function --- ding_reservation.module | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 72493d0..6caa0dd 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -132,13 +132,17 @@ function ding_reservation_ding_entity_buttons($type, $entity, $widget = 'default * Try to reserve the material, if the user is not logged in trigger a ajax * login. * - * @param TingEntity + * @param TingEntity $entity * Ting entity object. + * @param DingReservationReservable $reservable + * Object with information about the entity to reserve. Used to make + * reservation of periodical, where volume and issue is part of the + * reservation. * * @return array * Render array with Ajax commands. */ -function ding_reservation_reserve_ajax($entity) { +function ding_reservation_reserve_ajax($entity, $reservable = NULL) { $commands = array(); // Check if the logged in user is a library user. @@ -146,9 +150,15 @@ function ding_reservation_reserve_ajax($entity) { if (user_is_logged_in()) { if (ding_user_is_provider_user($user)) { if (is_object($entity) && $entity instanceof TingEntity) { + // Check if reservable object was paste. + if (is_null($reservable)) { + // If no object passed assume "normal" reservation (not periodical). + new DingReservationReservableEntity($entity); + } + // Try to make reservation. $form_state = array('values' => array()); - drupal_form_submit('ding_reservation_reserve_form', $form_state, new DingReservationReservableEntity($entity)); + drupal_form_submit('ding_reservation_reserve_form', $form_state, $reservable); // Return any status messages set by the form. $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), theme('status_messages')); From 5416181537c8341f714540732ff42201779a24f4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 26 Feb 2014 16:18:50 +0100 Subject: [PATCH 107/125] Added exception handling to ajax reservation callback --- ding_reservation.module | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 6caa0dd..9dfd61a 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -157,11 +157,26 @@ function ding_reservation_reserve_ajax($entity, $reservable = NULL) { } // Try to make reservation. - $form_state = array('values' => array()); - drupal_form_submit('ding_reservation_reserve_form', $form_state, $reservable); + try { + $form_state = array('values' => array()); + drupal_form_submit('ding_reservation_reserve_form', $form_state, $reservable); - // Return any status messages set by the form. - $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), theme('status_messages')); + // Return any status messages set by the form. + $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), theme('status_messages')); + } + catch (DingProviderAuthException $exception) { + // The form may have thrown an Auth exception, so display login. (the + // reservation link will be triggered on success). + $commands[] = ajax_command_ding_user_authenticate(''); + } + catch (Exception $exception) { + // The form may have thrown an auth exception as the login may have + // timed-out (the reservation link will be triggered on success). + $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Unknown error in reservation, please contact the library.') . '

'); + + // Log exception. + watchdog_exception('ding_reservation', $exception); + } } else { // Error not ting entity. From 2e5fd550bbd1ecd1ed318832652f6cd49e5c4438 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 27 Feb 2014 15:36:26 +0100 Subject: [PATCH 108/125] Fixed missing assingement --- ding_reservation.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index 9dfd61a..3d0eaac 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -153,7 +153,7 @@ function ding_reservation_reserve_ajax($entity, $reservable = NULL) { // Check if reservable object was paste. if (is_null($reservable)) { // If no object passed assume "normal" reservation (not periodical). - new DingReservationReservableEntity($entity); + $reservable = new DingReservationReservableEntity($entity); } // Try to make reservation. From 1f47f4d5dc451509298e2cf94e37d2aa11cfc691 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 5 May 2014 13:11:39 +0200 Subject: [PATCH 109/125] Added missing new line in info file --- ding_reservation.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.info b/ding_reservation.info index 5f0fae6..9bfd698 100644 --- a/ding_reservation.info +++ b/ding_reservation.info @@ -8,4 +8,4 @@ files[] = ding_reservation.test dependencies[] = ding_base dependencies[] = ding_provider dependencies[] = ding_user -dependencies[] = ding_popup \ No newline at end of file +dependencies[] = ding_popup From a4464df4058fda8bd7c474f48f206c3262149678 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 5 May 2014 13:11:39 +0200 Subject: [PATCH 110/125] Added missing new line in info file --- ding_reservation.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.info b/ding_reservation.info index 5f0fae6..9bfd698 100644 --- a/ding_reservation.info +++ b/ding_reservation.info @@ -8,4 +8,4 @@ files[] = ding_reservation.test dependencies[] = ding_base dependencies[] = ding_provider dependencies[] = ding_user -dependencies[] = ding_popup \ No newline at end of file +dependencies[] = ding_popup From fdd1b6a295b6713811f4c1658e5a271cc7bb3efc Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 5 May 2014 13:20:40 +0200 Subject: [PATCH 111/125] Fixed typo in ding_reservation_reserve_form_validate --- ding_reservation.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index 3d0eaac..0e9f0c3 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -317,7 +317,7 @@ function ding_reservation_reserve_form_validate($form, &$form_state) { if (empty($default) && empty($form_state['values']['provider_options'][$key])) { // Set form error to trigger display of the form in ding pop-up. The // message will not be shown and the user will have to select values. - form_error($key, t('Please select a valied value.')); + form_error($key, t('Please select a valid value.')); $form_state['rebuild'] = TRUE; } else { From deab177de0fc2a9b483947ef45ce77dcb3179f50 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 5 May 2014 13:20:40 +0200 Subject: [PATCH 112/125] Fixed typo in ding_reservation_reserve_form_validate --- ding_reservation.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index 296bd4a..b155562 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -208,7 +208,7 @@ function ding_reservation_reserve_form_validate($form, &$form_state) { if (empty($default) && empty($form_state['values']['provider_options'][$key])) { // Set form error to trigger display of the form in ding pop-up. The // message will not be shown and the user will have to select values. - form_error($key, t('Please select a valied value.')); + form_error($key, t('Please select a valid value.')); $form_state['rebuild'] = TRUE; } else { From 34dd03a267b46d4251056c4c709e0e7cb4c9f4e3 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 6 May 2014 14:00:08 +0200 Subject: [PATCH 113/125] Updated date to version 2.7 --- ding_reservation.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.make b/ding_reservation.make index cae1f1b..8f037de 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -4,7 +4,7 @@ core = 7.x ; Contrib projects[date][subdir] = "contrib" -projects[date][version] = "2.6" +projects[date][version] = "2.7" ; Ding 2 modules From a9a3d691bb4d6486a44ba6e2923f782e1fa7d453 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 9 May 2014 11:00:09 +0200 Subject: [PATCH 114/125] Ensured that the provider is asked for entity details for inter library loans etc. --- ding_reservation.module | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 0e9f0c3..28c01e9 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -454,13 +454,17 @@ function ding_reservation_reservations_form($form, &$form_state, $reservations, foreach ($reservations as $reservation) { $entity = $reservation->entity; - if (!is_object($entity)) { + if (!is_object($entity) || $entity->reply == FALSE) { $entity = ding_provider_get_pseudo_entity($reservation->ding_entity_id); + // Don't link the title as the data well do not known this title. It may + // be a inter library loan. + $title = $entity->getTitle() ? $entity->getTitle() : $reservation->display_name; + } + else { + // Create title that links to the object. + $uri = entity_uri('ting_object', $entity); + $title = l($entity->getTitle(), $uri['path']); } - - // Create title that links to the object. - $uri = entity_uri('ting_object', $entity); - $title = l($entity->getTitle() ? $entity->getTitle() : $reservation->display_name, $uri['path']); $pickup_branch = ding_provider_invoke('reservation', 'branch_name', $reservation->pickup_branch_id); switch ($reservation->reservation_type) { From ae4d41935491f82fc95ad625cb31ddd42b17e942 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 13 May 2014 10:27:34 +0200 Subject: [PATCH 115/125] Added check for preferred branch doing reservation and gives the user an option to select branch --- ding_reservation.module | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 28c01e9..e6f8a1a 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -158,11 +158,22 @@ function ding_reservation_reserve_ajax($entity, $reservable = NULL) { // Try to make reservation. try { - $form_state = array('values' => array()); - drupal_form_submit('ding_reservation_reserve_form', $form_state, $reservable); + // Check if user have preferred branch and interest period, if so + // submit the reservation form. If not display another for with the + // options to select branch and period. + $defaults = ding_provider_invoke('reservation', 'default_options', $user); + $matches = preg_grep("/preferred_branch$/", array_keys($defaults)); + if (empty($defaults[array_shift($matches)])) { + $form = ding_provider_get_form('ding_reservation_reserve_form', $reservable, FALSE); + $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), render($form)); + } + else { + $form_state = array('values' => array()); + drupal_form_submit('ding_reservation_reserve_form', $form_state, $reservable); - // Return any status messages set by the form. - $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), theme('status_messages')); + // Return any status messages set by the form. + $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), theme('status_messages')); + } } catch (DingProviderAuthException $exception) { // The form may have thrown an Auth exception, so display login. (the @@ -321,7 +332,7 @@ function ding_reservation_reserve_form_validate($form, &$form_state) { $form_state['rebuild'] = TRUE; } else { - if (empty($default)) { + if (empty($default) || !empty($form_state['values']['provider_options'][$key])) { // If default value id not defined, try using the forms value. $provider_options[$key] = $form_state['values']['provider_options'][$key]; } From 77518524232b1d51aba7e271abeb8ce38762ff80 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 13 May 2014 10:28:20 +0200 Subject: [PATCH 116/125] Updated comment about branch --- ding_reservation.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index e6f8a1a..a04b67e 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -159,8 +159,8 @@ function ding_reservation_reserve_ajax($entity, $reservable = NULL) { // Try to make reservation. try { // Check if user have preferred branch and interest period, if so - // submit the reservation form. If not display another for with the - // options to select branch and period. + // submit the reservation form. If not display another form for with + // the options to select branch and period. $defaults = ding_provider_invoke('reservation', 'default_options', $user); $matches = preg_grep("/preferred_branch$/", array_keys($defaults)); if (empty($defaults[array_shift($matches)])) { From d84f0f25fa2cfb7b7e1d55a16b8a36729f10897e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 8 Sep 2014 11:17:59 +0200 Subject: [PATCH 117/125] Updated date to 2.8 --- ding_reservation.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_reservation.make b/ding_reservation.make index 8f037de..9acfa86 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -4,7 +4,7 @@ core = 7.x ; Contrib projects[date][subdir] = "contrib" -projects[date][version] = "2.7" +projects[date][version] = "2.8" ; Ding 2 modules From 363b84c90b21ed9982b89f0c9a50fb874514c38e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 6 Oct 2014 13:43:06 +0200 Subject: [PATCH 118/125] Updated make file to point to development branch --- ding_reservation.make | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index 6269553..9acfa86 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -10,20 +10,20 @@ projects[date][version] = "2.8" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" -projects[ding_base][download][url] = "git@github.com:ding2/ding_base.git" -projects[ding_base][download][branch] = "master" +projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" +projects[ding_base][download][branch] = "development" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" -projects[ding_popup][download][url] = "git@github.com:ding2/ding_popup.git" -projects[ding_popup][download][branch] = "master" +projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" +projects[ding_popup][download][branch] = "development" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" -projects[ding_user][download][url] = "git@github.com:ding2/ding_user.git" -projects[ding_user][download][branch] = "master" +projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" +projects[ding_user][download][branch] = "development" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" -projects[ding_provider][download][url] = "git@github.com:ding2/ding_provider.git" -projects[ding_provider][download][branch] = "master" +projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" +projects[ding_provider][download][branch] = "development" From 59c01983cf00233fc5460c01cf7143099ec93f81 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 7 Oct 2014 08:26:02 +0200 Subject: [PATCH 119/125] Updated make file to point to master branch --- ding_reservation.make | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ding_reservation.make b/ding_reservation.make index 9acfa86..6269553 100644 --- a/ding_reservation.make +++ b/ding_reservation.make @@ -10,20 +10,20 @@ projects[date][version] = "2.8" projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" -projects[ding_base][download][url] = "git@github.com:ding2tal/ding_base.git" -projects[ding_base][download][branch] = "development" +projects[ding_base][download][url] = "git@github.com:ding2/ding_base.git" +projects[ding_base][download][branch] = "master" projects[ding_popup][type] = "module" projects[ding_popup][download][type] = "git" -projects[ding_popup][download][url] = "git@github.com:ding2tal/ding_popup.git" -projects[ding_popup][download][branch] = "development" +projects[ding_popup][download][url] = "git@github.com:ding2/ding_popup.git" +projects[ding_popup][download][branch] = "master" projects[ding_user][type] = "module" projects[ding_user][download][type] = "git" -projects[ding_user][download][url] = "git@github.com:ding2tal/ding_user.git" -projects[ding_user][download][branch] = "development" +projects[ding_user][download][url] = "git@github.com:ding2/ding_user.git" +projects[ding_user][download][branch] = "master" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" -projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" -projects[ding_provider][download][branch] = "development" +projects[ding_provider][download][url] = "git@github.com:ding2/ding_provider.git" +projects[ding_provider][download][branch] = "master" From e36335346bc84e0eac192eb7eea6257b0769ed26 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 21 Oct 2014 15:32:09 +0200 Subject: [PATCH 120/125] Reviewed: Added new permission to preform reservations --- ding_reservation.module | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index a04b67e..6ce5602 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -56,7 +56,7 @@ function ding_reservation_menu() { 'page callback' => 'ding_reservation_reserve_ajax', 'page arguments' => array(2), 'delivery callback' => 'ajax_deliver', - 'access arguments' => array('access content'), + 'access arguments' => array('preform reservation'), ); return $items; @@ -70,6 +70,18 @@ function ding_reservation_access($account) { return $user->uid == $account->uid; } +/** + * Implements hook_permission(). + */ +function ding_reservation_permission() { + return array( + 'preform reservation' => array( + 'title' => t('Preform reservation'), + 'description' => t('Perform reservation in the library system.'), + ), + ); +} + /** * Implements hook_ding_entity_menu(). */ From b3c56a2b8388735a111d2615c96cfeb672d87dd4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 21 Oct 2014 15:32:09 +0200 Subject: [PATCH 121/125] Reviewed: Added new permission to preform reservations --- ding_reservation.module | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ding_reservation.module b/ding_reservation.module index a04b67e..6ce5602 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -56,7 +56,7 @@ function ding_reservation_menu() { 'page callback' => 'ding_reservation_reserve_ajax', 'page arguments' => array(2), 'delivery callback' => 'ajax_deliver', - 'access arguments' => array('access content'), + 'access arguments' => array('preform reservation'), ); return $items; @@ -70,6 +70,18 @@ function ding_reservation_access($account) { return $user->uid == $account->uid; } +/** + * Implements hook_permission(). + */ +function ding_reservation_permission() { + return array( + 'preform reservation' => array( + 'title' => t('Preform reservation'), + 'description' => t('Perform reservation in the library system.'), + ), + ); +} + /** * Implements hook_ding_entity_menu(). */ From 9bd1bea39e59e98b4d7c5e2f6305198c60ae078e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 28 Oct 2014 11:32:13 +0100 Subject: [PATCH 122/125] Issue #624 by cableman: Fixed typo in reservation permissions --- ding_reservation.module | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 6ce5602..9a0289c 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -56,7 +56,7 @@ function ding_reservation_menu() { 'page callback' => 'ding_reservation_reserve_ajax', 'page arguments' => array(2), 'delivery callback' => 'ajax_deliver', - 'access arguments' => array('preform reservation'), + 'access arguments' => array('perform reservation'), ); return $items; @@ -75,8 +75,8 @@ function ding_reservation_access($account) { */ function ding_reservation_permission() { return array( - 'preform reservation' => array( - 'title' => t('Preform reservation'), + 'perform reservation' => array( + 'title' => t('Perform reservation'), 'description' => t('Perform reservation in the library system.'), ), ); From ab5c503accb6d5f17206de19c65b952e60d1e97d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 17 Nov 2014 15:09:48 +0100 Subject: [PATCH 123/125] Reviewed: Change logic in if statements in ding_reservation_reserve_ajax --- ding_reservation.module | 94 ++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 49 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 9a0289c..142920c 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -159,61 +159,57 @@ function ding_reservation_reserve_ajax($entity, $reservable = NULL) { // Check if the logged in user is a library user. global $user; - if (user_is_logged_in()) { - if (ding_user_is_provider_user($user)) { - if (is_object($entity) && $entity instanceof TingEntity) { - // Check if reservable object was paste. - if (is_null($reservable)) { - // If no object passed assume "normal" reservation (not periodical). - $reservable = new DingReservationReservableEntity($entity); - } - - // Try to make reservation. - try { - // Check if user have preferred branch and interest period, if so - // submit the reservation form. If not display another form for with - // the options to select branch and period. - $defaults = ding_provider_invoke('reservation', 'default_options', $user); - $matches = preg_grep("/preferred_branch$/", array_keys($defaults)); - if (empty($defaults[array_shift($matches)])) { - $form = ding_provider_get_form('ding_reservation_reserve_form', $reservable, FALSE); - $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), render($form)); - } - else { - $form_state = array('values' => array()); - drupal_form_submit('ding_reservation_reserve_form', $form_state, $reservable); - - // Return any status messages set by the form. - $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), theme('status_messages')); - } - } - catch (DingProviderAuthException $exception) { - // The form may have thrown an Auth exception, so display login. (the - // reservation link will be triggered on success). - $commands[] = ajax_command_ding_user_authenticate(''); - } - catch (Exception $exception) { - // The form may have thrown an auth exception as the login may have - // timed-out (the reservation link will be triggered on success). - $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Unknown error in reservation, please contact the library.') . '

'); + if (!user_is_logged_in()) { + // Trigger log-in (the reservation link will be triggered on success). + $commands[] = ajax_command_ding_user_authenticate(''); + } + elseif (!ding_user_is_provider_user($user)) { + // Error not library user. + $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Only library user can make reservations.') . '

'); + } + elseif (!(is_object($entity) && $entity instanceof TingEntity)) { + // Error not ting entity. + $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Unable to load information about the material.') . '

'); + } + else { + // Check if reservable object was paste. + if (is_null($reservable)) { + // If no object passed assume "normal" reservation (not periodical). + $reservable = new DingReservationReservableEntity($entity); + } - // Log exception. - watchdog_exception('ding_reservation', $exception); - } + // Try to make reservation. + try { + // Check if user have preferred branch and interest period, if so + // submit the reservation form. If not display another form for with + // the options to select branch and period. + $defaults = ding_provider_invoke('reservation', 'default_options', $user); + $matches = preg_grep("/preferred_branch$/", array_keys($defaults)); + if (empty($defaults[array_shift($matches)])) { + $form = ding_provider_get_form('ding_reservation_reserve_form', $reservable, FALSE); + $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), render($form)); } else { - // Error not ting entity. - $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Unable to load information about the material.') . '

'); + $form_state = array('values' => array()); + drupal_form_submit('ding_reservation_reserve_form', $form_state, $reservable); + + // Return any status messages set by the form. + $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), theme('status_messages')); } } - else { - // Error not library user. - $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Only library user can make reservations.') . '

'); + catch (DingProviderAuthException $exception) { + // The form may have thrown an Auth exception, so display login. (the + // reservation link will be triggered on success). + $commands[] = ajax_command_ding_user_authenticate(''); + } + catch (Exception $exception) { + // The form may have thrown an auth exception as the login may have + // timed-out (the reservation link will be triggered on success). + $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Unknown error in reservation, please contact the library.') . '

'); + + // Log exception. + watchdog_exception('ding_reservation', $exception); } - } - else { - // Trigger log-in (the reservation link will be triggered on success). - $commands[] = ajax_command_ding_user_authenticate(''); } // Return the ajax commands as an render array. From 681dbb5840289576587ef9754731764e9b46878d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 17 Nov 2014 15:09:48 +0100 Subject: [PATCH 124/125] Reviewed: Change logic in if statements in ding_reservation_reserve_ajax --- ding_reservation.module | 94 ++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 49 deletions(-) diff --git a/ding_reservation.module b/ding_reservation.module index 6ce5602..2674275 100644 --- a/ding_reservation.module +++ b/ding_reservation.module @@ -159,61 +159,57 @@ function ding_reservation_reserve_ajax($entity, $reservable = NULL) { // Check if the logged in user is a library user. global $user; - if (user_is_logged_in()) { - if (ding_user_is_provider_user($user)) { - if (is_object($entity) && $entity instanceof TingEntity) { - // Check if reservable object was paste. - if (is_null($reservable)) { - // If no object passed assume "normal" reservation (not periodical). - $reservable = new DingReservationReservableEntity($entity); - } - - // Try to make reservation. - try { - // Check if user have preferred branch and interest period, if so - // submit the reservation form. If not display another form for with - // the options to select branch and period. - $defaults = ding_provider_invoke('reservation', 'default_options', $user); - $matches = preg_grep("/preferred_branch$/", array_keys($defaults)); - if (empty($defaults[array_shift($matches)])) { - $form = ding_provider_get_form('ding_reservation_reserve_form', $reservable, FALSE); - $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), render($form)); - } - else { - $form_state = array('values' => array()); - drupal_form_submit('ding_reservation_reserve_form', $form_state, $reservable); - - // Return any status messages set by the form. - $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), theme('status_messages')); - } - } - catch (DingProviderAuthException $exception) { - // The form may have thrown an Auth exception, so display login. (the - // reservation link will be triggered on success). - $commands[] = ajax_command_ding_user_authenticate(''); - } - catch (Exception $exception) { - // The form may have thrown an auth exception as the login may have - // timed-out (the reservation link will be triggered on success). - $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Unknown error in reservation, please contact the library.') . '

'); + if (!user_is_logged_in()) { + // Trigger log-in (the reservation link will be triggered on success). + $commands[] = ajax_command_ding_user_authenticate(''); + } + elseif (!ding_user_is_provider_user($user)) { + // Error not library user. + $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Only library user can make reservations.') . '

'); + } + elseif (!(is_object($entity) && $entity instanceof TingEntity)) { + // Error not ting entity. + $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Unable to load information about the material.') . '

'); + } + else { + // Check if reservable object was paste. + if (is_null($reservable)) { + // If no object passed assume "normal" reservation (not periodical). + $reservable = new DingReservationReservableEntity($entity); + } - // Log exception. - watchdog_exception('ding_reservation', $exception); - } + // Try to make reservation. + try { + // Check if user have preferred branch and interest period, if so + // submit the reservation form. If not display another form for with + // the options to select branch and period. + $defaults = ding_provider_invoke('reservation', 'default_options', $user); + $matches = preg_grep("/preferred_branch$/", array_keys($defaults)); + if (empty($defaults[array_shift($matches)])) { + $form = ding_provider_get_form('ding_reservation_reserve_form', $reservable, FALSE); + $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), render($form)); } else { - // Error not ting entity. - $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Unable to load information about the material.') . '

'); + $form_state = array('values' => array()); + drupal_form_submit('ding_reservation_reserve_form', $form_state, $reservable); + + // Return any status messages set by the form. + $commands[] = ajax_command_ding_popup('ding_reservation', t('Reservation'), theme('status_messages')); } } - else { - // Error not library user. - $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Only library user can make reservations.') . '

'); + catch (DingProviderAuthException $exception) { + // The form may have thrown an Auth exception, so display login. (the + // reservation link will be triggered on success). + $commands[] = ajax_command_ding_user_authenticate(''); + } + catch (Exception $exception) { + // The form may have thrown an auth exception as the login may have + // timed-out (the reservation link will be triggered on success). + $commands[] = ajax_command_ding_popup('ding_reservation', t('Error'), '

' . t('Unknown error in reservation, please contact the library.') . '

'); + + // Log exception. + watchdog_exception('ding_reservation', $exception); } - } - else { - // Trigger log-in (the reservation link will be triggered on success). - $commands[] = ajax_command_ding_user_authenticate(''); } // Return the ajax commands as an render array. From a3ce4156bbc4ba99b8fda2ed3c38ac54a396fe8e Mon Sep 17 00:00:00 2001 From: Morten Bartvig Date: Tue, 13 Oct 2015 12:20:59 +0000 Subject: [PATCH 125/125] Feature #187 by bartvig: Don't set action-buttons-is-visible css class on action buttons. --- js/ding_reservation.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/js/ding_reservation.js b/js/ding_reservation.js index cde88c0..52ffa53 100644 --- a/js/ding_reservation.js +++ b/js/ding_reservation.js @@ -53,7 +53,6 @@ // Toggle buttons based on count. if (count > 0) { - btn.closest('.action-buttons').addClass('action-buttons-is-visible'); if (!actions_offset) { // First time buttons are shown, get their offset value. actions_offset = actions.offset().top; @@ -61,7 +60,6 @@ btn.removeAttr("disabled"); } else { - btn.closest('.action-buttons').removeClass('action-buttons-is-visible'); btn.prop('disabled', 'disabled'); } }); @@ -80,7 +78,7 @@ * moves the out of flow to follow the top of the screen on scroll. */ function toggle_scroll_buttons() { - if (actions_offset < win.scrollTop() && actions.hasClass('action-buttons-is-visible')) { + if (actions_offset < win.scrollTop()) { actions.addClass('action-buttons-is-scrolling'); } else {