first test of launch a research, read the url args and prepopulate the form, ajax add and remove filter are not working anymore
This commit is contained in:
parent
c90cfa63e4
commit
1b9f8e3ab4
@ -736,21 +736,50 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
||||
// dsm($form, 'form');
|
||||
// global $user;
|
||||
// $form = array();
|
||||
|
||||
// TODO: get vid from settings
|
||||
$vid = 15; // onthologie
|
||||
$voc = taxonomy_vocabulary_load($vid);
|
||||
$voc_machinename = $voc->machine_name;
|
||||
// dsm($voc, "voc");
|
||||
|
||||
$values = $form_state['values'];
|
||||
|
||||
// add a back to search/base home bouton if on explore/foo
|
||||
$args = arg();
|
||||
$path = array_shift($args);
|
||||
if ($path == 'explore' || $path == 'bookmarks' || $path == 'lists' ) {
|
||||
$link = l('<i class="fi-home"></i>', base_path().'actuality', array(
|
||||
'html'=>true,
|
||||
'attributes'=>array('class'=>'back-search-home')
|
||||
));
|
||||
$form['actu'] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => $link,
|
||||
);
|
||||
|
||||
// TODO: get the keywords from args and reconstruct the filter lines with default values
|
||||
// dsm($args, "args");
|
||||
$keywords = explode("+", $args[0]);
|
||||
// dsm($keywords, 'keywords');
|
||||
|
||||
$default_values = array();
|
||||
foreach ($keywords as $key => $value) {
|
||||
$name = str_replace('"', '', $value);
|
||||
//Get the term
|
||||
$terms = taxonomy_get_term_by_name($name, $voc_machinename);
|
||||
$term = array_shift($terms);
|
||||
// dsm($term, $term->tid.' : '.$term->name);
|
||||
// get parents
|
||||
if(isset($term->tid)){
|
||||
$parents = taxonomy_get_parents_all($term->tid);
|
||||
// dsm($parents, 'parents');
|
||||
// build default values
|
||||
for ($p=count($parents)-1; $p >=0 ; $p--) {
|
||||
$default_values[$key][] = $parents[$p]->tid;
|
||||
}
|
||||
}
|
||||
}
|
||||
// dsm($default_values, 'default_values');
|
||||
|
||||
|
||||
// define default number of lines, 1 or more if some were already added
|
||||
$form_state['filterlines'] =
|
||||
isset($form_state['filterlines'])
|
||||
? $form_state['filterlines']
|
||||
: count($default_values)
|
||||
? count($default_values)
|
||||
: 1;
|
||||
|
||||
// filters form container
|
||||
$form['filters'] = array(
|
||||
@ -759,12 +788,6 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
// define default number of lines, 1 or more if some were already added
|
||||
$form_state['filterlines'] =
|
||||
isset($form_state['filterlines'])
|
||||
? $form_state['filterlines']
|
||||
: 1;
|
||||
|
||||
$trigger = FALSE;
|
||||
if (!empty($form_state['triggering_element']['#name'])) {
|
||||
$trigger = $form_state['triggering_element'];
|
||||
@ -781,13 +804,22 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
||||
}
|
||||
|
||||
// remove a line if needed
|
||||
|
||||
if(strpos($trigger['#name'], 'rm-filter-') === 0){
|
||||
// $form_state['filterlines'] = $form_state['filterlines']+1;
|
||||
$rmline = $trigger['#return_value'];
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: show result count live
|
||||
// TODO: filter next select form item
|
||||
|
||||
// build first level taxonomy tree and select options
|
||||
$taxotree = taxonomy_get_tree($vid, 0, 1, false);
|
||||
$level_0_ops = array(0=>t("Choose a filter"));
|
||||
foreach ($taxotree as $index => $term) {
|
||||
$level_0_ops[$term->tid] = t($term->name);
|
||||
}
|
||||
|
||||
// build filters lines (ajax enabled)
|
||||
for ($l=0; $l < $form_state['filterlines']; $l++) {
|
||||
|
||||
@ -814,18 +846,22 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
||||
)
|
||||
);
|
||||
|
||||
// build first level taxonomy tree and select options
|
||||
$taxotree = taxonomy_get_tree(15, 0, 1, false);
|
||||
$level_0_ops = array(0=>t("Choose a filter"));
|
||||
foreach ($taxotree as $index => $term) {
|
||||
$level_0_ops[$term->tid] = t($term->name);
|
||||
// get the default value
|
||||
// from from_state values if ajax
|
||||
// or from url args
|
||||
// or 0
|
||||
if(isset($values['filter-'.$l.'-0']) && $values['filter-'.$l.'-0']){
|
||||
$default = $values['filter-'.$l.'-0'];
|
||||
}else{
|
||||
$default = isset($default_values[$l][0]) ? $default_values[$l][0] : 0;
|
||||
}
|
||||
|
||||
// form select element for first level
|
||||
$form['filters']['filterline-'.$ll]['filter-'.$ll.'-0'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $level_0_ops,
|
||||
'#name' => 'filter-'.$ll.'-0',
|
||||
'#default_value' => 0,
|
||||
'#default_value' => $default,
|
||||
'#ajax' => array(
|
||||
'callback' => 'materio_search_api_advanced_search_select_callback',
|
||||
'wrapper' => 'advancedsearch-filters',
|
||||
@ -833,24 +869,30 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
||||
);
|
||||
|
||||
// add level 1 filter if level 0 chosen
|
||||
if(isset($values['filter-'.$l.'-0'])
|
||||
&& $values['filter-'.$l.'-0']
|
||||
){
|
||||
$default = $values['filter-'.$l.'-0'];
|
||||
$form['filters']['filterline-'.$ll]['filter-'.$ll.'-0']['#default_value'] = $default;
|
||||
if($default){
|
||||
// $default = $values['filter-'.$l.'-0'];
|
||||
// $form['filters']['filterline-'.$ll]['filter-'.$ll.'-0']['#default_value'] = $default;
|
||||
|
||||
// build second level taxonomy tree and select options
|
||||
$taxotree1 = taxonomy_get_tree(15, $default, 1, false);
|
||||
$taxotree1 = taxonomy_get_tree($vid, $default, 1, false);
|
||||
$level_1_ops = array(0=>t("Choose a filter"));
|
||||
foreach ($taxotree1 as $index => $term) {
|
||||
$level_1_ops[$term->tid] = t($term->name);
|
||||
}
|
||||
|
||||
if(isset($values['filter-'.$l.'-1']) && $values['filter-'.$l.'-1']){
|
||||
$default = $values['filter-'.$l.'-1'];
|
||||
}else{
|
||||
$default = isset($default_values[$l][1]) ? $default_values[$l][1] : 0;
|
||||
}
|
||||
// dsm($default, "default 1");
|
||||
|
||||
// form select element for second level
|
||||
$form['filters']['filterline-'.$ll]['filter-'.$ll.'-1'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $level_1_ops,
|
||||
'#name' => 'filter-'.$ll.'-1',
|
||||
'#default_value' => 0,
|
||||
'#default_value' => $default,
|
||||
'#ajax' => array(
|
||||
'callback' => 'materio_search_api_advanced_search_select_callback',
|
||||
'wrapper' => 'advancedsearch-filters',
|
||||
@ -858,15 +900,17 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
||||
);
|
||||
|
||||
// add level 2 filter if level 1 chosen
|
||||
if(isset($values['filter-'.$l.'-1'])
|
||||
&& $values['filter-'.$l.'-1']
|
||||
){
|
||||
$default = $values['filter-'.$l.'-1'];
|
||||
$form['filters']['filterline-'.$ll]['filter-'.$ll.'-1']['#default_value'] = $default;
|
||||
if($default){
|
||||
// $default = $values['filter-'.$l.'-1'];
|
||||
// $form['filters']['filterline-'.$ll]['filter-'.$ll.'-1']['#default_value'] = $default;
|
||||
|
||||
|
||||
// build second level taxonomy tree and select options
|
||||
$taxotree2 = taxonomy_get_tree(15, $default, 1, false);
|
||||
$taxotree2 = taxonomy_get_tree($vid, $default, 1, false);
|
||||
if(count($taxotree2)){
|
||||
$default = isset($default_values[$l][2]) ? $default_values[$l][2] : 0;
|
||||
// dsm($default, "default 2");
|
||||
|
||||
$level_2_ops = array(0=>t("Choose a filter"));
|
||||
foreach ($taxotree2 as $index => $term) {
|
||||
$level_2_ops[$term->tid] = t($term->name);
|
||||
@ -876,7 +920,7 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
||||
'#type' => 'select',
|
||||
'#options' => $level_2_ops,
|
||||
'#name' => 'filter-'.$ll.'-2',
|
||||
'#default_value' => 0,
|
||||
'#default_value' => $default,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -904,7 +948,6 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
||||
$form_state['filterlines'] = $form_state['filterlines']-1;
|
||||
}
|
||||
|
||||
|
||||
// button to add a new line of criterias
|
||||
$form['filters']['addfilters'] = array(
|
||||
'#type' => 'image_button',
|
||||
@ -917,10 +960,29 @@ function materio_search_api_advanced_search_form($form, &$form_state){
|
||||
'wrapper' => 'advancedsearch-filters',
|
||||
),
|
||||
'#executes_submit_callback' => false,
|
||||
'#attributes' => array(
|
||||
'class'=>array('add-filter')
|
||||
),
|
||||
);
|
||||
|
||||
// filters form container
|
||||
$form['rightcol'] = array(
|
||||
'#type' => 'container',
|
||||
);
|
||||
// add a back to search/base home bouton if on explore/foo
|
||||
if ($path == 'explore' || $path == 'bookmarks' || $path == 'lists' ) {
|
||||
$link = l('<i class="fi-home"></i>', base_path().'actuality', array(
|
||||
'html'=>true,
|
||||
'attributes'=>array('class'=>'back-search-home')
|
||||
));
|
||||
$form['rightcol']['actu'] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => $link,
|
||||
);
|
||||
}
|
||||
|
||||
// submit the search
|
||||
$form['search'] = array(
|
||||
$form['rightcol']['search'] = array(
|
||||
'#type' => 'image_button',
|
||||
'#src' => drupal_get_path('module', 'materio_search_api') . '/images/search.png',
|
||||
'#title' => t('Search'),
|
||||
@ -943,6 +1005,45 @@ function materio_search_api_advanced_search_rmline_callback($form, &$form_state)
|
||||
return $form['filters'];
|
||||
}
|
||||
|
||||
function materio_search_api_advanced_search_form_validate($form, &$form_state){
|
||||
// dsm($form, '$form');
|
||||
// dsm($form_state, '$form_state');
|
||||
// dsm(strlen($form_state['values']['searchfield']));
|
||||
// if (strlen(trim($form_state['values']['searchfield'])) <= 1) {
|
||||
// form_set_error('searchfield', 'Please enter at least 2 characters keyword.');
|
||||
// }
|
||||
}
|
||||
|
||||
function materio_search_api_advanced_search_form_submit($form, &$form_state){
|
||||
// dsm($form_state, 'form_state');
|
||||
|
||||
$values = $form_state['values'];
|
||||
$filterlines = isset($form_state['filterlines']) ? $form_state['filterlines'] : 0;
|
||||
$keywords = array();
|
||||
|
||||
// extract last tag of each lines
|
||||
for ($l=0; $l < $filterlines ; $l++) {
|
||||
for ($i=2; $i > 0 ; $i--) {
|
||||
if(isset($values['filter-'.$l.'-'.$i]) && $values['filter-'.$l.'-'.$i]){
|
||||
$term = taxonomy_term_load($values['filter-'.$l.'-'.$i]);
|
||||
$keywords[$term->tid] = '"'.$term->name.'"';
|
||||
continue 2;
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// dsm($keywords, 'keywordstid');
|
||||
|
||||
$keywords_str = implode("+", $keywords);
|
||||
|
||||
// dsm($keywords_str);
|
||||
|
||||
$form_state['redirect'] = 'explore/'.$keywords_str; //rawurlencode($keywords_str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* viewmode
|
||||
|
@ -3900,25 +3900,46 @@ body.home-v2 #main {
|
||||
#tool-bar #block-materio-search-api-mo-searchapi-advanced-search > .inner:active {
|
||||
transition: box-shadow 0s ease-out;
|
||||
box-shadow: 0 0 5px rgba(0, 0, 0, 0.4); }
|
||||
#tool-bar #materio-search-api-advanced-search-form .filter-line {
|
||||
margin: 0.3em 0;
|
||||
padding-top: 0.3em; }
|
||||
#tool-bar #materio-search-api-advanced-search-form .filter-line:not(:first-child) {
|
||||
border-top: 1px dotted black; }
|
||||
#tool-bar #materio-search-api-advanced-search-form .filter-line .form-item {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
text-transform: capitalize;
|
||||
margin: 0 0em 0 0; }
|
||||
#tool-bar #materio-search-api-advanced-search-form .filter-line select {
|
||||
width: auto; }
|
||||
#tool-bar #materio-search-api-advanced-search-form .rm-btn {
|
||||
float: right;
|
||||
margin: 0.4em 0 0.4em 0.4em; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #edit-search {
|
||||
float: right; }
|
||||
#tool-bar #materio-search-api-advanced-search-form > div {
|
||||
position: relative; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #advancedsearch-filters, #tool-bar #materio-search-api-advanced-search-form #edit-rightcol {
|
||||
display: inline-block;
|
||||
vertical-align: top; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #edit-rightcol {
|
||||
position: relative;
|
||||
text-align: center; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #edit-rightcol > * {
|
||||
display: block; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #edit-rightcol a.back-search-home {
|
||||
color: #000;
|
||||
padding-top: 0.45em; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #edit-rightcol a.back-search-home i:before {
|
||||
font-size: 1.3em; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #edit-rightcol #edit-search {
|
||||
margin: 1em 0 0.5em; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #advancedsearch-filters {
|
||||
padding-right: 0.5em;
|
||||
margin-right: 0.5em;
|
||||
border-right: 1px solid #ccc; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #advancedsearch-filters .filter-line {
|
||||
margin: 0.3em 0;
|
||||
padding-top: 0.3em; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #advancedsearch-filters .filter-line:not(:first-child) {
|
||||
border-top: 1px solid #ccc; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #advancedsearch-filters .filter-line .form-item {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
text-transform: capitalize;
|
||||
margin: 0 0em 0 0; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #advancedsearch-filters .filter-line select {
|
||||
width: auto; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #advancedsearch-filters .rm-btn {
|
||||
float: right;
|
||||
margin: 0.4em 0 0.4em 0.4em; }
|
||||
#tool-bar #materio-search-api-advanced-search-form #advancedsearch-filters .add-filter {
|
||||
margin: 0.5em 0; }
|
||||
|
||||
#center {
|
||||
border-radius: 10px;
|
||||
|
@ -1118,37 +1118,70 @@ $headerouterheight:$headerheight+$headerpaddingtop+$headerpaddingbottom;
|
||||
}
|
||||
|
||||
#materio-search-api-advanced-search-form{
|
||||
.filter-line{
|
||||
margin:0.3em 0;
|
||||
padding-top:0.3em;
|
||||
>div{
|
||||
position: relative;
|
||||
}
|
||||
|
||||
&:not(:first-child){
|
||||
border-top: 1px dotted black;
|
||||
#advancedsearch-filters, #edit-rightcol{
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
#edit-rightcol{
|
||||
position: relative;
|
||||
text-align: center;
|
||||
>*{display:block;}
|
||||
a.back-search-home{
|
||||
color:#000;
|
||||
padding-top: 0.45em;
|
||||
i:before{
|
||||
font-size:1.3em;
|
||||
}
|
||||
}
|
||||
.form-item{
|
||||
display:inline-block;
|
||||
vertical-align: middle;
|
||||
@include fs12; line-height:1;
|
||||
// padding-right:3em;
|
||||
text-transform: capitalize;
|
||||
// min-width : 4em;
|
||||
margin:0 0em 0 0;
|
||||
}
|
||||
|
||||
select{
|
||||
width:auto;
|
||||
|
||||
#edit-search{
|
||||
margin: 1em 0 0.5em;
|
||||
}
|
||||
}
|
||||
|
||||
.rm-btn{
|
||||
float: right;
|
||||
margin:0.4em 0 0.4em 0.4em;
|
||||
#advancedsearch-filters{
|
||||
padding-right: 0.5em;
|
||||
margin-right: 0.5em;
|
||||
border-right: 1px solid #ccc;
|
||||
|
||||
.filter-line{
|
||||
margin:0.3em 0;
|
||||
padding-top:0.3em;
|
||||
|
||||
&:not(:first-child){
|
||||
border-top: 1px solid #ccc;
|
||||
}
|
||||
.form-item{
|
||||
display:inline-block;
|
||||
vertical-align: middle;
|
||||
@include fs12; line-height:1;
|
||||
// padding-right:3em;
|
||||
text-transform: capitalize;
|
||||
// min-width : 4em;
|
||||
margin:0 0em 0 0;
|
||||
}
|
||||
|
||||
select{
|
||||
width:auto;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
.rm-btn{
|
||||
float: right;
|
||||
margin:0.4em 0 0.4em 0.4em;
|
||||
}
|
||||
|
||||
.add-filter{
|
||||
margin:0.5em 0;
|
||||
}
|
||||
}
|
||||
|
||||
#edit-search{
|
||||
float: right;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user