From a44840eee833e40175f44966cb36a80de105e398 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Sep 2012 12:21:08 +0200 Subject: [PATCH 01/97] Updated make file to point to ding2tal --- ding_availability.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ding_availability.make b/ding_availability.make index 0720fa8..8a42522 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -3,8 +3,8 @@ core = 7.x 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][tag] = "7.x-0.13" +projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" +projects[ding_provider][download][branch] = "development" projects[blackhole][type] = "module" projects[blackhole][download][type] = "git" From 3fa8af2b2fa0f4d627cc9bf37e9600a347db7765 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Sep 2012 15:10:18 +0200 Subject: [PATCH 02/97] Added formatter settings to enable availability text to link back to ting entity --- ding_availability.field.inc | 61 +++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 5b8672b..6025f4a 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -71,10 +71,63 @@ function ding_availability_field_formatter_info() { 'field types' => array( 'ting_collection_types', ), + 'settings' => array( + 'link' => FALSE, + ), ), ); } + + +/** + * Implements hook_field_formatter_settings_form(). + */ +function ding_availability_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { + // Get display and current (or default) settings. + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + + // Initialize the return element (settings form). + $element = array(); + + switch ($field['type']) { + case 'ting_collection_types': + $element['link'] = array( + '#type' => 'checkbox', + '#title' => t('Links'), + '#description' => t('Convert the availability texts into links.'), + '#default_value' => $settings['link'], + ); + break; + } + + return $element; +} + + + +/** + * Implements hook_field_formatter_settings_summary(). + */ +function ding_availability_field_formatter_settings_summary($field, $instance, $view_mode) { + // Get settings information for the field instance. + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + + $linking = t('false'); + if ($settings['link']) { + $linking = t('true'); + } + + // Check if linking to the object have been selected + $summary = t('Link to ting objects: @link', array( + '@link' => $linking, + )); + + return $summary; +} + /** * Implements hook_field_formatter_view(). */ @@ -91,6 +144,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ drupal_get_path('module', 'ding_availability') . '/css/ding_availability.css' ), ); + switch ($field['type']) { case 'ding_availability_holdings': // Generate an unique id. @@ -106,14 +160,16 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $element[$delta] = array( '#markup' => '
', '#attached' => $attached, - ); - break; + ); + break; + case 'ding_availability_item': $element[$delta] = array( '#markup' => '
', '#attached' => $attached, ); break; + case 'ting_type': // Generate an unique id. $id = drupal_html_id('availability-' . $entity->id); @@ -136,6 +192,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ ), ); break; + case 'ting_collection_types': $id_mapping = array(); $typed_entities = array(); From 2f29bff6f9e8c148737adc052ae7c890cdcc83df Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Sep 2012 15:28:22 +0200 Subject: [PATCH 03/97] Converted availability texts into links back to the entity --- ding_availability.field.inc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 6025f4a..d6aed16 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -204,12 +204,20 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ foreach ($typed_entities as $type => $entities) { // Generate an unique id. $id = drupal_html_id('availability-' . $entity->id . '-' . $type); + + // Convert type into link. + if ($display['settings']['link']) { + $url = entity_uri('ting_object', $entity); + $type = l($type, $url['path'], $url['options']); + } + // Create a list element for each type. $types[] = array( 'data' => $type, 'id' => $id, 'class' => array('availability', drupal_html_class($type)), ); + // Map the HTML id to the list of entity ids. $id_mapping[$id] = $entities; } @@ -227,5 +235,6 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ break; } } + return $element; } From fc9681440573134302d64a89a648a8afd63499c0 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Sep 2012 15:57:20 +0200 Subject: [PATCH 04/97] Append availability status to links in the javascript --- ding_availability.field.inc | 1 + js/ding_availability.js | 45 ++++++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index d6aed16..6bbea95 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -225,6 +225,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $attached['js'][1] = array( 'data' => array( 'ding_availability' => $id_mapping, + 'ding_availability_link' => $display['settings']['link'], ), 'type' => 'setting'); $element[$delta] = array( diff --git a/js/ding_availability.js b/js/ding_availability.js index 5d8d35e..174a365 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -65,40 +65,55 @@ } }); - $('#' + id).removeClass('pending'); - $('#' + id).addClass('processed'); + var element = $('#' + id); + element.removeClass('pending').addClass('processed'); if (available) { - $('#' + id).addClass('available'); + element.addClass('available'); } if (reservable) { - $('#' + id).addClass('reservable'); + element.addClass('reservable'); } if (available && reservable) { - $('#' + id).attr('title', Drupal.t('available')); + element.attr('title', Drupal.t('available')); + // If availability is an link extrend information. + if (settings.ding_availability_link === 1) { + $('a', element).append('' + Drupal.t('available') + ''); + } } else if (!available && reservable) { - $('#' + id).attr('title', Drupal.t('on loan')); - } + element.attr('title', Drupal.t('on loan')); + // If availability is an link extrend information. + if (settings.ding_availability_link === 1) { + $('a', element).append('' + Drupal.t('on loan') + ''); + } } else if (available && ! reservable) { - $('#' + id).attr('title', Drupal.t('not reservable')); + element.attr('title', Drupal.t('not reservable')); + // If availability is an link extrend information. + if (settings.ding_availability_link === 1) { + $('a', element).append('' + Drupal.t('not reservable') + ''); + } } else if (!available && ! reservable) { - $('#' + id).attr('title', Drupal.t('unavailable')); + element.attr('title', Drupal.t('unavailable')); + // If availability is an link extrend information. + if (settings.ding_availability_link === 1) { + $('a', element).append('' + Drupal.t('unavailable') + ''); + } } } function updateHoldings(id, entity_ids) { var entity_id = entity_ids.pop(); - if (Drupal.DADB[entity_id] && (Drupal.DADB[entity_id]['holdings'] || Drupal.DADB[entity_id]['holdings_available'])) { + if (Drupal.DADB[entity_id] && (Drupal.DADB[entity_id]['holdings'] || Drupal.DADB[entity_id]['holdings_available'])) { var holdings; - var length; + var length; // Use holdings_available, if set and entity is not a periodical. if (Drupal.DADB[entity_id]['holdings_available'] && !Drupal.DADB[entity_id]['is_periodical'] ) { - holdings = Drupal.DADB[entity_id]['holdings_available']; - length = holdings.length; + holdings = Drupal.DADB[entity_id]['holdings_available']; + length = holdings.length; } else { holdings = Drupal.DADB[entity_id]['holdings']; @@ -106,7 +121,7 @@ length = Object.keys(holdings).length; } - + if (length > 0) { $('#' + id).append('

' + Drupal.t('Holdings available on the shelf') + '

'); $('#' + id).append('
    '); @@ -117,9 +132,7 @@ } } } - } }; - })(jQuery); From 2bc51aa1526d19c70ebbab3548aa1eaa62ab1c54 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 4 Sep 2012 13:15:57 +0200 Subject: [PATCH 05/97] Fix un-defined index in formatter settings summary --- ding_availability.field.inc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 6bbea95..8c00dbd 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -115,15 +115,17 @@ function ding_availability_field_formatter_settings_summary($field, $instance, $ $display = $instance['display'][$view_mode]; $settings = $display['settings']; - $linking = t('false'); - if ($settings['link']) { - $linking = t('true'); - } + if ($field['type'] == 'ting_collection_types') { + $linking = t('false'); + if ($settings['link']) { + $linking = t('true'); + } - // Check if linking to the object have been selected - $summary = t('Link to ting objects: @link', array( - '@link' => $linking, - )); + // Check if linking to the object have been selected + $summary = t('Link to ting objects: @link', array( + '@link' => $linking, + )); + } return $summary; } From df5aa50332a52d85f5fe9e468c3aa3e91b23f941 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 4 Sep 2012 13:18:33 +0200 Subject: [PATCH 06/97] Fixed un-initialized error in summary information --- ding_availability.field.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 8c00dbd..0b2d460 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -114,6 +114,7 @@ function ding_availability_field_formatter_settings_summary($field, $instance, $ // Get settings information for the field instance. $display = $instance['display'][$view_mode]; $settings = $display['settings']; + $summary = NULL; if ($field['type'] == 'ting_collection_types') { $linking = t('false'); From aae0b77f8b4aaa2393523946a3c8ae65ef27a8f7 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 18 Oct 2012 14:18:31 +0200 Subject: [PATCH 07/97] Changed blackhold to be fetch from d.o --- ding_availability.make | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ding_availability.make b/ding_availability.make index 8a42522..3c71dfd 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -6,6 +6,5 @@ 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[blackhole][type] = "module" -projects[blackhole][download][type] = "git" -projects[blackhole][download][url] = "git@github.com:xendk/blackhole.git" +projects[blackhole][subdir] = contrib +projects[blackhole][version] = "1.1" From 3bea2c81ad5fcc1a52bbb08d9a94f04a9a741e30 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 14 Nov 2012 13:07:39 +0100 Subject: [PATCH 08/97] Updated codeing style to match Drupal --- ding_availability.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.module b/ding_availability.module index 90e5f3e..c01daa9 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -159,7 +159,7 @@ function ding_availability_render_legend() { // render image html using theme_image (returns NULL if file doesn't exist) foreach ( $availability_legend as $key => $val ) { $format_label = '' . $val . ''; - $format_image = theme('image', array('path'=>$image_path, 'alt'=>$val, 'title'=>$val)); + $format_image = theme('image', array('path' => $image_path, 'alt' => $val, 'title' => $val)); $format_items[] = '
    ' . $format_image . $format_label . '
    '; }; $format_items[] = '
    '; From 6b4ede71d3be7d13bab3292e2540e3d82a6dfd2b Mon Sep 17 00:00:00 2001 From: Arni Date: Tue, 18 Dec 2012 14:25:57 +0100 Subject: [PATCH 09/97] fixes link to same object bug --- ding_availability.field.inc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 0b2d460..390dce5 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -201,17 +201,24 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $typed_entities = array(); // Sort entities into type -> ids. foreach ($entity->entities as $ent) { - $typed_entities[$ent->type][] = $ent->localId; + $typed_entities[$ent->type][] = $ent; } foreach ($typed_entities as $type => $entities) { // Generate an unique id. - $id = drupal_html_id('availability-' . $entity->id . '-' . $type); + $id = drupal_html_id('availability-' . $entities[0]->id . '-' . $type); // Convert type into link. if ($display['settings']['link']) { - $url = entity_uri('ting_object', $entity); + // If there is only 1 object there is a direct link + // else there is a link to the collection. + if (count($entities) == 1) { + $url = entity_uri('ting_object', $entities[0]); + } else { + $url = entity_uri('ting_collection', $entities[0]); + } $type = l($type, $url['path'], $url['options']); + } // Create a list element for each type. @@ -221,8 +228,12 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ 'class' => array('availability', drupal_html_class($type)), ); + $ids = array(); + foreach ($entities as $object_entity) { + $ids[] = $object_entity->localId; + } // Map the HTML id to the list of entity ids. - $id_mapping[$id] = $entities; + $id_mapping[$id] = $ids; } $attached['js'][1] = array( From 0665a3748f4a32b224dfe0d52726e3df6d4c50fa Mon Sep 17 00:00:00 2001 From: wiredloose Date: Thu, 31 Jan 2013 13:48:00 +0100 Subject: [PATCH 10/97] makes unavailable and not-reservable show up as classes as support for styling --- js/ding_availability.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js/ding_availability.js b/js/ding_availability.js index 174a365..8bce894 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -70,10 +70,17 @@ if (available) { element.addClass('available'); + } + else { + element.addClass('unavailable'); } + if (reservable) { element.addClass('reservable'); } + else { + element.addClass('not-reservable'); + } if (available && reservable) { element.attr('title', Drupal.t('available')); From 60f4f3993b1fb0d588a138d5d3b62eab88a3afb6 Mon Sep 17 00:00:00 2001 From: wiredloose Date: Thu, 31 Jan 2013 13:50:26 +0100 Subject: [PATCH 11/97] overwrite holding data, always marking internet resources as available --- ding_availability.module | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ding_availability.module b/ding_availability.module index c01daa9..e633133 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -68,6 +68,12 @@ function ding_availability_items($provider_ids) { 'reservable' => FALSE, 'available' => FALSE, ); + + //marks internet resources as available + if ($item['is_internet']) { + $item['available'] = TRUE; + } + _ding_availability_text($item); } } @@ -92,6 +98,12 @@ function ding_availability_holdings($provider_ids) { 'available' => FALSE, 'holdings' => array(), ); + + //marks internet resources as available + if ($item['is_internet']) { + $item['available'] = TRUE; + } + _ding_availability_text($item); } @@ -102,7 +114,7 @@ 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 ($item['available'] && $item['reservable'] || $item['is_internet']) { $item['status'] = t('available'); } elseif (!$item['available'] && $item['reservable']) { From 00b3b0bd4e315bee0fd02dd85703dae0a95260b0 Mon Sep 17 00:00:00 2001 From: wiredloose Date: Thu, 31 Jan 2013 13:51:39 +0100 Subject: [PATCH 12/97] "processed" styling gets same color as "pending" - to no longer hold the meaning of "unavailable" --- css/ding_availability.css | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/css/ding_availability.css b/css/ding_availability.css index c85cd49..7728c74 100644 --- a/css/ding_availability.css +++ b/css/ding_availability.css @@ -1,14 +1,8 @@ -.pending { +.pending, .availability.processed { color: #696a69; } -/* Not available or reservable */ -/* Note: This applies to online resources as well. However, it's possible to style these, based on material type */ -.availability.processed { - color: #ed1e88; -} - .availability.available { color: #0072bc; } From fe4e0e6ae0aa2064600c13d810c8c9af2b1243dc Mon Sep 17 00:00:00 2001 From: wiredloose Date: Thu, 31 Jan 2013 13:52:12 +0100 Subject: [PATCH 13/97] Nicer formatting of comments :-) --- ding_availability.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ding_availability.module b/ding_availability.module index e633133..6bb2e27 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -69,7 +69,7 @@ function ding_availability_items($provider_ids) { 'available' => FALSE, ); - //marks internet resources as available + // Marks internet resources as available. if ($item['is_internet']) { $item['available'] = TRUE; } @@ -99,7 +99,7 @@ function ding_availability_holdings($provider_ids) { 'holdings' => array(), ); - //marks internet resources as available + // Marks internet resources as available. if ($item['is_internet']) { $item['available'] = TRUE; } From 1e9c030588b531c146824f821102b3efa390034b Mon Sep 17 00:00:00 2001 From: wiredloose Date: Thu, 31 Jan 2013 14:18:59 +0100 Subject: [PATCH 14/97] sets the title tag of links to "available" when it is an internet resource --- js/ding_availability.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/ding_availability.js b/js/ding_availability.js index 8bce894..5aa5174 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -58,10 +58,12 @@ function updateAvailability(id, entity_ids) { var available = false; var reservable = false; + var is_internet = false; $.each(entity_ids, function(index, entity_id) { if (Drupal.DADB[entity_id]) { available = available || Drupal.DADB[entity_id]['available']; reservable = reservable || Drupal.DADB[entity_id]['reservable']; + is_internet = is_internet || Drupal.DADB[entity_id]['is_internet']; } }); @@ -82,7 +84,7 @@ element.addClass('not-reservable'); } - if (available && reservable) { + if (available && reservable || is_internet) { element.attr('title', Drupal.t('available')); // If availability is an link extrend information. if (settings.ding_availability_link === 1) { From d04b35ba7a6ccc752c6cd8ce335a4ee04d6208dd Mon Sep 17 00:00:00 2001 From: wiredloose Date: Mon, 4 Feb 2013 23:11:53 +0100 Subject: [PATCH 15/97] online types now display status of available + not-reservable, and no longer try to fetch holding data from the library system via ajax calls --- ding_availability.field.inc | 81 ++++++++++++++++++++++++++----------- js/ding_availability.js | 4 +- 2 files changed, 59 insertions(+), 26 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 390dce5..a098f69 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -136,6 +136,16 @@ function ding_availability_field_formatter_settings_summary($field, $instance, $ */ function ding_availability_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); + /* + * @todo move $online_types to configuration + */ + $online_types = array( + 'avis (net)', 'film (net)', 'lydbog (net)', 'musik (net)', 'ebog', 'periodikum (net)', 'pc-spil (net)', + 'tidsskrift (net)', 'netdokument', 'avis (net)', + 'lydbog (online)', 'netmusik (album)' /* Included to ensure backwards compatability with DKABM 1.x */ + ); + + foreach ($items as $delta => $item) { $attached = array( 'js' => array( @@ -152,14 +162,21 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ case 'ding_availability_holdings': // Generate an unique id. $id = drupal_html_id('holdings-' . $entity->id); - $attached['js'][1] = array( - 'data' => array( - 'ding_availability_mode' => 'holdings', - 'ding_availability' => array( - $id => array($entity->localId), - ), - ), 'type' => 'setting'); + // Mark as available (and 'not-reservable') if it is an online resource + $available_online = (in_array(drupal_strtolower($entity->type), $online_types)) ? 'available not-reservable' :''; + + // If it is not available online, prepare to check holding on the item + if (!$available_online) { + $attached['js'][1] = array( + 'data' => array( + 'ding_availability_mode' => 'holdings', + 'ding_availability' => array( + $id => array($entity->localId), + ), + ), 'type' => 'setting'); + } + $element[$delta] = array( '#markup' => '
    ', '#attached' => $attached, @@ -176,13 +193,20 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ case 'ting_type': // Generate an unique id. $id = drupal_html_id('availability-' . $entity->id); - $attached['js'][1] = array( - 'data' => array( - 'ding_availability' => array( - $id => array($entity->localId), - ), - ), 'type' => 'setting'); + + // Mark as available (and 'not-reservable') if it is an online resource + $available_online = (in_array(drupal_strtolower($entity->type), $online_types)) ? 'available not-reservable' :''; + // If it is not available online, prepare to check holding on the item + if (!$available_online) { + $attached['js'][1] = array( + 'data' => array( + 'ding_availability' => array( + $id => array($entity->localId), + ), + ), 'type' => 'setting'); + } + $element[$delta] = array( '#theme' => 'item_list', '#attached' => $attached, @@ -190,7 +214,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ array( 'data' => $entity->type, 'id' => $id, - 'class' => array('availability', drupal_html_class($entity->type)), + 'class' => array('availability', drupal_html_class($entity->type), $available_online), ) ), ); @@ -208,6 +232,9 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Generate an unique id. $id = drupal_html_id('availability-' . $entities[0]->id . '-' . $type); + $available_online = (in_array(drupal_strtolower($type), $online_types)) ? 'available not-reservable' : ''; + $available_online_label = ($available_online) ? '' . t('not reservable') . '' : ''; + // Convert type into link. if ($display['settings']['link']) { // If there is only 1 object there is a direct link @@ -223,25 +250,31 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Create a list element for each type. $types[] = array( - 'data' => $type, + 'data' => $type . $available_online_label, 'id' => $id, - 'class' => array('availability', drupal_html_class($type)), + 'class' => array('availability', drupal_html_class($type), $available_online), ); $ids = array(); foreach ($entities as $object_entity) { $ids[] = $object_entity->localId; } - // Map the HTML id to the list of entity ids. - $id_mapping[$id] = $ids; + + // If it is not available online, map the HTML id to the list of entity ids. + if (!$available_online) { + $id_mapping[$id] = $ids; + } } - $attached['js'][1] = array( - 'data' => array( - 'ding_availability' => $id_mapping, - 'ding_availability_link' => $display['settings']['link'], - ), 'type' => 'setting'); - + // Prepare to check holding on the item as long as $id_mapping holds at least 1 id + if (count($id_mapping) > 0) { + $attached['js'][1] = array( + 'data' => array( + 'ding_availability' => $id_mapping, + 'ding_availability_link' => $display['settings']['link'], + ), 'type' => 'setting'); + } + $element[$delta] = array( '#theme' => 'item_list', '#attached' => $attached, diff --git a/js/ding_availability.js b/js/ding_availability.js index 5aa5174..ca4dc77 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -22,7 +22,7 @@ }); }); - $.each(html_ids, function(index, id) { + $.each(html_ids, function(index, id) { $('#' + id).addClass('pending'); }); @@ -81,7 +81,7 @@ element.addClass('reservable'); } else { - element.addClass('not-reservable'); + element.addClass('not-reservable'); } if (available && reservable || is_internet) { From b673185c83276ccb970da22dd165a7a301d71d8f Mon Sep 17 00:00:00 2001 From: wiredloose Date: Tue, 5 Feb 2013 06:55:15 +0100 Subject: [PATCH 16/97] Online types are now looked up in Ting settings. This depends on Ting module commit, see https://github.com/ding2tal/ting/commit/9d31c46b7baa1739d53f7c9da71f5af2e1564cc0 --- ding_availability.field.inc | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index a098f69..a2785e8 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -136,15 +136,8 @@ function ding_availability_field_formatter_settings_summary($field, $instance, $ */ function ding_availability_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); - /* - * @todo move $online_types to configuration - */ - $online_types = array( - 'avis (net)', 'film (net)', 'lydbog (net)', 'musik (net)', 'ebog', 'periodikum (net)', 'pc-spil (net)', - 'tidsskrift (net)', 'netdokument', 'avis (net)', - 'lydbog (online)', 'netmusik (album)' /* Included to ensure backwards compatability with DKABM 1.x */ - ); + $online_types = variable_get('ting_online_types', _ting_default_online_types()); foreach ($items as $delta => $item) { $attached = array( From 8949701f49dd771cf3240e1236f54a2ac5bead4e Mon Sep 17 00:00:00 2001 From: wiredloose Date: Tue, 5 Feb 2013 09:45:38 +0100 Subject: [PATCH 17/97] including the availability-status tag inside the clickable link, and making class names on the availability label list items sane again --- ding_availability.field.inc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index a2785e8..6e56ddb 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -237,13 +237,14 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ } else { $url = entity_uri('ting_collection', $entities[0]); } - $type = l($type, $url['path'], $url['options']); + $url['options']['html'] = TRUE; + $typelink = l(check_plain($type) . $available_online_label, $url['path'], $url['options']); } - // Create a list element for each type. + // Create a list element for each type. $types[] = array( - 'data' => $type . $available_online_label, + 'data' => $typelink, 'id' => $id, 'class' => array('availability', drupal_html_class($type), $available_online), ); From f99033309a7a7f56e65834c1ef92601a7e8e9be2 Mon Sep 17 00:00:00 2001 From: wiredloose Date: Tue, 5 Feb 2013 11:18:20 +0100 Subject: [PATCH 18/97] restricts ajax calls for holding data only for records that are of the source "library materials" ("Bibliotekets materialer"). Also add class name 'pending' on all type labels to activate some basic styling. --- ding_availability.field.inc | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 6e56ddb..b3a1653 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -136,8 +136,8 @@ function ding_availability_field_formatter_settings_summary($field, $instance, $ */ function ding_availability_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); - $online_types = variable_get('ting_online_types', _ting_default_online_types()); + $lib_materials_type = 'bibliotekets materialer'; foreach ($items as $delta => $item) { $attached = array( @@ -156,11 +156,14 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Generate an unique id. $id = drupal_html_id('holdings-' . $entity->id); + // Extract records' source + $ac_source = reset($entity->reply->record['ac:source']); // Read ac:source with $ac_source[0] + // Mark as available (and 'not-reservable') if it is an online resource $available_online = (in_array(drupal_strtolower($entity->type), $online_types)) ? 'available not-reservable' :''; - // If it is not available online, prepare to check holding on the item - if (!$available_online) { + // If item is of type 'library materials' (where we can lookup holding data), prepare to check holding on the item + if (drupal_strtolower($ac_source[0]) == $lib_materials_type) { $attached['js'][1] = array( 'data' => array( 'ding_availability_mode' => 'holdings', @@ -187,11 +190,14 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Generate an unique id. $id = drupal_html_id('availability-' . $entity->id); + // Extract records' source + $ac_source = reset($entity->reply->record['ac:source']); // Read ac:source with $ac_source[0] + // Mark as available (and 'not-reservable') if it is an online resource $available_online = (in_array(drupal_strtolower($entity->type), $online_types)) ? 'available not-reservable' :''; - // If it is not available online, prepare to check holding on the item - if (!$available_online) { + // If item is of type 'library materials' (where we can lookup holding data), prepare to check holding on the item + if (drupal_strtolower($ac_source[0]) == $lib_materials_type) { $attached['js'][1] = array( 'data' => array( 'ding_availability' => array( @@ -207,7 +213,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ array( 'data' => $entity->type, 'id' => $id, - 'class' => array('availability', drupal_html_class($entity->type), $available_online), + 'class' => array('availability', drupal_html_class($entity->type), $available_online, 'pending'), ) ), ); @@ -224,7 +230,10 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ foreach ($typed_entities as $type => $entities) { // Generate an unique id. $id = drupal_html_id('availability-' . $entities[0]->id . '-' . $type); - + + // Extract records' source + $ac_source = reset($entities[0]->reply->record['ac:source']); // Read ac:source with $ac_source[0] + $available_online = (in_array(drupal_strtolower($type), $online_types)) ? 'available not-reservable' : ''; $available_online_label = ($available_online) ? '' . t('not reservable') . '' : ''; @@ -246,7 +255,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $types[] = array( 'data' => $typelink, 'id' => $id, - 'class' => array('availability', drupal_html_class($type), $available_online), + 'class' => array('availability', drupal_html_class($type), $available_online, 'pending'), ); $ids = array(); @@ -254,8 +263,8 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $ids[] = $object_entity->localId; } - // If it is not available online, map the HTML id to the list of entity ids. - if (!$available_online) { + // If item is of type 'library materials' (where we can lookup holding data), map the HTML id to the list of entity ids. + if (drupal_strtolower($ac_source[0]) == $lib_materials_type) { $id_mapping[$id] = $ids; } } From 7f2c88af0ad64e5d9c103209c88c90c453246597 Mon Sep 17 00:00:00 2001 From: wiredloose Date: Mon, 11 Feb 2013 10:59:47 +0100 Subject: [PATCH 19/97] tightening up test for looking up holding data --- ding_availability.field.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index b3a1653..48ff118 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -138,7 +138,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $element = array(); $online_types = variable_get('ting_online_types', _ting_default_online_types()); $lib_materials_type = 'bibliotekets materialer'; - + foreach ($items as $delta => $item) { $attached = array( 'js' => array( @@ -264,7 +264,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ } // If item is of type 'library materials' (where we can lookup holding data), map the HTML id to the list of entity ids. - if (drupal_strtolower($ac_source[0]) == $lib_materials_type) { + if (drupal_strtolower($ac_source[0]) == $lib_materials_type && !$available_online) { $id_mapping[$id] = $ids; } } From 693baa0bff3be856ce85d0dbe34d2d332167387b Mon Sep 17 00:00:00 2001 From: Rasmus Frey Date: Mon, 11 Mar 2013 10:50:37 +0100 Subject: [PATCH 20/97] Fixed a bug where javascript would fail when only display online elements, no setings object was created. --- ding_availability.field.inc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 48ff118..a3a6593 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -269,15 +269,15 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ } } - // Prepare to check holding on the item as long as $id_mapping holds at least 1 id - if (count($id_mapping) > 0) { - $attached['js'][1] = array( - 'data' => array( - 'ding_availability' => $id_mapping, - 'ding_availability_link' => $display['settings']['link'], - ), 'type' => 'setting'); - } - + // Prepare to check holding on the item. + // It's importants that this is attached even if empty, else javascript will fail beacuse it gets an empty object. + $attached['js'][1] = array( + 'data' => array( + 'ding_availability' => $id_mapping, + 'ding_availability_link' => $display['settings']['link'], + ), 'type' => 'setting' + ); + $element[$delta] = array( '#theme' => 'item_list', '#attached' => $attached, From da56edc98a4f7c4560f459082b632b3285f0f6ce Mon Sep 17 00:00:00 2001 From: Rasmus Frey Date: Mon, 11 Mar 2013 11:12:59 +0100 Subject: [PATCH 21/97] Some more related to previous commit, fixing bug where js would fail because of missing settings object --- ding_availability.field.inc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index a3a6593..b6e4a40 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -171,7 +171,12 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $id => array($entity->localId), ), ), 'type' => 'setting'); - } + } else { //We still need the settings js, else js will fail and break. + $attached['js'][1] = array( + 'data' => array( + 'ding_availability' => '' + ), 'type' => 'setting'); + } $element[$delta] = array( '#markup' => '
    ', @@ -204,6 +209,11 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $id => array($entity->localId), ), ), 'type' => 'setting'); + } else { //We still need the settings js, else js will fail and break. + $attached['js'][1] = array( + 'data' => array( + 'ding_availability' => '' + ), 'type' => 'setting'); } $element[$delta] = array( From 8214e1ce9da26b415519c7263499cb9792e30a0c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 21 Mar 2013 20:30:23 +0100 Subject: [PATCH 22/97] Code style clean up and logic clean up in data sent --- ding_availability.field.inc | 82 ++++++++++++++++--------------------- js/ding_availability.js | 24 ++++++----- 2 files changed, 50 insertions(+), 56 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index b6e4a40..5b5281a 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -137,47 +137,40 @@ function ding_availability_field_formatter_settings_summary($field, $instance, $ function ding_availability_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); $online_types = variable_get('ting_online_types', _ting_default_online_types()); - $lib_materials_type = 'bibliotekets materialer'; + $lib_materials_type = 'Bibliotekets materialer'; + // Attach front-end syle and JS to the element. foreach ($items as $delta => $item) { $attached = array( 'js' => array( - drupal_get_path('module', 'ding_availability') . '/js/ding_availability.js' => array( - 'type' => 'file', - ), + drupal_get_path('module', 'ding_availability') . '/js/ding_availability.js', ), 'css' => array( drupal_get_path('module', 'ding_availability') . '/css/ding_availability.css' ), ); + // Extract records' source + $ac_source = $entity->reply->record['ac:source'][''][0]; + switch ($field['type']) { case 'ding_availability_holdings': // Generate an unique id. $id = drupal_html_id('holdings-' . $entity->id); - // Extract records' source - $ac_source = reset($entity->reply->record['ac:source']); // Read ac:source with $ac_source[0] - - // Mark as available (and 'not-reservable') if it is an online resource - $available_online = (in_array(drupal_strtolower($entity->type), $online_types)) ? 'available not-reservable' :''; - // If item is of type 'library materials' (where we can lookup holding data), prepare to check holding on the item - if (drupal_strtolower($ac_source[0]) == $lib_materials_type) { - $attached['js'][1] = array( + if ($ac_source == $lib_materials_type) { + $attached['js'][] = array( 'data' => array( 'ding_availability_mode' => 'holdings', 'ding_availability' => array( $id => array($entity->localId), ), - ), 'type' => 'setting'); - } else { //We still need the settings js, else js will fail and break. - $attached['js'][1] = array( - 'data' => array( - 'ding_availability' => '' - ), 'type' => 'setting'); + ), + 'type' => 'setting' + ); } - + $element[$delta] = array( '#markup' => '
    ', '#attached' => $attached, @@ -194,28 +187,22 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ case 'ting_type': // Generate an unique id. $id = drupal_html_id('availability-' . $entity->id); - - // Extract records' source - $ac_source = reset($entity->reply->record['ac:source']); // Read ac:source with $ac_source[0] - + // Mark as available (and 'not-reservable') if it is an online resource - $available_online = (in_array(drupal_strtolower($entity->type), $online_types)) ? 'available not-reservable' :''; + $available_online = (in_array(drupal_strtolower($entity->type), $online_types)) ? 'available not-reservable' : 'not-available-online'; // If item is of type 'library materials' (where we can lookup holding data), prepare to check holding on the item - if (drupal_strtolower($ac_source[0]) == $lib_materials_type) { + if ($ac_source == $lib_materials_type) { $attached['js'][1] = array( 'data' => array( 'ding_availability' => array( $id => array($entity->localId), ), - ), 'type' => 'setting'); - } else { //We still need the settings js, else js will fail and break. - $attached['js'][1] = array( - 'data' => array( - 'ding_availability' => '' - ), 'type' => 'setting'); + ), + 'type' => 'setting' + ); } - + $element[$delta] = array( '#theme' => 'item_list', '#attached' => $attached, @@ -223,7 +210,12 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ array( 'data' => $entity->type, 'id' => $id, - 'class' => array('availability', drupal_html_class($entity->type), $available_online, 'pending'), + 'class' => array( + 'availability', + drupal_html_class($entity->type), + $available_online, + 'pending' + ), ) ), ); @@ -240,28 +232,26 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ foreach ($typed_entities as $type => $entities) { // Generate an unique id. $id = drupal_html_id('availability-' . $entities[0]->id . '-' . $type); - - // Extract records' source - $ac_source = reset($entities[0]->reply->record['ac:source']); // Read ac:source with $ac_source[0] - + $available_online = (in_array(drupal_strtolower($type), $online_types)) ? 'available not-reservable' : ''; - $available_online_label = ($available_online) ? '' . t('not reservable') . '' : ''; - + $available_online_label = ($available_online) ? '' . t('not reservable') . '' : 'not-available-online'; + // Convert type into link. if ($display['settings']['link']) { - // If there is only 1 object there is a direct link + // If there is only 1 object there is a direct link // else there is a link to the collection. if (count($entities) == 1) { $url = entity_uri('ting_object', $entities[0]); - } else { + } + else { $url = entity_uri('ting_collection', $entities[0]); } $url['options']['html'] = TRUE; $typelink = l(check_plain($type) . $available_online_label, $url['path'], $url['options']); - + } - // Create a list element for each type. + // Create a list element for each type. $types[] = array( 'data' => $typelink, 'id' => $id, @@ -272,9 +262,9 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ foreach ($entities as $object_entity) { $ids[] = $object_entity->localId; } - + // If item is of type 'library materials' (where we can lookup holding data), map the HTML id to the list of entity ids. - if (drupal_strtolower($ac_source[0]) == $lib_materials_type && !$available_online) { + if ($ac_source == $lib_materials_type && !$available_online) { $id_mapping[$id] = $ids; } } @@ -287,7 +277,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ 'ding_availability_link' => $display['settings']['link'], ), 'type' => 'setting' ); - + $element[$delta] = array( '#theme' => 'item_list', '#attached' => $attached, diff --git a/js/ding_availability.js b/js/ding_availability.js index ca4dc77..c1c80ca 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -12,15 +12,19 @@ attach: function(context, settings) { var ids = []; var html_ids = []; - $.each(settings.ding_availability, function(id, entity_ids) { - $.each(entity_ids, function(index, entity_id) { - if (Drupal.DADB[entity_id] === undefined) { - Drupal.DADB[entity_id] = null; - ids.push(entity_id); - html_ids.push(id); - } + + // Extract entity ids and add them to the settings array. + if (settings.hasOwnProperty('ding_availability')) { + $.each(settings.ding_availability, function(id, entity_ids) { + $.each(entity_ids, function(index, entity_id) { + if (Drupal.DADB[entity_id] === undefined) { + Drupal.DADB[entity_id] = null; + ids.push(entity_id); + html_ids.push(id); + } + }); }); - }); + } $.each(html_ids, function(index, id) { $('#' + id).addClass('pending'); @@ -72,11 +76,11 @@ if (available) { element.addClass('available'); - } + } else { element.addClass('unavailable'); } - + if (reservable) { element.addClass('reservable'); } From 13baa09ada5e3d966f03ffb8093ba8ebfd8e35f1 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 21 Mar 2013 21:20:59 +0100 Subject: [PATCH 23/97] Stream-lined the code based on the data available in the current providers --- ding_availability.module | 1 + js/ding_availability.js | 29 ++++------------------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/ding_availability.module b/ding_availability.module index 6bb2e27..5b97ae5 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -147,6 +147,7 @@ function ding_availability_block_info() { * Define availability legend block. */ function ding_availability_block_view($delta = '') { + $block = array(); $block['subject'] = t('Ding availability legend'); $block['content'] = ding_availability_render_legend(); return $block; diff --git a/js/ding_availability.js b/js/ding_availability.js index c1c80ca..d10a8da 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -119,33 +119,12 @@ function updateHoldings(id, entity_ids) { var entity_id = entity_ids.pop(); - if (Drupal.DADB[entity_id] && (Drupal.DADB[entity_id]['holdings'] || Drupal.DADB[entity_id]['holdings_available'])) { - var holdings; - var length; - - // Use holdings_available, if set and entity is not a periodical. - if (Drupal.DADB[entity_id]['holdings_available'] && !Drupal.DADB[entity_id]['is_periodical'] ) { - holdings = Drupal.DADB[entity_id]['holdings_available']; - length = holdings.length; - } - else { - holdings = Drupal.DADB[entity_id]['holdings']; - //holdings is an object - not array - length = Object.keys(holdings).length; - } - - - if (length > 0) { - $('#' + id).append('

    ' + Drupal.t('Holdings available on the shelf') + '

    '); - $('#' + id).append('
      '); - var container = $('#' + id + ' ul'); - $.each(holdings, function(i, holding) { - container.append('
    • ' + holding + '
    • '); - }); - } + if (Drupal.DADB[entity_id] && (Drupal.DADB[entity_id]['holdings'])) { + // Show status for material. + $('#' + id).append('

      ' + Drupal.t('Holdings available on the shelf') + '

      '); + $('#' + id).append(Drupal.DADB[entity_id].html) ; } } } }; })(jQuery); - From a217406b086a4d1fe59f77c1db6b67c681aaee45 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 21 Mar 2013 21:51:29 +0100 Subject: [PATCH 24/97] Fixed ac_source for collections --- ding_availability.field.inc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 5b5281a..db023a2 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -151,7 +151,9 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ ); // Extract records' source - $ac_source = $entity->reply->record['ac:source'][''][0]; + if ($field['type'] != 'ting_collection_types') { + $ac_source = $entity->reply->record['ac:source'][''][0]; + } switch ($field['type']) { case 'ding_availability_holdings': @@ -233,6 +235,9 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Generate an unique id. $id = drupal_html_id('availability-' . $entities[0]->id . '-' . $type); + // Extract records' source + $ac_source = $entities[0]->reply->record['ac:source'][''][0]; + $available_online = (in_array(drupal_strtolower($type), $online_types)) ? 'available not-reservable' : ''; $available_online_label = ($available_online) ? '' . t('not reservable') . '' : 'not-available-online'; From ab4ff2294265e213563a9b25a17253321c53cdde Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 21 Mar 2013 21:55:17 +0100 Subject: [PATCH 25/97] Removed not-available-online label --- ding_availability.field.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index db023a2..8d96bb9 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -239,7 +239,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $ac_source = $entities[0]->reply->record['ac:source'][''][0]; $available_online = (in_array(drupal_strtolower($type), $online_types)) ? 'available not-reservable' : ''; - $available_online_label = ($available_online) ? '' . t('not reservable') . '' : 'not-available-online'; + $available_online_label = ($available_online) ? '' . t('not reservable') . '' : ''; // Convert type into link. if ($display['settings']['link']) { From b9ab8ad63a58d8fc8efb1cfcd88e1c0d5737999d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 22 Mar 2013 14:33:42 +0100 Subject: [PATCH 26/97] Changed blackhold to virtual field --- ding_availability.info | 2 +- ding_availability.install | 15 ++++++++++++++- ding_availability.make | 9 +++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ding_availability.info b/ding_availability.info index 26c04e2..df1f3ce 100644 --- a/ding_availability.info +++ b/ding_availability.info @@ -5,4 +5,4 @@ version = "7.x-0.14" core = 7.x files[] = ding_availability.module dependencies[] = ding_provider -dependencies[] = blackhole +dependencies[] = virtual_field diff --git a/ding_availability.install b/ding_availability.install index e270bfd..a19876b 100644 --- a/ding_availability.install +++ b/ding_availability.install @@ -14,7 +14,7 @@ function ding_availability_ding_entity_fields() { 'field' => array( 'locked' => TRUE, 'storage' => array( - 'type' => 'blackhole', + 'type' => 'virtual_field', ), ), 'instance' => array( @@ -23,3 +23,16 @@ function ding_availability_ding_entity_fields() { ), ); } + +/** + * Convert blackhole field storage to virtual field. + */ +function ding_availability_update_7000() { + return db_update('field_config') + ->fields(array( + 'storage_type' => 'virtual_field', + 'storage_module' => 'virtual_field', + )) + ->condition('module', 'ding_availability') + ->execute(); +} diff --git a/ding_availability.make b/ding_availability.make index 3c71dfd..fe173ae 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -1,10 +1,15 @@ api = 2 core = 7.x +; contrib + +projects[virtual_field][subdir] = contrib +projects[virtual_field][version] = "1.1" + +; Ding2 + 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[blackhole][subdir] = contrib -projects[blackhole][version] = "1.1" From b59e3cf37b431ed1eea6b30cb2971870c7507fa9 Mon Sep 17 00:00:00 2001 From: wiredloose Date: Fri, 5 Apr 2013 12:52:20 +0200 Subject: [PATCH 27/97] Removed class of "not-reservable" from label on online resources --- ding_availability.field.inc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 8d96bb9..1ce5847 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -190,8 +190,8 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Generate an unique id. $id = drupal_html_id('availability-' . $entity->id); - // Mark as available (and 'not-reservable') if it is an online resource - $available_online = (in_array(drupal_strtolower($entity->type), $online_types)) ? 'available not-reservable' : 'not-available-online'; + // Mark as available if it is an online resource + $available_online = (in_array(drupal_strtolower($entity->type), $online_types)) ? 'available' : 'not-available-online'; // If item is of type 'library materials' (where we can lookup holding data), prepare to check holding on the item if ($ac_source == $lib_materials_type) { @@ -238,8 +238,9 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Extract records' source $ac_source = $entities[0]->reply->record['ac:source'][''][0]; - $available_online = (in_array(drupal_strtolower($type), $online_types)) ? 'available not-reservable' : ''; - $available_online_label = ($available_online) ? '' . t('not reservable') . '' : ''; + // Mark as available if it is an online resource + $available_online = (in_array(drupal_strtolower($type), $online_types)) ? 'available' : ''; + $available_online_label = ($available_online) ? '' . t('online') . '' : ''; // Convert type into link. if ($display['settings']['link']) { From 5ff264b393c6fa93cdeb603ef33fca7092914ef1 Mon Sep 17 00:00:00 2001 From: wiredloose Date: Fri, 5 Apr 2013 13:17:22 +0200 Subject: [PATCH 28/97] Making available + not-reservable a label color distinct from available --- css/ding_availability.css | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/css/ding_availability.css b/css/ding_availability.css index 7728c74..c8a390a 100644 --- a/css/ding_availability.css +++ b/css/ding_availability.css @@ -3,16 +3,18 @@ color: #696a69; } -.availability.available { - color: #0072bc; -} - .availability.reservable { color: #ea9123; } /* Available and reservable */ +.availability.available, .availability.available.reservable { color: #4c9f45; } +/* Available, but not reservable */ +.availability.available.not-reservable { + color: #0072bc; +} + From 92327a5c3b44571da3c95be58dea51180e7ead8d Mon Sep 17 00:00:00 2001 From: Rasmus Frey Date: Fri, 19 Apr 2013 13:54:38 +0200 Subject: [PATCH 29/97] Removed js inserted heading --- js/ding_availability.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/ding_availability.js b/js/ding_availability.js index d10a8da..70e6cfa 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -121,7 +121,6 @@ var entity_id = entity_ids.pop(); if (Drupal.DADB[entity_id] && (Drupal.DADB[entity_id]['holdings'])) { // Show status for material. - $('#' + id).append('

      ' + Drupal.t('Holdings available on the shelf') + '

      '); $('#' + id).append(Drupal.DADB[entity_id].html) ; } } From 7636f26f7cf98fe7b3607ad9952e30d7ff30fdcd Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 22 Apr 2013 19:29:00 +0200 Subject: [PATCH 30/97] Added missing "" to match the other make files --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index fe173ae..9439b26 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -3,7 +3,7 @@ core = 7.x ; contrib -projects[virtual_field][subdir] = contrib +projects[virtual_field][subdir] = "contrib" projects[virtual_field][version] = "1.1" ; Ding2 From 2bbf139236f4b5a44310b84bebb6ca67cb9777a2 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 24 Apr 2013 12:43:01 +0200 Subject: [PATCH 31/97] Added "Bibliotekskatalog" to availability types to prepare for the 3.x of the datawell --- ding_availability.field.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 1ce5847..68a3e57 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -137,7 +137,7 @@ function ding_availability_field_formatter_settings_summary($field, $instance, $ function ding_availability_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); $online_types = variable_get('ting_online_types', _ting_default_online_types()); - $lib_materials_type = 'Bibliotekets materialer'; + $lib_materials_types = array('Bibliotekets materialer', 'Bibliotekskatalog'); // Attach front-end syle and JS to the element. foreach ($items as $delta => $item) { @@ -161,7 +161,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $id = drupal_html_id('holdings-' . $entity->id); // If item is of type 'library materials' (where we can lookup holding data), prepare to check holding on the item - if ($ac_source == $lib_materials_type) { + if (in_array($ac_source, $lib_materials_types)) { $attached['js'][] = array( 'data' => array( 'ding_availability_mode' => 'holdings', @@ -194,7 +194,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $available_online = (in_array(drupal_strtolower($entity->type), $online_types)) ? 'available' : 'not-available-online'; // If item is of type 'library materials' (where we can lookup holding data), prepare to check holding on the item - if ($ac_source == $lib_materials_type) { + if (in_array($ac_source, $lib_materials_types)) { $attached['js'][1] = array( 'data' => array( 'ding_availability' => array( @@ -270,7 +270,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ } // If item is of type 'library materials' (where we can lookup holding data), map the HTML id to the list of entity ids. - if ($ac_source == $lib_materials_type && !$available_online) { + if (in_array($ac_source, $lib_materials_types) && !$available_online) { $id_mapping[$id] = $ids; } } From a6985cc2a9ef3fe41dff3e879ec0fd3b40f116c4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 24 Apr 2013 16:30:48 +0200 Subject: [PATCH 32/97] Added the posibility to select which datewell types should have fecthed/displayed holdings information --- ding_availability.admin.inc | 47 ++++++++++++++++++++ ding_availability.field.inc | 12 +++--- ding_availability.info | 1 + ding_availability.module | 85 +++++++++++++++++++++++++++++++++++-- 4 files changed, 136 insertions(+), 9 deletions(-) create mode 100644 ding_availability.admin.inc diff --git a/ding_availability.admin.inc b/ding_availability.admin.inc new file mode 100644 index 0000000..b8135b1 --- /dev/null +++ b/ding_availability.admin.inc @@ -0,0 +1,47 @@ + 'fieldset', + '#title' => t('Update from datawell'), + '#description' => t('Update the lists of known types and sources by asking the datawell for all types and sorces.') + ); + + $form['update']['update'] = array( + '#type' => 'submit', + '#value' => t('Update'), + '#submit' => array('ting_admin_reservable_settings_update'), + ); + + $types = variable_get('ting_well_types', array()); + + $form['ding_availability_holdings'] = array( + '#type' => 'fieldset', + '#title' => t('Holdings information'), + '#tree' => FALSE, + '#description' => t("Which ting object types should display holdings information in the holding field on the ting object."), + ); + + $form['ding_availability_holdings']['ding_availability_holdings_types'] = array( + '#type' => 'checkboxes', + '#title' => t('Types'), + '#options' => drupal_map_assoc(array_keys($types)), + '#default_value' => variable_get('ding_availability_holdings_types', _ding_availability_holdings_default_types()), + ); + // Save us the trouble of running array_filter. + $form['array_filter'] = array('#type' => 'value', '#value' => TRUE); + + return system_settings_form($form); +} diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 68a3e57..90b8132 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -161,7 +161,8 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $id = drupal_html_id('holdings-' . $entity->id); // If item is of type 'library materials' (where we can lookup holding data), prepare to check holding on the item - if (in_array($ac_source, $lib_materials_types)) { + $holding_types = variable_get('ding_availability_holdings_types', _ding_availability_holdings_default_types()); + if (in_array($ac_source, $lib_materials_types) && in_array(strtolower($entity->type), $holding_types)) { $attached['js'][] = array( 'data' => array( 'ding_availability_mode' => 'holdings', @@ -171,12 +172,13 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ ), 'type' => 'setting' ); + + $element[$delta] = array( + '#markup' => '
      ', + '#attached' => $attached, + ); } - $element[$delta] = array( - '#markup' => '
      ', - '#attached' => $attached, - ); break; case 'ding_availability_item': diff --git a/ding_availability.info b/ding_availability.info index df1f3ce..59ed159 100644 --- a/ding_availability.info +++ b/ding_availability.info @@ -6,3 +6,4 @@ core = 7.x files[] = ding_availability.module dependencies[] = ding_provider dependencies[] = virtual_field +dependencies[] = ting diff --git a/ding_availability.module b/ding_availability.module index 5b97ae5..be74ffa 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -11,6 +11,8 @@ module_load_include('inc', 'ding_availability', 'ding_availability.field'); * Implements hook_menu(). */ function ding_availability_menu() { + $items = array(); + $items['ding_availability/items'] = array( 'title' => 'Availability status', 'page callback' => 'ding_availability_js', @@ -25,6 +27,15 @@ function ding_availability_menu() { 'type' => MENU_CALLBACK, ); + $items['admin/config/ting/holdings'] = array( + 'title' => 'Provider availability holdings', + 'description' => 'Configure which ting object types there should have holdings information if avaiable.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('ding_availability_admin_holdings_settings'), + 'access arguments' => array('administer ting settings'), + 'file' => 'ding_availability.admin.inc' + ); + return $items; } @@ -68,12 +79,12 @@ function ding_availability_items($provider_ids) { 'reservable' => FALSE, 'available' => FALSE, ); - + // Marks internet resources as available. if ($item['is_internet']) { $item['available'] = TRUE; } - + _ding_availability_text($item); } } @@ -98,12 +109,12 @@ function ding_availability_holdings($provider_ids) { 'available' => FALSE, 'holdings' => array(), ); - + // Marks internet resources as available. if ($item['is_internet']) { $item['available'] = TRUE; } - + _ding_availability_text($item); } @@ -193,3 +204,69 @@ function ding_availability_preprocess_ting_object_entities(&$variables) { } } +/** + * The defaults types that should display holdings information. + * + * @return array + * List of datawell types that should be fetched holdings information if they + * have the library marterial or katalog source. + */ +function _ding_availability_holdings_default_types() { + return array( + 'bog', + 'cd (musik)', + 'node', + 'dvd', + 'billedbog', + 'lydbog (cd)', + 'lydbog (bÄnd)', + 'tegneserie', + 'cd', + 'sammensat materiale', + 'lydbog (cd-mp3)', + 'video', + 'bog stor skrift', + 'Ärbog', + 'cd-rom', + 'periodikum', + 'pc-spil', + 'blu-ray', + 'playstation 3', + 'playstation 2', + 'wii', + 'xbox 360', + 'nintendo ds', + 'graphic novel', + 'grafisk blad', + 'dvd-rom', + 'kort', + 'plakat', + 'gameboy advance', + 'xbox', + 'grammofonplade', + 'serie', + 'avis', + 'spil', + 'playstation', + 'mikroform', + 'bÄnd', + 'originalkunst', + 'puslespil', + 'laborativt materiale', + 'Þvelsesmodel', + 'foto', + 'maleri', + 'teaterdukke', + 'kassettelydbÄnd', + 'transparent', + 'billedkort', + 'diskette', + 'legetÞj', + 'gameboy', + 'punktskrift', + 'akvarel', + 'arkitekturtegning', + 'emnekasse', + 'spolelydbÄnd', + ); +} \ No newline at end of file From 5b6bd267a2cf7289a7884707c6edc778e14a6891 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 24 Apr 2013 19:07:53 +0200 Subject: [PATCH 33/97] Added better descriptions and documentation to the holdings admin form --- ding_availability.admin.inc | 4 +++- ding_availability.module | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ding_availability.admin.inc b/ding_availability.admin.inc index b8135b1..2916203 100644 --- a/ding_availability.admin.inc +++ b/ding_availability.admin.inc @@ -13,6 +13,7 @@ function ding_availability_admin_holdings_settings($form_state) { form_load_include($form_state, 'inc', 'ting', 'ting.admin'); $form = array(); + // Add button to update the types from the datawell. $form['update'] = array( '#type' => 'fieldset', '#title' => t('Update from datawell'), @@ -25,13 +26,14 @@ function ding_availability_admin_holdings_settings($form_state) { '#submit' => array('ting_admin_reservable_settings_update'), ); + // Get available types. $types = variable_get('ting_well_types', array()); $form['ding_availability_holdings'] = array( '#type' => 'fieldset', '#title' => t('Holdings information'), '#tree' => FALSE, - '#description' => t("Which ting object types should display holdings information in the holding field on the ting object."), + '#description' => t("Which ting object types should display provider holdings information in the holding field e.g. on the ting object view"), ); $form['ding_availability_holdings']['ding_availability_holdings_types'] = array( diff --git a/ding_availability.module b/ding_availability.module index be74ffa..2dd167f 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -29,7 +29,7 @@ function ding_availability_menu() { $items['admin/config/ting/holdings'] = array( 'title' => 'Provider availability holdings', - 'description' => 'Configure which ting object types there should have holdings information if avaiable.', + 'description' => 'Configure which ting object types should try to fetch provider holdings information.', 'page callback' => 'drupal_get_form', 'page arguments' => array('ding_availability_admin_holdings_settings'), 'access arguments' => array('administer ting settings'), @@ -205,7 +205,7 @@ function ding_availability_preprocess_ting_object_entities(&$variables) { } /** - * The defaults types that should display holdings information. + * The defaults types that should display provider holdings information. * * @return array * List of datawell types that should be fetched holdings information if they From 38af358c2d2137df44e9e529b436ad082c339065 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 25 Apr 2013 13:43:13 +0200 Subject: [PATCH 34/97] Fixed javascript error when no availability is available --- js/ding_availability.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/js/ding_availability.js b/js/ding_availability.js index 70e6cfa..33744e2 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -35,10 +35,12 @@ $.getJSON(settings.basePath + 'ding_availability/' + (settings.ding_availability_mode ? settings.ding_availability_mode: 'items') + '/' + ids.join(','), {}, update); } else { - // Apply already fetched availability - $.each(settings.ding_availability, function(id, entity_ids) { - updateAvailability(id, entity_ids); - }); + // Apply already fetched availability, if any. + if (settings.hasOwnProperty('ding_availability')) { + $.each(settings.ding_availability, function(id, entity_ids) { + updateAvailability(id, entity_ids); + }); + } } function update(data, textData) { From edb5462a5158834a232ac8e2cd3a76f023dba956 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 6 May 2013 11:26:56 +0200 Subject: [PATCH 35/97] Changed makefile to point to ding2 on github --- ding_availability.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ding_availability.make b/ding_availability.make index 9439b26..bdc7ef2 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -10,6 +10,6 @@ projects[virtual_field][version] = "1.1" 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 0797f5fe54fa4b1b2ef6c67285100794875ffac9 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 10 Jun 2013 14:25:51 +0200 Subject: [PATCH 36/97] Removed reservation form (button) when item is not reservable --- js/ding_availability.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/ding_availability.js b/js/ding_availability.js index 33744e2..6fe12b5 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -88,6 +88,12 @@ } else { element.addClass('not-reservable'); + + // Remove reservation form (button) when availability is not reservable. + var reserver_btn = element.parents('.ting-object:first').find('[id^=ding-reservation-reserve-form]'); + if (reserver_btn.length) { + reserver_btn.remove(); + } } if (available && reservable || is_internet) { @@ -102,7 +108,7 @@ // If availability is an link extrend information. if (settings.ding_availability_link === 1) { $('a', element).append('' + Drupal.t('on loan') + ''); - } } + }} else if (available && ! reservable) { element.attr('title', Drupal.t('not reservable')); // If availability is an link extrend information. From 919305077b36d669da881e38dda06ec7da4d9454 Mon Sep 17 00:00:00 2001 From: Rasmus Frey Date: Wed, 12 Jun 2013 13:27:32 +0200 Subject: [PATCH 37/97] Update color codes and changed the way class names are added to reserve button --- css/ding_availability.css | 11 +++++------ css/ding_availability_legend.css | 14 ++++++-------- js/ding_availability.js | 25 +++++++++++++++++++++---- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/css/ding_availability.css b/css/ding_availability.css index c8a390a..cfcc779 100644 --- a/css/ding_availability.css +++ b/css/ding_availability.css @@ -1,20 +1,19 @@ .pending, .availability.processed { - color: #696a69; + color: #959595; /* Grey */ } .availability.reservable { - color: #ea9123; + color: #f0cb28; /* Yellow */ } /* Available and reservable */ .availability.available, .availability.available.reservable { - color: #4c9f45; + color: #528c10; /* Green */ } /* Available, but not reservable */ .availability.available.not-reservable { - color: #0072bc; -} - + color: #a32e10; /* Red */ +} \ No newline at end of file diff --git a/css/ding_availability_legend.css b/css/ding_availability_legend.css index 5e4e687..f909d0e 100644 --- a/css/ding_availability_legend.css +++ b/css/ding_availability_legend.css @@ -22,23 +22,21 @@ } .availability-legend-item.available img { - background-color: #4c9f45; + background-color: #528c10; /* Green */ } .availability-legend-item.on-loan img { - background-color: #ea9123; + background-color: #f0cb28; /* Yellow */ } .availability-legend-item.unavailable img { - background-color: #ED1E88; + background-color: #a32e10; /* Red */ } .availability-legend-item.unavailable.netdokument img { - background-color: #2e2e2e; + background-color: #a32e10; /* Red */ } .availability-legend-item.unreservable img { - background-color: #0072bc; -} - - + background-color: #a32e10; /* Red */ +} \ No newline at end of file diff --git a/js/ding_availability.js b/js/ding_availability.js index 6fe12b5..903b827 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -76,23 +76,40 @@ var element = $('#' + id); element.removeClass('pending').addClass('processed'); + // Reserve button + var reserver_btn = element.parents('.ting-object:first').find('[id^=ding-reservation-reserve-form]'); + if (available) { element.addClass('available'); + + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('available'); + } } else { element.addClass('unavailable'); - } + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('unavailable'); + } + } + if (reservable) { element.addClass('reservable'); + + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('reservable'); + } } else { element.addClass('not-reservable'); - // Remove reservation form (button) when availability is not reservable. - var reserver_btn = element.parents('.ting-object:first').find('[id^=ding-reservation-reserve-form]'); + // Add class to reserve button if (reserver_btn.length) { - reserver_btn.remove(); + reserver_btn.addClass('not-reservable'); } } From eff30ea382219ab8a9282899aed2db9fb677fe1b Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 17 Jun 2013 10:15:13 +0200 Subject: [PATCH 38/97] Added comment about dependency to ting module --- ding_availability.admin.inc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ding_availability.admin.inc b/ding_availability.admin.inc index 2916203..226eab7 100644 --- a/ding_availability.admin.inc +++ b/ding_availability.admin.inc @@ -10,10 +10,11 @@ * information displayed. */ function ding_availability_admin_holdings_settings($form_state) { - form_load_include($form_state, 'inc', 'ting', 'ting.admin'); $form = array(); - // Add button to update the types from the datawell. + // Add button to update the types from the datawell. Which requires us to load + // the administation file for the ting module to get the information. + form_load_include($form_state, 'inc', 'ting', 'ting.admin'); $form['update'] = array( '#type' => 'fieldset', '#title' => t('Update from datawell'), From b44b1d00581116777b9f2b737433d3f2e9769989 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 17 Jun 2013 10:23:00 +0200 Subject: [PATCH 39/97] Provied better comment lines in the JavaScript --- ding_availability.module | 2 +- js/ding_availability.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ding_availability.module b/ding_availability.module index 2dd167f..b4727a3 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -269,4 +269,4 @@ function _ding_availability_holdings_default_types() { 'emnekasse', 'spolelydbÄnd', ); -} \ No newline at end of file +} diff --git a/js/ding_availability.js b/js/ding_availability.js index 33744e2..731650d 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -92,27 +92,27 @@ if (available && reservable || is_internet) { element.attr('title', Drupal.t('available')); - // If availability is an link extrend information. + // If availability is a link append the status inside the link. if (settings.ding_availability_link === 1) { $('a', element).append('' + Drupal.t('available') + ''); } } else if (!available && reservable) { element.attr('title', Drupal.t('on loan')); - // If availability is an link extrend information. + // If availability is a link append the status inside the link. if (settings.ding_availability_link === 1) { $('a', element).append('' + Drupal.t('on loan') + ''); } } else if (available && ! reservable) { element.attr('title', Drupal.t('not reservable')); - // If availability is an link extrend information. + // If availability is a link append the status inside the link. if (settings.ding_availability_link === 1) { $('a', element).append('' + Drupal.t('not reservable') + ''); } } else if (!available && ! reservable) { element.attr('title', Drupal.t('unavailable')); - // If availability is an link extrend information. + // If availability is a link append the status inside the link. if (settings.ding_availability_link === 1) { $('a', element).append('' + Drupal.t('unavailable') + ''); } From e6ddeee358eb153e7978e20795c685aabeca83e6 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 24 Jun 2013 14:22:46 +0200 Subject: [PATCH 40/97] Updated makefile to point to ding2tal --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index bdc7ef2..a811568 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -10,6 +10,6 @@ projects[virtual_field][version] = "1.1" 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 1e6dc70721e91ecd5b0f6076c8ee9cd5d9b6460e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 24 Jun 2013 14:57:58 +0200 Subject: [PATCH 41/97] Changed makefile to use development branch --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index a811568..9439b26 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -11,5 +11,5 @@ projects[virtual_field][version] = "1.1" 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 dfdbfbb89a7119d08d7cab4daaee70697c7fae83 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 3 Jul 2013 13:34:49 +0200 Subject: [PATCH 42/97] Updated makefile to point to development branch and ding2tal --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index bdc7ef2..5d2596d 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -11,5 +11,5 @@ projects[virtual_field][version] = "1.1" 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 2f58b76dd2cdc260b044a1d83c06c9d68f697f9f Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 17 Sep 2013 11:34:45 +0200 Subject: [PATCH 43/97] Updated coding style --- ding_availability.admin.inc | 12 ++++++------ ding_availability.field.inc | 39 ++++++++++++++++++++----------------- ding_availability.module | 38 +++++++++++++++++++++++++++--------- js/ding_availability.js | 1 + 4 files changed, 57 insertions(+), 33 deletions(-) diff --git a/ding_availability.admin.inc b/ding_availability.admin.inc index 226eab7..09074a8 100644 --- a/ding_availability.admin.inc +++ b/ding_availability.admin.inc @@ -1,24 +1,24 @@ 'fieldset', '#title' => t('Update from datawell'), - '#description' => t('Update the lists of known types and sources by asking the datawell for all types and sorces.') + '#description' => t('Update the lists of known types and sources by asking the datawell for all types and sorces.'), ); $form['update']['update'] = array( @@ -45,6 +45,6 @@ function ding_availability_admin_holdings_settings($form_state) { ); // Save us the trouble of running array_filter. $form['array_filter'] = array('#type' => 'value', '#value' => TRUE); - + return system_settings_form($form); } diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 90b8132..5a109cf 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -57,7 +57,7 @@ function ding_availability_field_formatter_info() { 'label' => t('Default'), 'field types' => array( 'ding_availability_item', - 'ding_availability_holdings' + 'ding_availability_holdings', ), ), 'ding_availability_type' => array( @@ -122,7 +122,7 @@ function ding_availability_field_formatter_settings_summary($field, $instance, $ $linking = t('true'); } - // Check if linking to the object have been selected + // Check if linking to the object have been selected. $summary = t('Link to ting objects: @link', array( '@link' => $linking, )); @@ -146,11 +146,11 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ drupal_get_path('module', 'ding_availability') . '/js/ding_availability.js', ), 'css' => array( - drupal_get_path('module', 'ding_availability') . '/css/ding_availability.css' + drupal_get_path('module', 'ding_availability') . '/css/ding_availability.css', ), ); - // Extract records' source + // Extract records' source. if ($field['type'] != 'ting_collection_types') { $ac_source = $entity->reply->record['ac:source'][''][0]; } @@ -160,7 +160,8 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Generate an unique id. $id = drupal_html_id('holdings-' . $entity->id); - // If item is of type 'library materials' (where we can lookup holding data), prepare to check holding on the item + // If item is of type 'library materials' (where we can lookup holding + // data), prepare to check holding on the item. $holding_types = variable_get('ding_availability_holdings_types', _ding_availability_holdings_default_types()); if (in_array($ac_source, $lib_materials_types) && in_array(strtolower($entity->type), $holding_types)) { $attached['js'][] = array( @@ -170,7 +171,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $id => array($entity->localId), ), ), - 'type' => 'setting' + 'type' => 'setting', ); $element[$delta] = array( @@ -192,10 +193,11 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Generate an unique id. $id = drupal_html_id('availability-' . $entity->id); - // Mark as available if it is an online resource + // Mark as available if it is an online resource, $available_online = (in_array(drupal_strtolower($entity->type), $online_types)) ? 'available' : 'not-available-online'; - // If item is of type 'library materials' (where we can lookup holding data), prepare to check holding on the item + // If item is of type 'library materials' (where we can lookup holding + // data), prepare to check holding on the item. if (in_array($ac_source, $lib_materials_types)) { $attached['js'][1] = array( 'data' => array( @@ -203,7 +205,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $id => array($entity->localId), ), ), - 'type' => 'setting' + 'type' => 'setting', ); } @@ -218,9 +220,9 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ 'availability', drupal_html_class($entity->type), $available_online, - 'pending' + 'pending', ), - ) + ), ), ); break; @@ -237,10 +239,10 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Generate an unique id. $id = drupal_html_id('availability-' . $entities[0]->id . '-' . $type); - // Extract records' source + // Extract records' source. $ac_source = $entities[0]->reply->record['ac:source'][''][0]; - // Mark as available if it is an online resource + // Mark as available if it is an online resource. $available_online = (in_array(drupal_strtolower($type), $online_types)) ? 'available' : ''; $available_online_label = ($available_online) ? '' . t('online') . '' : ''; @@ -256,7 +258,6 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ } $url['options']['html'] = TRUE; $typelink = l(check_plain($type) . $available_online_label, $url['path'], $url['options']); - } // Create a list element for each type. @@ -268,22 +269,24 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $ids = array(); foreach ($entities as $object_entity) { - $ids[] = $object_entity->localId; + $ids[] = $object_entity->localId; } - // If item is of type 'library materials' (where we can lookup holding data), map the HTML id to the list of entity ids. + // If item is of type 'library materials' (where we can lookup holding + // data), map the HTML id to the list of entity ids. if (in_array($ac_source, $lib_materials_types) && !$available_online) { $id_mapping[$id] = $ids; } } // Prepare to check holding on the item. - // It's importants that this is attached even if empty, else javascript will fail beacuse it gets an empty object. + // It's important that this is attached even if empty, else javascript + // will fail because it gets an empty object. $attached['js'][1] = array( 'data' => array( 'ding_availability' => $id_mapping, 'ding_availability_link' => $display['settings']['link'], - ), 'type' => 'setting' + ), 'type' => 'setting', ); $element[$delta] = array( diff --git a/ding_availability.module b/ding_availability.module index b4727a3..bc0c1bd 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -33,7 +33,7 @@ function ding_availability_menu() { 'page callback' => 'drupal_get_form', 'page arguments' => array('ding_availability_admin_holdings_settings'), 'access arguments' => array('administer ting settings'), - 'file' => 'ding_availability.admin.inc' + 'file' => 'ding_availability.admin.inc', ); return $items; @@ -52,21 +52,33 @@ function ding_availability_ding_provider_user() { } /** + * Output the availability information as json. * + * @param array $provider_ids + * Providers ID's to fetch availability information for. */ function ding_availability_js($provider_ids) { drupal_json_output(ding_availability_items(explode(',', $provider_ids))); } /** + * Output holdings information as json. * + * @param array $provider_ids + * Providers ID's to fetch holdings information for. */ function ding_availability_holdings_js($provider_ids) { drupal_json_output(ding_availability_holdings(explode(',', $provider_ids))); } /** + * Get availability from the provider. * + * @param array $provider_ids + * ID's to fetch data for. + * + * @return array + * Availability information. */ function ding_availability_items($provider_ids) { if (ding_provider_implements('availability', 'items')) { @@ -96,7 +108,13 @@ function ding_availability_items($provider_ids) { } /** + * Get holdings from the provider. + * + * @param array $provider_ids + * ID's to fetch data for. * + * @return array + * Holdings information. */ function ding_availability_holdings($provider_ids) { $items = ding_provider_invoke('availability', 'holdings', $provider_ids); @@ -142,6 +160,7 @@ function _ding_availability_text(&$item) { /** * Implements hook_block_info(). + * * Define availability legend block. */ function ding_availability_block_info() { @@ -155,9 +174,10 @@ function ding_availability_block_info() { /** * Implements hook_block_view(). + * * Define availability legend block. */ -function ding_availability_block_view($delta = '') { +function ding_availability_block_view($delta) { $block = array(); $block['subject'] = t('Ding availability legend'); $block['content'] = ding_availability_render_legend(); @@ -171,17 +191,17 @@ function ding_availability_render_legend() { drupal_add_css(drupal_get_path('module', 'ding_availability') . '/css/ding_availability_legend.css'); - // construct the image's path (.gif stored in a module subdir) + // Construct the image's path (.gif stored in a module subdir). $image_path = drupal_get_path('module', 'ding_availability') . '/images/blank.gif'; - // make some text, image's alt & title tags (SEO, accessibility) + // Make some text, image's alt & title tags (SEO, accessibility). $availability_legend['available'] = t('Available'); $availability_legend['on-loan'] = t('On loan'); $availability_legend['unavailable'] = t('Unavailable'); $availability_legend['unreservable'] = t('Not reservable'); - // render image html using theme_image (returns NULL if file doesn't exist) - foreach ( $availability_legend as $key => $val ) { + // Render image html using theme_image (returns NULL if file doesn't exist). + foreach ($availability_legend as $key => $val) { $format_label = '' . $val . ''; $format_image = theme('image', array('path' => $image_path, 'alt' => $val, 'title' => $val)); $format_items[] = '
      ' . $format_image . $format_label . '
      '; @@ -193,7 +213,7 @@ function ding_availability_render_legend() { } /** - * ting_object_entities preprocessor. + * Implements hook_preprocessor_ting_object_entities(). */ function ding_availability_preprocess_ting_object_entities(&$variables) { if (!empty($variables['content']) && function_exists('ding_availability_render_legend')) { @@ -208,8 +228,8 @@ function ding_availability_preprocess_ting_object_entities(&$variables) { * The defaults types that should display provider holdings information. * * @return array - * List of datawell types that should be fetched holdings information if they - * have the library marterial or katalog source. + * List of data well types that should be fetched holdings information if they + * have the library material or catalog source. */ function _ding_availability_holdings_default_types() { return array( diff --git a/js/ding_availability.js b/js/ding_availability.js index a68ebee..96c76ae 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -4,6 +4,7 @@ */ (function($) { + "use strict"; // Cache of fetched availability information. Drupal.DADB = {}; From 5b4c434e6a7284a29ca8c61ce4d5d5baa47539e7 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 17 Sep 2013 11:39:36 +0200 Subject: [PATCH 44/97] Fixed url encoding of online links --- ding_availability.field.inc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 5a109cf..23c78be 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -256,8 +256,9 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ else { $url = entity_uri('ting_collection', $entities[0]); } - $url['options']['html'] = TRUE; - $typelink = l(check_plain($type) . $available_online_label, $url['path'], $url['options']); + + // The online url can't be used with l(), has it will encode it. + $typelink = '' . check_plain($type) . $available_online_label . ''; } // Create a list element for each type. From a73594f8bae0eea0630322d2e1cfc6cf1b721383 Mon Sep 17 00:00:00 2001 From: Thomas Johansen Date: Wed, 9 Oct 2013 12:15:00 +0200 Subject: [PATCH 45/97] Fixed link in typelink to include a slash --- ding_availability.field.inc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 23c78be..faae45e 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -105,8 +105,6 @@ function ding_availability_field_formatter_settings_form($field, $instance, $vie return $element; } - - /** * Implements hook_field_formatter_settings_summary(). */ @@ -258,7 +256,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ } // The online url can't be used with l(), has it will encode it. - $typelink = '' . check_plain($type) . $available_online_label . ''; + $typelink = '' . check_plain($type) . $available_online_label . ''; } // Create a list element for each type. From d1ee0519c32ce859508504d07a778e7cf7c19270 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 17 Oct 2013 17:02:23 +0200 Subject: [PATCH 46/97] Changed what not-reservalbe is to not-available and not-reservable --- ding_availability.module | 4 ++-- js/ding_availability.js | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ding_availability.module b/ding_availability.module index bc0c1bd..442e0fe 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -93,7 +93,7 @@ function ding_availability_items($provider_ids) { ); // Marks internet resources as available. - if ($item['is_internet']) { + if (isset($item['is_internet']) && $item['is_internet']) { $item['available'] = TRUE; } @@ -143,7 +143,7 @@ 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'] || $item['is_internet']) { + if ($item['available'] || (isset($item['is_internet']) && $item['is_internet'])) { $item['status'] = t('available'); } elseif (!$item['available'] && $item['reservable']) { diff --git a/js/ding_availability.js b/js/ding_availability.js index 96c76ae..80bfb19 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -105,7 +105,8 @@ reserver_btn.addClass('reservable'); } } - else { + + if (!available && !reservable) { element.addClass('not-reservable'); // Add class to reserve button @@ -114,7 +115,7 @@ } } - if (available && reservable || is_internet) { + if (available || is_internet) { element.attr('title', Drupal.t('available')); // If availability is a link append the status inside the link. if (settings.ding_availability_link === 1) { @@ -134,7 +135,7 @@ $('a', element).append('' + Drupal.t('not reservable') + ''); } } - else if (!available && ! reservable) { + else if (!available && !reservable) { element.attr('title', Drupal.t('unavailable')); // If availability is a link append the status inside the link. if (settings.ding_availability_link === 1) { From 1448b9b8f1906998fd2f4a33f7002b2f06a483ef Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Sun, 20 Oct 2013 15:48:24 +0200 Subject: [PATCH 47/97] Added total counts above the holdings tables --- js/ding_availability.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/js/ding_availability.js b/js/ding_availability.js index 80bfb19..8d2674f 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -33,7 +33,7 @@ // Fetch availability. if (ids.length > 0) { - $.getJSON(settings.basePath + 'ding_availability/' + (settings.ding_availability_mode ? settings.ding_availability_mode: 'items') + '/' + ids.join(','), {}, update); + $.getJSON(settings.basePath + 'ding_availability/' + (settings.ding_availability_mode ? settings.ding_availability_mode : 'items') + '/' + ids.join(','), {}, update); } else { // Apply already fetched availability, if any. @@ -148,7 +148,13 @@ var entity_id = entity_ids.pop(); if (Drupal.DADB[entity_id] && (Drupal.DADB[entity_id]['holdings'])) { // Show status for material. - $('#' + id).append(Drupal.DADB[entity_id].html) ; + $('#' + id).append(Drupal.DADB[entity_id].html); + + // Add reservation and total counts. + if (Drupal.DADB[entity_id].total_count != undefined) { + var reserver = Drupal.t('We have !x copies and !y reservations for this material.', {'!x' : Drupal.DADB[entity_id].total_count, '!y' : Drupal.DADB[entity_id].reserved_count}); + $('#' + id).prepend($('

      ', { 'class' : 'holdings-total-count', 'text' : reserver })); + } } } } From 7b9e821e6a4405c90890d03f51e2cf8ec77bc59d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 22 Oct 2013 19:12:20 +0200 Subject: [PATCH 48/97] Ensured that x of y in holdings is not displayed --- js/ding_availability.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/ding_availability.js b/js/ding_availability.js index 8d2674f..0561723 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -151,7 +151,7 @@ $('#' + id).append(Drupal.DADB[entity_id].html); // Add reservation and total counts. - if (Drupal.DADB[entity_id].total_count != undefined) { + if (Drupal.DADB[entity_id].total_count != undefined || Drupal.DADB[entity_id].total_count > 0) { var reserver = Drupal.t('We have !x copies and !y reservations for this material.', {'!x' : Drupal.DADB[entity_id].total_count, '!y' : Drupal.DADB[entity_id].reserved_count}); $('#' + id).prepend($('

      ', { 'class' : 'holdings-total-count', 'text' : reserver })); } From 9be78e66ea88e8a8d37e9b0e86ae20550cc822a0 Mon Sep 17 00:00:00 2001 From: Rune Schjellerup Philosof Date: Wed, 23 Oct 2013 21:07:12 +0000 Subject: [PATCH 49/97] Move html creation from ding_providers to ding_availability. Backwards compatible, will only try to create the html if the provider didn't supply html. --- ding_availability.module | 55 +++++++++++++++++++++++++++++ templates/ding-availability.tpl.php | 22 ++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 templates/ding-availability.tpl.php diff --git a/ding_availability.module b/ding_availability.module index 442e0fe..4a8e12a 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -51,6 +51,27 @@ function ding_availability_ding_provider_user() { ); } +/** + * Implements hook_theme(); + */ +function ding_availability_theme($existing, $type, $theme, $path) { + return array( + 'ding_availability' => array( + 'template' => 'ding-availability', + 'variables' => array( + 'status' => NULL, + 'reservable' => NULL, + 'available' => NULL, + 'holdings' => NULL, + 'total_count' => NULL, + 'reservable_count' => NULL, + 'reserved_count' => NULL, + ), + 'path' => $path . '/templates', + ), + ); +} + /** * Output the availability information as json. * @@ -134,6 +155,40 @@ function ding_availability_holdings($provider_ids) { } _ding_availability_text($item); + + // Support for creating the html here instead of in the provider. + // The provider must devliver a location array, total_count, available_count, reserved_count, reservable_count. + // We assume that the provider supports this, if it didn't deliver html. + if (isset($item['html'])) { + // If it is there then don't try to create it. + continue; + } + $rows = array(); + foreach ($item['holdings'] as $holding) { + $rows[] = array( + 'class' => array($holding['available_count'] > 0 ? 'available' : 'unava$ + 'data' => array( + 'placement' => join(' → ', $holding['location']), + 'home' => $holding['available_count'], + ), + ); + } + $holdings = theme('table__ding_availability', array( + 'header' => array( + 'placement' => t('Placement'), + 'home' => t('Home'), + ), + 'rows' => $rows, + )); + $item['html'] = theme('ding_availability', array( + 'status' => $item['status'], + 'reservable' => $item['reservable'], + 'available' => $item['available'], + 'holdings' => $holdings, + 'total_count' => $item['total_count'], + 'reservable_count' => $item['reservable_count'], + 'reserved_count' => $item['reserved_count'], + )); } return $items; diff --git a/templates/ding-availability.tpl.php b/templates/ding-availability.tpl.php new file mode 100644 index 0000000..86bc738 --- /dev/null +++ b/templates/ding-availability.tpl.php @@ -0,0 +1,22 @@ + $reservable_count)); +$reserved_text = format_plural($reserved_count, 'There is 1 user in queue to loan the material', 'There are @count users in queue to loan the material'); +?> +

      +

      + From fd8615ace53abc5a7075993fedad2accc77e8401 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 30 Oct 2013 18:10:59 +0100 Subject: [PATCH 50/97] Updated the holdings information to match new HTML tables --- ding_availability.module | 85 +++++++++++++++++------------ js/ding_availability.js | 6 -- templates/ding-availability.tpl.php | 18 ++---- 3 files changed, 57 insertions(+), 52 deletions(-) diff --git a/ding_availability.module b/ding_availability.module index 4a8e12a..d50ef69 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -52,19 +52,15 @@ function ding_availability_ding_provider_user() { } /** - * Implements hook_theme(); + * Implements hook_theme(). */ function ding_availability_theme($existing, $type, $theme, $path) { return array( 'ding_availability' => array( 'template' => 'ding-availability', 'variables' => array( - 'status' => NULL, - 'reservable' => NULL, - 'available' => NULL, 'holdings' => NULL, 'total_count' => NULL, - 'reservable_count' => NULL, 'reserved_count' => NULL, ), 'path' => $path . '/templates', @@ -157,43 +153,64 @@ function ding_availability_holdings($provider_ids) { _ding_availability_text($item); // Support for creating the html here instead of in the provider. - // The provider must devliver a location array, total_count, available_count, reserved_count, reservable_count. + // The provider contains a location array, total_count, available_count, + // reserved_count, reservable_count. // We assume that the provider supports this, if it didn't deliver html. - if (isset($item['html'])) { - // If it is there then don't try to create it. - continue; - } - $rows = array(); - foreach ($item['holdings'] as $holding) { - $rows[] = array( - 'class' => array($holding['available_count'] > 0 ? 'available' : 'unava$ - 'data' => array( - 'placement' => join(' → ', $holding['location']), - 'home' => $holding['available_count'], - ), + if (!isset($item['html'])) { + $header = array( + 'placement' => t('Placement'), + 'copies' => t('Copies'), + 'home' => t('At home'), ); + + $attributes = array( + 'class' => array('availability-holdings-table'), + ); + + $rows = array(); + foreach ($item['holdings'] as $holding) { + $rows[] = ding_availability_holdings_row($holding); + } + + // Theme the output. + $item['html'] = theme('ding_availability', array( + 'holdings' => array( + '#theme' => 'table', + '#header' => $header, + '#rows' => $rows, + '#attributes' => $attributes, + ), + 'total_count' => $item['total_count'], + 'reserved_count' => $item['reserved_count'], + )); } - $holdings = theme('table__ding_availability', array( - 'header' => array( - 'placement' => t('Placement'), - 'home' => t('Home'), - ), - 'rows' => $rows, - )); - $item['html'] = theme('ding_availability', array( - 'status' => $item['status'], - 'reservable' => $item['reservable'], - 'available' => $item['available'], - 'holdings' => $holdings, - 'total_count' => $item['total_count'], - 'reservable_count' => $item['reservable_count'], - 'reserved_count' => $item['reserved_count'], - )); } return $items; } +/** + * @param $holding + * + * @return array + */ +function ding_availability_holdings_row($holding) { + $row = array(); + + // Create placement string. + $row['placement'] = implode(' > ', $holding['placement']); + + // Library copies. + $row['copies'] = isset($holding['total_count']) ? (int) $holding['total_count'] : 0; + + // Calculate copies home. + $home = isset($holding['available_count']) ? (int) $holding['available_count'] : 0; + $home += isset($holding['reference_count']) ? (int) $holding['reference_count'] : 0; + $row['home'] = $home; + + return $row; +} + /** * Adds the human readable status text of an item. */ diff --git a/js/ding_availability.js b/js/ding_availability.js index 0561723..36f693f 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -149,12 +149,6 @@ if (Drupal.DADB[entity_id] && (Drupal.DADB[entity_id]['holdings'])) { // Show status for material. $('#' + id).append(Drupal.DADB[entity_id].html); - - // Add reservation and total counts. - if (Drupal.DADB[entity_id].total_count != undefined || Drupal.DADB[entity_id].total_count > 0) { - var reserver = Drupal.t('We have !x copies and !y reservations for this material.', {'!x' : Drupal.DADB[entity_id].total_count, '!y' : Drupal.DADB[entity_id].reserved_count}); - $('#' + id).prepend($('

      ', { 'class' : 'holdings-total-count', 'text' : reserver })); - } } } } diff --git a/templates/ding-availability.tpl.php b/templates/ding-availability.tpl.php index 86bc738..0efbb9a 100644 --- a/templates/ding-availability.tpl.php +++ b/templates/ding-availability.tpl.php @@ -4,19 +4,13 @@ * Displays holdings information * * Available variables: - * - $status: Human readable status text (available, on loan, not reservable, unavailable). - * - $reservable: Boolean. - * - $available: Boolean. - * - $holdings: Html showing detailed holdings information. - * - $total_count: Total amount of copies. - * - $reservable_count: Amount of copies that are reservable. - * - $reserved_count: Amount of reservations. - * + * - $holdings: Html showing detailed holdings information. + * - $total_count: Total amount of copies. + * - $reserved_count: Amount of reservations. */ -$total_text = format_plural($total_count, 'We have 1 copy (@reservable_count reservable).', 'We have @count copies (@reservable_count reservable).', array('@reservable_count' => $reservable_count)); -$reserved_text = format_plural($reserved_count, 'There is 1 user in queue to loan the material', 'There are @count users in queue to loan the material'); +$total_text = format_plural($total_count, 'We have 1 copy.', 'We have @count copies.', array('@count' => $total_count)); +$reserved_text = format_plural($reserved_count, 'There is 1 user in queue to loan the material.', 'There are @count users in queue to loan the material.'); ?> -

      - + From 3eca74757fc87e0c108e80b4e3f65c3c42eab735 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 4 Nov 2013 21:20:50 +0100 Subject: [PATCH 51/97] Updated makefile to point to tag 7.x-1.0-beta2 --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index 9439b26..317f2e5 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -11,5 +11,5 @@ projects[virtual_field][version] = "1.1" 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 ad6355a493dd50c2b2a1642b532e7c932634f7f8 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 11 Nov 2013 16:19:19 +0100 Subject: [PATCH 52/97] Renamed ding_availability theme function to ding_holdings --- ding_availability.field.inc | 7 ++++++- ding_availability.module | 6 +++--- .../{ding-availability.tpl.php => ding-holdings.tpl.php} | 0 3 files changed, 9 insertions(+), 4 deletions(-) rename templates/{ding-availability.tpl.php => ding-holdings.tpl.php} (100%) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index faae45e..e7918e9 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -263,7 +263,12 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $types[] = array( 'data' => $typelink, 'id' => $id, - 'class' => array('availability', drupal_html_class($type), $available_online, 'pending'), + 'class' => array( + 'availability', + drupal_html_class($type), + $available_online, + 'pending', + ), ); $ids = array(); diff --git a/ding_availability.module b/ding_availability.module index d50ef69..768fe77 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -56,8 +56,8 @@ function ding_availability_ding_provider_user() { */ function ding_availability_theme($existing, $type, $theme, $path) { return array( - 'ding_availability' => array( - 'template' => 'ding-availability', + 'ding_holdings' => array( + 'template' => 'ding-holdings', 'variables' => array( 'holdings' => NULL, 'total_count' => NULL, @@ -173,7 +173,7 @@ function ding_availability_holdings($provider_ids) { } // Theme the output. - $item['html'] = theme('ding_availability', array( + $item['html'] = theme('ding_holdings', array( 'holdings' => array( '#theme' => 'table', '#header' => $header, diff --git a/templates/ding-availability.tpl.php b/templates/ding-holdings.tpl.php similarity index 100% rename from templates/ding-availability.tpl.php rename to templates/ding-holdings.tpl.php From b1b3fc5061e9d54d56d85b233af149778fe95f28 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 11 Nov 2013 21:09:29 +0100 Subject: [PATCH 53/97] Added new availability field formatter and matching theme functions --- ding_availability.field.inc | 121 ++++++++++++++++++++-- ding_availability.module | 15 +++ templates/ding-availability-type.tpl.php | 14 +++ templates/ding-availability-types.tpl.php | 12 +++ 4 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 templates/ding-availability-type.tpl.php create mode 100644 templates/ding-availability-types.tpl.php diff --git a/ding_availability.field.inc b/ding_availability.field.inc index e7918e9..7091fae 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -75,6 +75,12 @@ function ding_availability_field_formatter_info() { 'link' => FALSE, ), ), + 'ding_availability_with_labels' => array( + 'label' => t('Availability information with labels'), + 'field types' => array( + 'ting_collection_types', + ), + ), ); } @@ -114,7 +120,7 @@ function ding_availability_field_formatter_settings_summary($field, $instance, $ $settings = $display['settings']; $summary = NULL; - if ($field['type'] == 'ting_collection_types') { + if ($display['type'] == 'ding_collection_types') { $linking = t('false'); if ($settings['link']) { $linking = t('true'); @@ -137,7 +143,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $online_types = variable_get('ting_online_types', _ting_default_online_types()); $lib_materials_types = array('Bibliotekets materialer', 'Bibliotekskatalog'); - // Attach front-end syle and JS to the element. + // Attach front-end style and JS to the element. foreach ($items as $delta => $item) { $attached = array( 'js' => array( @@ -153,8 +159,8 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $ac_source = $entity->reply->record['ac:source'][''][0]; } - switch ($field['type']) { - case 'ding_availability_holdings': + switch ($display['type']) { + case 'ding_availability_default': // Generate an unique id. $id = drupal_html_id('holdings-' . $entity->id); @@ -187,7 +193,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ ); break; - case 'ting_type': + case 'ding_availability_type': // Generate an unique id. $id = drupal_html_id('availability-' . $entity->id); @@ -225,7 +231,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ ); break; - case 'ting_collection_types': + case 'ding_availability_types': $id_mapping = array(); $typed_entities = array(); // Sort entities into type -> ids. @@ -299,6 +305,109 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ '#items' => $types, ); break; + + case 'ding_availability_with_labels': + $id_mapping = array(); + $typed_entities = array(); + + // Sort entities into type -> ids. + foreach ($entity->entities as $ent) { + $typed_entities[$ent->type][] = $ent; + } + + $output = array( + '#theme' => 'ding_availability_types', + '#types' => array(), + '#attached' => array( + 'js' => array(), + ), + ); + + foreach ($typed_entities as $type => $entities) { + // Generate an unique id. + $id = drupal_html_id('availability-' . $entities[0]->id . '-' . $type); + + // Extract records' source. + $ac_source = $entities[0]->reply->record['ac:source'][''][0]; + + // Get link to first element in the collection of the current type. + $url = entity_uri('ting_object', $entities[0]); + + // Mark as available if it is an online resource. + if (in_array(drupal_strtolower($type), $online_types)) { + if (!isset($output['#types']['online'])) { + // Add label "online" to output. + $output['#types']['online'] = array( + '#theme' => 'ding_availability_type', + '#label' => t('Online'), + '#links' => array(), + ); + } + // Add it to the online label. + $output['#types']['online']['#links'][] = array( + 'status' => 'available', + 'type' => $type, + 'link' => array( + // The online url can't be used with l(), has it will encode + // it. + '#markup' => '' . check_plain($type) . '', + ), + ); + } + else { + if (!isset($output['#types']['pending'])) { + // Add label "Pending" to output as in waiting for information. + $output['#types']['pending'] = array( + '#theme' => 'ding_availability_type', + '#label' => t('Pending'), + '#links' => array(), + ); + } + $output['#types']['pending']['#links'][] = array( + 'status' => 'pending', + 'type' => $type, + 'link' => array( + '#theme' => 'link', + '#text' => check_plain($type), + '#path' => $url['path'], + '#options' => array( + 'attributes' => array( + 'class' => array( + 'search-result--availability-link', + 'availability', + 'js-pending', + ), + 'id' => $id, + ), + 'html' => FALSE, + ), + ), + ); + } + + // If item is of type 'library materials' (where we can lookup + // availability data), map the HTML id to the list of entity ids. + // This is for the current material type group (book, cd, etc.). + if (in_array($ac_source, $lib_materials_types) && !in_array(drupal_strtolower($type), $online_types)) { + $id_mapping[$id] = array(); + foreach ($entities as $object_entity) { + $id_mapping[$id][] = $object_entity->localId; + } + } + } + + // Prepare to check holding on the item. + // It's important that this is attached even if empty, else javascript + // will fail because it gets an empty object. + $output['#attached']['js'][] = array( + 'data' => array( + 'ding_availability' => $id_mapping, + ), 'type' => 'setting', + ); + $output['#attached']['js'][] = drupal_get_path('module', 'ding_availability') . '/js/ding_availability.js'; + + $element[$delta] = $output; + break; } } diff --git a/ding_availability.module b/ding_availability.module index 768fe77..d408778 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -65,6 +65,21 @@ function ding_availability_theme($existing, $type, $theme, $path) { ), 'path' => $path . '/templates', ), + 'ding_availability_types' => array( + 'template' => 'ding-availability-types', + 'variables' => array( + 'types' => array(), + ), + 'path' => $path . '/templates', + ), + 'ding_availability_type' => array( + 'template' => 'ding-availability-type', + 'variables' => array( + 'label' => NULL, + 'links' => array(), + ), + 'path' => $path . '/templates', + ), ); } diff --git a/templates/ding-availability-type.tpl.php b/templates/ding-availability-type.tpl.php new file mode 100644 index 0000000..16b9e35 --- /dev/null +++ b/templates/ding-availability-type.tpl.php @@ -0,0 +1,14 @@ + +: + + + diff --git a/templates/ding-availability-types.tpl.php b/templates/ding-availability-types.tpl.php new file mode 100644 index 0000000..f1d9097 --- /dev/null +++ b/templates/ding-availability-types.tpl.php @@ -0,0 +1,12 @@ + + +

      + From a77af4e202e6ea90432b9d641c95ec4bacf4b48e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 11 Nov 2013 21:17:06 +0100 Subject: [PATCH 54/97] Added colors to availability links --- ding_availability.field.inc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 7091fae..525b5b2 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -318,9 +318,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $output = array( '#theme' => 'ding_availability_types', '#types' => array(), - '#attached' => array( - 'js' => array(), - ), + '#attached' => $attached, ); foreach ($typed_entities as $type => $entities) { @@ -350,7 +348,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ 'link' => array( // The online url can't be used with l(), has it will encode // it. - '#markup' => '' . check_plain($type) . '', + '#markup' => '' . check_plain($type) . '', ), ); } From dc1d2e3fda704ba54fccc00c54acb051d07750be Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 12 Nov 2013 09:58:07 +0100 Subject: [PATCH 55/97] Fixed pending class on availbility on search result page --- css/ding_availability.css | 5 +++-- ding_availability.field.inc | 2 +- templates/ding-availability-types.tpl.php | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/css/ding_availability.css b/css/ding_availability.css index cfcc779..c944039 100644 --- a/css/ding_availability.css +++ b/css/ding_availability.css @@ -1,5 +1,6 @@ -.pending, .availability.processed { +.availability.pending, +.availability.processed { color: #959595; /* Grey */ } @@ -16,4 +17,4 @@ /* Available, but not reservable */ .availability.available.not-reservable { color: #a32e10; /* Red */ -} \ No newline at end of file +} diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 525b5b2..18325d0 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -373,7 +373,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ 'class' => array( 'search-result--availability-link', 'availability', - 'js-pending', + 'pending', ), 'id' => $id, ), diff --git a/templates/ding-availability-types.tpl.php b/templates/ding-availability-types.tpl.php index f1d9097..30f3b07 100644 --- a/templates/ding-availability-types.tpl.php +++ b/templates/ding-availability-types.tpl.php @@ -8,5 +8,5 @@ */ ?> -

      +

      From 56a83b2dcc29cae18d5379006a1e5b1945895ec3 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 12 Nov 2013 10:02:36 +0100 Subject: [PATCH 56/97] Removed old availability formatter --- ding_availability.field.inc | 135 ------------------------------------ 1 file changed, 135 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 18325d0..8e2de56 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -66,15 +66,6 @@ function ding_availability_field_formatter_info() { 'ting_type', ), ), - 'ding_availability_types' => array( - 'label' => t('With availability information'), - 'field types' => array( - 'ting_collection_types', - ), - 'settings' => array( - 'link' => FALSE, - ), - ), 'ding_availability_with_labels' => array( 'label' => t('Availability information with labels'), 'field types' => array( @@ -84,57 +75,6 @@ function ding_availability_field_formatter_info() { ); } - - -/** - * Implements hook_field_formatter_settings_form(). - */ -function ding_availability_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { - // Get display and current (or default) settings. - $display = $instance['display'][$view_mode]; - $settings = $display['settings']; - - // Initialize the return element (settings form). - $element = array(); - - switch ($field['type']) { - case 'ting_collection_types': - $element['link'] = array( - '#type' => 'checkbox', - '#title' => t('Links'), - '#description' => t('Convert the availability texts into links.'), - '#default_value' => $settings['link'], - ); - break; - } - - return $element; -} - -/** - * Implements hook_field_formatter_settings_summary(). - */ -function ding_availability_field_formatter_settings_summary($field, $instance, $view_mode) { - // Get settings information for the field instance. - $display = $instance['display'][$view_mode]; - $settings = $display['settings']; - $summary = NULL; - - if ($display['type'] == 'ding_collection_types') { - $linking = t('false'); - if ($settings['link']) { - $linking = t('true'); - } - - // Check if linking to the object have been selected. - $summary = t('Link to ting objects: @link', array( - '@link' => $linking, - )); - } - - return $summary; -} - /** * Implements hook_field_formatter_view(). */ @@ -231,81 +171,6 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ ); break; - case 'ding_availability_types': - $id_mapping = array(); - $typed_entities = array(); - // Sort entities into type -> ids. - foreach ($entity->entities as $ent) { - $typed_entities[$ent->type][] = $ent; - } - - foreach ($typed_entities as $type => $entities) { - // Generate an unique id. - $id = drupal_html_id('availability-' . $entities[0]->id . '-' . $type); - - // Extract records' source. - $ac_source = $entities[0]->reply->record['ac:source'][''][0]; - - // Mark as available if it is an online resource. - $available_online = (in_array(drupal_strtolower($type), $online_types)) ? 'available' : ''; - $available_online_label = ($available_online) ? '' . t('online') . '' : ''; - - // Convert type into link. - if ($display['settings']['link']) { - // If there is only 1 object there is a direct link - // else there is a link to the collection. - if (count($entities) == 1) { - $url = entity_uri('ting_object', $entities[0]); - } - else { - $url = entity_uri('ting_collection', $entities[0]); - } - - // The online url can't be used with l(), has it will encode it. - $typelink = '' . check_plain($type) . $available_online_label . ''; - } - - // Create a list element for each type. - $types[] = array( - 'data' => $typelink, - 'id' => $id, - 'class' => array( - 'availability', - drupal_html_class($type), - $available_online, - 'pending', - ), - ); - - $ids = array(); - foreach ($entities as $object_entity) { - $ids[] = $object_entity->localId; - } - - // If item is of type 'library materials' (where we can lookup holding - // data), map the HTML id to the list of entity ids. - if (in_array($ac_source, $lib_materials_types) && !$available_online) { - $id_mapping[$id] = $ids; - } - } - - // Prepare to check holding on the item. - // It's important that this is attached even if empty, else javascript - // will fail because it gets an empty object. - $attached['js'][1] = array( - 'data' => array( - 'ding_availability' => $id_mapping, - 'ding_availability_link' => $display['settings']['link'], - ), 'type' => 'setting', - ); - - $element[$delta] = array( - '#theme' => 'item_list', - '#attached' => $attached, - '#items' => $types, - ); - break; - case 'ding_availability_with_labels': $id_mapping = array(); $typed_entities = array(); From 6e133189308d45f7122ab3207912501175b96301 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 12 Nov 2013 10:49:41 +0100 Subject: [PATCH 57/97] Cleaned up availability javascript --- ding_availability.field.inc | 2 +- js/ding_availability.js | 152 ++++++++++++++++-------------------- 2 files changed, 70 insertions(+), 84 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 8e2de56..d5faa5b 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -222,7 +222,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Add label "Pending" to output as in waiting for information. $output['#types']['pending'] = array( '#theme' => 'ding_availability_type', - '#label' => t('Pending'), + '#label' => t('Pending availability'), '#links' => array(), ); } diff --git a/js/ding_availability.js b/js/ding_availability.js index 36f693f..070ff8a 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -1,8 +1,8 @@ /** - * @file ding.availability.js - * JavaScript behaviours for fetching and displaying availability. + * @file + * JavaScript behaviours for fetching and displaying availability and holdings + * information on TingEntities. */ - (function($) { "use strict"; @@ -14,7 +14,7 @@ var ids = []; var html_ids = []; - // Extract entity ids and add them to the settings array. + // Extract entity ids from Drupal settings array. if (settings.hasOwnProperty('ding_availability')) { $.each(settings.ding_availability, function(id, entity_ids) { $.each(entity_ids, function(index, entity_id) { @@ -27,124 +27,110 @@ }); } - $.each(html_ids, function(index, id) { - $('#' + id).addClass('pending'); - }); - // Fetch availability. if (ids.length > 0) { - $.getJSON(settings.basePath + 'ding_availability/' + (settings.ding_availability_mode ? settings.ding_availability_mode : 'items') + '/' + ids.join(','), {}, update); + var mode = settings.ding_availability_mode ? settings.ding_availability_mode : 'items'; + var path = settings.basePath + 'ding_availability/' + mode + '/' + ids.join(','); + $.ajax({ + dataType: "json", + url: path, + success: function(data) { + $.each(data, function(id, item) { + // Update cache. + Drupal.DADB[id] = item; + }); + + $.each(settings.ding_availability, function(id, entity_ids) { + if (id.match(/^availability-/)) { + // Update availability indicators. + update_availability(id, entity_ids); + } + else { + // Update holding information. + update_holdings(id, entity_ids); + } + }); + } + }); } else { // Apply already fetched availability, if any. if (settings.hasOwnProperty('ding_availability')) { $.each(settings.ding_availability, function(id, entity_ids) { - updateAvailability(id, entity_ids); + update_availability(id, entity_ids); }); } } - function update(data, textData) { - $.each(data, function(id, item) { - // Update cache. - Drupal.DADB[id] = item; - }); - - $.each(settings.ding_availability, function(id, entity_ids) { - if (id.match(/^availability-/)) { - // Update availability indicators. - updateAvailability(id, entity_ids); - } - else { - // Update holding information. - updateHoldings(id, entity_ids); - } - }); - } - - function updateAvailability(id, entity_ids) { + /** + * Update availability on the page. + * + * The array of entity_ids is an array as we only show one availability + * label per material type. So if one of these have an available status + * the label have to reflect this. + * + * @param id + * The element id that this should target. + * @param entity_ids + * Array of entities. + */ + function update_availability(id, entity_ids) { + console.log(entity_ids); var available = false; var reservable = false; - var is_internet = false; $.each(entity_ids, function(index, entity_id) { if (Drupal.DADB[entity_id]) { available = available || Drupal.DADB[entity_id]['available']; reservable = reservable || Drupal.DADB[entity_id]['reservable']; - is_internet = is_internet || Drupal.DADB[entity_id]['is_internet']; } }); var element = $('#' + id); element.removeClass('pending').addClass('processed'); - // Reserve button + // Get hold of the reserve button (it hidden as default, so we may need + // to show it). var reserver_btn = element.parents('.ting-object:first').find('[id^=ding-reservation-reserve-form]'); if (available) { - element.addClass('available'); - - // Add class to reserve button - if (reserver_btn.length) { - reserver_btn.addClass('available'); - } + update_availability_elements(element, reserver_btn, 'available'); } else { - element.addClass('unavailable'); - - // Add class to reserve button - if (reserver_btn.length) { - reserver_btn.addClass('unavailable'); - } + update_availability_elements(element, reserver_btn, 'unavailable'); } if (reservable) { - element.addClass('reservable'); - - // Add class to reserve button - if (reserver_btn.length) { - reserver_btn.addClass('reservable'); - } + update_availability_elements(element, reserver_btn, 'reservable'); } if (!available && !reservable) { - element.addClass('not-reservable'); - - // Add class to reserve button - if (reserver_btn.length) { - reserver_btn.addClass('not-reservable'); - } + update_availability_elements(element, reserver_btn, 'not-reservable'); } + } - if (available || is_internet) { - element.attr('title', Drupal.t('available')); - // If availability is a link append the status inside the link. - if (settings.ding_availability_link === 1) { - $('a', element).append('' + Drupal.t('available') + ''); - } - } - else if (!available && reservable) { - element.attr('title', Drupal.t('on loan')); - // If availability is a link append the status inside the link. - if (settings.ding_availability_link === 1) { - $('a', element).append('' + Drupal.t('on loan') + ''); - }} - else if (available && ! reservable) { - element.attr('title', Drupal.t('not reservable')); - // If availability is a link append the status inside the link. - if (settings.ding_availability_link === 1) { - $('a', element).append('' + Drupal.t('not reservable') + ''); - } - } - else if (!available && !reservable) { - element.attr('title', Drupal.t('unavailable')); - // If availability is a link append the status inside the link. - if (settings.ding_availability_link === 1) { - $('a', element).append('' + Drupal.t('unavailable') + ''); - } + /** + * Add class to both an element and the reservation button. + * + * @param element + * jQuery availability element to add the class to. + * @param btn + * Reservation button to add the class to. + * @param class_name + * The class to add to the elements. + */ + function update_availability_elements(element, btn, class_name) { + element.addClass(class_name); + if (btn.length) { + btn.addClass(class_name); } } - function updateHoldings(id, entity_ids) { + /** + * + * @param id + * @param entity_ids + */ + function update_holdings(id, entity_ids) { var entity_id = entity_ids.pop(); if (Drupal.DADB[entity_id] && (Drupal.DADB[entity_id]['holdings'])) { // Show status for material. From 2743084a656659a16508b31600306e29945f7b1e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 12 Nov 2013 12:52:28 +0100 Subject: [PATCH 58/97] Updated availability to handle the new formatter and clean out the old one --- ding_availability.field.inc | 2 + ding_availability.module | 1 + js/ding_availability.js | 89 +++++++++++++++++++++-- templates/ding-availability-types.tpl.php | 2 +- 4 files changed, 85 insertions(+), 9 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index d5faa5b..02c4d9b 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -202,6 +202,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Add label "online" to output. $output['#types']['online'] = array( '#theme' => 'ding_availability_type', + '#class' => 'js-online', '#label' => t('Online'), '#links' => array(), ); @@ -222,6 +223,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Add label "Pending" to output as in waiting for information. $output['#types']['pending'] = array( '#theme' => 'ding_availability_type', + '#class' => 'js-pending', '#label' => t('Pending availability'), '#links' => array(), ); diff --git a/ding_availability.module b/ding_availability.module index d408778..d2b3251 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -75,6 +75,7 @@ function ding_availability_theme($existing, $type, $theme, $path) { 'ding_availability_type' => array( 'template' => 'ding-availability-type', 'variables' => array( + 'class' => NULL, 'label' => NULL, 'links' => array(), ), diff --git a/js/ding_availability.js b/js/ding_availability.js index 070ff8a..a1f7c83 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -50,6 +50,7 @@ update_holdings(id, entity_ids); } }); + update_availability_remove_pending(); } }); } @@ -59,6 +60,7 @@ $.each(settings.ding_availability, function(id, entity_ids) { update_availability(id, entity_ids); }); + update_availability_remove_pending(); } } @@ -75,9 +77,12 @@ * Array of entities. */ function update_availability(id, entity_ids) { - console.log(entity_ids); + // Default the status to not available and not reservable. var available = false; var reservable = false; + + // Loop over the entity ids and if one has available or reservable + // true save that value. $.each(entity_ids, function(index, entity_id) { if (Drupal.DADB[entity_id]) { available = available || Drupal.DADB[entity_id]['available']; @@ -95,17 +100,82 @@ if (available) { update_availability_elements(element, reserver_btn, 'available'); } + else if (reservable) { + update_availability_elements(element, reserver_btn, 'reservable'); + } + else if (!available && !reservable) { + update_availability_elements(element, reserver_btn, 'not-reservable'); + } else { update_availability_elements(element, reserver_btn, 'unavailable'); } - - if (reservable) { - update_availability_elements(element, reserver_btn, 'reservable'); - } + } - if (!available && !reservable) { - update_availability_elements(element, reserver_btn, 'not-reservable'); + /** + * Helper function to crate labels groups and move the materials based on + * availability. + * + * @param element + * The target element (material that should be moved). + * @param type + * The type of availability the element has. + */ + function update_availability_type(element, type) { + // Select type, if any or create the type. + var groups_wrapper = element.closest('.search-result--availability'); + var group = $('.js-' + type, groups_wrapper); + if (group.length !== 1) { + // Create group. + if (type === 'available') { + // Add as first line. + group = $('

      ' + Drupal.t('Available') + ':

      '); + groups_wrapper.prepend(group); + } + else if (type === 'unavailable') { + // Add last. + group = $('

      ' + Drupal.t('Unavailable') + ':

      '); + group.insertBefore('.js-pending', groups_wrapper); + } + else if (type === 'reservable') { + // First or after available. + group = $('

      ' + Drupal.t('Reservable') + ':

      '); + if ($('.js-available', groups_wrapper).length) { + group.insertAfter($('.js-available', groups_wrapper)); + } + else { + groups_wrapper.prepend(group); + } + } + else { + // Add last to not-reservable. + group = $('

      ' + Drupal.t('Not reservable') + ':

      '); + groups_wrapper.append(group); + } } + + // Move the element into that type. + group.append(element); + } + + /** + * Removes js-pending groups (labels) if they are empty or changes the + * label to "Can be obtained". This should be called as the last function + * in updating availability information and see as a clean-up function. + */ + function update_availability_remove_pending() { + // Loop over all pending availability groups. + $('.js-pending').each(function() { + var elm = $(this); + var children = elm.children(); + if (children.length) { + // Change the label from pending. + elm.contents().first()[0].textContent = Drupal.t('Can be obtained:') + ' '; + } + else { + // The current pending group is empty, so simply remove it. + elm.remove(); + } + }); } /** @@ -123,10 +193,13 @@ if (btn.length) { btn.addClass(class_name); } + + update_availability_type(element, class_name); } /** - * + * Insert holdings information. + * * @param id * @param entity_ids */ diff --git a/templates/ding-availability-types.tpl.php b/templates/ding-availability-types.tpl.php index 30f3b07..0e4b9c3 100644 --- a/templates/ding-availability-types.tpl.php +++ b/templates/ding-availability-types.tpl.php @@ -8,5 +8,5 @@ */ ?> -

      +

      From 8b6cd170b7084d08b0eff75fe06c3b552a04ce8e Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 12 Nov 2013 13:33:57 +0100 Subject: [PATCH 59/97] Fixed link to collction if more than one material is behind availability label --- ding_availability.field.inc | 8 +++++++- js/ding_availability.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 02c4d9b..97a404c 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -194,7 +194,13 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $ac_source = $entities[0]->reply->record['ac:source'][''][0]; // Get link to first element in the collection of the current type. - $url = entity_uri('ting_object', $entities[0]); + // If more than one exists link to the collection. + if (count($entities) == 1) { + $url = entity_uri('ting_object', $entities[0]); + } + else { + $url = entity_uri('ting_collection', $entities[0]); + } // Mark as available if it is an online resource. if (in_array(drupal_strtolower($type), $online_types)) { diff --git a/js/ding_availability.js b/js/ding_availability.js index a1f7c83..3acf17a 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -199,7 +199,7 @@ /** * Insert holdings information. - * + * * @param id * @param entity_ids */ From 7ff806046a3b7d5bc7411e2e1c4b1ac7f6542617 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 12 Nov 2013 14:35:51 +0100 Subject: [PATCH 60/97] Fixed javascript in availability to match both formatters --- ding_availability.field.inc | 22 +++- js/ding_availability.js | 151 ++++++------------------- js/ding_availability_labels.js | 197 +++++++++++++++++++++++++++++++++ 3 files changed, 249 insertions(+), 121 deletions(-) create mode 100644 js/ding_availability_labels.js diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 97a404c..44d892a 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -86,9 +86,6 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Attach front-end style and JS to the element. foreach ($items as $delta => $item) { $attached = array( - 'js' => array( - drupal_get_path('module', 'ding_availability') . '/js/ding_availability.js', - ), 'css' => array( drupal_get_path('module', 'ding_availability') . '/css/ding_availability.css', ), @@ -104,6 +101,11 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Generate an unique id. $id = drupal_html_id('holdings-' . $entity->id); + // Add javascript. + $attached['js'] = array( + drupal_get_path('module', 'ding_availability') . '/js/ding_availability.js', + ); + // If item is of type 'library materials' (where we can lookup holding // data), prepare to check holding on the item. $holding_types = variable_get('ding_availability_holdings_types', _ding_availability_holdings_default_types()); @@ -127,6 +129,11 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ break; case 'ding_availability_item': + // Add javascript. + $attached['js'] = array( + drupal_get_path('module', 'ding_availability') . '/js/ding_availability.js', + ); + $element[$delta] = array( '#markup' => '
      ', '#attached' => $attached, @@ -140,6 +147,11 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // Mark as available if it is an online resource, $available_online = (in_array(drupal_strtolower($entity->type), $online_types)) ? 'available' : 'not-available-online'; + // Add javascript. + $attached['js'] = array( + drupal_get_path('module', 'ding_availability') . '/js/ding_availability.js', + ); + // If item is of type 'library materials' (where we can lookup holding // data), prepare to check holding on the item. if (in_array($ac_source, $lib_materials_types)) { @@ -180,12 +192,14 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ $typed_entities[$ent->type][] = $ent; } + // Build basic output render array. $output = array( '#theme' => 'ding_availability_types', '#types' => array(), '#attached' => $attached, ); + // Loop over the different material types. foreach ($typed_entities as $type => $entities) { // Generate an unique id. $id = drupal_html_id('availability-' . $entities[0]->id . '-' . $type); @@ -275,7 +289,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ 'ding_availability' => $id_mapping, ), 'type' => 'setting', ); - $output['#attached']['js'][] = drupal_get_path('module', 'ding_availability') . '/js/ding_availability.js'; + $output['#attached']['js'][] = drupal_get_path('module', 'ding_availability') . '/js/ding_availability_labels.js'; $element[$delta] = $output; break; diff --git a/js/ding_availability.js b/js/ding_availability.js index 3acf17a..2781a9a 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -1,8 +1,8 @@ /** - * @file - * JavaScript behaviours for fetching and displaying availability and holdings - * information on TingEntities. + * @file ding.availability.js + * JavaScript behaviours for fetching and displaying availability. */ + (function($) { "use strict"; @@ -14,7 +14,7 @@ var ids = []; var html_ids = []; - // Extract entity ids from Drupal settings array. + // Extract entity ids and add them to the settings array. if (settings.hasOwnProperty('ding_availability')) { $.each(settings.ding_availability, function(id, entity_ids) { $.each(entity_ids, function(index, entity_id) { @@ -27,6 +27,10 @@ }); } + $.each(html_ids, function(index, id) { + $('#' + id).addClass('pending'); + }); + // Fetch availability. if (ids.length > 0) { var mode = settings.ding_availability_mode ? settings.ding_availability_mode : 'items'; @@ -50,7 +54,6 @@ update_holdings(id, entity_ids); } }); - update_availability_remove_pending(); } }); } @@ -60,149 +63,63 @@ $.each(settings.ding_availability, function(id, entity_ids) { update_availability(id, entity_ids); }); - update_availability_remove_pending(); } } - /** - * Update availability on the page. - * - * The array of entity_ids is an array as we only show one availability - * label per material type. So if one of these have an available status - * the label have to reflect this. - * - * @param id - * The element id that this should target. - * @param entity_ids - * Array of entities. - */ function update_availability(id, entity_ids) { - // Default the status to not available and not reservable. var available = false; var reservable = false; - - // Loop over the entity ids and if one has available or reservable - // true save that value. + var is_internet = false; $.each(entity_ids, function(index, entity_id) { if (Drupal.DADB[entity_id]) { available = available || Drupal.DADB[entity_id]['available']; reservable = reservable || Drupal.DADB[entity_id]['reservable']; + is_internet = is_internet || Drupal.DADB[entity_id]['is_internet']; } }); var element = $('#' + id); element.removeClass('pending').addClass('processed'); - // Get hold of the reserve button (it hidden as default, so we may need - // to show it). + // Reserve button var reserver_btn = element.parents('.ting-object:first').find('[id^=ding-reservation-reserve-form]'); if (available) { - update_availability_elements(element, reserver_btn, 'available'); - } - else if (reservable) { - update_availability_elements(element, reserver_btn, 'reservable'); - } - else if (!available && !reservable) { - update_availability_elements(element, reserver_btn, 'not-reservable'); + element.addClass('available'); + + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('available'); + } } else { - update_availability_elements(element, reserver_btn, 'unavailable'); - } - } + element.addClass('unavailable'); - /** - * Helper function to crate labels groups and move the materials based on - * availability. - * - * @param element - * The target element (material that should be moved). - * @param type - * The type of availability the element has. - */ - function update_availability_type(element, type) { - // Select type, if any or create the type. - var groups_wrapper = element.closest('.search-result--availability'); - var group = $('.js-' + type, groups_wrapper); - if (group.length !== 1) { - // Create group. - if (type === 'available') { - // Add as first line. - group = $('

      ' + Drupal.t('Available') + ':

      '); - groups_wrapper.prepend(group); + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('unavailable'); } - else if (type === 'unavailable') { - // Add last. - group = $('

      ' + Drupal.t('Unavailable') + ':

      '); - group.insertBefore('.js-pending', groups_wrapper); - } - else if (type === 'reservable') { - // First or after available. - group = $('

      ' + Drupal.t('Reservable') + ':

      '); - if ($('.js-available', groups_wrapper).length) { - group.insertAfter($('.js-available', groups_wrapper)); - } - else { - groups_wrapper.prepend(group); - } - } - else { - // Add last to not-reservable. - group = $('

      ' + Drupal.t('Not reservable') + ':

      '); - groups_wrapper.append(group); + } + + if (reservable) { + element.addClass('reservable'); + + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('reservable'); } } - // Move the element into that type. - group.append(element); - } + if (!available && !reservable) { + element.addClass('not-reservable'); - /** - * Removes js-pending groups (labels) if they are empty or changes the - * label to "Can be obtained". This should be called as the last function - * in updating availability information and see as a clean-up function. - */ - function update_availability_remove_pending() { - // Loop over all pending availability groups. - $('.js-pending').each(function() { - var elm = $(this); - var children = elm.children(); - if (children.length) { - // Change the label from pending. - elm.contents().first()[0].textContent = Drupal.t('Can be obtained:') + ' '; + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('not-reservable'); } - else { - // The current pending group is empty, so simply remove it. - elm.remove(); - } - }); - } - - /** - * Add class to both an element and the reservation button. - * - * @param element - * jQuery availability element to add the class to. - * @param btn - * Reservation button to add the class to. - * @param class_name - * The class to add to the elements. - */ - function update_availability_elements(element, btn, class_name) { - element.addClass(class_name); - if (btn.length) { - btn.addClass(class_name); } - - update_availability_type(element, class_name); } - /** - * Insert holdings information. - * - * @param id - * @param entity_ids - */ function update_holdings(id, entity_ids) { var entity_id = entity_ids.pop(); if (Drupal.DADB[entity_id] && (Drupal.DADB[entity_id]['holdings'])) { diff --git a/js/ding_availability_labels.js b/js/ding_availability_labels.js new file mode 100644 index 0000000..6786742 --- /dev/null +++ b/js/ding_availability_labels.js @@ -0,0 +1,197 @@ +/** + * @file + * JavaScript behaviours for fetching and displaying availability information + * on TingEntities. + */ +(function($) { + "use strict"; + + // Cache of fetched availability information. + Drupal.DADB = {}; + + Drupal.behaviors.dingAvailabilityAttach = { + attach: function(context, settings) { + var ids = []; + var html_ids = []; + + // Extract entity ids from Drupal settings array. + if (settings.hasOwnProperty('ding_availability')) { + $.each(settings.ding_availability, function(id, entity_ids) { + $.each(entity_ids, function(index, entity_id) { + if (Drupal.DADB[entity_id] === undefined) { + Drupal.DADB[entity_id] = null; + ids.push(entity_id); + html_ids.push(id); + } + }); + }); + } + + // Fetch availability. + if (ids.length > 0) { + var mode = settings.ding_availability_mode ? settings.ding_availability_mode : 'items'; + var path = settings.basePath + 'ding_availability/' + mode + '/' + ids.join(','); + $.ajax({ + dataType: "json", + url: path, + success: function(data) { + $.each(data, function(id, item) { + // Update cache. + Drupal.DADB[id] = item; + }); + + $.each(settings.ding_availability, function(id, entity_ids) { + if (id.match(/^availability-/)) { + // Update availability indicators. + update_availability(id, entity_ids); + } + }); + update_availability_remove_pending(); + } + }); + } + else { + // Apply already fetched availability, if any. + if (settings.hasOwnProperty('ding_availability')) { + $.each(settings.ding_availability, function(id, entity_ids) { + update_availability(id, entity_ids); + }); + update_availability_remove_pending(); + } + } + + /** + * Update availability on the page. + * + * The array of entity_ids is an array as we only show one availability + * label per material type. So if one of these have an available status + * the label have to reflect this. + * + * @param id + * The element id that this should target. + * @param entity_ids + * Array of entities. + */ + function update_availability(id, entity_ids) { + // Default the status to not available and not reservable. + var available = false; + var reservable = false; + + // Loop over the entity ids and if one has available or reservable + // true save that value. + $.each(entity_ids, function(index, entity_id) { + if (Drupal.DADB[entity_id]) { + available = available || Drupal.DADB[entity_id]['available']; + reservable = reservable || Drupal.DADB[entity_id]['reservable']; + } + }); + + var element = $('#' + id); + element.removeClass('pending').addClass('processed'); + + // Get hold of the reserve button (it hidden as default, so we may need + // to show it). + var reserver_btn = element.parents('.ting-object:first').find('[id^=ding-reservation-reserve-form]'); + + if (available) { + update_availability_elements(element, reserver_btn, 'available'); + } + else if (reservable) { + update_availability_elements(element, reserver_btn, 'reservable'); + } + else if (!available && !reservable) { + update_availability_elements(element, reserver_btn, 'not-reservable'); + } + else { + update_availability_elements(element, reserver_btn, 'unavailable'); + } + } + + /** + * Helper function to crate labels groups and move the materials based on + * availability. + * + * @param element + * The target element (material that should be moved). + * @param type + * The type of availability the element has. + */ + function update_availability_type(element, type) { + // Select type, if any or create the type. + var groups_wrapper = element.closest('.search-result--availability'); + var group = $('.js-' + type, groups_wrapper); + if (group.length !== 1) { + // Create group. + if (type === 'available') { + // Add as first line. + group = $('

      ' + Drupal.t('Available') + ':

      '); + groups_wrapper.prepend(group); + } + else if (type === 'unavailable') { + // Add last. + group = $('

      ' + Drupal.t('Unavailable') + ':

      '); + group.insertBefore('.js-pending', groups_wrapper); + } + else if (type === 'reservable') { + // First or after available. + group = $('

      ' + Drupal.t('Reservable') + ':

      '); + if ($('.js-available', groups_wrapper).length) { + group.insertAfter($('.js-available', groups_wrapper)); + } + else { + groups_wrapper.prepend(group); + } + } + else { + // Add last to not-reservable. + group = $('

      ' + Drupal.t('Not reservable') + ':

      '); + groups_wrapper.append(group); + } + } + + // Move the element into that type. + group.append(element); + } + + /** + * Removes js-pending groups (labels) if they are empty or changes the + * label to "Can be obtained". This should be called as the last function + * in updating availability information and see as a clean-up function. + */ + function update_availability_remove_pending() { + // Loop over all pending availability groups. + $('.js-pending').each(function() { + var elm = $(this); + var children = elm.children(); + if (children.length) { + // Change the label from pending. + elm.contents().first()[0].textContent = Drupal.t('Can be obtained:') + ' '; + } + else { + // The current pending group is empty, so simply remove it. + elm.remove(); + } + }); + } + + /** + * Add class to both an element and the reservation button. + * + * @param element + * jQuery availability element to add the class to. + * @param btn + * Reservation button to add the class to. + * @param class_name + * The class to add to the elements. + */ + function update_availability_elements(element, btn, class_name) { + element.addClass(class_name); + if (btn.length) { + btn.addClass(class_name); + } + + update_availability_type(element, class_name); + } + } + }; +})(jQuery); From de40d0767a1ffbc91366472735c7778a29644a10 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 26 Nov 2013 12:45:03 +0100 Subject: [PATCH 61/97] Updated makefile to point to tag 7.x-1.0-beta3 --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index 317f2e5..987edb3 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -11,5 +11,5 @@ projects[virtual_field][version] = "1.1" 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 ccc10026ed6c5a251078aff365f86aa257e31b3d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 27 Nov 2013 16:12:11 +0100 Subject: [PATCH 62/97] Fixed javascript to work in IE9 and older versions --- js/ding_availability_labels.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/ding_availability_labels.js b/js/ding_availability_labels.js index 6786742..c3d0661 100644 --- a/js/ding_availability_labels.js +++ b/js/ding_availability_labels.js @@ -165,7 +165,8 @@ var children = elm.children(); if (children.length) { // Change the label from pending. - elm.contents().first()[0].textContent = Drupal.t('Can be obtained:') + ' '; + var label = elm.contents().first()[0]; + label.nodeValue = Drupal.t('Can be obtained:') + ' '; } else { // The current pending group is empty, so simply remove it. From c26bd7b5dbbfc7eb21caa8f48b4d35a268f29f3c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 3 Dec 2013 20:12:18 +0100 Subject: [PATCH 63/97] Updated default availbility javascript so it will not run again after an ajax reservation --- js/ding_availability.js | 226 ++++++++++++++++++++++------------------ 1 file changed, 124 insertions(+), 102 deletions(-) diff --git a/js/ding_availability.js b/js/ding_availability.js index 2781a9a..0e6e780 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -9,124 +9,146 @@ // Cache of fetched availability information. Drupal.DADB = {}; - Drupal.behaviors.dingAvailabilityAttach = { - attach: function(context, settings) { - var ids = []; - var html_ids = []; - - // Extract entity ids and add them to the settings array. - if (settings.hasOwnProperty('ding_availability')) { - $.each(settings.ding_availability, function(id, entity_ids) { - $.each(entity_ids, function(index, entity_id) { - if (Drupal.DADB[entity_id] === undefined) { - Drupal.DADB[entity_id] = null; - ids.push(entity_id); - html_ids.push(id); - } - }); + $(document).ready(function() { + var settings = Drupal.settings; + var ids = []; + var html_ids = []; + + // Extract entity ids and add them to the settings array. + if (settings.hasOwnProperty('ding_availability')) { + $.each(settings.ding_availability, function(id, entity_ids) { + $.each(entity_ids, function(index, entity_id) { + if (Drupal.DADB[entity_id] === undefined) { + Drupal.DADB[entity_id] = null; + ids.push(entity_id); + html_ids.push(id); + } }); - } - - $.each(html_ids, function(index, id) { - $('#' + id).addClass('pending'); }); + } + + $.each(html_ids, function(index, id) { + $('#' + id).addClass('pending'); + }); + + // Fetch availability. + if (ids.length > 0) { + var mode = settings.ding_availability_mode ? settings.ding_availability_mode : 'items'; + var path = settings.basePath + 'ding_availability/' + mode + '/' + ids.join(','); + $.ajax({ + dataType: "json", + url: path, + success: function(data) { + $.each(data, function(id, item) { + // Update cache. + Drupal.DADB[id] = item; + }); - // Fetch availability. - if (ids.length > 0) { - var mode = settings.ding_availability_mode ? settings.ding_availability_mode : 'items'; - var path = settings.basePath + 'ding_availability/' + mode + '/' + ids.join(','); - $.ajax({ - dataType: "json", - url: path, - success: function(data) { - $.each(data, function(id, item) { - // Update cache. - Drupal.DADB[id] = item; - }); - - $.each(settings.ding_availability, function(id, entity_ids) { - if (id.match(/^availability-/)) { - // Update availability indicators. - update_availability(id, entity_ids); - } - else { - // Update holding information. - update_holdings(id, entity_ids); - } - }); - } - }); - } - else { - // Apply already fetched availability, if any. - if (settings.hasOwnProperty('ding_availability')) { $.each(settings.ding_availability, function(id, entity_ids) { - update_availability(id, entity_ids); + if (id.match(/^availability-/)) { + // Update availability indicators. + ding_availability_update_availability(id, entity_ids); + } + else { + // Update holding information. + ding_availability_update_holdings(id, entity_ids); + } }); } - } - - function update_availability(id, entity_ids) { - var available = false; - var reservable = false; - var is_internet = false; - $.each(entity_ids, function(index, entity_id) { - if (Drupal.DADB[entity_id]) { - available = available || Drupal.DADB[entity_id]['available']; - reservable = reservable || Drupal.DADB[entity_id]['reservable']; - is_internet = is_internet || Drupal.DADB[entity_id]['is_internet']; - } + }); + } + else { + // Apply already fetched availability, if any. + if (settings.hasOwnProperty('ding_availability')) { + $.each(settings.ding_availability, function(id, entity_ids) { + ding_availability_update_availability(id, entity_ids); }); + } + } + }); + + + /** + * Update availability information. + * + * Add classes to reservation texts and display reservation button based on + * availability information + * + * @param id + * HTML id of the availability to update. + * @param entity_ids + * Entity id for which to update availability information. + */ + function ding_availability_update_availability(id, entity_ids) { + var available = false; + var reservable = false; + var is_internet = false; + $.each(entity_ids, function(index, entity_id) { + if (Drupal.DADB[entity_id]) { + available = available || Drupal.DADB[entity_id]['available']; + reservable = reservable || Drupal.DADB[entity_id]['reservable']; + is_internet = is_internet || Drupal.DADB[entity_id]['is_internet']; + } + }); - var element = $('#' + id); - element.removeClass('pending').addClass('processed'); - - // Reserve button - var reserver_btn = element.parents('.ting-object:first').find('[id^=ding-reservation-reserve-form]'); + var element = $('#' + id); + element.removeClass('pending').addClass('processed'); - if (available) { - element.addClass('available'); + // Reserve button + var reserver_btn = element.parents('.ting-object:first').find('[id^=ding-reservation-reserve-form]'); - // Add class to reserve button - if (reserver_btn.length) { - reserver_btn.addClass('available'); - } - } - else { - element.addClass('unavailable'); + if (available) { + element.addClass('available'); - // Add class to reserve button - if (reserver_btn.length) { - reserver_btn.addClass('unavailable'); - } - } - - if (reservable) { - element.addClass('reservable'); + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('available'); + } + } + else { + element.addClass('unavailable'); - // Add class to reserve button - if (reserver_btn.length) { - reserver_btn.addClass('reservable'); - } - } + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('unavailable'); + } + } - if (!available && !reservable) { - element.addClass('not-reservable'); + if (reservable) { + element.addClass('reservable'); - // Add class to reserve button - if (reserver_btn.length) { - reserver_btn.addClass('not-reservable'); - } - } + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('reservable'); } + } - function update_holdings(id, entity_ids) { - var entity_id = entity_ids.pop(); - if (Drupal.DADB[entity_id] && (Drupal.DADB[entity_id]['holdings'])) { - // Show status for material. - $('#' + id).append(Drupal.DADB[entity_id].html); - } + if (!available && !reservable) { + element.addClass('not-reservable'); + + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('not-reservable'); } } - }; + } + + /** + * Update availability holdings information. + * + * Insert HTML with information about where the entities are located. + * + * @param id + * HTML id of the availability to update. + * @param entity_ids + * Entity id for which to update availability holdings information. + */ + function ding_availability_update_holdings(id, entity_ids) { + var entity_id = entity_ids.pop(); + if (Drupal.DADB[entity_id] && (Drupal.DADB[entity_id]['holdings'])) { + // Show status for material. + $('#' + id).append(Drupal.DADB[entity_id].html); + } + } + })(jQuery); From 27aa6bbf9e4b8c64d0b0e5c51d5af9d6e0897090 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 5 Dec 2013 12:31:18 +0100 Subject: [PATCH 64/97] Updated library material types to use configuration variable --- ding_availability.field.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 44d892a..462b6b6 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -81,7 +81,7 @@ function ding_availability_field_formatter_info() { function ding_availability_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); $online_types = variable_get('ting_online_types', _ting_default_online_types()); - $lib_materials_types = array('Bibliotekets materialer', 'Bibliotekskatalog'); + $lib_materials_types = variable_get('ting_reservable_sources', _ting_default_reservable_sources()); // Attach front-end style and JS to the element. foreach ($items as $delta => $item) { From fb20b3e99e1c7c40aae92ead7f32167f9a5fb2a0 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 5 Dec 2013 12:41:39 +0100 Subject: [PATCH 65/97] Ensured that ac.source match library material type (strtolower) --- ding_availability.field.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 462b6b6..ff77c92 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -81,7 +81,7 @@ function ding_availability_field_formatter_info() { function ding_availability_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); $online_types = variable_get('ting_online_types', _ting_default_online_types()); - $lib_materials_types = variable_get('ting_reservable_sources', _ting_default_reservable_sources()); + $reservable_sources = variable_get('ting_reservable_sources', _ting_default_reservable_sources()); // Attach front-end style and JS to the element. foreach ($items as $delta => $item) { @@ -109,7 +109,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // If item is of type 'library materials' (where we can lookup holding // data), prepare to check holding on the item. $holding_types = variable_get('ding_availability_holdings_types', _ding_availability_holdings_default_types()); - if (in_array($ac_source, $lib_materials_types) && in_array(strtolower($entity->type), $holding_types)) { + if (in_array(strtolower($ac_source), $reservable_sources) && in_array(strtolower($entity->type), $holding_types)) { $attached['js'][] = array( 'data' => array( 'ding_availability_mode' => 'holdings', @@ -154,7 +154,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // If item is of type 'library materials' (where we can lookup holding // data), prepare to check holding on the item. - if (in_array($ac_source, $lib_materials_types)) { + if (in_array(strtolower($ac_source), $reservable_sources)) { $attached['js'][1] = array( 'data' => array( 'ding_availability' => array( @@ -273,7 +273,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ // If item is of type 'library materials' (where we can lookup // availability data), map the HTML id to the list of entity ids. // This is for the current material type group (book, cd, etc.). - if (in_array($ac_source, $lib_materials_types) && !in_array(drupal_strtolower($type), $online_types)) { + if (in_array(strtolower($ac_source), $reservable_sources) && !in_array(drupal_strtolower($type), $online_types)) { $id_mapping[$id] = array(); foreach ($entities as $object_entity) { $id_mapping[$id][] = $object_entity->localId; From 1ae69991195b2570863471ea211b73d9343eaf31 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 5 Dec 2013 21:48:04 +0100 Subject: [PATCH 66/97] Added loader to holdings information formatter --- ding_availability.field.inc | 3 ++- js/ding_availability.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index ff77c92..bd17ea5 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -121,7 +121,8 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ ); $element[$delta] = array( - '#markup' => '
      ', + // @todo: move this into tpl file. + '#markup' => '

      ' . t('Fetching holdings information.') . '

      ', '#attached' => $attached, ); } diff --git a/js/ding_availability.js b/js/ding_availability.js index 0e6e780..65abb9e 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -147,7 +147,7 @@ var entity_id = entity_ids.pop(); if (Drupal.DADB[entity_id] && (Drupal.DADB[entity_id]['holdings'])) { // Show status for material. - $('#' + id).append(Drupal.DADB[entity_id].html); + $('#' + id).html(Drupal.DADB[entity_id].html); } } From 8c4ae0fb10310ab43c8918ce53cccb3657cb8d74 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 12 Dec 2013 13:12:25 +0100 Subject: [PATCH 67/97] Updated makefile to point to tag 7.x-1.0-beta4 --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index 987edb3..7129e76 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -11,5 +11,5 @@ projects[virtual_field][version] = "1.1" 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 3dea2655ef007857144503da041805ed72675a42 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 18 Dec 2013 05:02:19 +0100 Subject: [PATCH 68/97] Updated makefile to point to tag 7.x-1.0-beta5 --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index 7129e76..9aee773 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -11,5 +11,5 @@ projects[virtual_field][version] = "1.1" 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 b3a12d197d5878dee13ee131b69ba8cd8cf5b517 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 19 Dec 2013 17:27:42 +0100 Subject: [PATCH 69/97] Updated default availability types to get holdings for --- ding_availability.module | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ding_availability.module b/ding_availability.module index d2b3251..db7791f 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -352,6 +352,7 @@ function _ding_availability_holdings_default_types() { 'gameboy advance', 'xbox', 'grammofonplade', + 'wii u', 'serie', 'avis', 'spil', @@ -376,5 +377,6 @@ function _ding_availability_holdings_default_types() { 'arkitekturtegning', 'emnekasse', 'spolelydbÄnd', + 'udstillingsmontage', ); } From 446c1b0a368d912e93e2cf5926b3fd019936a677 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 20 Dec 2013 10:02:44 +0100 Subject: [PATCH 70/97] Setting availability to online for material with online url --- ding_availability.field.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index bd17ea5..0ea0e54 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -218,7 +218,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ } // Mark as available if it is an online resource. - if (in_array(drupal_strtolower($type), $online_types)) { + if (in_array(drupal_strtolower($type), $online_types) || isset($entities[0]->online_url)) { if (!isset($output['#types']['online'])) { // Add label "online" to output. $output['#types']['online'] = array( From 03bb8ff85acfff2286d80acc366a5da2066de8e4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 20 Dec 2013 15:38:38 +0100 Subject: [PATCH 71/97] Updated makefile to point to tag 7.x-1.0-rc1 --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index 9aee773..ec3381a 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -11,5 +11,5 @@ projects[virtual_field][version] = "1.1" 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 f831d279a0aaf681d56f14f14f0a285bd05a4a20 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 8 Jan 2014 21:57:00 +0100 Subject: [PATCH 72/97] Updated makefile to point to tag 7.x-1.0-rc2 --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index ec3381a..ea56855 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -11,5 +11,5 @@ projects[virtual_field][version] = "1.1" 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 c471bebae06ab8c3a4f60f634400e2e1f31cd96c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 20 Jan 2014 12:24:34 +0100 Subject: [PATCH 73/97] Updated makefile to point to tag 7.x-1.0-rc3 --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index ea56855..f5801fd 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -11,5 +11,5 @@ projects[virtual_field][version] = "1.1" 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 2a477c535f82fa9a9626bc48b0547ec53b837f19 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 3 Feb 2014 11:15:28 +0100 Subject: [PATCH 74/97] Updated makefile to point to ding2 master branches --- ding_availability.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ding_availability.make b/ding_availability.make index f5801fd..bdc7ef2 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -10,6 +10,6 @@ projects[virtual_field][version] = "1.1" 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 53298edf30295b13273139e3ba6fc7b3e2b64fbc Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 25 Feb 2014 13:26:54 +0100 Subject: [PATCH 75/97] Updated the javascript to handle the new reservation buttons --- js/ding_availability.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/ding_availability.js b/js/ding_availability.js index 65abb9e..aade951 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -95,7 +95,7 @@ element.removeClass('pending').addClass('processed'); // Reserve button - var reserver_btn = element.parents('.ting-object:first').find('[id^=ding-reservation-reserve-form]'); + var reserver_btn = element.parents('.ting-object:first').find('.reserve-button'); if (available) { element.addClass('available'); From 73fd36b4fe9d699e9e93a81b448423407cc8f1b6 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 19 Mar 2014 16:07:41 +0100 Subject: [PATCH 76/97] Fixed index error in availability render call --- templates/ding-availability-type.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/ding-availability-type.tpl.php b/templates/ding-availability-type.tpl.php index 16b9e35..55be665 100644 --- a/templates/ding-availability-type.tpl.php +++ b/templates/ding-availability-type.tpl.php @@ -10,5 +10,5 @@ ?> : - + From 9de0f3cc47a88d85ba3dbfb1d7e9b630effc2d63 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 30 Apr 2014 10:21:44 +0200 Subject: [PATCH 77/97] Added missing new line --- css/ding_availability_legend.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/ding_availability_legend.css b/css/ding_availability_legend.css index f909d0e..0e39d9c 100644 --- a/css/ding_availability_legend.css +++ b/css/ding_availability_legend.css @@ -39,4 +39,4 @@ .availability-legend-item.unreservable img { background-color: #a32e10; /* Red */ -} \ No newline at end of file +} From 9144e3c9277c94b37e217c3b71da407c0d6c15c9 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 30 Apr 2014 10:21:44 +0200 Subject: [PATCH 78/97] Added missing new line --- css/ding_availability_legend.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/ding_availability_legend.css b/css/ding_availability_legend.css index f909d0e..0e39d9c 100644 --- a/css/ding_availability_legend.css +++ b/css/ding_availability_legend.css @@ -39,4 +39,4 @@ .availability-legend-item.unreservable img { background-color: #a32e10; /* Red */ -} \ No newline at end of file +} From 40df3da18a1abdde3aa18f2e2ec32a419f87fa2f Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 30 Apr 2014 10:54:47 +0200 Subject: [PATCH 79/97] Renamed home variable to available --- ding_availability.module | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ding_availability.module b/ding_availability.module index db7791f..9d655d7 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -176,7 +176,7 @@ function ding_availability_holdings($provider_ids) { $header = array( 'placement' => t('Placement'), 'copies' => t('Copies'), - 'home' => t('At home'), + 'available' => t('At home'), ); $attributes = array( @@ -220,9 +220,9 @@ function ding_availability_holdings_row($holding) { $row['copies'] = isset($holding['total_count']) ? (int) $holding['total_count'] : 0; // Calculate copies home. - $home = isset($holding['available_count']) ? (int) $holding['available_count'] : 0; - $home += isset($holding['reference_count']) ? (int) $holding['reference_count'] : 0; - $row['home'] = $home; + $available = isset($holding['available_count']) ? (int) $holding['available_count'] : 0; + $available += isset($holding['reference_count']) ? (int) $holding['reference_count'] : 0; + $row['available'] = $available; return $row; } @@ -297,7 +297,6 @@ function ding_availability_render_legend() { $format_items[] = '
      '; return '
      ' . implode($format_items) . '
      '; - } /** From 3ea757a6593e2e3c523b09622b479f03b89fa0ae Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 30 Apr 2014 11:10:35 +0200 Subject: [PATCH 80/97] Moved ":" outside label in JavaScript translation string --- js/ding_availability_labels.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/ding_availability_labels.js b/js/ding_availability_labels.js index c3d0661..e3f2479 100644 --- a/js/ding_availability_labels.js +++ b/js/ding_availability_labels.js @@ -166,7 +166,7 @@ if (children.length) { // Change the label from pending. var label = elm.contents().first()[0]; - label.nodeValue = Drupal.t('Can be obtained:') + ' '; + label.nodeValue = Drupal.t('Can be obtained') + ': '; } else { // The current pending group is empty, so simply remove it. From 7e027253d25f2c91188c04d8cbe633dc24d11ff6 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 30 Apr 2014 11:10:35 +0200 Subject: [PATCH 81/97] Moved ":" outside label in JavaScript translation string --- js/ding_availability_labels.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/ding_availability_labels.js b/js/ding_availability_labels.js index c3d0661..e3f2479 100644 --- a/js/ding_availability_labels.js +++ b/js/ding_availability_labels.js @@ -166,7 +166,7 @@ if (children.length) { // Change the label from pending. var label = elm.contents().first()[0]; - label.nodeValue = Drupal.t('Can be obtained:') + ' '; + label.nodeValue = Drupal.t('Can be obtained') + ': '; } else { // The current pending group is empty, so simply remove it. From 4e3928b2768defb501fe8441aee5274c42bf2b42 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 6 May 2014 12:23:19 +0200 Subject: [PATCH 82/97] Updated virtual field to version 1.2 --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index 9439b26..5762f40 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -4,7 +4,7 @@ core = 7.x ; contrib projects[virtual_field][subdir] = "contrib" -projects[virtual_field][version] = "1.1" +projects[virtual_field][version] = "1.2" ; Ding2 From dc5aba62de6ba369215c798a95c20d70b9eea302 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 15 May 2014 12:55:18 +0200 Subject: [PATCH 83/97] Issue #373 cableman: Fixed loading of relations only when needed --- ding_availability.field.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 0ea0e54..086a95f 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -218,7 +218,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ } // Mark as available if it is an online resource. - if (in_array(drupal_strtolower($type), $online_types) || isset($entities[0]->online_url)) { + if (in_array(drupal_strtolower($type), $online_types) || $entities[0]->getOnline_url(FALSE)) { if (!isset($output['#types']['online'])) { // Add label "online" to output. $output['#types']['online'] = array( From 021f2a558aac0d9e106ddf062d1df4882146d0cb Mon Sep 17 00:00:00 2001 From: Martin Cording Date: Fri, 22 Aug 2014 16:31:00 +0200 Subject: [PATCH 84/97] DDBEASY-45 - Availability fixes. --- ding_availability.field.inc | 3 +- js/ding_availability.js | 66 ++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 086a95f..6d16fbe 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -80,7 +80,7 @@ function ding_availability_field_formatter_info() { */ function ding_availability_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); - $online_types = variable_get('ting_online_types', _ting_default_online_types()); + $online_types = array_filter(variable_get('ting_online_types', _ting_default_online_types())); $reservable_sources = variable_get('ting_reservable_sources', _ting_default_reservable_sources()); // Attach front-end style and JS to the element. @@ -291,6 +291,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ ), 'type' => 'setting', ); $output['#attached']['js'][] = drupal_get_path('module', 'ding_availability') . '/js/ding_availability_labels.js'; + $output['#attached']['js'][] = drupal_get_path('module', 'ding_availability') . '/js/ding_availability.js'; $element[$delta] = $output; break; diff --git a/js/ding_availability.js b/js/ding_availability.js index aade951..a456ba3 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -88,49 +88,49 @@ available = available || Drupal.DADB[entity_id]['available']; reservable = reservable || Drupal.DADB[entity_id]['reservable']; is_internet = is_internet || Drupal.DADB[entity_id]['is_internet']; - } - }); - var element = $('#' + id); - element.removeClass('pending').addClass('processed'); + var element = $('#' + id); + element.removeClass('pending').addClass('processed'); - // Reserve button - var reserver_btn = element.parents('.ting-object:first').find('.reserve-button'); + // Reserve button + var reserver_btn = element.parents('.ting-object:first').find('.reserve-button'); - if (available) { - element.addClass('available'); + if (available) { + element.addClass('available'); - // Add class to reserve button - if (reserver_btn.length) { - reserver_btn.addClass('available'); - } - } - else { - element.addClass('unavailable'); + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('available'); + } + } + else { + element.addClass('unavailable'); - // Add class to reserve button - if (reserver_btn.length) { - reserver_btn.addClass('unavailable'); - } - } + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('unavailable'); + } + } - if (reservable) { - element.addClass('reservable'); + if (reservable) { + element.addClass('reservable'); - // Add class to reserve button - if (reserver_btn.length) { - reserver_btn.addClass('reservable'); - } - } + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('reservable'); + } + } - if (!available && !reservable) { - element.addClass('not-reservable'); + if (!available && !reservable) { + element.addClass('not-reservable'); - // Add class to reserve button - if (reserver_btn.length) { - reserver_btn.addClass('not-reservable'); + // Add class to reserve button + if (reserver_btn.length) { + reserver_btn.addClass('not-reservable'); + } + } } - } + }); } /** From 6206c317b657252c4b9156158aee48d5ff2cc300 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 25 Aug 2014 10:10:05 +0200 Subject: [PATCH 85/97] Issue #453 by cableman: Removed load of both javascripts in label only --- ding_availability.field.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index 6d16fbe..a7a1790 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -291,7 +291,6 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ ), 'type' => 'setting', ); $output['#attached']['js'][] = drupal_get_path('module', 'ding_availability') . '/js/ding_availability_labels.js'; - $output['#attached']['js'][] = drupal_get_path('module', 'ding_availability') . '/js/ding_availability.js'; $element[$delta] = $output; break; From 961c608eb12d05890382406e2fcd79ee689436c5 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 25 Aug 2014 10:15:27 +0200 Subject: [PATCH 86/97] Issue #453 by cableman: Filter reservable sources --- ding_availability.field.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index a7a1790..edcb15b 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -81,7 +81,7 @@ function ding_availability_field_formatter_info() { function ding_availability_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); $online_types = array_filter(variable_get('ting_online_types', _ting_default_online_types())); - $reservable_sources = variable_get('ting_reservable_sources', _ting_default_reservable_sources()); + $reservable_sources = array_filter(variable_get('ting_reservable_sources', _ting_default_reservable_sources())); // Attach front-end style and JS to the element. foreach ($items as $delta => $item) { From 9835e1d75329261e068c14480bfd383eda0ee31d Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 6 Oct 2014 12:15:49 +0200 Subject: [PATCH 87/97] Updated make file to point to development branch --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index 4d3a7c2..f4ff156 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -11,5 +11,5 @@ projects[virtual_field][version] = "1.2" 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 6c4737167ad4022e09a5e525ce9c44e361e4db19 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 6 Oct 2014 12:29:02 +0200 Subject: [PATCH 88/97] Updated make file to point to development branch --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index f4ff156..5762f40 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -10,6 +10,6 @@ projects[virtual_field][version] = "1.2" 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] = "development" From c2d2dd3bbf7f7bfcd2b6ee811cd05d94f295c987 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 6 Oct 2014 14:44:15 +0200 Subject: [PATCH 89/97] Updated make file to point to master branch --- ding_availability.make | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ding_availability.make b/ding_availability.make index 5762f40..4d3a7c2 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -10,6 +10,6 @@ projects[virtual_field][version] = "1.2" 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 20ebd82965cc559bfffbb66d0d51ca3e6f054af6 Mon Sep 17 00:00:00 2001 From: JrgenGNielsen Date: Wed, 4 Mar 2015 15:23:11 +0100 Subject: [PATCH 90/97] issue #1014 by JrgenGNielsen: modify ding_availability_update_availability() to include bookmark reservation buttons --- js/ding_availability.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/ding_availability.js b/js/ding_availability.js index a456ba3..f427e74 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -93,7 +93,7 @@ element.removeClass('pending').addClass('processed'); // Reserve button - var reserver_btn = element.parents('.ting-object:first').find('.reserve-button'); + var reserver_btn = element.parents('.ting-object:first, .material-item:first').find('.reserve-button'); if (available) { element.addClass('available'); From 9dcb42f508a0cadb9de6096d840befa304c7b89a Mon Sep 17 00:00:00 2001 From: Martin Cording Date: Tue, 21 Apr 2015 15:04:00 +0200 Subject: [PATCH 91/97] Issue #618 by guddo: Refactoring availability logic. --- ding_availability.field.inc | 2 +- js/ding_availability.js | 19 +++--- js/ding_availability_labels.js | 109 ++++++++++++++++++--------------- 3 files changed, 70 insertions(+), 60 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index edcb15b..cef7bee 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -235,7 +235,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ 'link' => array( // The online url can't be used with l(), has it will encode // it. - '#markup' => '' . check_plain($type) . '', + '#markup' => '' . check_plain($type) . '', ), ); } diff --git a/js/ding_availability.js b/js/ding_availability.js index f427e74..c1962d6 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -83,18 +83,18 @@ var available = false; var reservable = false; var is_internet = false; + var element = $('#' + id); + element.removeClass('pending').addClass('processed'); + $.each(entity_ids, function(index, entity_id) { + // Reserve button + var reserver_btn = element.parents('.ting-object:first').find('a[id$=' + entity_id + '].reserve-button'); + if (Drupal.DADB[entity_id]) { available = available || Drupal.DADB[entity_id]['available']; reservable = reservable || Drupal.DADB[entity_id]['reservable']; is_internet = is_internet || Drupal.DADB[entity_id]['is_internet']; - var element = $('#' + id); - element.removeClass('pending').addClass('processed'); - - // Reserve button - var reserver_btn = element.parents('.ting-object:first, .material-item:first').find('.reserve-button'); - if (available) { element.addClass('available'); @@ -120,8 +120,7 @@ reserver_btn.addClass('reservable'); } } - - if (!available && !reservable) { + else { element.addClass('not-reservable'); // Add class to reserve button @@ -130,6 +129,10 @@ } } } + + else { + reserver_btn.addClass('not-reservable'); + } }); } diff --git a/js/ding_availability_labels.js b/js/ding_availability_labels.js index e3f2479..862493d 100644 --- a/js/ding_availability_labels.js +++ b/js/ding_availability_labels.js @@ -74,15 +74,17 @@ */ function update_availability(id, entity_ids) { // Default the status to not available and not reservable. - var available = false; - var reservable = false; + var status = { + available: false, + reservable: false + }; // Loop over the entity ids and if one has available or reservable // true save that value. $.each(entity_ids, function(index, entity_id) { if (Drupal.DADB[entity_id]) { - available = available || Drupal.DADB[entity_id]['available']; - reservable = reservable || Drupal.DADB[entity_id]['reservable']; + status.available = status.available || Drupal.DADB[entity_id]['available']; + status.reservable = status.reservable || Drupal.DADB[entity_id]['reservable']; } }); @@ -93,18 +95,7 @@ // to show it). var reserver_btn = element.parents('.ting-object:first').find('[id^=ding-reservation-reserve-form]'); - if (available) { - update_availability_elements(element, reserver_btn, 'available'); - } - else if (reservable) { - update_availability_elements(element, reserver_btn, 'reservable'); - } - else if (!available && !reservable) { - update_availability_elements(element, reserver_btn, 'not-reservable'); - } - else { - update_availability_elements(element, reserver_btn, 'unavailable'); - } + update_availability_elements(element, reserver_btn, status); } /** @@ -113,38 +104,38 @@ * * @param element * The target element (material that should be moved). - * @param type - * The type of availability the element has. + * @param status + * Structure with available and reservable state. */ - function update_availability_type(element, type) { - // Select type, if any or create the type. + function update_availability_type(element, status) { var groups_wrapper = element.closest('.search-result--availability'); - var group = $('.js-' + type, groups_wrapper); - if (group.length !== 1) { - // Create group. - if (type === 'available') { - // Add as first line. - group = $('

      ' + Drupal.t('Available') + ':

      '); - groups_wrapper.prepend(group); - } - else if (type === 'unavailable') { - // Add last. - group = $('

      ' + Drupal.t('Unavailable') + ':

      '); - group.insertBefore('.js-pending', groups_wrapper); + var reservable = status['reservable']; + var available = status['available']; + + var group = null; + if ($('.js-online', groups_wrapper).length !== 0) { + group = $('.js-online', groups_wrapper); + } + else if (available) { + group = $('.js-available', groups_wrapper); + + if (group.length === 0) { + group = $('

      ' + Drupal.t('Available') + ':

      '); + groups_wrapper.append(group); } - else if (type === 'reservable') { - // First or after available. - group = $('

      ' + Drupal.t('Reservable') + ':

      '); - if ($('.js-available', groups_wrapper).length) { - group.insertAfter($('.js-available', groups_wrapper)); - } - else { - groups_wrapper.prepend(group); - } + } + else if (reservable) { + group = $('.js-reservable', groups_wrapper); + if (group.length === 0) { + group = $('

      ' + Drupal.t('Reservable') + ':

      '); + groups_wrapper.append(group); } - else { - // Add last to not-reservable. - group = $('

      ' + Drupal.t('Not reservable') + ':

      '); + } + else { + group = $('.js-unavailable', groups_wrapper); + + if (group.length === 0) { + group = $('

      ' + Drupal.t('Not available') + ':

      '); groups_wrapper.append(group); } } @@ -182,16 +173,32 @@ * jQuery availability element to add the class to. * @param btn * Reservation button to add the class to. - * @param class_name - * The class to add to the elements. + * @param status + * Structure with available and reservable state. */ - function update_availability_elements(element, btn, class_name) { - element.addClass(class_name); - if (btn.length) { - btn.addClass(class_name); + function update_availability_elements(element, btn, status) { + var class_name = null; + + for (var i in status) { + if (status[i] === true) { + class_name = i; + } + else { + if (i === 'available') { + class_name = 'un' + i; + } + else if (i === 'reservable') { + class_name = 'not-' + i; + } + } + + element.addClass(class_name); + if (btn.length) { + btn.addClass(class_name); + } } - update_availability_type(element, class_name); + update_availability_type(element, status); } } }; From b92188aaf75171974e6073dcaa5cb727553e73f4 Mon Sep 17 00:00:00 2001 From: JrgenGNielsen Date: Mon, 1 Jun 2015 14:32:18 +0200 Subject: [PATCH 92/97] issue #1014 by JrgenGNielsen: Fix merge conflict with issue #618 --- js/ding_availability.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/ding_availability.js b/js/ding_availability.js index c1962d6..c3944f8 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -88,7 +88,7 @@ $.each(entity_ids, function(index, entity_id) { // Reserve button - var reserver_btn = element.parents('.ting-object:first').find('a[id$=' + entity_id + '].reserve-button'); + var reserver_btn = element.parents('.ting-object:first, .material-item:first').find('a[id$=' + entity_id + '].reserve-button'); if (Drupal.DADB[entity_id]) { available = available || Drupal.DADB[entity_id]['available']; From 793c2b10f80217ea60d00a28759c1b8f2b19f749 Mon Sep 17 00:00:00 2001 From: JrgenGNielsen Date: Mon, 15 Jun 2015 15:44:51 +0200 Subject: [PATCH 93/97] issue #336 by JrgenGNielsen: Show "in acquisition" info --- ding_availability.module | 20 ++++++++++++++++++-- templates/ding-holdings.tpl.php | 6 +++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ding_availability.module b/ding_availability.module index 9d655d7..47f596a 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -159,6 +159,7 @@ function ding_availability_holdings($provider_ids) { 'reservable' => FALSE, 'available' => FALSE, 'holdings' => array(), + 'ordered_count' => 0, ); // Marks internet resources as available. @@ -183,9 +184,18 @@ function ding_availability_holdings($provider_ids) { 'class' => array('availability-holdings-table'), ); + // check if there are items in acquisition + foreach ($item['holdings'] as $holding) { + $item['ordered_count'] += $holding[ordered_count]; + } + // if yes, add a column + if ($item['ordered_count']) { + $header['acquisition'] = t('In acquisition'); + } + $rows = array(); foreach ($item['holdings'] as $holding) { - $rows[] = ding_availability_holdings_row($holding); + $rows[] = ding_availability_holdings_row($holding, $item['ordered_count']); } // Theme the output. @@ -198,6 +208,7 @@ function ding_availability_holdings($provider_ids) { ), 'total_count' => $item['total_count'], 'reserved_count' => $item['reserved_count'], + 'ordered_count' => $item['ordered_count'], )); } } @@ -210,7 +221,7 @@ function ding_availability_holdings($provider_ids) { * * @return array */ -function ding_availability_holdings_row($holding) { +function ding_availability_holdings_row($holding, $ordered_count) { $row = array(); // Create placement string. @@ -224,6 +235,11 @@ function ding_availability_holdings_row($holding) { $available += isset($holding['reference_count']) ? (int) $holding['reference_count'] : 0; $row['available'] = $available; + // copies in acquisition. + if ($ordered_count) { + $row['ordered_count'] = isset($holding['ordered_count']) ? (int) $holding['ordered_count'] : 0; + } + return $row; } diff --git a/templates/ding-holdings.tpl.php b/templates/ding-holdings.tpl.php index 0efbb9a..edcfc73 100644 --- a/templates/ding-holdings.tpl.php +++ b/templates/ding-holdings.tpl.php @@ -11,6 +11,10 @@ $total_text = format_plural($total_count, 'We have 1 copy.', 'We have @count copies.', array('@count' => $total_count)); $reserved_text = format_plural($reserved_count, 'There is 1 user in queue to loan the material.', 'There are @count users in queue to loan the material.'); +$acquisition_text = ''; +if ( $ordered_count ) { + $acquisition_text = format_plural($ordered_count, '1 copy in acquisition.', '@count copies are in acquisition.', array('@count' => $ordered_count)); +} ?> -

      +

      From 6c442302083029d8bb129586a61d21930f4cceaa Mon Sep 17 00:00:00 2001 From: JrgenGNielsen Date: Thu, 9 Jul 2015 13:43:03 +0200 Subject: [PATCH 94/97] issue #336 by JrgenGNielsen: Remove whitespace --- templates/ding-holdings.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/ding-holdings.tpl.php b/templates/ding-holdings.tpl.php index edcfc73..92768ab 100644 --- a/templates/ding-holdings.tpl.php +++ b/templates/ding-holdings.tpl.php @@ -12,7 +12,7 @@ $total_text = format_plural($total_count, 'We have 1 copy.', 'We have @count copies.', array('@count' => $total_count)); $reserved_text = format_plural($reserved_count, 'There is 1 user in queue to loan the material.', 'There are @count users in queue to loan the material.'); $acquisition_text = ''; -if ( $ordered_count ) { +if ($ordered_count) { $acquisition_text = format_plural($ordered_count, '1 copy in acquisition.', '@count copies are in acquisition.', array('@count' => $ordered_count)); } ?> From 234d648683987ae5d8a44f3d25ae498ce5dbf489 Mon Sep 17 00:00:00 2001 From: JrgenGNielsen Date: Thu, 9 Jul 2015 14:00:05 +0200 Subject: [PATCH 95/97] Rename variable, update docblock, and fix key --- ding_availability.module | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ding_availability.module b/ding_availability.module index 47f596a..e517c35 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -171,7 +171,7 @@ function ding_availability_holdings($provider_ids) { // Support for creating the html here instead of in the provider. // The provider contains a location array, total_count, available_count, - // reserved_count, reservable_count. + // reserved_count, reservable_count, ordered_count. // We assume that the provider supports this, if it didn't deliver html. if (!isset($item['html'])) { $header = array( @@ -186,7 +186,7 @@ function ding_availability_holdings($provider_ids) { // check if there are items in acquisition foreach ($item['holdings'] as $holding) { - $item['ordered_count'] += $holding[ordered_count]; + $item['ordered_count'] += $holding['ordered_count']; } // if yes, add a column if ($item['ordered_count']) { @@ -218,10 +218,11 @@ function ding_availability_holdings($provider_ids) { /** * @param $holding + * @param $show_ordered_count * * @return array */ -function ding_availability_holdings_row($holding, $ordered_count) { +function ding_availability_holdings_row($holding, $show_ordered_count) { $row = array(); // Create placement string. @@ -236,7 +237,7 @@ function ding_availability_holdings_row($holding, $ordered_count) { $row['available'] = $available; // copies in acquisition. - if ($ordered_count) { + if ($show_ordered_count) { $row['ordered_count'] = isset($holding['ordered_count']) ? (int) $holding['ordered_count'] : 0; } From eedeffbb812ab267280d9b103270d659c8378e25 Mon Sep 17 00:00:00 2001 From: JrgenGNielsen Date: Thu, 9 Jul 2015 14:07:44 +0200 Subject: [PATCH 96/97] Check if ordered_count is set --- ding_availability.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.module b/ding_availability.module index e517c35..92de100 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -186,7 +186,7 @@ function ding_availability_holdings($provider_ids) { // check if there are items in acquisition foreach ($item['holdings'] as $holding) { - $item['ordered_count'] += $holding['ordered_count']; + $item['ordered_count'] += (isset($holding['ordered_count'])) ? (int) $holding['ordered_count'] : 0; } // if yes, add a column if ($item['ordered_count']) { From 1f36db06fb4d26ac7caea31b538b1473e970e397 Mon Sep 17 00:00:00 2001 From: JrgenGNielsen Date: Fri, 14 Aug 2015 14:03:36 +0200 Subject: [PATCH 97/97] issue #1334 by JrgenGNielsen: Update add inAcquisition to totals --- ding_availability.module | 17 ++++++++++------- templates/ding-holdings.tpl.php | 4 +++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ding_availability.module b/ding_availability.module index 92de100..5bd2276 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -62,6 +62,7 @@ function ding_availability_theme($existing, $type, $theme, $path) { 'holdings' => NULL, 'total_count' => NULL, 'reserved_count' => NULL, + 'total_plus_ordered_count' => NULL, ), 'path' => $path . '/templates', ), @@ -206,9 +207,10 @@ function ding_availability_holdings($provider_ids) { '#rows' => $rows, '#attributes' => $attributes, ), - 'total_count' => $item['total_count'], - 'reserved_count' => $item['reserved_count'], - 'ordered_count' => $item['ordered_count'], + 'total_count' => (int) $item['total_count'], + 'reserved_count' => (int) $item['reserved_count'], + 'ordered_count' => (int) $item['ordered_count'], + 'total_plus_ordered_count' => (int) $item['total_count'] + (int) $item['ordered_count'], )); } } @@ -232,13 +234,14 @@ function ding_availability_holdings_row($holding, $show_ordered_count) { $row['copies'] = isset($holding['total_count']) ? (int) $holding['total_count'] : 0; // Calculate copies home. - $available = isset($holding['available_count']) ? (int) $holding['available_count'] : 0; - $available += isset($holding['reference_count']) ? (int) $holding['reference_count'] : 0; - $row['available'] = $available; + $row['available'] = isset($holding['available_count']) ? (int) $holding['available_count'] : 0; + $row['available'] += isset($holding['reference_count']) ? (int) $holding['reference_count'] : 0; // copies in acquisition. if ($show_ordered_count) { - $row['ordered_count'] = isset($holding['ordered_count']) ? (int) $holding['ordered_count'] : 0; + $ordered_count = isset($holding['ordered_count']) ? (int) $holding['ordered_count'] : 0; + $row['copies'] += $ordered_count; + $row['ordered_count'] = $ordered_count; } return $row; diff --git a/templates/ding-holdings.tpl.php b/templates/ding-holdings.tpl.php index 92768ab..56ebbea 100644 --- a/templates/ding-holdings.tpl.php +++ b/templates/ding-holdings.tpl.php @@ -7,14 +7,16 @@ * - $holdings: Html showing detailed holdings information. * - $total_count: Total amount of copies. * - $reserved_count: Amount of reservations. + * - $ordered_count: Amount in acquisition. + * - $total_plus_ordered_count: Sum of Total + Amount in acquisition */ -$total_text = format_plural($total_count, 'We have 1 copy.', 'We have @count copies.', array('@count' => $total_count)); $reserved_text = format_plural($reserved_count, 'There is 1 user in queue to loan the material.', 'There are @count users in queue to loan the material.'); $acquisition_text = ''; if ($ordered_count) { $acquisition_text = format_plural($ordered_count, '1 copy in acquisition.', '@count copies are in acquisition.', array('@count' => $ordered_count)); } +$total_text = format_plural($total_plus_ordered_count, 'We have 1 copy.', 'We have @count copies.', array('@count' => $total_plus_ordered_count)); ?>