handled ajax call for advanced search, handled permissions for advanced form display
This commit is contained in:
parent
042e111bc4
commit
e9146c29ce
@ -1,5 +1,5 @@
|
||||
|
||||
(function($){MaterioSearchApiAjax=function(){var _isloadingresults=false;var _$content=$('#content');function init(){initSearchAjax();initViewMode();};function initSearchAjax(){$('#materio-search-api-search-form').bind('submit',function(event){setTimeout(function(){loadResults(getSearchKeys());},10);return false;});$("#edit-searchfield").bind('autocompleteSelect',function(event){setTimeout(function(){loadResults(getSearchKeys(),"taxonomy");},10);}).bind('focus',function(event){$(this).select();});$(document).bind('theme-ready',onThemeReady).bind('init-scroller-pager',onInitScrollerPager).bind('load-scroller-pager',onLoadScrollerPager).bind('view-mode-changed',onViewModeChanged).bind('history-state-change',onHistoryStateChange);};function onThemeReady(event){if(isActuality()||isExplore()){$.event.trigger({type:'resultschanged',container:isActuality()?'#content .actuality-items':'#content .search-results'});}};function getSearchKeys(){return $('#materio-search-api-search-form').find('input[name*="searchfield"]').val();};function loadResults(keys,searchmode){if(keys!==undefined&&keys!==''&&keys.length>=2){keys=keys.replace('/',' ');searchmode=searchmode||"fulltext";var types={},stringTypes=[];$('#edit-bundles-filter','#materio-search-api-search-form').find('input[type*="checkbox"]').each(function(i){$this=$(this);if($this.attr('checked'))
|
||||
(function($){MaterioSearchApiAjax=function(){var _isloadingresults=false;var _$content=$('#content');function init(){initSearchAjax();initViewMode();};function initSearchAjax(){trace('initSearchAjax');$('#materio-search-api-search-form').bind('submit',function(event){setTimeout(function(){loadResults(getSearchKeys());},10);return false;});$('#materio-search-api-advanced-search-form').bind('submit',function(event){event.preventDefault();setTimeout(function(){loadResults(getSearchFilters(),'advanced');},10);return false;});$("#edit-searchfield").bind('autocompleteSelect',function(event){setTimeout(function(){loadResults(getSearchKeys(),"taxonomy");},10);}).bind('focus',function(event){$(this).select();});$(document).bind('theme-ready',onThemeReady).bind('init-scroller-pager',onInitScrollerPager).bind('load-scroller-pager',onLoadScrollerPager).bind('view-mode-changed',onViewModeChanged).bind('history-state-change',onHistoryStateChange);};function onThemeReady(event){if(isActuality()||isExplore()){$.event.trigger({type:'resultschanged',container:isActuality()?'#content .actuality-items':'#content .search-results'});}};function getSearchKeys(){return $('#materio-search-api-search-form').find('input[name*="searchfield"]').val();};function getSearchFilters(){var keys=[];$('#materio-search-api-advanced-search-form').find('.filter-line').each(function(i,line){var $selects=$($('.form-item.form-type-select select',line).get().reverse()).slice(0,-1);$selects.each(function(j,select){if($(select).val()!==""){keys.push('"'+$("option:selected",select).text()+'"');return false;}});});trace("getSearchFilters :: keys",keys);return keys.join("+");};function loadResults(keys,searchmode){trace('loadResults keys',keys);if(keys!==undefined&&keys!==''&&keys.length>=2){keys=keys.replace('/',' ');searchmode=searchmode||"fulltext";var types={},stringTypes=[];$('#edit-bundles-filter','#materio-search-api-search-form').find('input[type*="checkbox"]').each(function(i){$this=$(this);if($this.attr('checked'))
|
||||
stringTypes.push($this.val());types[$this.val()]=$this.attr('checked');});if(!_isloadingresults){$.event.trigger('loading-content');_isloadingresults=true;$('#materio-search-api-search-form').addClass('loading');$.getJSON(Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_search_api_ajax/search/',{'types':types,'current_path':document.location.href,'keys':keys,'searchmode':searchmode},function(json){$.event.trigger({type:"record-stat",categorie:'Search',action:keys,label:'filters : '+stringTypes.join(' ,'),value:json.count});if(json.redirect){window.location=json.redirect;}else{$.event.trigger('loaded-content');_isloadingresults=false;$('#materio-search-api-search-form').removeClass('loading');changeContent(json);}});}}};function loadActuality(){if(!_isloadingresults){$.event.trigger('loading-content');_isloadingresults=true;$('#materio-search-api-search-form').addClass('loading');var url=Drupal.settings.basePath+Drupal.settings.pathPrefix+'materio_search_api_ajax/actuality';$.getJSON(url,function(json){$.event.trigger('loaded-content');_isloadingresults=false;$('#materio-search-api-search-form').removeClass('loading');changeContent(json);});}};function changeContent(json){if(json.returned){$.event.trigger('loaded-content');$('.inner-content',_$content).html(json.returned).find('ul.pager').hide();triggerContentChanged();}else{}
|
||||
$.event.trigger({type:'new-history-page',path:Drupal.settings.basePath+Drupal.settings.pathPrefix+json.path,title:json.title,content:json.returned});for(language in Drupal.settings.materio_search_api_ajax.languages){var l=Drupal.settings.materio_search_api_ajax.languages[language];$('#block-locale-language li.'+language+' a').attr('href',Drupal.settings.basePath+l.prefix+'/'+json.search_path+'/'+json.keys)};};function triggerContentChanged(){$.event.trigger({type:'resultschanged',container:'#content .search-results, #content .actuality-items'});};function onInitScrollerPager(event){if(isActuality()||isExplore())
|
||||
event.pager.hide();};function onLoadScrollerPager(event){if(!_isloadingresults){if(isExplore())
|
||||
|
@ -22,8 +22,9 @@ MaterioSearchApiAjax = function(){
|
||||
* searchAjax
|
||||
*/
|
||||
function initSearchAjax(){
|
||||
// trace('initSearchAjax');
|
||||
trace('initSearchAjax');
|
||||
|
||||
// fulltext search form
|
||||
$('#materio-search-api-search-form').bind('submit', function(event) {
|
||||
// trace('search submited', event);
|
||||
// var $this = $(this);
|
||||
@ -33,6 +34,17 @@ MaterioSearchApiAjax = function(){
|
||||
return false;
|
||||
});
|
||||
|
||||
// filtered search form
|
||||
$('#materio-search-api-advanced-search-form').bind('submit', function(event) {
|
||||
event.preventDefault();
|
||||
// trace('advanced search submited', event);
|
||||
// var $this = $(this);
|
||||
setTimeout(function(){
|
||||
loadResults(getSearchFilters(), 'advanced');
|
||||
},10);
|
||||
return false;
|
||||
});
|
||||
|
||||
// /!\ AUTOCOMPLETE SELECT EVENT need a patch http://drupal.org/node/365241#comment-5374686
|
||||
$("#edit-searchfield")
|
||||
.bind('autocompleteSelect', function(event) {
|
||||
@ -67,8 +79,27 @@ MaterioSearchApiAjax = function(){
|
||||
return $('#materio-search-api-search-form').find('input[name*="searchfield"]').val();
|
||||
};
|
||||
|
||||
function getSearchFilters(){
|
||||
var keys = [];
|
||||
$('#materio-search-api-advanced-search-form')
|
||||
.find('.filter-line').each(function(i, line) {
|
||||
// get the select form items from last to first
|
||||
// remove the first select object as it's not keywords for search
|
||||
var $selects = $($('.form-item.form-type-select select', line).get().reverse()).slice(0,-1);
|
||||
// get the keys from select form items
|
||||
$selects.each(function(j, select) {
|
||||
if($(select).val() !== ""){
|
||||
keys.push('"' + $("option:selected",select).text() + '"');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
trace("getSearchFilters :: keys", keys);
|
||||
return keys.join("+");
|
||||
};
|
||||
|
||||
function loadResults(keys, searchmode){
|
||||
//trace('keys', keys);
|
||||
trace('loadResults keys', keys);
|
||||
if(keys !== undefined && keys !== '' && keys.length >= 2){
|
||||
keys = keys.replace('/', ' ');
|
||||
|
||||
|
@ -504,7 +504,10 @@ function materio_search_api_block_view($delta = '') {
|
||||
|
||||
switch ($delta) {
|
||||
case 'materio_search_api_search':
|
||||
if (user_access('use materio search api') || user_access('use materio search api for breves')) {
|
||||
if (user_access('use materio search api') && user_access('use materio advanced search')) {
|
||||
$block['subject'] = t('Search');
|
||||
$block['content'] = theme('materio_search_api_double_search_block', array());
|
||||
}else if (user_access('use materio search api') || user_access('use materio search api for breves')) {
|
||||
$block['subject'] = t('Search');
|
||||
$block['content'] = theme('materio_search_api_search_block', array());
|
||||
}
|
||||
@ -617,20 +620,13 @@ function materio_search_api_search_form($form, &$form_state){
|
||||
|
||||
$args = arg();
|
||||
$path = array_shift($args);
|
||||
// dsm($args, 'args');
|
||||
// if(isset($args[0]) && $args[0] == "advanced"){
|
||||
// $advanced = true;
|
||||
// array_shift($args);
|
||||
// // dsm($args, 'shifted arsg');
|
||||
// // foreach ($args as $arg) {
|
||||
// // $typed[] = $arg;//(integer)$arg;
|
||||
// // }
|
||||
// $keys = implode(' +', $args);
|
||||
// }else{
|
||||
$keys = implode('/', $args);
|
||||
// }
|
||||
if (isset($args[0]) && $args[0] == "filters") {
|
||||
$path .= '/'.array_shift($args);
|
||||
}
|
||||
|
||||
$is_explore = $path == 'explore' || $path == 'explore/filters';
|
||||
|
||||
$keys = implode('/', $args);
|
||||
|
||||
if(user_access('use materio search api autocomplete')){ // use materio search api autocomplete | use materio search api filters
|
||||
$query = new EntityFieldQuery();
|
||||
@ -646,7 +642,7 @@ function materio_search_api_search_form($form, &$form_state){
|
||||
|
||||
$form['searchfield'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $path == 'explore' ? $keys : $default_value, // TODO: set the search page path global or a variable in settings
|
||||
'#default_value' => $is_explore ? $keys : $default_value, // TODO: set the search page path global or a variable in settings
|
||||
'#autocomplete_path' => 'materiosearchapi/autocomplete/searchapi',
|
||||
//'#autocomplete_path' => 'materiosearchapi/autocomplete/dbselect',
|
||||
'#size' => 30,
|
||||
@ -681,7 +677,7 @@ function materio_search_api_search_form($form, &$form_state){
|
||||
);
|
||||
|
||||
// add a back to search/base home bouton if on explore/foo
|
||||
if ($path == 'explore' || $path == 'bookmarks' || $path == 'lists' ) {
|
||||
if ($path == 'explore' || $path == 'explore/filters' || $path == 'bookmarks' || $path == 'lists' ) {
|
||||
|
||||
// buttons form container
|
||||
$form['rightcol'] = array(
|
||||
@ -1020,7 +1016,7 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
||||
'#type' => 'container',
|
||||
);
|
||||
// add a back to search/base home bouton if on explore/foo
|
||||
if ($path == 'explore' || $path == 'bookmarks' || $path == 'lists' ) {
|
||||
if ($path == 'explore' || $path == 'explore/filters' || $path == 'bookmarks' || $path == 'lists' ) {
|
||||
$link = l('<i class="fi-home"></i>', base_path().'actuality', array(
|
||||
'html'=>true,
|
||||
'attributes'=>array('class'=>'back-search-home')
|
||||
@ -1137,6 +1133,11 @@ function materio_search_api_theme($existing, $type, $theme, $path) {
|
||||
'template' => 'materio-search-api-advanced-search-block',
|
||||
'path' => drupal_get_path('module', 'materio_search_api').'/templates',
|
||||
),
|
||||
'materio_search_api_double_search_block' => array(
|
||||
'arguments' => array(),
|
||||
'template' => 'materio-search-api-double-search-block',
|
||||
'path' => drupal_get_path('module', 'materio_search_api').'/templates',
|
||||
),
|
||||
'materio_search_api_select_viewmode_block' => array(
|
||||
'arguments' => array(),
|
||||
'template' => 'materio-search-api-select-viewmode-block',
|
||||
@ -1193,15 +1194,11 @@ function materio_search_api_theme($existing, $type, $theme, $path) {
|
||||
|
||||
|
||||
/**
|
||||
* template_preprocess_materiobase_search_block();
|
||||
* template_preprocess_materiobase_advanced_search_block();
|
||||
*/
|
||||
function template_preprocess_materio_search_api_search_block(&$vars){
|
||||
// dsm($vars, '$vars');
|
||||
$vars['search_title'] = t("Text search");
|
||||
$vars['searchform'] = drupal_get_form("materio_search_api_search_form");
|
||||
|
||||
$vars['advanced_search_title'] = t("Filtered search");
|
||||
$vars['advanced_searchform'] = drupal_get_form("materio_search_api_advanced_search_form");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1212,6 +1209,18 @@ function template_preprocess_materio_search_api_advanced_search_block(&$vars){
|
||||
$vars['searchform'] = drupal_get_form("materio_search_api_advanced_search_form");
|
||||
}
|
||||
|
||||
/**
|
||||
* template_preprocess_materiobase_search_block();
|
||||
*/
|
||||
function template_preprocess_materio_search_api_double_search_block(&$vars){
|
||||
// dsm($vars, '$vars');
|
||||
$vars['search_title'] = t("Text search");
|
||||
$vars['searchform'] = drupal_get_form("materio_search_api_search_form");
|
||||
|
||||
$vars['advanced_search_title'] = t("Filtered search");
|
||||
$vars['advanced_searchform'] = drupal_get_form("materio_search_api_advanced_search_form");
|
||||
}
|
||||
|
||||
|
||||
function template_preprocess_materio_search_api_select_viewmode_block(&$vars){
|
||||
global $user;
|
||||
|
@ -5,21 +5,18 @@ function materio_search_api_ajax_search($page = 0){
|
||||
$debug = false;
|
||||
global $user, $base_url;
|
||||
// TODO: set research path configurable
|
||||
$search_path = "explore";
|
||||
|
||||
$searchmode = $_GET['searchmode'];
|
||||
// dsm($searchmode, 'searchmode');
|
||||
|
||||
$search_path = $searchmode == "advanced" ? "explore/filters" : "explore";
|
||||
|
||||
# execute search
|
||||
$_GET['page'] = $page;
|
||||
|
||||
$keys = rawurldecode($_GET['keys']);
|
||||
// $keys = $_GET['keys'];
|
||||
// dsm($keys, 'keys');
|
||||
|
||||
// foreach(explode(' ', $keys) as $word){
|
||||
// $words[] = rawurlencode($word);
|
||||
// }
|
||||
// $keys_encoded = implode(' ', $words);
|
||||
// dsm($words, 'words');
|
||||
|
||||
// we encode to times the keys ... is this necessary ??
|
||||
$keys_encoded = rawurlencode($keys);
|
||||
|
||||
$path = $search_path . '/' . $keys;//. ($page ? '?page='.$page : '');
|
||||
@ -80,10 +77,10 @@ function materio_search_api_ajax_search($page = 0){
|
||||
|
||||
// define mode (between full text or only term selected on autocompletion)
|
||||
// TODO implement the new search mode (only term)
|
||||
if(isset($_GET['searchmode'])){
|
||||
$searchmode = $_GET['searchmode'];
|
||||
user_save($user, array("data"=>array('materiosearchapi_searchmode' => $searchmode)));
|
||||
}
|
||||
// if(isset($_GET['searchmode'])){
|
||||
// $searchmode = $_GET['searchmode'];
|
||||
// user_save($user, array("data"=>array('materiosearchapi_searchmode' => $searchmode)));
|
||||
// }
|
||||
|
||||
// dsm($path, 'path');
|
||||
// execute the searcj path and retrive results
|
||||
|
@ -0,0 +1,10 @@
|
||||
<div class="inner">
|
||||
<div class="msa-form-wrapper msa-search">
|
||||
<h4 class="form-title"><?php print $search_title; ?></h4>
|
||||
<?php print render($searchform); ?>
|
||||
</div>
|
||||
<div class="msa-form-wrapper msa-advanced-search">
|
||||
<h4 class="form-title"><?php print $advanced_search_title; ?></h4>
|
||||
<?php print render($advanced_searchform); ?>
|
||||
</div>
|
||||
</div>
|
@ -1,11 +1,5 @@
|
||||
<div class="inner">
|
||||
<div class="msa-form-wrapper msa-search">
|
||||
<h4 class="form-title"><?php print $search_title; ?></h4>
|
||||
<?php print render($searchform); ?>
|
||||
</div>
|
||||
<div class="msa-form-wrapper msa-advanced-search">
|
||||
<h4 class="form-title"><?php print $advanced_search_title; ?></h4>
|
||||
<?php print render($advanced_searchform); ?>
|
||||
</div>
|
||||
|
||||
<?php print render($searchform); ?>
|
||||
|
||||
</div>
|
||||
|
@ -52,7 +52,7 @@
|
||||
_isMembershipForm = _$body.is('.page-node-11186'), //$('body').is('.page-node-11187') || ,
|
||||
_isBreveMateriauNodePage = _$body.is('.node-type-breve') || _$body.is('.node-type-materiau'),
|
||||
// _isBreveMateriauNodePage = _themeSettings.page_callback == 'node_page_view' && (_themeSettings.node_type == 'materiau' || _themeSettings.node_type == 'breve'),
|
||||
_hasDoubleSearchForm = $('#block-materio-search-api-materio-search-api-search').length,
|
||||
_hasDoubleSearchForm = $('#block-materio-search-api-materio-search-api-search .msa-search').length && $('#block-materio-search-api-materio-search-api-search .msa-advanced-search').length,
|
||||
_resizeTimer,
|
||||
_max_480 = function(){ return (viewport().width < 479); },
|
||||
_480_768 = function(){ return ( !_max_480() && _max_768() ); },
|
||||
@ -1607,7 +1607,6 @@
|
||||
* Forms
|
||||
*/
|
||||
function initForms(){
|
||||
|
||||
$('#edit-searchfield:not(.processed)')
|
||||
.bind('focus', function(event) {
|
||||
var $this = $(this);
|
||||
@ -1624,7 +1623,7 @@
|
||||
})
|
||||
.addClass('processed');
|
||||
|
||||
hideLabelsFromRegisterForm();
|
||||
hideLabelsFromRegisterForm();
|
||||
};
|
||||
|
||||
function hideLabelsFromRegisterForm () {
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
(function($){Drupal.behaviors.init_theme={};Drupal.behaviors.init_theme.attach=function(context){$('#messages-and-help > div.messages:not(.processed)').addClass('processed').each(function(){if($('a',this).size()||$(this).is('.error')||$(this).is('.warning')||$(this).text().length>100){$(this).prepend("<span class='close'>X</span>");$('span.close',this).click(function(){$(this).parent().slideUp('fast');});}
|
||||
else{$(this).animate({opacity:1},5000,'linear',function(){$(this).slideUp('fast');});}});};Drupal.behaviors.materio={};Drupal.behaviors.materio.attach=function(context){};MaterioBaseTheme=function(){var _settings=Drupal.settings,_themeSettings=_settings.materiobasetheme,_strings=_themeSettings.strings,_History=window.History,_this=this,_$body=$('body'),_$content=$('#content'),_jsp,_$tooltip=$('<div id="tooltip" class="op-hidden">').appendTo('body'),_$homeUtilities,_$homeBlockDidactique,_hoverHomeDidactique=false,_homeTimeInterval,_touch=$('html').is('.touch'),_statePushed=false,position={x:null,y:null},translate3d_content=0,_isLoggedIn=!_$body.is('.not-logged-in'),_isFrontNotLogged=_$body.is('.front.not-logged-in'),_isFrontHomeV2=_$body.is('.home-v2'),_skrollr,_isMembershipForm=_$body.is('.page-node-11186'),_isBreveMateriauNodePage=_$body.is('.node-type-breve')||_$body.is('.node-type-materiau'),_hasDoubleSearchForm=$('#block-materio-search-api-materio-search-api-search').length,_resizeTimer,_max_480=function(){return(viewport().width<479);},_480_768=function(){return(!_max_480()&&_max_768());},_max_768=function(){return(viewport().width<767);},_768_980=function(){return(!_max_768()&&_max_980());},_max_980=function(){return(viewport().width<979);},_980_1200=function(){return(!_max_980()&&_max_1200());},_max_1200=function(){return(viewport().width<1199);},_previewIsOpen=false,_viewmodes={bookmark:50,cardsmall:100,cardmedium:210,cardbig:425,cardfull:850};var v1,v2,v3,v4,v5;function init(){trace('init MaterioBaseTheme');checkIE();initHistoryNav();if(_isFrontHomeV2)
|
||||
else{$(this).animate({opacity:1},5000,'linear',function(){$(this).slideUp('fast');});}});};Drupal.behaviors.materio={};Drupal.behaviors.materio.attach=function(context){};MaterioBaseTheme=function(){var _settings=Drupal.settings,_themeSettings=_settings.materiobasetheme,_strings=_themeSettings.strings,_History=window.History,_this=this,_$body=$('body'),_$content=$('#content'),_jsp,_$tooltip=$('<div id="tooltip" class="op-hidden">').appendTo('body'),_$homeUtilities,_$homeBlockDidactique,_hoverHomeDidactique=false,_homeTimeInterval,_touch=$('html').is('.touch'),_statePushed=false,position={x:null,y:null},translate3d_content=0,_isLoggedIn=!_$body.is('.not-logged-in'),_isFrontNotLogged=_$body.is('.front.not-logged-in'),_isFrontHomeV2=_$body.is('.home-v2'),_skrollr,_isMembershipForm=_$body.is('.page-node-11186'),_isBreveMateriauNodePage=_$body.is('.node-type-breve')||_$body.is('.node-type-materiau'),_hasDoubleSearchForm=$('#block-materio-search-api-materio-search-api-search .msa-search').length&&$('#block-materio-search-api-materio-search-api-search .msa-advanced-search').length,_resizeTimer,_max_480=function(){return(viewport().width<479);},_480_768=function(){return(!_max_480()&&_max_768());},_max_768=function(){return(viewport().width<767);},_768_980=function(){return(!_max_768()&&_max_980());},_max_980=function(){return(viewport().width<979);},_980_1200=function(){return(!_max_980()&&_max_1200());},_max_1200=function(){return(viewport().width<1199);},_previewIsOpen=false,_viewmodes={bookmark:50,cardsmall:100,cardmedium:210,cardbig:425,cardfull:850};var v1,v2,v3,v4,v5;function init(){trace('init MaterioBaseTheme');checkIE();initHistoryNav();if(_isFrontHomeV2)
|
||||
initHomeV2();if(_isMembershipForm)
|
||||
initMembershipForm();initForms();if(!_isFrontHomeV2)
|
||||
initLayout();initInfinitScroller();initEvents();initKeyboardShortcuts();initViewmodes();if(_hasDoubleSearchForm)
|
||||
|
Loading…
x
Reference in New Issue
Block a user