Explorar el Código

materiobaseajax module

first ajax geed results
+ 2 different custom autocomplete func (not used for now)
	- deselect
	- searchapi

Signed-off-by: bachy <git@g-u-i.net>
bachy hace 12 años
padre
commit
fb30fe966e

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 4 - 0
materiobaseajax-ck.js


+ 29 - 0
materiobaseajax.info

@@ -0,0 +1,29 @@
+name = Materiobaseajax
+description = "The description of this module"
+
+; Core version (required)
+core = 7.x
+
+; Package name (see http://drupal.org/node/542202 for a list of names)
+package = Materio
+
+; PHP version requirement (optional)
+; php = 5.2
+
+; Loadable code files
+  files[] = materiobaseajax.module
+; files[] = materiobaseajax.admin.inc
+; files[] = materiobaseajax.class.inc
+
+; Module dependencies
+; dependencies[] = mymodule
+; dependencies[] = theirmodule (1.2)
+; dependencies[] = anothermodule (>=2.4)
+; dependencies[] = views (3.x)
+
+; Configuration page
+; configure = admin/config/materiobaseajax
+
+
+; For further information about configuration options, see
+; - http://drupal.org/node/542202

+ 37 - 0
materiobaseajax.js

@@ -0,0 +1,37 @@
+// @codekit-prepend "gui.js"
+(function($) {
+
+    $('#search-api-page-search-form-grid').bind('submit', function(event) {
+      trace('search submited', event);
+      var keys = $(this).find('input[name*="keys"]').val(),
+          id = $(this).find('input[name="id"]').val();
+      trace('keys', keys);
+      trace('form_id', id);
+
+      $.getJSON('/materiobaseajax/search/'+id+'/'+keys,
+        // {form_id: "theform_id", keys: "thekeys"},
+        function(json){
+          trace('json', json);
+          if(json.return){
+            $('#content').html(json.return);
+          }
+      });
+      
+      return false;
+    });
+    
+    // select event need a patch http://drupal.org/node/365241#comment-5374686
+    
+    // $("input.form-text", '#search-api-page-search-form-grid').bind('autocomplete_select', function(event) {
+    //   trace('val', $(this).val());
+    //   var $form = $(this).parent('form');
+    //   // setTimeout(function(){
+    //   //   $form.submit();        
+    //   // }, 10);
+    // });
+
+    function navigate(){
+      
+    };
+  
+})(jQuery);

+ 74 - 0
materiobaseajax.module

@@ -0,0 +1,74 @@
+<?php
+/**
+ * @file
+ * This is the file description for Materiobaseajax module.
+ *
+ * In this more verbose, multi-line description, you can specify what this
+ * file does exactly. Make sure to wrap your documentation in column 78 so
+ * that the file can be displayed nicely in default-sized consoles.
+ */
+
+/**
+ * Implements hook_init().
+ */
+function materiobaseajax_init() {
+  drupal_add_js(drupal_get_path('module', 'materiobaseajax').'/materiobaseajax-ck.js');
+}
+
+/**
+ * Implements hook_menu().
+ */
+function materiobaseajax_menu() {
+  $items = array();
+
+  $items['materiobaseajax/search'] = array(
+    'title' => 'Matrio base ajax',
+    'page callback' => 'materiobaseajax_search_ajax',
+    'page arguments' => array(2, 3),
+    // 'access callback' => TRUE,
+    'access arguments' => array('access search_api_page'),
+    'file' => 'materiobaseajax.pages.inc',
+    'type' => MENU_CALLBACK,
+  );
+
+  return $items;
+}
+
+
+
+/**
+ * Implements hook_search_api_ajax_settings().
+ */
+function materiobaseajax_search_api_ajax_settings() {
+  $settings = array(
+  
+    // CSS id for main content (search results html)
+    // format: content => CSS id
+    'content' => '#content',
+    
+    // CSS id's for regions containing search blocks
+    // check your region names in mytheme.info
+    // format: region_name => CSS id
+    'regions' => array(
+      'headerblock_left' => '#headerblock-left',
+      // 'sidebar_second' => '#sidebar-second',
+    ),
+    
+    // OPTIONAL: if you want to provide an AJAX spinner
+    // this paht is for a default spinner path provided with this module
+    // @note: see the search_api_ajax.css
+    'spinner' => drupal_get_path('module', 'search_api_ajax') .'/spinner.gif',
+    
+    // OPTIONAL: if you want to use scroll-to-top functionality when paging
+    // scroll target div
+    // 'scrolltarget' => '#main-content',
+    // 'scrollspeed' => 1000,
+    
+    // OPTIONAL: if you want to fade search results when Ajaxing
+    // please set to 1 for TRUE
+    'fade' => 1,
+    'opacity' => 0.3,    
+  );
+  
+  return $settings;
+}

+ 22 - 0
materiobaseajax.pages.inc

@@ -0,0 +1,22 @@
+<?php
+
+
+function materiobaseajax_search_ajax($id, $keys){
+  
+  $page = search_api_page_load($id);
+  
+  $return = menu_execute_active_handler($page->path . '/' . $keys, FALSE);
+  
+  if (is_array($return)) {
+    $return = drupal_render($return);
+  }
+  
+  $rep = array(
+    'id'=>$id,
+    'keys'=>$keys,
+    'page'=>$page,
+    'return'=>$return,
+  );
+  
+  return drupal_json_output($rep);
+}

+ 66 - 8
materiobasemod.module

@@ -26,13 +26,21 @@ function materiobasemod_permission() {
  */
 function materiobasemod_menu() {
   $items = array();
-  $items['materiobase/search/autocomplete'] = array(
+  $items['materiobase/search/autocomplete/dbselect'] = array(
     'title' => 'Autocomplete materiobase search',
-    'page callback' => 'materiobase_search_autocomplete',
+    'page callback' => 'materiobase_search_autocomplete_dbselect',
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
     'file' => 'materiobasemod.pages.inc',
   );
+  $items['materiobase/search/autocomplete/searchapi'] = array(
+    'title' => 'Autocomplete materiobase search',
+    'page callback' => 'materiobase_search_autocomplete_searchapi',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+    'file' => 'materiobasemod.pages.inc',
+  );
+  
   return $items;
 }
 
@@ -81,28 +89,79 @@ function materiobasemod_block_view($delta = '') {
   return $block;
 }
 
+/**
+ * Implements hook_block_view_alter().
+ */
+function materiobasemod_block_view_alter(&$data, $block) {
+  if ($block->module == 'search_api_page') {
+    $page = search_api_page_load($block->delta);
+    $item = menu_get_item();
+    
+    if (isset($page->path) && $page->path == $item['path']) {
+      $keys = arg(count(arg(NULL, $page->path)));
+      if ($keys) {
+        $data['content']['keys_' . $page->id]['#default_value'] = $keys;
+        $data['content']['keys_' . $page->id]['#value'] = $keys;
+      }
+    }
+  }
+}
+
+/**
+ * Implements hook_entity_info_alter().
+ */
+function materiobasemod_entity_info_alter(&$entity_info) {
+  $entity_info['node']['view modes']['cardsmall'] = array(
+    'label' => t('Small card for the grid'),
+    'custom settings' => TRUE,
+  );
+  
+  $entity_info['node']['view modes']['cardmedium'] = array(
+    'label' => t('Medium card for the grid'),
+    'custom settings' => TRUE,
+  );
+  
+  $entity_info['node']['view modes']['cardbig'] = array(
+    'label' => t('Big card for the grid'),
+    'custom settings' => TRUE,
+  );
+}
+
+/**
+* Implements hook_preprocess_node().
+*/
+function materiobasemod_preprocess_node(&$vars) {
+  $vars['theme_hook_suggestions'][] = 'node__'.$vars['view_mode'];
+  $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'];
+  // dsm($vars, '$vars');
+}
+
+function materiobasemod_preprocess_field(&$vars) {
+  $vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#view_mode'];
+  $vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_type'] . '__' . $vars['element']['#view_mode'];
+  $vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_name'] . '__' . $vars['element']['#view_mode'];
+  // dsm($vars, '$vars');
+}
+
 
 /**
  * materiobase_search_form()
  */
 function materiobase_search_form(){
-  
   $form = array();
-  
   $form['searchfield'] = array(
     '#type' => 'textfield',
     '#default_value' => '',
-    '#autocomplete_path' => 'materiobase/search/autocomplete',
+    // '#autocomplete_path' => 'materiobase/search/autocomplete/searchapi',
+    '#autocomplete_path' => 'materiobase/search/autocomplete/dbselect',
     '#size' => 30,
     '#maxlength' => 1024,
   //  '#element_validate' => array('taxonomy_autocomplete_validate'),
   );
-
   $form['create'] = array(
     '#type' => 'submit',
     '#value' => t('Search'),
   );
-
   return $form;
 }
 
@@ -115,4 +174,3 @@ function template_preprocess_materiobase_search_block(&$vars){
   
   
 }
-

+ 47 - 1
materiobasemod.pages.inc

@@ -6,7 +6,7 @@
  * inspired by taxonomy_autocomplete()
  * 
  */
-function materiobase_search_autocomplete($typed = ''){
+function materiobase_search_autocomplete_dbselect($typed = ''){
   // If the request has a '/' in the search text, then the menu system will have
   // split it into multiple arguments, recover the intended $tags_typed.
   $args = func_get_args();
@@ -51,4 +51,50 @@ function materiobase_search_autocomplete($typed = ''){
 
   drupal_json_output($term_matches);
   
+}
+
+function materiobase_search_autocomplete_searchapi($typed = ''){
+  // If the request has a '/' in the search text, then the menu system will have
+  // split it into multiple arguments, recover the intended $tags_typed.
+  $args = func_get_args();
+  $typed = implode('/', $args);
+  
+  /*
+    TODO riche serach engine + \\ etc gmail like
+  */
+  
+  if ($typed != '') {
+
+
+    $query = search_api_query('referencement');
+
+    $query_filter = $query->createFilter();
+    $query_filter->condition('name', $typed);
+    // $query_filter->condition('type', 'article');
+
+    $query->filter($query_filter);
+
+    $tags_return = $query->execute();
+    
+    dsm($tags_return, '$tags_return');
+
+    $term_matches = array();
+    $index = search_api_index_load('referencement');
+    foreach ($index->loadItems(array_keys($tags_return['results'])) as $item) {
+      dsm($item, '$item');
+    }
+    
+    // 
+    // foreach ($tags_return as $tid => $name) {
+    //   $n = $name;
+    //   // Term names containing commas or quotes must be wrapped in quotes.
+    //   // if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
+    //   //   $n = '"' . str_replace('"', '""', $name) . '"';
+    //   // }
+    //   $term_matches[$n] = check_plain($name);
+    // }
+  }
+
+  drupal_json_output($term_matches);
+  
 }

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio