Browse Source

advanced search ajax callback for dynamic form building are almost working + started css

Bachir Soussi Chiadmi 6 years ago
parent
commit
1ee4e95491

BIN
sites/all/modules/gui/materiobasemod/images/addfilter.png


File diff suppressed because it is too large
+ 66 - 0
sites/all/modules/gui/materiobasemod/images/addfilter.svg


+ 117 - 16
sites/all/modules/gui/materiobasemod/materio_search_api.module

@@ -613,7 +613,7 @@ function materio_search_api_search_form($form, &$form_state){
   $args = arg();
   $path = array_shift($args);
   // dsm($args, 'args');
-  if($args[0] == "advanced"){
+  if(isset($args[0]) && $args[0] == "advanced"){
     $advanced = true;
     array_shift($args);
     // dsm($args, 'shifted arsg');
@@ -734,44 +734,145 @@ function materio_search_api_search_form_submit($form, &$form_state){
 function materio_search_api_advanced_search_form($form, &$form_state){
   //  dsm($form_state, 'form_state');
   // dsm($form, 'form');
-  global $user;
+  // global $user;
   $form = array();
 
+  // add a back to search/base home bouton if on explore/foo
   $args = arg();
   $path = array_shift($args);
-
-  // 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['actu'] = array(
       '#type' => 'markup',
       '#markup' => $link,
     );
   }
 
-  $form['searchfield'] = array(
-    '#type' => 'textfield',
-    '#default_value' => $path == '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,
-    '#maxlength' => 1024,
-    '#attributes' => array("default"=>$default_value),
+  // filters
+  $form['filters'] = array(
+    '#type' => 'container',
+    '#prefix' => '<div id="advancedsearch-filters">',
+    '#suffix' => '</div>',
   );
 
+  // building first level texonomy tree
+  $taxotree = taxonomy_get_tree(15, 0, 1, false);
+  // dsm($taxotree, "taxotree");
+  $level_0_ops = array(0=>t("Choose a filter"));
+  foreach ($taxotree as $index => $term) {
+    $level_0_ops[$term->tid] = $term->name;
+  }
 
-  $form['create'] = array(
+  $filterlines = isset($form_state['values']['filterlines']) ? $form_state['values']['filterlines'] : 1;
+
+  if (!empty($form_state['triggering_element'])) {
+    dsm($form_state['values'], 'form state values');
+  }
+
+  if(isset($form_state['triggering_element']['#name']) && $form_state['triggering_element']['#name'] == 'addfilters'){
+    $filterlines = $filterlines + 1;
+  }
+
+  $form['filterlines'] =  array(
+    '#type' => 'hidden',
+    '#value' => $filterlines,
+  );
+
+  // build filters lines (ajax enabled)
+  for ($i=0; $i < $filterlines; $i++) {
+
+    $form['filters']['filterline-'.$i] = array(
+      '#type' => 'container',
+      '#attributes' => array(
+        'class' => array("filter-line")
+      )
+    );
+
+    $form['filters']['filterline-'.$i]['filter-'.$i.'-0'] = array(
+      '#type' => 'select',
+      '#options' => $level_0_ops,
+      '#ajax' => array(
+        'callback' => 'materio_search_api_advanced_search_callback',
+        'wrapper' => 'advancedsearch-filters',
+        // 'methode' => 'replace',
+        // 'effect' => 'fade',
+      ),
+    );
+
+    // add level 1 filter if level 0 chosen
+    if(isset($form_state["values"]['filter-'.$i.'-0'])
+      & $form_state["values"]['filter-'.$i.'-0']
+      ){
+
+        $value = $form_state["values"]['filter-'.$i.'-0'];
+
+        $taxotree1 = taxonomy_get_tree(15, $value, 1, false);
+        dsm($taxotree1, "taxotree1");
+        $level_1_ops = array(
+          0=>t("Choose a filter")
+        );
+        foreach ($taxotree1 as $index => $term) {
+          $level_1_ops[$term->tid] = $term->name;
+        }
+
+        $form['filters']['filterline-'.$i]['filter-'.$i.'-1'] = array(
+          '#type' => 'select',
+          '#options' => $level_1_ops,
+          '#ajax' => array(
+            'callback' => 'materio_search_api_advanced_search_callback',
+            'wrapper' => 'advancedsearch-filters',
+            'methode' => 'replace',
+            // 'effect' => 'fade',
+          ),
+        );
+    }
+
+  }
+
+
+  // add a new line of criterias
+  $form['addfilters'] = array(
     '#type' => 'image_button',
-    '#src' => drupal_get_path('module', 'materio_search_api') . '/images/search.png',
-    '#value' => t('Search'),
+    '#src' => drupal_get_path('module', 'materio_search_api') . '/images/addfilter.png',
+    '#title' => t('Add a filter line'),
+    '#default_value' => 0,
+    '#return_value' => 1,
+    '#name' => "addfilters",
+    '#executes_submit_callback' => false,
+    '#ajax' => array(
+      'callback' => 'materio_search_api_advanced_search_callback',
+      'wrapper' => 'advancedsearch-filters',
+      'trigger_as' => array("name"=>"addfilters"),
+      // 'methode' => 'replacewith',
+      // 'speed' => 5000,
+      // 'effect' => 'slide',
+    ),
   );
+
+  // submit
+  // $form['create'] = array(
+  //   '#type' => 'image_button',
+  //   '#src' => drupal_get_path('module', 'materio_search_api') . '/images/search.png',
+  //   '#value' => t('Search'),
+  //   '#name' => "search",
+  //   '#executes_submit_callback' => false,
+  // );
+
   return $form;
 }
 
+function materio_search_api_advanced_search_callback($form, $form_state) {
+  // dsm($form_state, "callback form state");
+  // $form["filters"]['test']= array(
+  //   "#markup" => "test",
+  // );
+  return $form['filters'];
+}
+
+
 /**
  * viewmode
  */

File diff suppressed because it is too large
+ 235 - 204
sites/all/themes/gui/materiobasetheme/css/styles.css


+ 25 - 0
sites/all/themes/gui/materiobasetheme/scss/styles.scss

@@ -1086,8 +1086,33 @@ $headerouterheight:$headerheight+$headerpaddingtop+$headerpaddingbottom;
       #edit-bundles-filter{display:none;}
     }
   }
+
+
+  #block-materio-search-api-mo-searchapi-advanced-search{
+    // @include inlineblock(); vertical-align: middle ;
+    // position:absolute; top:10px; right:0;
+    float:right;
+    >.inner{
+      @include inlineblock(); margin:0 0 0 10px;
+      padding: 3px 10px; background-color:#fff; @include rounded(3px);
+      @include shadowBtn(); text-align: right;
+    }
+  }
+
+  #materio-search-api-advanced-search-form{
+    .filter-line{
+      .form-item.form-type-select{
+        display:inline-block;
+        vertical-align: middle;
+        @include fs12; line-height:1;
+        padding-right:3em;
+      }
+    }
+  }
+
 }
 
+
 #center{
   // background-color: #e6e6e6;
   @include rounded(10px);

Some files were not shown because too many files changed in this diff