diff --git a/ding_availability.field.inc b/ding_availability.field.inc
index 5b8672b..0c05539 100644
--- a/ding_availability.field.inc
+++ b/ding_availability.field.inc
@@ -106,7 +106,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $
$element[$delta] = array(
'#markup' => '
',
'#attached' => $attached,
- );
+ );
break;
case 'ding_availability_item':
$element[$delta] = array(
diff --git a/ding_availability.module b/ding_availability.module
index 90e5f3e..bdf4e89 100644
--- a/ding_availability.module
+++ b/ding_availability.module
@@ -15,6 +15,7 @@ function ding_availability_menu() {
'title' => 'Availability status',
'page callback' => 'ding_availability_js',
'access arguments' => array('access content'),
+ 'delivery callback' => 'ajax_deliver',
'type' => MENU_CALLBACK,
);
@@ -22,6 +23,7 @@ function ding_availability_menu() {
'title' => 'Availability and holding status',
'page callback' => 'ding_availability_holdings_js',
'access arguments' => array('access content'),
+ 'delivery callback' => 'ajax_deliver',
'type' => MENU_CALLBACK,
);
@@ -44,14 +46,62 @@ function ding_availability_ding_provider_user() {
*
*/
function ding_availability_js($provider_ids) {
+ $data = $_POST['availability'];
drupal_json_output(ding_availability_items(explode(',', $provider_ids)));
}
/**
*
*/
-function ding_availability_holdings_js($provider_ids) {
- drupal_json_output(ding_availability_holdings(explode(',', $provider_ids)));
+function ding_availability_holdings_js($provider_ids = NULL) {
+ $commands = array();
+ $availability = $_POST['availability'];
+
+ $holdings = $_POST['holdings'];
+ if(is_array($availability) && is_array($holdings))
+ $ids = array_merge($availability, $holdings);
+ else
+ $ids = is_array($availability) ? $availability : $holdings;
+ $data = ding_availability_holdings($ids);
+
+ if(is_array($availability)) {
+ // Set availability
+ foreach($availability as $html_id => $avid) {
+ if(isset($data[$avid])) {
+ $return = theme('ding_availability_status', array('availability' => $data[$avid]));
+ $commands[] = ajax_command_replace('#' . $html_id, $return);
+ } else {
+ $default_data = array(
+ 'local_id' => $avid,
+ 'available' => 0,
+ 'reservable' => 0,
+ 'show_reservation_button' => 0,
+ 'reserved_count' => 0,
+ 'deferred_period' => FALSE,
+ 'is_periodical' => 0,
+ 'is_internet' => TRUE,
+ 'status' => 'unavailable',
+ );
+ $return = theme('ding_availability_status', array('availability' => $default_data));
+ $commands[] = ajax_command_replace('#' . $html_id, $return);
+ }
+ }
+ }
+ if(is_array($holdings)) {
+ // Set holdings
+ foreach($holdings as $html_id => $avid) {
+ if(empty($data[$avid]) || !isset($data[$avid])) {
+ $data[$avid]['location']['holdings'][][] = t('Not provided');
+ }
+ $return = theme('ding_availability_holdings', array('holdings' => $data[$avid]));
+ $commands[] = ajax_command_html('#' . $html_id, $return);
+ }
+ }
+
+ return array(
+ '#type' => 'ajax',
+ '#commands' => $commands,
+ );
}
/**
@@ -102,7 +152,10 @@ function ding_availability_holdings($provider_ids) {
* Adds the human readable status text of an item.
*/
function _ding_availability_text(&$item) {
- if ($item['available'] && $item['reservable']) {
+ if (isset($item['status']) && $item['status'] == 'inAcquisition') {
+ $item['status'] = t('in acquisition');
+ }
+ elseif (($item['available'] && $item['reservable']) || $item['is_internet']) {
$item['status'] = t('available');
}
elseif (!$item['available'] && $item['reservable']) {
@@ -180,3 +233,18 @@ function ding_availability_preprocess_ting_object_entities(&$variables) {
}
}
+/**
+ * Implements hook_theme
+ */
+function ding_availability_theme($existing, $type, $theme, $path) {
+ return array(
+ 'ding_availability_holdings' => array(
+ 'variables' => array('holdings' => array()),
+ 'file' => 'ding_availability.theme.inc',
+ ),
+ 'ding_availability_status' => array(
+ 'variables' => array('availability' => NULL),
+ 'file' => 'ding_availability.theme.inc',
+ ),
+ );
+}
\ No newline at end of file
diff --git a/ding_availability.theme.inc b/ding_availability.theme.inc
new file mode 100644
index 0000000..f90657f
--- /dev/null
+++ b/ding_availability.theme.inc
@@ -0,0 +1,101 @@
+ 'markup',
+ '#markup' => '' . t('Position') . '
',
+ );
+ $items = array();
+ if(isset($holdings['location'])) {
+ foreach($holdings['location']['holdings'] as $count => $location) {
+ $items[] = join(' → ', $location);
+ }
+ $variables['content']['location'] = array(
+ '#theme' => 'item_list',
+ '#items' => $items,
+ '#title' => '',
+ '#type' => 'ul',
+ '#attributes' => array(
+ 'class' => array(drupal_html_class('ding_availability_location')),
+ ),
+ );
+ }
+ if(isset($holdings['holdings'])) {
+ $variables['content']['holdings'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('View all holdings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ '#attached' => array(
+ 'js' => array(
+ 'misc/form.js',
+ 'misc/collapse.js',
+ ),
+ ),
+ '#attributes' => array(
+ 'class' => array('collapsible', 'collapsed'),
+ ),
+ );
+ $row = array();
+ $row['data']['Library'] = t('Reservations');
+ $row['data']['Copies'] = $variables['holdings']['reserved_count'];
+ $row['data']['Home'] = '';
+ $row['data']['Reference'] = '';
+ $row['data']['Checked_out'] = '';
+ $row['class'] = array(drupal_html_class('availability_holdings_last_row'));
+ $holdings['holdings']['rows'][] = $row;
+
+ $variables['content']['holdings']['table'] = array(
+ '#theme' => 'table',
+ '#attributes' => $holdings['holdings']['attributes'],
+ '#header' => $holdings['holdings']['header'],
+ '#rows' => $holdings['holdings']['rows'],
+ );
+ }
+ $variables['classes'] = '';
+ $variables['classes_array'] = array();
+ $variables['classes_array'][] = 'ding_availability_holdings';
+}
+
+/**
+ * Theme ding_availability_holdings
+ */
+function theme_ding_availability_holdings(&$variables) {
+ return '' . render($variables['content']) . '
';
+}
+
+/**
+ * Preprocess ding_availability_status
+ */
+function template_preprocess_ding_availability_status(&$variables) {
+ $availability = $variables['availability'];
+ $variables['attributes']['title'] = $availability['status'];
+ if($availability['available']) {
+ $variables['attributes']['class'][] = 'available';
+ }
+ if($availability['reservable']) {
+ $variables['attributes']['class'][] = 'reservable';
+ }
+ if($availability['is_internet']) {
+ $variables['attributes']['class'][] = drupal_html_class('is_internet');
+ }
+ if($availability['is_periodical']) {
+ $variables['attributes']['class'][] = drupal_html_class('is_periodical');
+ }
+ $variables['data'] = t(ucfirst($availability['status']));
+ $variables['classes_array'][] = 'ding_availability_status';
+}
+
+/**
+ * Theme ding_availability_holdings
+ */
+function theme_ding_availability_status(&$variables) {
+ return '' . $variables['data'] . "";
+}
\ No newline at end of file
diff --git a/js/ding_availability.js b/js/ding_availability.js
index 5d8d35e..efbc48e 100644
--- a/js/ding_availability.js
+++ b/js/ding_availability.js
@@ -10,6 +10,39 @@
Drupal.behaviors.dingAvailabilityAttach = {
attach: function(context, settings) {
+ if($('.availability:not(.processed), .holdings:not(.processed)', context).size()) {
+ var $url = settings.basePath + settings.pathPrefix + 'ding_availability/holdings';
+ var element_settings = { 'url': $url, 'event': 'click', 'progress': { 'type': 'throbber' }, 'submit': {} };
+ if($.browser.msie && ($.browser.version == '8.0' || $.browser.version == '7.0')) {
+ element_settings.success = function (response, status) {
+ for (var i in response) {
+ if(response[i].selector) {
+ $(response[i].selector)[response[i].method](response[i].data);
+ if(response[i].selector.indexOf('holdings-') != -1) {
+ var settings = response.settings || Drupal.ajax.settings || Drupal.settings;
+ Drupal.attachBehaviors($(response[i].selector), settings);
+ }
+ }
+ }
+ }
+ }
+
+ var $ids = {};
+ $('.availability:not(.processed)', context).addClass('processed').each(function() {
+ $ids[$(this).attr('id')] = settings.ding_availability[$(this).attr('id')][0];
+ });
+ element_settings.submit.availability = $ids;
+ $ids = {};
+ $('.holdings:not(.processed)', context).addClass('processed').each(function() {
+ $ids[$(this).attr('id')] = settings.ding_availability[$(this).attr('id')][0];
+ });
+ element_settings.submit.holdings = $ids;
+
+ var base = $('.availability.processed:first');
+ Drupal.ajax[base.attr('id')] = new Drupal.ajax(base.attr('id'), base, element_settings);
+ base.trigger('click');
+ }
+ /*return;
var ids = [];
var html_ids = [];
$.each(settings.ding_availability, function(id, entity_ids) {
@@ -76,17 +109,18 @@
}
if (available && reservable) {
- $('#' + id).attr('title', Drupal.t('available'));
+ $('#' + id).attr('title', Drupal.t('Available'));
}
else if (!available && reservable) {
- $('#' + id).attr('title', Drupal.t('on loan'));
+ $('#' + id).attr('title', Drupal.t('On loan'));
}
else if (available && ! reservable) {
- $('#' + id).attr('title', Drupal.t('not reservable'));
+ $('#' + id).attr('title', Drupal.t('Not reservable'));
}
else if (!available && ! reservable) {
- $('#' + id).attr('title', Drupal.t('unavailable'));
+ $('#' + id).attr('title', Drupal.t('Unavailable'));
}
+ $('#' + id).text($('#' + id).attr('title'));
}
function updateHoldings(id, entity_ids) {
@@ -117,9 +151,8 @@
}
}
}
-
+*/
}
};
})(jQuery);
-