Work on the new selectArrayAjax widget

This commit is contained in:
Laurent Destailleur 2015-10-21 20:43:11 +02:00
parent 9a1ec900bd
commit fd72b4a400
4 changed files with 75 additions and 9 deletions

View File

@ -37,12 +37,69 @@ include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$search_boxvalue=GETPOST('q'); $search_boxvalue=GETPOST('q');
$arrayresult=array('a'=>'aaaa', 'b'=>'bbbb'); $arrayresult=array();
if ($conf->projet->enabled) // Define $searchform
if ((( ! empty($conf->societe->enabled) && (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))) || ! empty($conf->fournisseur->enabled)) && ! empty($conf->global->MAIN_SEARCHFORM_SOCIETE) && $user->rights->societe->lire)
{ {
$arrayresult['searchintoproject']=$langs->trans("SearchIntoProject", $search_boxvalue); $langs->load("companies");
//$searchform.=printSearchForm(DOL_URL_ROOT.'/societe/list.php', DOL_URL_ROOT.'/societe/list.php', $langs->trans("ThirdParties"), 'soc', 'sall', 'T', 'searchleftt', img_object('','company'));
$arrayresult['searchintothirdparty']=$langs->trans("SearchIntoThirdparties", $search_boxvalue);
} }
if (! empty($conf->societe->enabled) && ! empty($conf->global->MAIN_SEARCHFORM_CONTACT) && $user->rights->societe->lire)
{
$langs->load("companies");
//$searchform.=printSearchForm(DOL_URL_ROOT.'/contact/list.php', DOL_URL_ROOT.'/contact/list.php', $langs->trans("Contacts"), 'contact', 'sall', 'A', 'searchleftc', img_object('','contact'));
$arrayresult['searchintocontact']=$langs->trans("SearchIntoContacts", $search_boxvalue);
}
if (((! empty($conf->product->enabled) && $user->rights->produit->lire) || (! empty($conf->service->enabled) && $user->rights->service->lire))
&& ! empty($conf->global->MAIN_SEARCHFORM_PRODUITSERVICE))
{
$langs->load("products");
//$searchform.=printSearchForm(DOL_URL_ROOT.'/product/list.php', DOL_URL_ROOT.'/product/list.php', $langs->trans("Products")."/".$langs->trans("Services"), 'products', 'sall', 'P', 'searchleftp', img_object('','product'));
$arrayresult['searchintoproduct']=$langs->trans("SearchIntoProductsOrServices", $search_boxvalue);
}
/*if (((! empty($conf->product->enabled) && $user->rights->produit->lire) || (! empty($conf->service->enabled) && $user->rights->service->lire)) && ! empty($conf->fournisseur->enabled)
&& ! empty($conf->global->MAIN_SEARCHFORM_PRODUITSERVICE_SUPPLIER))
{
$langs->load("products");
$searchform.=printSearchForm(DOL_URL_ROOT.'/fourn/product/list.php', DOL_URL_ROOT.'/fourn/product/list.php', $langs->trans("SupplierRef"), 'products', 'srefsupplier', '', 'searchlefts', img_object('','product'));
}*/
if (! empty($conf->adherent->enabled) && ! empty($conf->global->MAIN_SEARCHFORM_ADHERENT) && $user->rights->adherent->lire)
{
$langs->load("members");
//$searchform.=printSearchForm(DOL_URL_ROOT.'/adherents/list.php', DOL_URL_ROOT.'/adherents/list.php', $langs->trans("Members"), 'member', 'sall', 'M', 'searchleftm', img_object('','user'));
$arrayresult['searchintomember']=$langs->trans("SearchIntoMembers", $search_boxvalue);
}
if (! empty($conf->projet->enabled) && ! empty($conf->global->MAIN_SEARCHFORM_PROJECT) && $user->rights->projet->lire)
{
$langs->load("projects");
//$searchform.=printSearchForm(DOL_URL_ROOT.'/projet/list.php', DOL_URL_ROOT.'/projet/list.php', $langs->trans("Projects"), 'project', 'search_all', 'Q', 'searchleftproj', img_object('','projectpub'));
$arrayresult['searchintoprojects']=$langs->trans("SearchIntoProjects", $search_boxvalue);
}
// Execute hook printSearchForm
$parameters=array();
$reshook=$hookmanager->executeHooks('printSearchForm',$parameters); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
{
$searchform.=$hookmanager->resPrint;
}
else $searchform=$hookmanager->resPrint;
print json_encode($arrayresult); print json_encode($arrayresult);
if (is_object($db)) $db->close(); if (is_object($db)) $db->close();

View File

@ -4501,7 +4501,7 @@ class Form
/** /**
* Return a HTML select string, built from an array of key+value but content returned into select come from an Ajax call of an URL. * Return a HTML select string, built from an array of key+value but content returned into select come from an Ajax call of an URL.
* Note: Do not apply langs->trans function on returned content, content may be entity encoded twice. * Note: Do not apply langs->trans function on returned content of Ajax service, content may be entity encoded twice.
* *
* @param string $htmlname Name of html select area * @param string $htmlname Name of html select area
* @param string $url Url * @param string $url Url
@ -4534,9 +4534,14 @@ class Form
}; };
}, },
results: function (remoteData, pageNumber, query) { results: function (remoteData, pageNumber, query) {
console.log(remoteData); //console.log(remoteData);
return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false} result = []
//return {results:[remoteData], more:false} $.each( remoteData, function( key, value ) {
result.push({id: key, text: value});
});
//console.log(result);
//return {results:[{id:\'none\', text:\'aa\'}, {id:\'rrr\', text:\'Red\'},{id:\'bbb\', text:\'Search a into projects\'}], more:false}
return {results: result, more:false}
}, },
/*processResults: function (data, page) { /*processResults: function (data, page) {
// parse the results into the format expected by Select2. // parse the results into the format expected by Select2.

View File

@ -752,4 +752,8 @@ ShortSaturday=S
ShortSunday=S ShortSunday=S
SelectMailModel=Select email template SelectMailModel=Select email template
SetRef=Set ref SetRef=Set ref
SearchIntoProject=Search %s into projects SearchIntoThirdparties=Search %s into thirdparties
SearchIntoContacts=Search %s into contacts
SearchIntoMembers=Search %s into members
SearchIntoProductsOrServices=Search %s into products or services
SearchIntoProjects=Search %s into projects

View File

@ -1606,7 +1606,7 @@ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $me
if (! empty($conf->projet->enabled) && ! empty($conf->global->MAIN_SEARCHFORM_PROJECT) && $user->rights->projet->lire) if (! empty($conf->projet->enabled) && ! empty($conf->global->MAIN_SEARCHFORM_PROJECT) && $user->rights->projet->lire)
{ {
$langs->load("members"); $langs->load("projects");
$searchform.=printSearchForm(DOL_URL_ROOT.'/projet/list.php', DOL_URL_ROOT.'/projet/list.php', $langs->trans("Projects"), 'project', 'search_all', 'Q', 'searchleftproj', img_object('','projectpub')); $searchform.=printSearchForm(DOL_URL_ROOT.'/projet/list.php', DOL_URL_ROOT.'/projet/list.php', $langs->trans("Projects"), 'project', 'search_all', 'Q', 'searchleftproj', img_object('','projectpub'));
} }