From 0181c8e925f90b6a27694607a5103c8cdb48ac03 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Wed, 10 Apr 2013 14:19:22 -0300 Subject: [PATCH] updated cufts target and evergreen target now does ajax --- targets/cufts/roblib_search_cufts.module | 3 +- .../cufts/theme/roblib-search-cufts.tpl.php | 2 +- targets/evergreen/js/evergreen_results.js | 23 ++++++++ .../evergreen/roblib_search_evergreen.module | 57 ++++++++++++------- .../theme/roblib-search-evergreen.tpl.php | 15 ++--- targets/evergreen/theme/theme.inc | 15 ++++- 6 files changed, 82 insertions(+), 33 deletions(-) create mode 100644 targets/evergreen/js/evergreen_results.js diff --git a/targets/cufts/roblib_search_cufts.module b/targets/cufts/roblib_search_cufts.module index a3ed629..a3fdcd4 100644 --- a/targets/cufts/roblib_search_cufts.module +++ b/targets/cufts/roblib_search_cufts.module @@ -200,7 +200,8 @@ function roblib_search_cufts_help($path, $arg) { case 'admin/help#roblib_search_cufts': return t( '

- provides a target for the Roblib search module + provides a target for the Roblib search module. This target uses javascript + to render the results.

' ); } diff --git a/targets/cufts/theme/roblib-search-cufts.tpl.php b/targets/cufts/theme/roblib-search-cufts.tpl.php index a3063fa..a604166 100644 --- a/targets/cufts/theme/roblib-search-cufts.tpl.php +++ b/targets/cufts/theme/roblib-search-cufts.tpl.php @@ -17,7 +17,7 @@ */ ?> -
+
diff --git a/targets/evergreen/js/evergreen_results.js b/targets/evergreen/js/evergreen_results.js new file mode 100644 index 0000000..0a7ddf8 --- /dev/null +++ b/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('
'); + items.push('
'); + items.push(''+val.title+'
'); + items.push('
'); + }); + } + jQuery('#' + 'roblib-search-content-evergreen').empty().append(items.join('')); + }); + } + +} + + + diff --git a/targets/evergreen/roblib_search_evergreen.module b/targets/evergreen/roblib_search_evergreen.module index 3073197..f5fb2af 100644 --- a/targets/evergreen/roblib_search_evergreen.module +++ b/targets/evergreen/roblib_search_evergreen.module @@ -45,15 +45,22 @@ function roblib_search_evergreen_menu() { '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; } - function roblib_search_evergreen_config_form($form, &$form_state) { /* * $url = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52'); - $url_suffix = variable_get('roblib_search_evergreen_suffix', '/opac/extras/sru?version=1.1&operation=searchRetrieve&query='); - $number_of_records = variable_get('roblib_search_evergreen_num_results', '5'); + $url_suffix = variable_get('roblib_search_evergreen_suffix', '/opac/extras/sru?version=1.1&operation=searchRetrieve&query='); + $number_of_records = variable_get('roblib_search_evergreen_num_results', '5'); */ $form['roblib_search_evergreen_url'] = array( '#type' => 'textfield', @@ -83,7 +90,7 @@ function roblib_search_evergreen_config_form($form, &$form_state) { '#description' => t('The number of results to display in the Bento box'), '#required' => TRUE, ); - + return system_settings_form($form); } @@ -123,7 +130,6 @@ function roblib_search_evergreen_theme() { ); } - function roblib_search_evergreen_block_info() { $blocks['roblib_search_evergreen_results'] = array( @@ -146,22 +152,26 @@ function roblib_search_evergreen_block_view($delta = '') { $block['subject'] = t('Evergreen Results'); // The content of the block is typically generated by calling a custom // function. - $block['content'] = roblib_search_evergreen_get_results(); + $block['content'] = theme('roblib_search_evergreen', array('results' => NULL)); break; } return $block; } -function roblib_search_evergreen_get_results() { - drupal_add_css(drupal_get_path('module', 'roblib_search_evergreen') . '/css/roblib_search_evergreen.theme.css'); +function roblib_search_evergreen_ajax($query) { + $output = roblib_search_evergreen_get_results($query); + print $output; + exit(); +} - // Url parameters. - 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_suffix = variable_get('roblib_search_evergreen_search_suffix', '/opac/extras/sru?version=1.1&operation=searchRetrieve&query='); @@ -175,9 +185,16 @@ function roblib_search_evergreen_get_results() { $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) { $xml = $results->data; if (!isset($xml)) { @@ -196,10 +213,10 @@ function roblib_search_evergreen_parse_results($results) { $title = (string) $title[0]; $id = $record->xpath('marcxml:datafield[@tag="901"]/marcxml:subfield[@code="c"]'); $id = (string) $id[0]; - $output[$index]['title'] = $title ; - $output[$index++]['url'] = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52') - . variable_get('roblib_search_evergreen_detail_suffix','/opac/en-CA/skin/default/xml/rdetail.xml?r=') - . (string) $id ; + $output[$index]['title'] = $title; + $output[$index++]['url'] = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52') + . variable_get('roblib_search_evergreen_detail_suffix', '/opac/en-CA/skin/default/xml/rdetail.xml?r=') + . (string) $id; } } return $output; diff --git a/targets/evergreen/theme/roblib-search-evergreen.tpl.php b/targets/evergreen/theme/roblib-search-evergreen.tpl.php index 3eff248..a93ef59 100644 --- a/targets/evergreen/theme/roblib-search-evergreen.tpl.php +++ b/targets/evergreen/theme/roblib-search-evergreen.tpl.php @@ -17,13 +17,8 @@ */ ?> -
- -
- -
-
-
- -
Search the Catalog
-
\ No newline at end of file +
+ + +
+
Search all Results
\ No newline at end of file diff --git a/targets/evergreen/theme/theme.inc b/targets/evergreen/theme/theme.inc index af486b4..5898bde 100644 --- a/targets/evergreen/theme/theme.inc +++ b/targets/evergreen/theme/theme.inc @@ -6,6 +6,19 @@ */ 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')); } ?>