',
+ ),
+ );
// Normal behavior - periodicals, dc.type=tidsskrift.
$iss[$i] = array(
- 'data' => '' . $issue . '',
- 'children' => $holding,
+ 'data' => '' . $issue . '',
'class' => array(
drupal_html_class('ding-periodical-container'),
),
);
- // Suppose we have dc.type=årbog
- // Keys for those periodicals are empty.
+ // Suppose we have dc.type=årbog, where keys for those periodicals are
+ // empty or 0. Move the layout out.
if (empty($issue)) {
- $iss[$i]['data'] = $holding[0]['data'];
+ $iss[$i]['data'] = $holdings[0]['data'];
$iss[$i]['class'][] = drupal_html_class('ding-periodical-no-issues');
$iss[$i]['class'][] = drupal_html_class('ding-reservable-periodical');
$iss[$i]['id'][] = drupal_html_id('periodical-id-' . $normalized_id);
- unset($iss[$i]['children']);
+ }
+ else {
+ // Set children with holding information for periodicals.
+ $iss[$i]['children'] = $holdings;
}
$i++;
@@ -87,40 +202,13 @@ function theme_ding_periodical_issues($variables) {
$items[] = $vol;
}
- return theme('item_list', array('items' => $items, 'attributes' => array('class' => drupal_html_class('ding_periodical_issues'))));
-}
-
-/**
- * Fetch periodical availability table.
- *
- * @param $item
- * Ting object local id, parent of periodical.
- * @param $periodical
- * Periodical id.
- * @return type
- * HTML markup.
- */
-function ding_periodical_holding_data($item = NULL, $volume = NULL, $issue = NULL) {
- $availability_table = '';
- if (!empty($item)) {
- $holdings = &drupal_static(__FUNCTION__, NULL);
- if (!isset($holdings[$item])) {
- $holdings = ding_provider_invoke('availability', 'holdings', array($item));
- }
-
- if (!empty($volume) && !empty($issue)) {
- $issue = $holdings[$item]['issues'][$volume][$issue];
- $availability_table = ding_periodical_build_table($issue);
- }
- }
-
- return $availability_table;
+ return theme('item_list', array('items' => $items, 'attributes' => array('class' => 'ding-periodical-issues')));
}
/**
* Build a markup for the availability table.
*
- * @param $issue
+ * @param array $availability
* Issue array, with keys:
* - local_id: Periodical identifier.
* - provider: Provider identifier, 'alma' here.
@@ -133,18 +221,10 @@ function ding_periodical_holding_data($item = NULL, $volume = NULL, $issue = NUL
* - available_count
* - reservable
*
- * Keys checked_out_count, reference_count, ordered_count
- * appear only in alma.
- *
- * @todo
- * This table DOES NOT contain the reservations count,
- * since this number comes as a separate value, for the whole
- * ting item, not the periodicals.
- *
- * @return
+ * @return $string
* HTML markup for the availability table.
*/
-function ding_periodical_build_table($issue) {
+function ding_periodical_build_table($availability) {
$header = array(
'placement' => t('Placement'),
'copies' => t('Copies'),
@@ -153,26 +233,46 @@ function ding_periodical_build_table($issue) {
$rows = array();
- if ($issue['provider'] === 'alma') {
- $header['not_for_loan'] = t('Not for loan');
- $header['checked_out'] = t('Checked out');
- }
-
$i = 0;
- foreach ($issue['placement'] as $placement) {
+ foreach ($availability['placement'] as $data) {
+ $home = isset($data['available_count']) ? (int) $data['available_count'] : 0;
+ $home += isset($data['reference_count']) ? (int) $data['reference_count'] : 0;
+
$rows[$i] = array(
- $placement['location'],
- $placement['total_count'],
- $placement['available_count'],
+ $data['location'],
+ $data['total_count'],
+ $home,
);
- if ($issue['provider'] === 'alma') {
- $rows[$i][] = $placement['reference_count'];
- $rows[$i][] = $placement['checked_out_count'];
- }
-
$i++;
}
- return theme('table', array('header' => $header, 'rows' => $rows));
+ // Note: If stikcy header is TRUE, it will keep adding the js in FF until the
+ // browser goes down.
+ return theme('table', array(
+ 'header' => $header,
+ 'rows' => $rows,
+ 'sticky' => FALSE,
+ ));
+}
+
+/**
+ * Check if a given issue of a periodical have any copies on the libraries.
+ *
+ * @param array $issue
+ * An periodical issue form the provider.
+ *
+ * @return bool
+ * If a copy exists it return TRUE else FALSE.
+ */
+function ding_periodical_is_reservable($issue) {
+ foreach ($issue['placement'] as $placement) {
+ if ($placement['reservable']) {
+ // Found on placement that had a reservable copy.
+ return TRUE;
+ }
+ }
+
+ // No placements found with reservable copy.
+ return FALSE;
}
diff --git a/ding_periodical_reservable.class.inc b/ding_periodical_reservable.class.inc
new file mode 100644
index 0000000..07b7941
--- /dev/null
+++ b/ding_periodical_reservable.class.inc
@@ -0,0 +1,70 @@
+id = $id;
+ $this->volume = $volume;
+ $this->issue = $issue;
+ $this->entity = $entity;
+ }
+
+ /**
+ * Gets the provider id based on the provider.
+ *
+ * @return string
+ * The id for the issue.
+ */
+ public function getProviderId() {
+ $type = ding_provider_get_provider_module_name('reservation');
+ switch ($type) {
+ case 'openruth':
+ return array($this->entity->provider_id, $this->id);
+
+ default:
+ return $this->id;
+ }
+ }
+
+ /**
+ * Returns the entity that represents this issue.
+ *
+ * @return DingEntity
+ * The entity for the reservation.
+ */
+ public function getEntity() {
+ return $this->entity;
+ }
+
+ /**
+ * The periodical title with volume and issue information.
+ *
+ * @return string
+ * Formatted string with issue and volume information.
+ */
+ public function getTitle() {
+ $title = '@title, vol @volume';
+ $title .= !empty($this->issue) ? ', issue @issue' : '';
+
+ return t($title, array('@title' => $this->entity->title, '@volume' => $this->volume, '@issue' => $this->issue));
+ }
+}
diff --git a/ding_periodical_reservation/ding_periodical_reservation.info b/ding_periodical_reservation/ding_periodical_reservation.info
deleted file mode 100644
index ccd1c94..0000000
--- a/ding_periodical_reservation/ding_periodical_reservation.info
+++ /dev/null
@@ -1,8 +0,0 @@
-name = Ding periodical reservation
-description = Handles reservation of issues on periodicals.
-package = Ding!
-version = 0.1+dbc.1
-core = 7.x
-files[] = ding_periodical_reservation.module
-dependencies[] = ding_periodical
-dependencies[] = ding_reservation
diff --git a/ding_periodical_reservation/ding_periodical_reservation.module b/ding_periodical_reservation/ding_periodical_reservation.module
deleted file mode 100644
index 5b164fb..0000000
--- a/ding_periodical_reservation/ding_periodical_reservation.module
+++ /dev/null
@@ -1,125 +0,0 @@
- MENU_CALLBACK,
- 'access arguments' => array('search content'),
- 'page arguments' => array(2),
- 'page callback' => 'ding_periodical_reservation_ajax_reserve',
- 'delivery callback' => 'ajax_deliver',
- );
-
- return $items;
-}
-
-/**
- * Implements hook_init().
- */
-function ding_periodical_reservation_init() {
- // We need those only for item landing page.
- if (arg(0) == 'ting' && arg(1) == 'object') {
- drupal_add_library('system', 'drupal.ajax');
- drupal_add_library('system', 'jquery.form');
- drupal_add_js(drupal_get_path('module', 'ding_periodical_reservation') . '/js/ding_periodical_reservation.scripts.js');
- }
-}
-
-/**
- * Ajax responder for periodical reservations.
- *
- * @param $id
- * Reservable id.
- * @return type
- * Array, with ajax specific commands.
- */
-function ding_periodical_reservation_ajax_reserve($id = '') {
- $commands = array();
-
- if (!empty($id)) {
- $reservable = isset($_SESSION['ding_periodical_reservation'][$id]) ? $_SESSION['ding_periodical_reservation'][$id] : NULL;
-
- if (is_array($reservable)) {
- $reservation_form = ding_periodical_reservation_button(
- $reservable['issue_id'],
- $reservable['volume'],
- $reservable['key'],
- $reservable['entity']
- );
-
- $commands[] = ajax_command_append('html', $reservation_form);
- $commands[] = ding_periodical_reservation_trigger_periodical_reservation($id);
- }
- }
-
- return array('#type' => 'ajax', '#commands' => $commands);
-}
-
-/**
- * Function wrapper for custom AJAX command.
- *
- * Command for triggering periodical reservation procedure, after a certain
- * reservation form was created.
- */
-function ding_periodical_reservation_trigger_periodical_reservation($entity_id = '') {
- if (!empty($entity_id)) {
- return array('command' => 'trigger_periodical_reservation', 'data' => $entity_id);
- }
-}
-
-/**
- * A periodical reservation.
- */
-class DingPeriodicalReservable extends DingReservationReservableEntity {
- public function __construct($id, $volume, $issue, $entity) {
- $this->id = $id;
- $this->volume = $volume;
- $this->issue = $issue;
- $this->entity = $entity;
- }
-
- public function getProviderId() {
- // pjo 16-01-12 reservations did not work for alma-periodicals;
- // switch on provider type
- $type = ding_provider_get_provider_module_name('reservation');
- switch ($type) {
- case 'openruth':
- return array($this->entity->provider_id, $this->id);
- case 'alma':
- return $this->id;
- default:
- return $this->id;
- }
- }
-
- public function getEntity() {
- return $this->entity;
- }
-
- public function getTitle() {
- $title = '@title, vol @volume';
- $title .= !empty($this->issue) ? ', issue @issue' : '';
-
- return t($title, array('@title' => $this->entity->title, '@volume' => $this->volume, '@issue' => $this->issue));
- }
-}
diff --git a/ding_periodical_reservation/js/ding_periodical_reservation.scripts.js b/ding_periodical_reservation/js/ding_periodical_reservation.scripts.js
deleted file mode 100644
index 4d28c4e..0000000
--- a/ding_periodical_reservation/js/ding_periodical_reservation.scripts.js
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * @file
- * Script file for the periodical reservations.
- */
-(function ($) {
- Drupal.extractPeriodicalId = function(ele) {
- classname = $(ele).attr('id');
- id = classname.match(/periodical-id-(.+)/);
-
- if (id != null) {
- return id[1];
- }
- else {
- return false;
- }
- }
-
- trigger_periodical_reservation = function(ajax, response, status) {
- var entity_id = response.data.replace(' ', '%20');
- var forms = $('form');
- var regex = new RegExp(entity_id, 'g');
- // Loop through all forms on a page, deeper filtering comes next.
- forms.each(function() {
- form = $(this);
- // Wee seek for reservations forms, thus specific form whose item was clicked.
- if (form.attr('id').match(/ding-reservation-reserve-form/g) && form.attr('action').match(regex)) {
- form.hide();
- // Make sure we don't miss the form.
- setTimeout(function() {
- // Call mousedown(), since click() event is forbidden by #ajax['prevent'].
- form.find('.form-submit').mousedown();
- }, 500);
- }
- });
- }
-
- Drupal.behaviors.ding_periodical_reservation = {
- attach: function (context, settings) {
- Drupal.ajax.prototype.commands.trigger_periodical_reservation = trigger_periodical_reservation;
- $('.ding-reservable-periodical', context).once('ding-reservable-periodical', function() {
- var id = Drupal.extractPeriodicalId($(this));
- if (id) {
- var element_settings = {};
- element_settings.url = '/ding_periodical_reservation/reserve/' + id;
- element_settings.event = 'click';
- element_settings.progress = { type: 'throbber' };
- base = $(this).attr('id');
-
- Drupal.ajax[base] = new Drupal.ajax(base, $(this).parent().find('.periodical-reserve button'), element_settings);
- }
- });
- }
- }
-}(jQuery));
diff --git a/images/arrow-down-blue.png b/images/arrow-down-blue.png
deleted file mode 100644
index e0e8f1a..0000000
Binary files a/images/arrow-down-blue.png and /dev/null differ
diff --git a/images/arrow-down-grey.png b/images/arrow-down-grey.png
deleted file mode 100644
index 04e7e52..0000000
Binary files a/images/arrow-down-grey.png and /dev/null differ
diff --git a/images/arrow-right-blue.png b/images/arrow-right-blue.png
deleted file mode 100644
index bd41167..0000000
Binary files a/images/arrow-right-blue.png and /dev/null differ
diff --git a/images/arrow-right-grey.png b/images/arrow-right-grey.png
deleted file mode 100644
index b9c942e..0000000
Binary files a/images/arrow-right-grey.png and /dev/null differ
diff --git a/images/more-button-blue.png b/images/more-button-blue.png
deleted file mode 100644
index 823f965..0000000
Binary files a/images/more-button-blue.png and /dev/null differ
diff --git a/images/more-button-grey.png b/images/more-button-grey.png
deleted file mode 100644
index eea6682..0000000
Binary files a/images/more-button-grey.png and /dev/null differ
diff --git a/js/ding_periodical.js b/js/ding_periodical.js
new file mode 100644
index 0000000..636b1a1
--- /dev/null
+++ b/js/ding_periodical.js
@@ -0,0 +1,16 @@
+(function ($) {
+ $(document).ready(function(){
+ // Hide all elements.
+ $('.ding-periodical-issues li').children('.item-list').hide();
+
+ // Add class to style the list as being expandable.
+ $('.ding-periodical-fold').addClass('expand expand-more');
+
+ // Attach click event to fold in/out the issues.
+ $('.field-name-ding-periodical-issues .ding-periodical-fold').live("click", function() {
+ $(this).next().toggle();
+ $(this).next().toggleClass('expanded-periodicals');
+ $(this).parent().toggleClass('expanded-periodicals-parent');
+ });
+ });
+}(jQuery));
diff --git a/js/ding_periodical_ajax.js b/js/ding_periodical_ajax.js
new file mode 100644
index 0000000..881cd1f
--- /dev/null
+++ b/js/ding_periodical_ajax.js
@@ -0,0 +1,31 @@
+(function ($) {
+ $(document).ready(function(){
+ var ids = Drupal.settings.ding_periodical;
+ $(ids).each(function (index, info){
+ // Make ajax call to get holdings table (opt. use the information fetched
+ // by availability for the entity).
+ $.ajax({
+ type: 'GET',
+ url: '/ding_periodical/issues/' + info.ding_entity_id
+ }).done(function(data) {
+ var div = $('.ding-periodical-issues-ajax.' + info.id);
+ if (!data.html || 0 === data.html.length) {
+ // No informtion found.
+ div.html('
' + Drupal.t('No periodical issue information found.') + '
');
+ }
+ else {
+ // Insert the information.
+ div.parent().html(data.html);
+
+ // Hide all elements.
+ $('.ding-periodical-issues li').children('.item-list').hide();
+
+ // Add class to style the list as being expandable.
+ $('.ding-periodical-fold').addClass('expand expand-more');
+ }
+ });
+
+ // Insert tabelles on succes and hide label on failure.
+ });
+ });
+}(jQuery));