Skip to content

Commit

Permalink
Merge pull request #9 from ATM-Consulting/NEW_preview_search_result
Browse files Browse the repository at this point in the history
NEW search preview
  • Loading branch information
ATM-Marc authored Feb 27, 2018
2 parents 5867534 + 9d54b7c commit 0ff4791
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 83 deletions.
9 changes: 9 additions & 0 deletions admin/searcheverywhere_setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@
print ajax_constantonoff('SEARCHEVERYWHERE_SEARCH_ONLY_IN_ENTITY');
print '</td></tr>';

$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("SEARCHEVERYWHERE_SEARCH_PREVIEW").'</td>';
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="center" width="300">';
print ajax_constantonoff('SEARCHEVERYWHERE_SEARCH_PREVIEW');
print '</td></tr>';


print '</table>';

llxFooter();
Expand Down
115 changes: 95 additions & 20 deletions class/actions_searcheverywhere.class.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,115 @@
<?php
class ActionsSearcheverywhere
{
/** Overloading the doActions function : replacing the parent's function with the one below
* @param parameters meta datas of the hook (context, etc...)
* @param object the object you want to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
* @param action current action (if set). Generally create or edit or null
* @return void
{
/** Overloading the doActions function : replacing the parent's function with the one below
* @param parameters meta datas of the hook (context, etc...)
* @param object the object you want to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
* @param action current action (if set). Generally create or edit or null
* @return void
*/
function printSearchForm($parameters, &$object, &$action, $hookmanager) {
global $langs,$db;

if (in_array('searchform',explode(':',$parameters['context'])) && DOL_VERSION <= 3.8)
global $langs,$db,$conf;

if (in_array('searchform',explode(':',$parameters['context'])) && (DOL_VERSION <= 3.8
|| !empty($conf->global->SEARCHEVERYWHERE_SEARCH_PREVIEW) ))
{
$langs->load('searcheverywhere@searcheverywhere');

$res = '';

$res.='<form method="post" action="'.dol_buildpath('/searcheverywhere/search.php',1).'">';
$res.= '<div class="menu_titre menu_titre_search"><label for="sew_keyword"><a class="vsmenu" href="'.dol_buildpath('/searcheverywhere/search.php',1).'">'.img_object($langs->trans('searcheverywhere'),'searcheverywhere@searcheverywhere').' '.$langs->trans('Searcheverywhere').'</a></label></div>';
$res.= ' <input type="text" size="10" name="keyword" title="'.$langs->trans('Keyword').'" class="flat" id="sew_keyword" /><input type="submit" value="'.$langs->trans('Go').'" class="button" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px">
$res.= ' <input type="text" size="10" name="keyword" title="'.$langs->trans('Keyword').'" class="flat" id="sew_keyword" /><input type="submit" value="'.$langs->trans('Go').'" class="button">
</form>';


if(!empty($conf->global->SEARCHEVERYWHERE_SEARCH_PREVIEW) ) {

$res.= '<script type="text/javascript">
$("#sew_keyword").autocomplete({
source: function( request, response ) {
$.ajax({
url: "'.dol_buildpath('/searcheverywhere/script/interface.php',1).'",
dataType: "json",
data: {
keyword: request.term
,get:"search-all"
}
,success: function( data ) {
var c = [];
$.each(data, function (i, cat) {
var first = true;
$.each(cat, function(j, obj) {
if(first) {
c.push({value:i, label:i, object:"title"});
first = false;
}
c.push({ value: j, label:" "+obj.label_clean, url:obj.url, desc:" "+obj.desc, object:i});
});
});
response(c);
}
});
},
minLength: 1,
select: function( event, ui ) {
if(ui.item.url) {
document.location.href = ui.item.url;
}
return false;
},
open: function( event, ui ) {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
$( "#sew_keyword" ).autocomplete( "instance" )._renderItem = function( ul, item ) {
$li = $( "<li style=\"white-space: nowrap;\" />" )
.attr( "data-value", item.value )
.append("<span class=\"select2-results\" >"+item.label+"</span>" )
.appendTo( ul );
if(item.object=="title") $li.css("font-weight","bold");
return $li;
};
</script>
';


}

$this->resprints = $res;
}

return 0;
}

function addSearchEntry($parameters, &$object, &$action, $hookmanager) {
global $langs;
if (in_array('searchform',explode(':',$parameters['context'])) && DOL_VERSION > 3.8) {

if (in_array('searchform',explode(':',$parameters['context'])) && DOL_VERSION > 3.8 && empty($conf->global->SEARCHEVERYWHERE_SEARCH_PREVIEW)) {
$search_boxvalue = $parameters['search_boxvalue'];

$langs->load('searcheverywhere@searcheverywhere');

$this->results = array(
'searcheverywhere' => array(
'img'=>'object_searcheverywhere'
Expand All @@ -44,7 +119,7 @@ function addSearchEntry($parameters, &$object, &$action, $hookmanager) {
)
);
}

return 0;
}
}
2 changes: 1 addition & 1 deletion core/modules/modsearcheverywhere.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct($db)
// (where XXX is value of numeric property 'numero' of module)
$this->description = "Description of module searcheverywhere";
// Possible values for version are: 'development', 'experimental' or version
$this->version = '1.1';
$this->version = '1.2';
// Key used in llx_const table to save module status enabled/disabled
// (where MYMODULE is value of property name of module in uppercase)
$this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
Expand Down
3 changes: 2 additions & 1 deletion langs/fr_FR/searcheverywhere.lang
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ SearchInfo=(Recherche strict du terme par défaut, ajoutez % pour une recherche
SearcheverywhereAbout=A propos
searcheverywhereSetup=Configuration
searcheverywhereNoSetupRequired=Aucune configuration requise
searcheverywhereSearchOnlyInEntity=Rechercher uniquement les données de l'entité dans laquelle on se trouve
searcheverywhereSearchOnlyInEntity=Rechercher uniquement les données de l'entité dans laquelle on se trouve
SEARCHEVERYWHERE_SEARCH_PREVIEW=Utiliser la recherche avec preview
Loading

0 comments on commit 0ff4791

Please sign in to comment.