LSsearch : added predefined filters parameters

This commit is contained in:
Benjamin Renard 2010-02-03 02:10:04 +01:00
parent 5d02706132
commit bc1a92ec35
6 changed files with 81 additions and 8 deletions

View file

@ -118,7 +118,11 @@ $GLOBALS['LSobjects']['LSpeople'] = array (
'mail' 'mail'
), ),
'params' => array ( 'params' => array (
'recursive' => true 'recursive' => true,
),
'predefinedFilters' => array (
'personalTitle=Mr.' => 'Man',
'personalTitle=Ms' => 'Woman'
) )
), ),

View file

@ -286,10 +286,10 @@ a.question {
* LSview_search * LSview_search
********************* *********************
*/ */
form.LSview_search { div.LSview_search {
float: right; float: right;
margin: 0; margin: 0;
margin-top: 0.5em; margin-top: -0.5em;
margin-right: 2em; margin-right: 2em;
} }
@ -313,3 +313,10 @@ input[type='submit'].LSview_search {
background-color: #0072b8; background-color: #0072b8;
color: #fff; color: #fff;
} }
#LSview_search_predefinedFilter {
float: left;
margin-top: -1.8em;
margin-bottom: 0;
margin-left: 1.2em;
}

View file

@ -41,6 +41,7 @@ class LSsearch {
// Search params // Search params
'filter' => NULL, 'filter' => NULL,
'pattern' => NULL, 'pattern' => NULL,
'predefinedFilter' => false,
'basedn' => NULL, 'basedn' => NULL,
'subDn' => NULL, 'subDn' => NULL,
'scope' => NULL, 'scope' => NULL,
@ -438,6 +439,28 @@ class LSsearch {
} }
} }
// 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 // Display Format
if (is_string($params['displayFormat'])) { if (is_string($params['displayFormat'])) {
$this -> params['displayFormat'] = $params['displayFormat']; $this -> params['displayFormat'] = $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 // Filter
$objFilter=LSldapObject::getObjectFilter($this -> LSobject); $objFilter=LSldapObject::getObjectFilter($this -> LSobject);
if ($objFilter) { if ($objFilter) {
@ -662,7 +698,6 @@ class LSsearch {
} }
} }
// Recursive // Recursive
if (is_null($retval['basedn'])) { if (is_null($retval['basedn'])) {
if (!is_null($this -> params['subDn'])) { if (!is_null($this -> params['subDn'])) {
@ -925,6 +960,9 @@ class LSsearch {
$this -> _canCopy = LSsession :: canCreate($this -> LSobject); $this -> _canCopy = LSsession :: canCreate($this -> LSobject);
return $this -> _canCopy; return $this -> _canCopy;
} }
elseif ($key=='predefinedFilters') {
return ((is_array($this -> config['predefinedFilters']))?$this -> config['predefinedFilters']:array());
}
else { else {
throw new Exception('Incorrect property !'); throw new Exception('Incorrect property !');
} }

View file

@ -30,6 +30,18 @@ var LSview = new Class({
el.addEvent('click',this.onRemoveViewBtnClick.bindWithEvent(this,el)); el.addEvent('click',this.onRemoveViewBtnClick.bindWithEvent(this,el));
} }
}, this); }, 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) { onTdLSobjectListNamesClick: function(td) {

View file

@ -1,6 +1,7 @@
{include file='top.tpl'} {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} {foreach from=$searchForm.hiddenFields item=value key=name}
<input type='hidden' name='{$name}' value='{$value}' /> <input type='hidden' name='{$name}' value='{$value}' />
{/foreach} {/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> <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} {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> </p>
</form> </div>
<h1> <h1>
{$pagetitle} {$pagetitle}
@ -27,6 +28,16 @@
</ul> </ul>
{/if} {/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'> <table class='LSobject-list'>
<tr class='LSobject-list'> <tr class='LSobject-list'>
<th class='LSobject-list'> <th class='LSobject-list'>

View file

@ -111,7 +111,8 @@ if(LSsession :: startLSsession()) {
'names' => array ( 'names' => array (
'submit' => 'LSsearch_submit' 'submit' => 'LSsearch_submit'
), ),
'hiddenFields' => $LSsearch -> getHiddenFieldForm() 'hiddenFields' => $LSsearch -> getHiddenFieldForm(),
'predefinedFilter' => $LSsearch->getParam('predefinedFilter')
); );
$GLOBALS['Smarty']->assign('searchForm',$searchForm); $GLOBALS['Smarty']->assign('searchForm',$searchForm);