BUG 13323 "Suggest Requirement" SOLVED

- Nuevo requerimiento de funciones, nueva funcionalidad de filtrado para el campo "Suggest"
- Solucion:
  Se ha implementado un nuevo atributo para el campo "Suggest" en el formulario "Add Suggest"
  que consta de un Dropdown que nos permite seleccionar una opcion, la misma permite el filtrado
  de texto, de la siguiente manera:
      > Results that contain the entered text
      > Results that start with the entered text
      > Results that finish with the entered text
  Esta opciones estan seteadas en el atributo "Search Type" con sus correspondientes opciones.
  Disponible para la version 2.5.2
This commit is contained in:
Luis Fernando Saisa Lopez
2013-10-18 09:06:21 -04:00
parent 8a053bc153
commit 4170a6ded0
6 changed files with 84 additions and 33 deletions

View File

@@ -1480,9 +1480,9 @@ axis.y=i.y;this.showAt(axis.x,axis.y,true);e.visibility="",this.focus()},h.manag
var Static_AutosuggestResponseData;var swStoreEntry=1;if(typeof(bsn)=="undefined")
_b=bsn={};if(typeof(_b.Autosuggest)=="undefined")
_b.Autosuggest={};else
alert("Autosuggest is already set!");_b.AutoSuggest=function(id,param)
alert("Autosuggest is already set!");_b.AutoSuggest=function(id,param,st)
{if(!document.getElementById)
return 0;this.fld=_b.DOM.gE(id);if(!this.fld)
return 0;this.fld=_b.DOM.gE(id);this.searchType=st;if(!this.fld)
return 0;this.sInp="";this.nInpC=0;this.aSug=[];this.iHigh=0;this.oP=param?param:{};var k,def={minchars:1,meth:"get",varname:"input",className:"autosuggest",timeout:5000,delay:50,offsety:-5,shownoresults:true,noresults:"No results!",maxheight:250,cache:true,maxentries:25};for(k in def)
{if(typeof(this.oP[k])!=typeof(def[k]))
this.oP[k]=def[k];}
@@ -1499,8 +1499,10 @@ return 0;_b.DOM.remE(this.idAs);this.sInp=val;if(val.length<this.oP.minchars)
{this.aSug=[];this.nInpC=val.length;return 0;}
var ol=this.nInpC;this.nInpC=val.length?val.length:0;var l=this.aSug.length;if(this.nInpC>ol&&l&&l<this.oP.maxentries&&this.oP.cache)
{var arr=[];for(var i=0;i<l;i++)
{if(this.aSug[i].value.substr(0,val.length).toLowerCase()==val.toLowerCase()||this.aSug[i].value.toLowerCase().indexOf(val.toLowerCase())>0)
arr.push(this.aSug[i]);}
{var flagSearch=0;if(this.searchType=="*searchtype*"&&this.aSug[i].value.toLowerCase().indexOf(val.toLowerCase())>0){flagSearch=1;}
if(this.searchType=="searchtype*"&&this.aSug[i].value.substr(0,val.length).toLowerCase()==val.toLowerCase()){flagSearch=1;}
if(this.searchType=="*searchtype"&&this.aSug[i].value.substr(this.aSug[i].value.length-val.length).toLowerCase()==val.toLowerCase()){flagSearch=1;}
if(flagSearch==1){arr.push(this.aSug[i]);}}
this.aSug=arr;this.createList(this.aSug);return false;}
else
{var pointer=this;var input=this.sInp;clearTimeout(this.ajID);this.ajID=setTimeout(function(){pointer.doAjaxRequest(input)},this.oP.delay);}

View File

@@ -23,7 +23,7 @@ if (typeof(_b.Autosuggest) == "undefined")
else
alert("Autosuggest is already set!");
_b.AutoSuggest = function (id, param)
_b.AutoSuggest = function (id, param, st)
{
// no DOM - give up!
//
@@ -34,6 +34,8 @@ _b.AutoSuggest = function (id, param)
//
this.fld = _b.DOM.gE(id);
this.searchType = st;
if (!this.fld)
return 0;
@@ -67,6 +69,7 @@ _b.AutoSuggest = function (id, param)
//_b.DOM.addEvent( this.fld, 'keyup', function(ev){ return pointer.onKeyPress(ev); } );
this.fld.onkeypress = function(ev){ return p.onKeyPress(ev); };
this.fld.onkeyup = function(ev){ return p.onKeyUp(ev); };
this.fld.setAttribute("autocomplete","off");
@@ -162,7 +165,6 @@ _b.AutoSuggest.prototype.onKeyUp = function (ev)
_b.AutoSuggest.prototype.getSuggestions = function (val)
{
// if input stays the same, do nothing
//
if (val == this.sInp)
@@ -172,7 +174,6 @@ _b.AutoSuggest.prototype.getSuggestions = function (val)
//
_b.DOM.remE(this.idAs);
this.sInp = val;
// input length is less than the min required to trigger a request
@@ -191,6 +192,8 @@ _b.AutoSuggest.prototype.getSuggestions = function (val)
// if caching enabled, and user is typing (ie. length of input is increasing)
// filter results out of aSuggestions from last request
//
var l = this.aSug.length;
if (this.nInpC > ol && l && l<this.oP.maxentries && this.oP.cache)
{
@@ -198,9 +201,24 @@ _b.AutoSuggest.prototype.getSuggestions = function (val)
for (var i=0;i<l;i++)
{
// if (this.aSug[i].value.substr(0,val.length).toLowerCase() == val.toLowerCase())
if (this.aSug[i].value.substr(0,val.length).toLowerCase() == val.toLowerCase() ||
this.aSug[i].value.toLowerCase().indexOf(val.toLowerCase()) > 0)
arr.push( this.aSug[i] );
var flagSearch = 0;
if (this.searchType == "*searchtype*" && this.aSug[i].value.toLowerCase().indexOf(val.toLowerCase()) > 0) {
flagSearch = 1;
}
if (this.searchType == "searchtype*" && this.aSug[i].value.substr(0,val.length).toLowerCase() == val.toLowerCase()) {
flagSearch = 1;
}
if (this.searchType == "*searchtype" && this.aSug[i].value.substr(this.aSug[i].value.length - val.length).toLowerCase() == val.toLowerCase()) {
flagSearch = 1;
}
if (flagSearch == 1) {
arr.push(this.aSug[i]);
}
}
this.aSug = arr;

View File

@@ -73,9 +73,11 @@ if( isset($request) ){
G::LoadClass('phpSqlParser');
$parser = new PHPSQLParser($SQL);
$searchType = $_GET["searchType"];
// Verif parsed array
// print_r($parser->parsed);
$SQL = queryModified($parser->parsed, $_GET['input']);
$SQL = queryModified($parser->parsed, $_GET['input'], $searchType);
$aRows = Array();
try {
@@ -225,7 +227,7 @@ function sortByChar($aRows, $charSel)
* @param string $inputSel default value empty string
* @return string
*/
function queryModified($sqlParsed, $inputSel = "")
function queryModified($sqlParsed, $inputSel = "", $searchType)
{
if(!empty($sqlParsed['SELECT'])) {
$sqlSelectOptions = (isset($sqlParsed["OPTIONS"]) && count($sqlParsed["OPTIONS"]) > 0)? implode(" ", $sqlParsed["OPTIONS"]) : null;
@@ -278,16 +280,27 @@ function queryModified($sqlParsed, $inputSel = "")
}
}
$sqlConditionLike = "LIKE '%" . $inputSel . "%'";
switch ($searchType) {
case "searchtype*":
$sqlConditionLike = "LIKE '" . $inputSel . "%'";
break;
case "*searchtype":
$sqlConditionLike = "LIKE '%" . $inputSel . "'";
break;
}
if(!empty($sqlParsed['WHERE'])){
$sqlWhere = " WHERE ";
$aWhere = $sqlParsed['WHERE'];
foreach($aWhere as $key => $value ){
$sqlWhere .= $value['base_expr'] . " ";
}
$sqlWhere .= " AND " . $sFieldSel . " LIKE '%". $inputSel . "%'";
$sqlWhere .= " AND " . $sFieldSel . " " . $sqlConditionLike;
}
else {
$sqlWhere = " WHERE " . $sFieldSel . " LIKE '%". $inputSel ."%' ";
$sqlWhere = " WHERE " . $sFieldSel . " " . $sqlConditionLike;
}
$sqlGroupBy = "";

View File

@@ -1267,6 +1267,7 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
public $sqlConnection = 0;
public $sql = '';
public $sqlOption = array ();
public $searchType = "*searchtext*";
//Atributes only for grids
public $gridFieldType = 'suggest';
public $formula = '';
@@ -1418,7 +1419,9 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
$sOptions .= ' return "' . $this->ajaxServer . '?request=suggest&json=true&limit=' . $this->maxresults;
$sOptions .= '&hash=' . $hash . '&dependentFieldsKeys=' . $sResultKeys . '&dependentFieldsValue="';
$sOptions .= $depValues . '"&input="+inputValue+"&inputEnconde64=enable"; ';
$sOptions .= $depValues . '"&input="+inputValue+"&inputEnconde64=enable&searchType=' . $this->searchType . '";';
$sOptions .= '},';
$sOptions .= 'json: true,';
$sOptions .= 'limit: ' . $this->maxresults . ',';
@@ -1481,7 +1484,7 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
$sOptions .= '}';
$str .= '<script type="text/javascript">';
$str .= 'var as_json = new bsn.AutoSuggest(\'form[' . $this->name . '_label]\', {' . $sOptions . $storeEntryData . '});';
$str .= 'var as_json = new bsn.AutoSuggest(\'form[' . $this->name . '_label]\', {' . $sOptions . $storeEntryData . '}, "' . $this->searchType . '");';
$str .= '</script>';
return $str;
@@ -1609,7 +1612,8 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
$sOptions .= ' return "' . $this->ajaxServer . '?request=suggest&json=true&limit=' . $this->maxresults;
$sOptions .= '&hash=' . $hash . '&dependentFieldsKeys=' . $sResultKeys . '&dependentFieldsValue="';
$sOptions .= $depValues . '"&input="+inputValue+"&inputEnconde64=enable"; ';
$sOptions .= $depValues . '"&input="+inputValue+"&inputEnconde64=enable&searchType=' . $this->searchType . '";';
$sOptions .= '},';
$sOptions .= 'json: true,';
$sOptions .= 'limit: ' . $this->maxresults . ',';
@@ -1665,7 +1669,7 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
$sOptions .= '}';
$str .= '<script type="text/javascript">';
$str .= 'var as_json = new bsn.AutoSuggest(\'form' . $rowId . '[' . $this->name . '_label]\', {' . $sOptions . $storeEntryData . '}); ';
$str .= 'var as_json = new bsn.AutoSuggest(\'form' . $rowId . '[' . $this->name . '_label]\', {' . $sOptions . $storeEntryData . '}, "' . $this->searchType . '"); ';
$str .= '</script>';
return $str;

View File

@@ -22,7 +22,7 @@
<tr>
<td class='FormLabel' width="{$form_labelWidth}"><font color="red">* </font>{$PME_XMLNODE_NAME}</td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_XMLNODE_NAME} </td> //-->
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_XMLNODE_NAME}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_XMLNODE_NAME}</td>
</tr>
<tr style="display: none">
<td colspan="2">{$form.PME_XMLNODE_NAME_OLD}</td>
@@ -33,7 +33,7 @@
<tr>
<td class='FormLabel' width="{$form_labelWidth}">{$PME_LABEL}</td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_LABEL} </td> //-->
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_LABEL}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_LABEL}</td>
</tr>
<tr>
<td class='FormTitle' colspan="2" align="">{$form.PME_SUBTITLE3}</td>
@@ -41,17 +41,17 @@
<tr>
<td class='FormLabel' width="{$form_labelWidth}">{$PME_STRTO}</td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_STRTO} </td> //-->
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_STRTO}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_STRTO}</td>
</tr>
<tr>
<td class='FormLabel' width="{$form_labelWidth}">{$PME_REQUIRED}</td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_REQUIRED} </td> //-->
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_REQUIRED}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_REQUIRED}</td>
</tr>
<tr>
<td class='FormLabel' width="{$form_labelWidth}">{$PME_READONLY}</td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_READONLY} </td> //-->
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_READONLY}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_READONLY}</td>
</tr>
<tr>
<td class="FormLabel" width="{$form_labelWidth}">{$PME_DEPENDENTFIELDS}</td>
@@ -61,11 +61,11 @@
<td class='FormLabel' width="{$form_labelWidth}">{$PME_SAVELABEL}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_SAVELABEL}</td>
</tr>
<tr>
<td class='FormLabel' width="{$form_labelWidth}">{$PME_HINT}</td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_HINT} </td> //-->
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_HINT}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_HINT}</td>
</tr>
<tr>
<td class='FormTitle' colspan="2" align="">{$form.PME_SUBTITLE}</td>
@@ -73,12 +73,12 @@
<tr>
<td class='FormLabel' width="{$form_labelWidth}">{$PME_SIZE}</td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_SIZE} </td> //-->
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_SIZE}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_SIZE}</td>
</tr>
<tr>
<td class='FormLabel' width="{$form_labelWidth}">{$PME_MODE}</td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_MODE} </td> //-->
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_MODE}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_MODE}</td>
</tr>
<tr>
<td class='FormTitle' colspan="2" align="">{$form.PME_SUBTITLE2}</td>
@@ -86,17 +86,17 @@
<tr>
<td class='FormLabel' width="{$form_labelWidth}"><font color="red">* </font>{$PME_SQLCONNECTION}</td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_SQLCONNECTION} </td> //-->
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_SQLCONNECTION}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_SQLCONNECTION}</td>
</tr>
<tr>
<td class='FormLabel' width="{$form_labelWidth}"><font color="red">* </font>{$PME_XMLNODE_VALUE}</td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_XMLNODE_VALUE} </td> //-->
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_XMLNODE_VALUE}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_XMLNODE_VALUE}</td>
</tr>
<tr>
<td class='FormLabel' width="{$form_labelWidth}">{$PME_MAXRESULTS}</td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_MAXRESULTS} </td> //-->
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_MAXRESULTS}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_MAXRESULTS}</td>
</tr>
<tr>
@@ -107,8 +107,14 @@
<tr>
<td class='FormLabel' width="{$form_labelWidth}"></td>
<!-- <td class='FormFieldContent' width="{$form_width}" >{$form.PME_STORE_NEW_ENTRY} </td> //-->
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_STORE_NEW_ENTRY}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_STORE_NEW_ENTRY}</td>
</tr>
<tr>
<td class='FormLabel' width="{$form_labelWidth}">{$PME_SEARCHTYPE}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_SEARCHTYPE}</td>
</tr>
<tr>
<td class='FormLabel' width="{$form_labelWidth}"><font color="red">* </font>{$PME_TABLE}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >
@@ -117,10 +123,10 @@
{$PME_PRIMARY_KEY_TYPE} {$form.PME_PRIMARY_KEY_TYPE}
</td>
</tr>
<tr>
<td class='FormLabel' width="{$form_labelWidth}">{$PME_CALLBACK}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_CALLBACK}</td>
<td class='FormFieldContent' width='{$form_fieldContentWidth}' >{$form.PME_CALLBACK}</td>
</tr>

View File

@@ -107,6 +107,14 @@ select XMLNODE_NAME, XMLNODE_NAME AS NAME FROM dynaForm WHERE XMLNODE_NAME <> @@
<en>Store new entry</en>
</PME_STORE_NEW_ENTRY>
<PME_SEARCHTYPE type="dropdown" required="0" readonly="0" optgroup="0" mode="edit">
<en>Search Type
<option name="*searchtype*">Results that contain the entered text</option>
<option name="searchtype*">Results that start with the entered text</option>
<option name="*searchtype">Results that finish with the entered text</option>
</en>
</PME_SEARCHTYPE>
<PME_TABLE_DATA type="hidden"/>
<PME_TABLE type="dropdown" sqlconnection="" required="1">
<en>Table</en>