added genres an langues condition to search, added close column bouton

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-19 22:15:44 +01:00
parent 4d2a3f85ce
commit 6af6e60946
12 changed files with 367 additions and 82 deletions
@@ -13,7 +13,8 @@
function initEvents(){
$('body')
.on('new-content-ajax-loaded', initAjax);
.on('new-content-ajax-loaded', initAjax)
.on('edlp_search_search_form-col-closed', onSearchClosed);
};
function initAjax(){
@@ -41,7 +42,15 @@
args.entries.push($(this).val());
});
loadResults(args)
// langues
args.langues = $('input[name="langues"]', this).val();
// genres
args.genres = $('input[name="genres"]', this).val();
console.log('EdlpSearch onSubmitForm() : args',args);
loadResults(args);
return false;
};
@@ -49,6 +58,8 @@
function loadResults(args){
console.log('EdlpSearch loadResults() : args', args);
_$form.addClass('ajax-loading');
_$body.addClass('ajax-loading');
$('[theme="edlp_search_results"]', _$container).addClass('ajax-loading');
var path = window.location.origin + drupalSettings.path.baseUrl +settings.results_ajax_url;
$.getJSON(path, args)
.done(function(data){
@@ -61,6 +72,9 @@
function onResultsLoaded(data){
console.log('EdlpSearch onResultsLoaded()', data);
_$form.removeClass('ajax-loading');
_$body.removeClass('ajax-loading');
// insert results col
$prev_results = $('[theme="edlp_search_results"]', _$container);
if($prev_results.length){
@@ -68,7 +82,7 @@
}else{
_$container.append(data.rendered);
}
// trigger event
_$body.trigger({
'type':'search-results-loaded',
@@ -81,5 +95,12 @@
console.warn('EdlpSearch : search results ajax load failed : '+error, jqxhr.responseText);
};
function onSearchClosed(e){
console.log('Edlp Search onSearchClosed()', e);
$('div[theme="edlp_search_results"]').remove();
// trigger event
_$body.trigger({'type':'search-closed'});
}
init();
})(jQuery, Drupal, drupalSettings);
@@ -273,6 +273,16 @@ class EdlpSearchController extends ControllerBase {
$query->keys($this->keys);
}
// TODO: langues
if (!empty($this->langues)) {
$query->addCondition('field_langues', $this->langues, "=");
}
// TODO: genres
if (!empty($this->genres)) {
$query->addCondition('field_genres', $this->genres, "=");
}
// entries
if (!empty($this->entries)){
$entries_condition_group = $query->createConditionGroup();
@@ -283,13 +293,8 @@ class EdlpSearchController extends ControllerBase {
$query->addConditionGroup($entries_condition_group);
}
// TODO: genres
// TODO: locuteurs
// TODO: langues
$result = $query->execute();
$items = $result->getResultItems();
// dpm($items);
@@ -318,6 +323,8 @@ class EdlpSearchController extends ControllerBase {
private function getRequestSearchArgs(){
// dpm($this->request);
$this->keys = $this->request->query->get('keys');
$this->langues = $this->request->query->get('langues');
$this->genres = $this->request->query->get('genres');
$this->entries = $this->request->query->get('entries');
}