Browse Source

updated cufts target and evergreen target now does ajax

2.x-ebsco
Paul Pound 12 years ago
parent
commit
0181c8e925
  1. 3
      targets/cufts/roblib_search_cufts.module
  2. 2
      targets/cufts/theme/roblib-search-cufts.tpl.php
  3. 23
      targets/evergreen/js/evergreen_results.js
  4. 43
      targets/evergreen/roblib_search_evergreen.module
  5. 11
      targets/evergreen/theme/roblib-search-evergreen.tpl.php
  6. 15
      targets/evergreen/theme/theme.inc

3
targets/cufts/roblib_search_cufts.module

@ -200,7 +200,8 @@ function roblib_search_cufts_help($path, $arg) {
case 'admin/help#roblib_search_cufts': case 'admin/help#roblib_search_cufts':
return t( return t(
'<p> '<p>
provides a target for the Roblib search module provides a target for the Roblib search module. This target uses javascript
to render the results.
</p>' </p>'
); );
} }

2
targets/cufts/theme/roblib-search-cufts.tpl.php

@ -17,7 +17,7 @@
*/ */
?> ?>
<div class ="roblib-search-content-cufts" id="roblib-search-content-cufts"> <div class ="roblib-search-content cufts" id="roblib-search-content-cufts">
<img src="<?php print $spinner_path; ?>"/> <img src="<?php print $spinner_path; ?>"/>
</div> </div>

23
targets/evergreen/js/evergreen_results.js

@ -0,0 +1,23 @@
Drupal.behaviors.roblib_search_evergreen = {
attach: function(context, settings) {
$url = settings.roblib_search_evergreen.search_url;
jQuery.getJSON($url, function(data) {
var items = [];
if(data.length < 1){
jQuery('#' + 'roblib-search-content-evergreen').empty().append('No Results');
} else {
jQuery.each(data, function(key, val) {
items.push('<div class ="roblib-search-row">');
items.push('<div class="roblib-title evergreen">');
items.push('<a href = "'+val.url+'">'+val.title+'</a></div>');
items.push('</div>');
});
}
jQuery('#' + 'roblib-search-content-evergreen').empty().append(items.join(''));
});
}
}

43
targets/evergreen/roblib_search_evergreen.module

@ -45,10 +45,17 @@ function roblib_search_evergreen_menu() {
'type' => MENU_NORMAL_ITEM, 'type' => MENU_NORMAL_ITEM,
); );
$items['roblib_search/evergreen/ajax/%'] = array(
'title' => 'evergreen ajax',
'page callback' => 'roblib_search_evergreen_ajax',
'page arguments' => array(3),
'type' => MENU_CALLBACK,
'access arguments' => array('search roblib evergreen'),
);
return $items; return $items;
} }
function roblib_search_evergreen_config_form($form, &$form_state) { function roblib_search_evergreen_config_form($form, &$form_state) {
/* /*
* $url = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52'); * $url = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52');
@ -123,7 +130,6 @@ function roblib_search_evergreen_theme() {
); );
} }
function roblib_search_evergreen_block_info() { function roblib_search_evergreen_block_info() {
$blocks['roblib_search_evergreen_results'] = array( $blocks['roblib_search_evergreen_results'] = array(
@ -146,23 +152,27 @@ function roblib_search_evergreen_block_view($delta = '') {
$block['subject'] = t('Evergreen Results'); $block['subject'] = t('Evergreen Results');
// The content of the block is typically generated by calling a custom // The content of the block is typically generated by calling a custom
// function. // function.
$block['content'] = roblib_search_evergreen_get_results(); $block['content'] = theme('roblib_search_evergreen', array('results' => NULL));
break; break;
} }
return $block; return $block;
} }
function roblib_search_evergreen_get_results() { function roblib_search_evergreen_ajax($query) {
drupal_add_css(drupal_get_path('module', 'roblib_search_evergreen') . '/css/roblib_search_evergreen.theme.css'); $output = roblib_search_evergreen_get_results($query);
print $output;
// Url parameters. exit();
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
}
else {
return '';
} }
/**
*
* @param string $query
* @return string
* json
*/
function roblib_search_evergreen_get_results($query) {
drupal_add_css(drupal_get_path('module', 'roblib_search_evergreen') . '/css/roblib_search_evergreen.theme.css');
$url = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52'); $url = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52');
$url_suffix = variable_get('roblib_search_evergreen_search_suffix', '/opac/extras/sru?version=1.1&operation=searchRetrieve&query='); $url_suffix = variable_get('roblib_search_evergreen_search_suffix', '/opac/extras/sru?version=1.1&operation=searchRetrieve&query=');
$number_of_records = variable_get('roblib_search_evergreen_num_results', '5'); $number_of_records = variable_get('roblib_search_evergreen_num_results', '5');
@ -175,9 +185,16 @@ function roblib_search_evergreen_get_results() {
$output = 'Error retrieving Evergreen results ' . $results->status_message; $output = 'Error retrieving Evergreen results ' . $results->status_message;
} }
return theme('roblib_search_evergreen', array('results' => $output)); return json_encode($output);
} }
/**
*
* @param string $results
* results in marcxml
* @return array $output
* information we want from the xml stored in an array
*/
function roblib_search_evergreen_parse_results($results) { function roblib_search_evergreen_parse_results($results) {
$xml = $results->data; $xml = $results->data;
if (!isset($xml)) { if (!isset($xml)) {

11
targets/evergreen/theme/roblib-search-evergreen.tpl.php

@ -17,13 +17,8 @@
*/ */
?> ?>
<div class ="roblib-search-content-evergreen"> <div class ="roblib-search-content evergreen" id="roblib-search-content-evergreen">
<?php foreach($results as $result): ?> <img src="<?php print $spinner_path; ?>"/>
<div class ="roblib-search-row">
<div class="rolib-title evergreen"><a href = "<?php print $result['url']; ?>"><?php print $result['title']; ?></a>
</div>
</div>
<?php endforeach; ?>
<div class ="roblib-search-more">Search the Catalog</div>
</div> </div>
<div class ="roblib-search-more">Search all Results</div>

15
targets/evergreen/theme/theme.inc

@ -6,6 +6,19 @@
*/ */
function roblib_search_evergreen_preprocess_roblib_search_evergreen(&$variables) { function roblib_search_evergreen_preprocess_roblib_search_evergreen(&$variables) {
//not yet implemented global $base_url;
if (!isset($query)) {
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
}
else {
return '';
}
}
$spinner_path = $base_url . '/' . drupal_get_path('module', 'roblib_search') . '/img/'.'spinner.gif';
$variables['spinner_path'] = $spinner_path;
$search_url = $base_url .'/roblib_search/evergreen/ajax/'.urlencode($query);
drupal_add_js(drupal_get_path('module', 'roblib_search_evergreen') . '/js/evergreen_results.js');
drupal_add_js(array('roblib_search_evergreen' => array('search_url' => $search_url)), array('type' => 'setting'));
} }
?> ?>

Loading…
Cancel
Save