LSsearch : added predefined filters parameters
authorBenjamin Renard <brenard@easter-eggs.com>
Wed, 3 Feb 2010 01:10:04 +0000 (02:10 +0100)
committerBenjamin Renard <brenard@easter-eggs.com>
Wed, 3 Feb 2010 01:10:04 +0000 (02:10 +0100)
public_html/conf/LSobjects/config.LSobjects.LSpeople.php
public_html/css/default/base.css
public_html/includes/class/class.LSsearch.php
public_html/includes/js/LSview.js
public_html/templates/default/viewSearch.tpl
public_html/view.php

index 7ec8f26..b55c96c 100644 (file)
@@ -118,7 +118,11 @@ $GLOBALS['LSobjects']['LSpeople'] = array (
       'mail'
     ),
     'params' => array (
-      'recursive' => true
+      'recursive' => true,
+    ),
+    'predefinedFilters' => array (
+      'personalTitle=Mr.' => 'Man',
+      'personalTitle=Ms' => 'Woman'
     )
   ),
   
index c30c402..522a2a8 100644 (file)
@@ -286,10 +286,10 @@ a.question {
  * LSview_search
  *********************
  */
-form.LSview_search {
+div.LSview_search {
   float:              right;
   margin:             0;
-  margin-top:         0.5em;
+  margin-top:         -0.5em;
   margin-right:       2em;
 }
 
@@ -313,3 +313,10 @@ input[type='submit'].LSview_search {
   background-color:   #0072b8;
   color:              #fff;
 }
+
+#LSview_search_predefinedFilter {
+  float:              left;
+  margin-top:         -1.8em;
+  margin-bottom:      0;
+  margin-left:        1.2em;
+}
index adf7da2..44dd42e 100644 (file)
@@ -41,6 +41,7 @@ class LSsearch {
     // Search params
     'filter' => NULL,
     'pattern' => NULL,
+    'predefinedFilter' => false,
     'basedn' => NULL,
     'subDn' => NULL,
     'scope' => NULL,
@@ -437,6 +438,28 @@ class LSsearch {
         $OK=false;
       }
     }
+
+    // predefinedFilter
+    if (isset($params['predefinedFilter'])) {
+      if (is_string($params['predefinedFilter'])) {
+        if (empty($params['predefinedFilter'])) {
+          $this->params['predefinedFilter']=false;
+        }
+        elseif(is_array($this -> config['predefinedFilters'])) {
+          if(isset($this->config['predefinedFilters'][$params['predefinedFilter']])) {
+            $this -> params['predefinedFilter'] = $params['predefinedFilter'];
+          }
+          else {
+            LSerror :: addErrorCode('LSsearch_03','predefinedFilter');
+            $OK=false;
+          }
+        }
+      }
+      else {
+        LSerror :: addErrorCode('LSsearch_03','predefinedFilter');
+        $OK=false;
+      }
+    }
     
     // Display Format
     if (is_string($params['displayFormat'])) {
@@ -648,6 +671,19 @@ class LSsearch {
       }
     }
     
+    // predefinedFilter
+    if (is_string($this -> params['predefinedFilter'])) {
+      if (!is_null($retval['filter'])) {
+        $filter=LSldap::combineFilters('and',array($this -> params['predefinedFilter'],$retval['filter']));
+        if ($filter) {
+          $retval['filter']=$filter;
+        }
+      }
+      else {
+        $retval['filter']=$this -> params['predefinedFilter'];
+      }
+    }
+    
     // Filter
     $objFilter=LSldapObject::getObjectFilter($this -> LSobject);
     if ($objFilter) {
@@ -662,7 +698,6 @@ class LSsearch {
       }
     }
     
-    
     // Recursive
     if (is_null($retval['basedn'])) {
       if (!is_null($this -> params['subDn'])) {
@@ -925,6 +960,9 @@ class LSsearch {
       $this -> _canCopy = LSsession :: canCreate($this -> LSobject);
       return $this -> _canCopy;
     }
+    elseif ($key=='predefinedFilters') {
+      return ((is_array($this -> config['predefinedFilters']))?$this -> config['predefinedFilters']:array());
+    }
     else {
       throw new Exception('Incorrect property !');
     }
index 6dc98ee..d8ff8b5 100644 (file)
@@ -30,6 +30,18 @@ var LSview = new Class({
           el.addEvent('click',this.onRemoveViewBtnClick.bindWithEvent(this,el));
         }
       }, this);
+      
+      this.LSsearchForm = $('LSsearch_form');
+      this.LSsearchPredefinedFilter = $('LSview_search_predefinedFilter');
+      if($type(this.LSsearchPredefinedFilter) && $type('LSsearch_form')) {
+        this.LSsearchPredefinedFilter.addEvent('change',this.onLSsearchPredefinedFilterChange.bind(this));
+      }
+    },
+    
+    onLSsearchPredefinedFilterChange: function() {
+      if (this.LSsearchForm) {
+        this.LSsearchForm.submit();
+      }
     },
 
     onTdLSobjectListNamesClick: function(td) {
index 467b3df..499b4d7 100644 (file)
@@ -1,6 +1,7 @@
 {include file='top.tpl'}
-<form action='{$searchForm.action}' method='post' class='LSview_search'>
-  
+<form action='{$searchForm.action}' method='post' class='LSview_search' id='LSsearch_form'>
+
+<div class='LSview_search'>
   {foreach from=$searchForm.hiddenFields item=value key=name}
     <input type='hidden' name='{$name}' value='{$value}' />
   {/foreach}
@@ -11,7 +12,7 @@
     <label class='LSview_search'>{$searchForm.labels.approx} : <input type='checkbox' name='approx' class='LSview_search' {if $searchForm.values.approx!=''}checked="true"{/if} /></label>
     {if $searchForm.recursive}<label class='LSview_search'>{$searchForm.labels.recursive} : <input type='checkbox' name='recursive' class='LSview_search' {if $searchForm.values.recursive!=''}checked="true"{/if}/></label>{/if}
   </p>
-</form>
+</div>
 
 <h1>
   {$pagetitle}
 </ul>
 {/if}
 
+{if ! empty($LSsearch)}
+  <select id='LSview_search_predefinedFilter' name='predefinedFilter'>
+    <option value=''>--</option>
+    {html_options options=$LSsearch->predefinedFilters selected=$searchForm.predefinedFilter}
+  </select>
+{/if}
+
+
+</form>
+
 <table class='LSobject-list'>
     <tr class='LSobject-list'>
       <th class='LSobject-list'>
index 4de9eb4..0d06d32 100644 (file)
@@ -111,7 +111,8 @@ if(LSsession :: startLSsession()) {
             'names' => array (
               'submit' => 'LSsearch_submit'
             ),
-            'hiddenFields' => $LSsearch -> getHiddenFieldForm()
+            'hiddenFields' => $LSsearch -> getHiddenFieldForm(),
+            'predefinedFilter' => $LSsearch->getParam('predefinedFilter')
           );
           $GLOBALS['Smarty']->assign('searchForm',$searchForm);