diff --git a/css/ding_periodical.css b/css/ding_periodical.css deleted file mode 100644 index 1c8e580..0000000 --- a/css/ding_periodical.css +++ /dev/null @@ -1,85 +0,0 @@ -.field-name-ding-periodical-issues .item-list ul { - margin-left: -23px; -} -.ding-periodical-issues { - margin-left: -23px; -} -.ding-periodical-fold { - color: #44A8A4; - cursor: pointer; - height: 17px; - margin-left: 25px; - padding: 7px 0 0; - font-size: 11px; -} - -.ding-periodical-fold:hover { - color: #44A8A4; - text-decoration: underline; -} -.ding-periodical-foldable { - background: url(../images/arrow-right-grey.png) no-repeat scroll 3px 9px transparent; -} - -.ding-periodical-foldable:hover { - background: url(../images/arrow-right-blue.png) no-repeat scroll 3px 9px transparent; -} - -.ding-periodical-foldable.expanded-periodicals-parent { - background: url(../images/arrow-down-grey.png) no-repeat scroll 0 11px transparent; -} - -.ding-periodical-foldable.expanded-periodicals-parent:hover { - background: url(../images/arrow-down-blue.png) no-repeat scroll 0 11px transparent; -} - -.ding-periodical-foldable .item-list ul.ding-periodical-foldable { - margin: 0 0 0 20px; - padding: 0; - background: none; -} - -.ding-periodical-foldable .item-list ul.ding-periodical-foldable li { - background: url(../images/more-button-grey.png) no-repeat scroll 0 8px transparent; - color: #44a8a4; - font: 11px 'Soho Gothic W01 Light', Helvetica, Arial, sans-serif; - letter-spacing: 0.2px; - line-height: 27px; - padding: 0 0 0 20px; -} - -.ding-periodical-foldable .item-list ul.ding-periodical-foldable li.ding-periodical-no-issues { - background: transparent; - padding: 0; -} - -.ding-periodical-foldable .item-list ul.ding-periodical-foldable li span { - margin: 0; -} - -.ding-periodical-foldable .item-list ul.ding-periodical-foldable li:hover { - background: url(../images/more-button-blue.png) no-repeat scroll 0 8px transparent; -} - -.ding-periodical-foldable .item-list ul.ding-periodical-foldable .ding-periodical-container li { - background: transparent; - padding: 0; -} - -.ding-periodical-foldable .item-list ul.ding-periodical-foldable li:hover { - text-decoration: underline; -} - -.ding-periodical-foldable .item-list ul.ding-periodical-foldable li form { - text-decoration: none; -} - -.ding-periodical-foldable .item-listitem-list li { - margin: 0; - padding: 0; - background: none; -} - -.ui-dialog-content ul.ding-periodical-foldable { - background: none -} diff --git a/ding-periodical-issues.tpl.php b/ding-periodical-issues.tpl.php new file mode 100644 index 0000000..7ed84c3 --- /dev/null +++ b/ding-periodical-issues.tpl.php @@ -0,0 +1,3 @@ +
+ +
diff --git a/ding_periodical.field.inc b/ding_periodical.field.inc index 121852c..e0d9d53 100644 --- a/ding_periodical.field.inc +++ b/ding_periodical.field.inc @@ -55,6 +55,12 @@ function ding_periodical_field_formatter_info() { 'ding_periodical_issues', ), ), + 'ding_periodical_issues_ajax' => array( + 'label' => t('Ajax load'), + 'field types' => array( + 'ding_periodical_issues', + ), + ), ); } @@ -63,30 +69,68 @@ function ding_periodical_field_formatter_info() { */ function ding_periodical_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); - foreach ($items as $delta => $item) { - if ( !ding_provider_implements('availability', 'holdings') ) { - return $element; - } - - $availability = ding_provider_invoke('availability', 'holdings', array($entity->provider_id)); - if (isset($availability[$entity->provider_id])) { - $issues = $availability[$entity->provider_id]['issues']; - // array_walk($issues, 'asort') complains about 'Notice: A non - // well formed numeric value encountered'. - foreach ($issues as $k => $v) { - asort($v); - } - ksort($issues); + // Check that the provider provides holdings information. + if (!ding_provider_implements('availability', 'holdings')) { + return $element; + } - if ($issues) { + // Switch over the different formatters. + switch ($display['type']) { + case 'ding_periodical_issues_ajax': + foreach ($items as $delta => $item) { $element[$delta] = array( - '#theme' => 'ding_periodical_issues', - '#entity' => $entity, - '#issues' => $issues, + '#theme' => 'ding_periodical_issues_ajax', + '#ding_entity_id' => $entity->ding_entity_id, + '#attached' => array( + 'js' => array( + array( + 'data' => drupal_get_path('module', 'ding_periodical') . '/js/ding_periodical_ajax.js', + ), + array( + 'data' => array( + 'ding_periodical' => array( + 'id' => drupal_html_class($entity->ding_entity_id), + 'ding_entity_id' => $entity->ding_entity_id, + ), + ), + 'type' => 'setting', + ), + ), + ), ); } - } + break; + + default: + // Handles the default formatter. + foreach ($items as $delta => $item) { + $availability = ding_provider_invoke('availability', 'holdings', array($entity->provider_id)); + if (isset($availability[$entity->provider_id])) { + $issues = $availability[$entity->provider_id]['issues']; + krsort($issues); + + if ($issues) { + $element[$delta] = array( + '#theme' => 'ding_periodical_issues', + '#entity' => $entity, + '#issues' => $issues, + '#availability' => $availability, + ); + } + } + } + break; } + + // Add script to collapsed the issue list, if any elements found. + if (!empty($element)) { + $element['#attached']['js'] = array( + array( + 'data' => drupal_get_path('module', 'ding_periodical') . '/js/ding_periodical.js', + ), + ); + } + return $element; } diff --git a/ding_periodical.info b/ding_periodical.info index 18eb5d7..3bebfd8 100644 --- a/ding_periodical.info +++ b/ding_periodical.info @@ -4,7 +4,8 @@ package = Ding! version = "7.x-1.9.4" core = 7.x files[] = ding_periodical.module -scripts[] = ding_periodical.js -dependencies[] = blackhole +files[] = ding_periodical_reservable.class.inc +dependencies[] = virtual_field dependencies[] = ding_provider dependencies[] = ding_entity +dependencies[] = ding_reservation diff --git a/ding_periodical.install b/ding_periodical.install index cf020e7..b6e1d42 100644 --- a/ding_periodical.install +++ b/ding_periodical.install @@ -14,7 +14,7 @@ function ding_periodical_ding_entity_fields() { 'field' => array( 'locked' => TRUE, 'storage' => array( - 'type' => 'blackhole', + 'type' => 'virtual_field', ), ), 'instance' => array( @@ -23,3 +23,17 @@ function ding_periodical_ding_entity_fields() { ), ); } + + +/** + * Convert blackhole field storage to virtual field. + */ +function ding_periodical_update_7000() { + return db_update('field_config') + ->fields(array( + 'storage_type' => 'virtual_field', + 'storage_module' => 'virtual_field', + )) + ->condition('module', 'ding_periodical') + ->execute(); +} \ No newline at end of file diff --git a/ding_periodical.js b/ding_periodical.js deleted file mode 100644 index 87f3cc7..0000000 --- a/ding_periodical.js +++ /dev/null @@ -1,22 +0,0 @@ -(function ($) { - $(document).ready(function(){ - $('.field-name-ding-periodical-issues li').children('.item-list').hide(); - }); - - Drupal.behaviors.ding_periodical = { - attach: function (context, settings) { - $('.field-name-ding-periodical-issues .ding-periodical-fold').toggle(function() { - $(this).next().show(); - $('.page-ting-object .panel-pane.pane-ting-object-ding-availability-holdings').addClass('holdings-collapsed'); - $('.page-ting-object .grid-3 .panel-pane.pane-ting-object-ding-entity-buttons').addClass('holdings-collapsed'); - $(this).next().toggleClass('expanded-periodicals'); - $(this).parent().toggleClass('expanded-periodicals-parent'); - }, - function () { - $(this).next().hide(); - $(this).next().toggleClass('expanded-periodicals'); - $(this).parent().toggleClass('expanded-periodicals-parent'); - }); - } - } -}(jQuery)); diff --git a/ding_periodical.make b/ding_periodical.make new file mode 100644 index 0000000..55560d3 --- /dev/null +++ b/ding_periodical.make @@ -0,0 +1,16 @@ +api = 2 +core = 7.x + +; Ding! +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_entity][type] = "module" +projects[ding_entity][download][type] = "git" +projects[ding_entity][download][url] = "git@github.com:ding2/ding_entity.git" +projects[ding_entity][download][branch] = "master" + +projects[virtual_field][subdir] = "contrib" +projects[virtual_field][version] = "1.2" diff --git a/ding_periodical.module b/ding_periodical.module index caa2d65..155ab33 100644 --- a/ding_periodical.module +++ b/ding_periodical.module @@ -1,5 +1,4 @@ 'Periodical issue information', + 'page callback' => 'ding_periodical_issues_ajax', + 'page arguments' => array(2), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); + + // Ajax link reservation callback (with local_id, volume and issue). + $items['ting/object/%ting_object/reserve/%/%/%'] = array( + 'page callback' => 'ding_periodical_reserve_ajax', + 'page arguments' => array(2, 4, 5, 6), + 'delivery callback' => 'ajax_deliver', + 'access arguments' => array('access content'), + ); + + return $items; +} + +/** + * Ajax reservation callback. + * + * @param TingEntity $entity + * Ting entity for the periodical. + * @param string $local_id + * Local library id (faust) for the issue (base64 encoded). + * @param string $volume + * Volume number (for year books the year, base64 encoded). + * @param string $issue + * The issue in the volume to reserve (base64_encoded). + * + * @return array + * Render array with Ajax commands. + */ +function ding_periodical_reserve_ajax($entity, $local_id, $volume, $issue) { + $reservable = new DingPeriodicalReservable(base64_decode($local_id), base64_decode($volume), base64_decode($issue), $entity); + + // Use ding reservation logic to create the reservation and ajax commands. + return ding_reservation_reserve_ajax($entity, $reservable); +} + +/** + * Callback function that load holdings information for a periodical. + * + * The information returned is a HTML table JSON encoded. + * + * @param string $ding_entity_id + * Ding entity id for the periodical. + */ +function ding_periodical_issues_ajax($ding_entity_id) { + $output = array(); + + // Load the entity for the periodical. + $entity = ding_entity_load($ding_entity_id); + + // Get availability. + $availability = ding_provider_invoke('availability', 'holdings', array($entity->provider_id)); + if (isset($availability[$entity->provider_id])) { + $issues = $availability[$entity->provider_id]['issues']; + krsort($issues); + + if ($issues) { + $output = array( + '#theme' => 'ding_periodical_issues', + '#entity' => $entity, + '#issues' => $issues, + '#availability' => $availability, + ); + } + } + + // Render the output to HTML an return it. + drupal_json_output(array( + 'html' => empty($output) ? '' : render($output), + )); +} /** * Implements hook_theme(). @@ -16,19 +97,30 @@ drupal_add_css(drupal_get_path('module', 'ding_periodical') . '/css/ding_periodi function ding_periodical_theme() { return array( 'ding_periodical_issues' => array( - // 'variables' => array('entity', 'issues'), - 'render element' => 'elements', + 'variables' => array( + 'entity' => NULL, + 'issues' => array(), + 'availability' => array(), + ), + ), + 'ding_periodical_issues_ajax' => array( + 'variables' => array( + 'ding_entity_id' => NULL, + ), + 'template' => 'ding-periodical-issues', ), ); } /** - * Theming function. + * Implements theme_ding_periodical_issues(). + * + * Create list of periodical issues order by year. */ function theme_ding_periodical_issues($variables) { $items = array(); - foreach ($variables['elements']['#issues'] as $volume => $issues) { + foreach ($variables['issues'] as $volume => $issues) { $iss = array(); $i = 0; @@ -37,42 +129,65 @@ function theme_ding_periodical_issues($variables) { $issue_id = $availability['local_id']; $normalized_id = md5($issue_id); - // @todo - // This is to be refactored to prevent segfaults. - if (!empty($issue_id) && module_exists('ding_periodical_reservation')) { - $_SESSION['ding_periodical_reservation'][$normalized_id] = array( - 'issue_id' => $issue_id, - 'volume' => $volume, - 'key' => $key, - 'entity' => $variables['elements']['#entity'], + + // Build table with holding information for the current volume. + $holding_data = ding_periodical_build_table($availability); + + // Check if the volume is reservable and add reservation button. + if (!empty($issue_id) && ding_periodical_is_reservable($issues[$key])) { + $item_id = array($issue_id, $volume, $key); + $item_id = array_map('base64_encode', $item_id); + + $button = array( + array( + '#theme' => 'link', + '#text' => t('Reserve'), + '#path' => 'ting/object/' . $variables['entity']->id . '/reserve/' . implode('/', $item_id), + '#options' => array( + 'attributes' => array( + 'class' => array( + 'action-button', + 'reserve-button', + 'reservable', + 'available', + 'use-ajax', + ), + 'id' => 'reservation-' . $issue_id, + ), + 'html' => FALSE, + ), + ), ); - } - $local_id = $variables['elements']['#entity']->localId; - $holding_data = ding_periodical_holding_data($local_id, $volume, $issue); - $holding_data .= '
'; + // @todo This should first be render in the template layer. + $holding_data .= drupal_render($button); + } - $holding = array(array( - 'data' => '
' . $holding_data . '
', - )); + $holdings = array( + array( + 'data' => '
' . $holding_data . '
', + ), + ); // Normal behavior - periodicals, dc.type=tidsskrift. $iss[$i] = array( - 'data' => '' . $issue . '', - 'children' => $holding, + 'data' => '' . $issue . '', 'class' => array( drupal_html_class('ding-periodical-container'), ), ); - // Suppose we have dc.type=årbog - // Keys for those periodicals are empty. + // Suppose we have dc.type=årbog, where keys for those periodicals are + // empty or 0. Move the layout out. if (empty($issue)) { - $iss[$i]['data'] = $holding[0]['data']; + $iss[$i]['data'] = $holdings[0]['data']; $iss[$i]['class'][] = drupal_html_class('ding-periodical-no-issues'); $iss[$i]['class'][] = drupal_html_class('ding-reservable-periodical'); $iss[$i]['id'][] = drupal_html_id('periodical-id-' . $normalized_id); - unset($iss[$i]['children']); + } + else { + // Set children with holding information for periodicals. + $iss[$i]['children'] = $holdings; } $i++; @@ -87,40 +202,13 @@ function theme_ding_periodical_issues($variables) { $items[] = $vol; } - return theme('item_list', array('items' => $items, 'attributes' => array('class' => drupal_html_class('ding_periodical_issues')))); -} - -/** - * Fetch periodical availability table. - * - * @param $item - * Ting object local id, parent of periodical. - * @param $periodical - * Periodical id. - * @return type - * HTML markup. - */ -function ding_periodical_holding_data($item = NULL, $volume = NULL, $issue = NULL) { - $availability_table = ''; - if (!empty($item)) { - $holdings = &drupal_static(__FUNCTION__, NULL); - if (!isset($holdings[$item])) { - $holdings = ding_provider_invoke('availability', 'holdings', array($item)); - } - - if (!empty($volume) && !empty($issue)) { - $issue = $holdings[$item]['issues'][$volume][$issue]; - $availability_table = ding_periodical_build_table($issue); - } - } - - return $availability_table; + return theme('item_list', array('items' => $items, 'attributes' => array('class' => 'ding-periodical-issues'))); } /** * Build a markup for the availability table. * - * @param $issue + * @param array $availability * Issue array, with keys: * - local_id: Periodical identifier. * - provider: Provider identifier, 'alma' here. @@ -133,18 +221,10 @@ function ding_periodical_holding_data($item = NULL, $volume = NULL, $issue = NUL * - available_count * - reservable * - * Keys checked_out_count, reference_count, ordered_count - * appear only in alma. - * - * @todo - * This table DOES NOT contain the reservations count, - * since this number comes as a separate value, for the whole - * ting item, not the periodicals. - * - * @return + * @return $string * HTML markup for the availability table. */ -function ding_periodical_build_table($issue) { +function ding_periodical_build_table($availability) { $header = array( 'placement' => t('Placement'), 'copies' => t('Copies'), @@ -153,26 +233,46 @@ function ding_periodical_build_table($issue) { $rows = array(); - if ($issue['provider'] === 'alma') { - $header['not_for_loan'] = t('Not for loan'); - $header['checked_out'] = t('Checked out'); - } - $i = 0; - foreach ($issue['placement'] as $placement) { + foreach ($availability['placement'] as $data) { + $home = isset($data['available_count']) ? (int) $data['available_count'] : 0; + $home += isset($data['reference_count']) ? (int) $data['reference_count'] : 0; + $rows[$i] = array( - $placement['location'], - $placement['total_count'], - $placement['available_count'], + $data['location'], + $data['total_count'], + $home, ); - if ($issue['provider'] === 'alma') { - $rows[$i][] = $placement['reference_count']; - $rows[$i][] = $placement['checked_out_count']; - } - $i++; } - return theme('table', array('header' => $header, 'rows' => $rows)); + // Note: If stikcy header is TRUE, it will keep adding the js in FF until the + // browser goes down. + return theme('table', array( + 'header' => $header, + 'rows' => $rows, + 'sticky' => FALSE, + )); +} + +/** + * Check if a given issue of a periodical have any copies on the libraries. + * + * @param array $issue + * An periodical issue form the provider. + * + * @return bool + * If a copy exists it return TRUE else FALSE. + */ +function ding_periodical_is_reservable($issue) { + foreach ($issue['placement'] as $placement) { + if ($placement['reservable']) { + // Found on placement that had a reservable copy. + return TRUE; + } + } + + // No placements found with reservable copy. + return FALSE; } diff --git a/ding_periodical_reservable.class.inc b/ding_periodical_reservable.class.inc new file mode 100644 index 0000000..07b7941 --- /dev/null +++ b/ding_periodical_reservable.class.inc @@ -0,0 +1,70 @@ +id = $id; + $this->volume = $volume; + $this->issue = $issue; + $this->entity = $entity; + } + + /** + * Gets the provider id based on the provider. + * + * @return string + * The id for the issue. + */ + public function getProviderId() { + $type = ding_provider_get_provider_module_name('reservation'); + switch ($type) { + case 'openruth': + return array($this->entity->provider_id, $this->id); + + default: + return $this->id; + } + } + + /** + * Returns the entity that represents this issue. + * + * @return DingEntity + * The entity for the reservation. + */ + public function getEntity() { + return $this->entity; + } + + /** + * The periodical title with volume and issue information. + * + * @return string + * Formatted string with issue and volume information. + */ + public function getTitle() { + $title = '@title, vol @volume'; + $title .= !empty($this->issue) ? ', issue @issue' : ''; + + return t($title, array('@title' => $this->entity->title, '@volume' => $this->volume, '@issue' => $this->issue)); + } +} diff --git a/ding_periodical_reservation/ding_periodical_reservation.info b/ding_periodical_reservation/ding_periodical_reservation.info deleted file mode 100644 index ccd1c94..0000000 --- a/ding_periodical_reservation/ding_periodical_reservation.info +++ /dev/null @@ -1,8 +0,0 @@ -name = Ding periodical reservation -description = Handles reservation of issues on periodicals. -package = Ding! -version = 0.1+dbc.1 -core = 7.x -files[] = ding_periodical_reservation.module -dependencies[] = ding_periodical -dependencies[] = ding_reservation diff --git a/ding_periodical_reservation/ding_periodical_reservation.module b/ding_periodical_reservation/ding_periodical_reservation.module deleted file mode 100644 index 5b164fb..0000000 --- a/ding_periodical_reservation/ding_periodical_reservation.module +++ /dev/null @@ -1,125 +0,0 @@ - MENU_CALLBACK, - 'access arguments' => array('search content'), - 'page arguments' => array(2), - 'page callback' => 'ding_periodical_reservation_ajax_reserve', - 'delivery callback' => 'ajax_deliver', - ); - - return $items; -} - -/** - * Implements hook_init(). - */ -function ding_periodical_reservation_init() { - // We need those only for item landing page. - if (arg(0) == 'ting' && arg(1) == 'object') { - drupal_add_library('system', 'drupal.ajax'); - drupal_add_library('system', 'jquery.form'); - drupal_add_js(drupal_get_path('module', 'ding_periodical_reservation') . '/js/ding_periodical_reservation.scripts.js'); - } -} - -/** - * Ajax responder for periodical reservations. - * - * @param $id - * Reservable id. - * @return type - * Array, with ajax specific commands. - */ -function ding_periodical_reservation_ajax_reserve($id = '') { - $commands = array(); - - if (!empty($id)) { - $reservable = isset($_SESSION['ding_periodical_reservation'][$id]) ? $_SESSION['ding_periodical_reservation'][$id] : NULL; - - if (is_array($reservable)) { - $reservation_form = ding_periodical_reservation_button( - $reservable['issue_id'], - $reservable['volume'], - $reservable['key'], - $reservable['entity'] - ); - - $commands[] = ajax_command_append('html', $reservation_form); - $commands[] = ding_periodical_reservation_trigger_periodical_reservation($id); - } - } - - return array('#type' => 'ajax', '#commands' => $commands); -} - -/** - * Function wrapper for custom AJAX command. - * - * Command for triggering periodical reservation procedure, after a certain - * reservation form was created. - */ -function ding_periodical_reservation_trigger_periodical_reservation($entity_id = '') { - if (!empty($entity_id)) { - return array('command' => 'trigger_periodical_reservation', 'data' => $entity_id); - } -} - -/** - * A periodical reservation. - */ -class DingPeriodicalReservable extends DingReservationReservableEntity { - public function __construct($id, $volume, $issue, $entity) { - $this->id = $id; - $this->volume = $volume; - $this->issue = $issue; - $this->entity = $entity; - } - - public function getProviderId() { - // pjo 16-01-12 reservations did not work for alma-periodicals; - // switch on provider type - $type = ding_provider_get_provider_module_name('reservation'); - switch ($type) { - case 'openruth': - return array($this->entity->provider_id, $this->id); - case 'alma': - return $this->id; - default: - return $this->id; - } - } - - public function getEntity() { - return $this->entity; - } - - public function getTitle() { - $title = '@title, vol @volume'; - $title .= !empty($this->issue) ? ', issue @issue' : ''; - - return t($title, array('@title' => $this->entity->title, '@volume' => $this->volume, '@issue' => $this->issue)); - } -} diff --git a/ding_periodical_reservation/js/ding_periodical_reservation.scripts.js b/ding_periodical_reservation/js/ding_periodical_reservation.scripts.js deleted file mode 100644 index 4d28c4e..0000000 --- a/ding_periodical_reservation/js/ding_periodical_reservation.scripts.js +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @file - * Script file for the periodical reservations. - */ -(function ($) { - Drupal.extractPeriodicalId = function(ele) { - classname = $(ele).attr('id'); - id = classname.match(/periodical-id-(.+)/); - - if (id != null) { - return id[1]; - } - else { - return false; - } - } - - trigger_periodical_reservation = function(ajax, response, status) { - var entity_id = response.data.replace(' ', '%20'); - var forms = $('form'); - var regex = new RegExp(entity_id, 'g'); - // Loop through all forms on a page, deeper filtering comes next. - forms.each(function() { - form = $(this); - // Wee seek for reservations forms, thus specific form whose item was clicked. - if (form.attr('id').match(/ding-reservation-reserve-form/g) && form.attr('action').match(regex)) { - form.hide(); - // Make sure we don't miss the form. - setTimeout(function() { - // Call mousedown(), since click() event is forbidden by #ajax['prevent']. - form.find('.form-submit').mousedown(); - }, 500); - } - }); - } - - Drupal.behaviors.ding_periodical_reservation = { - attach: function (context, settings) { - Drupal.ajax.prototype.commands.trigger_periodical_reservation = trigger_periodical_reservation; - $('.ding-reservable-periodical', context).once('ding-reservable-periodical', function() { - var id = Drupal.extractPeriodicalId($(this)); - if (id) { - var element_settings = {}; - element_settings.url = '/ding_periodical_reservation/reserve/' + id; - element_settings.event = 'click'; - element_settings.progress = { type: 'throbber' }; - base = $(this).attr('id'); - - Drupal.ajax[base] = new Drupal.ajax(base, $(this).parent().find('.periodical-reserve button'), element_settings); - } - }); - } - } -}(jQuery)); diff --git a/images/arrow-down-blue.png b/images/arrow-down-blue.png deleted file mode 100644 index e0e8f1a..0000000 Binary files a/images/arrow-down-blue.png and /dev/null differ diff --git a/images/arrow-down-grey.png b/images/arrow-down-grey.png deleted file mode 100644 index 04e7e52..0000000 Binary files a/images/arrow-down-grey.png and /dev/null differ diff --git a/images/arrow-right-blue.png b/images/arrow-right-blue.png deleted file mode 100644 index bd41167..0000000 Binary files a/images/arrow-right-blue.png and /dev/null differ diff --git a/images/arrow-right-grey.png b/images/arrow-right-grey.png deleted file mode 100644 index b9c942e..0000000 Binary files a/images/arrow-right-grey.png and /dev/null differ diff --git a/images/more-button-blue.png b/images/more-button-blue.png deleted file mode 100644 index 823f965..0000000 Binary files a/images/more-button-blue.png and /dev/null differ diff --git a/images/more-button-grey.png b/images/more-button-grey.png deleted file mode 100644 index eea6682..0000000 Binary files a/images/more-button-grey.png and /dev/null differ diff --git a/js/ding_periodical.js b/js/ding_periodical.js new file mode 100644 index 0000000..636b1a1 --- /dev/null +++ b/js/ding_periodical.js @@ -0,0 +1,16 @@ +(function ($) { + $(document).ready(function(){ + // Hide all elements. + $('.ding-periodical-issues li').children('.item-list').hide(); + + // Add class to style the list as being expandable. + $('.ding-periodical-fold').addClass('expand expand-more'); + + // Attach click event to fold in/out the issues. + $('.field-name-ding-periodical-issues .ding-periodical-fold').live("click", function() { + $(this).next().toggle(); + $(this).next().toggleClass('expanded-periodicals'); + $(this).parent().toggleClass('expanded-periodicals-parent'); + }); + }); +}(jQuery)); diff --git a/js/ding_periodical_ajax.js b/js/ding_periodical_ajax.js new file mode 100644 index 0000000..881cd1f --- /dev/null +++ b/js/ding_periodical_ajax.js @@ -0,0 +1,31 @@ +(function ($) { + $(document).ready(function(){ + var ids = Drupal.settings.ding_periodical; + $(ids).each(function (index, info){ + // Make ajax call to get holdings table (opt. use the information fetched + // by availability for the entity). + $.ajax({ + type: 'GET', + url: '/ding_periodical/issues/' + info.ding_entity_id + }).done(function(data) { + var div = $('.ding-periodical-issues-ajax.' + info.id); + if (!data.html || 0 === data.html.length) { + // No informtion found. + div.html('

' + Drupal.t('No periodical issue information found.') + '

'); + } + else { + // Insert the information. + div.parent().html(data.html); + + // Hide all elements. + $('.ding-periodical-issues li').children('.item-list').hide(); + + // Add class to style the list as being expandable. + $('.ding-periodical-fold').addClass('expand expand-more'); + } + }); + + // Insert tabelles on succes and hide label on failure. + }); + }); +}(jQuery));